/* =========================================
   JournalByTTS — base.css
   Reset, body, typography, global variables,
   scrollbar, animations, utilities
   ========================================= */

:root {
    /* ── Legacy variable bridge → brand tokens ── */
    --vermillion-h: var(--accent-hover);
    --gold:         var(--warn);
    --gold-light:   var(--warn);
    --jade:         var(--pos);
    --jade-light:   var(--pos-soft);
    --crimson-light:var(--neg-soft);
    --text:         var(--ink);
    --storm:        var(--border-strong);
    --storm-light:  var(--bg-hover);
    --border-dark:  var(--border-strong);
    --shadow:       var(--shadow-md);
    --shadow-deep:  var(--shadow-lg);
    --surface:      var(--surface);
    /* Old background aliases */
    --washi:        var(--bg-sunk);
    --cream:        var(--surface);
    --ink-old:      var(--bg-elev);
}

/* ─── RESET Y BASE ─── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg);
    color: var(--ink);
    margin: 0; padding: 0;
    min-height: 100vh;
    display: flex;
    font-size: var(--text-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.005em;
}

img, video, canvas, svg, table {
    max-width: 100%;
}

h1, h2, h3, h4 {
    font-family: var(--font-sans);
    color: var(--ink);
    margin-top: 0;
    font-weight: 600;
    letter-spacing: -0.01em;
}
h1 { font-size: var(--text-4xl); font-weight: 400; letter-spacing: -0.02em; }
h2 { font-size: var(--text-lg); font-weight: 600; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ─── SCROLLBAR PERSONALIZADA ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--washi); }
::-webkit-scrollbar-thumb { background: var(--ink-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bamboo-dark, #b8a68a); }
::-webkit-scrollbar-thumb { border-radius: 10px; }

/* ─── ANIMACIONES ─── */
.fade-in { animation: fadeIn 0.25s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.slide-in { animation: slideIn 0.25s ease-out; }
@keyframes slideIn {
    from { transform: translateY(-12px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}

/* Floating alert animation */
.slide-in { animation: slideInRight 0.3s ease; }
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);   opacity: 1; }
}

/* Popover / dropdown menu entrance animation */
@keyframes popoverIn {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ─── UTILIDADES ─── */
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.text-left    { text-align: left; }
.text-muted   { color: var(--ink-3) !important; }
.d-none       { display: none !important; }
.d-block      { display: block !important; }
.d-flex       { display: flex !important; }
.flex-column  { flex-direction: column !important; }
.justify-content-between { justify-content: space-between !important; }
.align-items-center { align-items: center !important; }
.w-100        { width: 100% !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }
.ml-auto { margin-left: auto !important; }
.py-4 { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
.p-3  { padding: 1rem !important; }
.is-invalid { border-color: var(--accent) !important; }
.text-right  { text-align: right !important; }
.text-center { text-align: center !important; }
.fw-600      { font-weight: 600; }

/* Positive / negative amounts */
.positive-value  { color: var(--pos); }
.negative-value  { color: var(--neg); }
.kpi-profit-negative { color: var(--neg) !important; }
.kpi-profit-positive { color: var(--pos) !important; }
.profit-positive { color: #34d399; font-weight: 600; }
.profit-negative { color: #f87171; font-weight: 600; }

/* ─── TOOLTIP INFORMATIVOS ─── */
.info-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
    margin-left: 6px;
}
.info-tooltip i {
    font-size: 0.72rem;
    color: var(--ink-3);
    transition: color 0.15s;
}
.info-tooltip:hover i { color: var(--accent); }
.info-tooltip .tooltip-text {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-elev);
    color: var(--ink-2);
    font-size: 0.75rem;
    line-height: 1.5;
    padding: 8px 12px;
    border-radius: 10px;
    width: 220px;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    box-shadow: 0 4px 14px var(--shadow-deep);
    z-index: 9999;
    pointer-events: none;
    font-family: var(--font-sans);
    font-weight: 400;
}
.info-tooltip .tooltip-text::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--bg-elev);
}
.info-tooltip:hover .tooltip-text { display: block; }

/* Cards que contienen un info-tooltip: desactivar overflow:hidden para que el
   popover no se corte al salir de los bordes (mismo motivo que .kpi-card). */
.card:has(.info-tooltip) { overflow: visible; }

/* ─── AVATAR CON CÁMARA (perfil + academia) ─── */
.profile-avatar-wrap {
    position: relative;
    width: 96px;
    height: 96px;
    margin: 0 auto;
    flex-shrink: 0;
}
.profile-avatar-wrap.avatar-sm {
    width: 72px;
    height: 72px;
}
.profile-avatar-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--accent);
    display: block;
}
.profile-avatar-placeholder {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--bg-elev);
    color: var(--ink-3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-serif);
    font-size: 2.2rem;
    font-weight: 600;
    border: 3px solid var(--accent);
}
.profile-avatar-wrap.avatar-sm .profile-avatar-placeholder {
    font-size: 1.6rem;
}
.profile-avatar-edit {
    position: absolute;
    bottom: 0; right: 0;
    width: 28px; height: 28px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    cursor: pointer;
    border: 2px solid var(--cream);
    transition: background 0.2s;
    z-index: 2;
}
.profile-avatar-edit:hover { background: var(--accent-hover); }

/* ─── PAGE TITLE ─── */
.page-title { font-family: var(--font-serif); font-style: italic; font-size: var(--text-4xl); font-weight: 400; letter-spacing: -0.02em; color: var(--ink); margin: 0; }
.page-sub { color: var(--ink-3); font-size: var(--text-sm); margin: 6px 0 0; }
.page-subtitle { color: var(--ink-3); font-size: 0.82rem; margin: 0; margin-top: 4px; }

/* ─── APP FOOTER ─── */
.app-footer {
    padding: 12px 36px;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.app-footer-text  { font-size: 0.72rem; color: var(--ink-3); }
.app-footer-sep   { color: var(--border); font-size: 0.75rem; }
.app-footer-copy  { font-size: 0.72rem; color: var(--ink-3); }

/* ─── FORM CHECK ─── */
.form-check { display: flex; align-items: center; margin-bottom: 12px; gap: 8px; }
.form-check-input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ─── BOTÓN FLOTANTE DE HISTORIAL DE ACCIONES ─── */
.history-fab {
    position: fixed; bottom: 24px; right: 24px;
    width: 44px; height: 44px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    box-shadow: 0 4px 16px rgba(232,92,74,0.4);
    z-index: 1000; transition: transform 0.2s, box-shadow 0.2s;
}
.history-fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(232,92,74,0.5); }

.history-popup {
    position: fixed; bottom: 78px; right: 24px;
    width: 320px; max-height: 420px;
    background: var(--bg-elev);
    border: 1px solid rgba(120,144,176,0.15);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
    z-index: 1000; display: none; flex-direction: column; overflow: hidden;
}
.history-popup.open { display: flex; }
.history-popup-header {
    padding: 12px 16px; border-bottom: 1px solid rgba(120,144,176,0.08);
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(255,255,255,0.02);
}
.history-popup-title { font-size: 0.78rem; font-weight: 600; color: var(--ink-3); }
.history-popup-close { background: none; border: none; color: var(--ink-3); font-size: 1.2rem; cursor: pointer; line-height: 1; }
.history-popup-close:hover { color: var(--text); }
.history-popup-list { flex: 1; overflow-y: auto; }
.history-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid rgba(120,144,176,0.06);
}
.history-item:last-child { border-bottom: none; }
.history-item-icon { width: 28px; height: 28px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; flex-shrink: 0; }
.history-icon-create { background: rgba(18,184,120,0.12); color: #34d399; }
.history-icon-delete { background: rgba(232,92,74,0.12); color: #f87171; }
.history-icon-update { background: rgba(120,144,176,0.12); color: var(--ink-3); }
.history-item-body { flex: 1; min-width: 0; }
.history-item-desc { font-size: 0.75rem; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-time { font-size: 0.65rem; color: var(--ink-3); margin-top: 2px; }
.history-undo-btn { font-size: 0.68rem; padding: 3px 9px; border-radius: 6px; border: 1px solid rgba(232,92,74,0.25); background: rgba(232,92,74,0.08); color: var(--accent); cursor: pointer; white-space: nowrap; }
.history-undo-btn:hover { background: rgba(232,92,74,0.16); }
.history-loading, .history-empty { padding: 16px; text-align: center; font-size: 0.8rem; color: var(--ink-3); }

@media (max-width: 480px) {
    .history-popup { width: calc(100vw - 24px); right: 12px; }
    .history-fab   { bottom: 18px; right: 18px; }
}

/* ─── THEME TOGGLE BUTTON ─── */
.theme-toggle-btn {
    background: none;
    border: 1px solid rgba(120,144,176,0.2);
    border-radius: 8px;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--ink-3);
    transition: background 0.18s, color 0.18s, border-color 0.18s;
    flex-shrink: 0;
    font-size: 0.85rem;
}
.theme-toggle-btn:hover {
    background: rgba(120,144,176,0.1);
    color: var(--text);
    border-color: rgba(120,144,176,0.35);
}
.theme-toggle-btn i { line-height: 1; }
/* Default (dark): show moon, hide sun */
.theme-icon-light { display: none; }
.theme-icon-dark  { display: inline; }
html[data-theme="dark"]  .theme-icon-light { display: none; }
html[data-theme="dark"]  .theme-icon-dark  { display: inline; }
/* Light: show sun, hide moon */
html[data-theme="light"] .theme-icon-light { display: inline; }
html[data-theme="light"] .theme-icon-dark  { display: none; }

/* ─── LIGHT THEME — override dark values ─── */
html[data-theme="light"] {
    --ink:         #1a2a3a;
    --ink-3:   #ffffff;
    --washi:       #f2f5fa;
    --cream:       #f8faff;
    --text:        #1a2a3a;
    --ink-3:    #445566;
    --ink-3:       #7890b0;
    --border:      rgba(30,60,100,0.12);
    --border-dark: rgba(30,60,100,0.22);
    --surface:     #ffffff;
    --shadow:      rgba(0,0,0,0.08);
    --shadow-deep: rgba(0,0,0,0.15);
}
html[data-theme="light"] body {
    background: var(--washi);
    color: var(--text);
}
/* Positive / negative amounts */
html[data-theme="light"] .positive { color: #059669; }
html[data-theme="light"] .negative { color: #dc2626; }
/* History popup */
html[data-theme="light"] .history-popup {
    background: #ffffff;
    border-color: rgba(30,60,100,0.12);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
/* Activity list */
html[data-theme="light"] .actividad-item:hover { background: rgba(0,0,0,0.02); }
html[data-theme="light"] .actividad-sep { border-color: rgba(30,60,100,0.06); }

/* ─── SECTION-HEADER ─── */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--ink-2);
}
.section-header h2 { margin: 0; font-size: 1.05rem; }
.section-header { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px solid var(--ink-2); }

/* ─── BOTONES DE ACCIÓN EN TABLA ─── */
.action-btns { display: flex; gap: 6px; }
.table tr.account-row { cursor: pointer; }

/* ─── ADMIN NOTIFICATIONS ─── */
.admin-notif-dot {
    display: inline-block;
    width: 7px; height: 7px;
    background: var(--accent);
    border-radius: 50%;
    margin-left: 4px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(232,92,74,0.25);
    animation: notifPulse 2s infinite;
}
@keyframes notifPulse {
    0%, 100% { box-shadow: 0 0 0 2px rgba(232,92,74,0.25); }
    50%       { box-shadow: 0 0 0 4px rgba(232,92,74,0.10); }
}

.admin-notif-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(102,153,204,0.08), rgba(232,92,74,0.06));
    border: 1px solid rgba(102,153,204,0.2);
    border-radius: 12px;
    padding: 12px 18px;
    margin-bottom: 20px;
    transition: opacity 0.3s, transform 0.3s;
    flex-wrap: wrap;
    gap: 12px;
}
.admin-notif-items {
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: wrap;
}
.admin-notif-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.83rem;
    color: var(--ink);
    padding: 0 16px;
}
.admin-notif-item:first-child { padding-left: 0; }
.admin-notif-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
}
.admin-notif-dismiss {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--ink-3);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.14s, color 0.14s;
}
.admin-notif-dismiss:hover { background: var(--washi); color: var(--ink); }

/* Toast notifications */
.admin-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 0.84rem;
    font-weight: 500;
    min-width: 280px;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(13,20,36,0.18);
    opacity: 0;
    transform: translateX(16px);
    transition: opacity 0.28s ease, transform 0.28s ease;
}
.admin-toast.visible {
    opacity: 1;
    transform: translateX(0);
}
.admin-toast-success {
    background: var(--bg-elev);
    color: #e8f0fa;
    border: 1px solid rgba(120,144,176,0.2);
}
.admin-toast-error {
    background: #4a1515;
    color: #fdd;
    border: 1px solid rgba(232,92,74,0.3);
}

/* Status badges (shared admin use) */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}
.status-approved {
    background: rgba(18,184,120,0.1);
    color: var(--jade);
    border: 1px solid rgba(18,184,120,0.25);
}
.status-rejected {
    background: rgba(232,92,74,0.1);
    color: var(--accent);
    border: 1px solid rgba(232,92,74,0.2);
}
.status-pending {
    background: rgba(240,168,68,0.12);
    color: #b07800;
    border: 1px solid rgba(240,168,68,0.3);
}

/* Beta pending badge */
.beta-pending-badge {
    background: var(--accent);
    color: #fff;
    font-size: 0.76rem;
    padding: 4px 12px;
    border-radius: 50px;
}
.beta-link-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--washi);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 8px 4px 10px;
    max-width: 240px;
}
.beta-link-text {
    font-size: 0.7rem;
    color: var(--ink-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    cursor: text;
    user-select: all;
}
.beta-copy-btn {
    border: none;
    background: transparent;
    color: var(--ink-3);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.78rem;
    flex-shrink: 0;
    transition: color 0.2s;
}
.beta-copy-btn:hover { color: var(--ink); }
.btn-approve-beta {
    background: rgba(18,184,120,0.1);
    color: var(--jade);
    border: 1px solid rgba(18,184,120,0.3);
}
.btn-approve-beta:hover { background: rgba(18,184,120,0.18); }
.beta-row {
    transition: opacity 0.5s ease, transform 0.5s ease, max-height 0.5s ease;
    max-height: 200px;
    overflow: hidden;
}
.beta-row-exit {
    opacity: 0;
    transform: translateX(20px);
    max-height: 0;
}

/* ─── jb component canvas reset ─── */
.jb {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  font-size: var(--text-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}
.jb *, .jb *::before, .jb *::after { box-sizing: border-box; }
.jb h1,.jb h2,.jb h3,.jb h4,.jb p { margin: 0; }
.jb button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
.jb input { font-family: inherit; color: inherit; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1, "ss01" 1; letter-spacing: -0.01em; }
.serif { font-family: var(--font-serif); font-style: italic; letter-spacing: -0.01em; }

/* Divider */
.divider { height: 1px; background: var(--divider); margin: 24px 0; }
.label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-3); font-weight: 600; }

/* Sparkline */
.spark { width: 100%; height: 28px; }
.spark path.line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.spark path.area { fill: var(--accent-soft); }

/* General-purpose toast notifications (used by Toast.js) */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 500;
    min-width: 300px;
    max-width: 450px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 280ms ease-out, transform 280ms ease-out;
    pointer-events: auto;
    z-index: 9999;
}

.toast--visible {
    opacity: 1;
    transform: translateY(0);
}

.toast--success {
    background: var(--bg-elev);
    color: var(--pos);
    border: 1px solid rgba(43, 170, 110, 0.25);
}

[data-theme="light"] .toast--success {
    background: var(--pos-soft);
    color: var(--pos);
    border-color: rgba(31, 138, 87, 0.2);
}

.toast--error,
.toast--danger {
    background: var(--bg-elev);
    color: var(--neg);
    border: 1px solid rgba(224, 62, 90, 0.25);
}

[data-theme="light"] .toast--error,
[data-theme="light"] .toast--danger {
    background: var(--neg-soft);
    color: var(--neg);
    border-color: rgba(184, 40, 68, 0.2);
}

.toast--warning {
    background: var(--bg-elev);
    color: var(--warn);
    border: 1px solid rgba(214, 154, 44, 0.25);
}

[data-theme="light"] .toast--warning {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: rgba(176, 122, 31, 0.15);
}

.toast--info {
    background: var(--bg-elev);
    color: var(--blue-500);
    border: 1px solid rgba(61, 125, 220, 0.25);
}

[data-theme="light"] .toast--info {
    background: rgba(61, 125, 220, 0.08);
    color: var(--blue-500);
    border-color: rgba(61, 125, 220, 0.15);
}
