/* ============================================================
   VAULT & VISTA — Design System
   Dark mode premium · Inter + JetBrains Mono
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap');

/* ---------- CSS Custom Properties (Design Tokens) ---------- */
:root {
    /* Surface scale */
    --bg:               #060e20;
    --surface-low:      #0b1326;
    --surface:          #131b2e;
    --surface-mid:      #171f33;
    --surface-high:     #222a3d;
    --surface-highest:  #2d3449;

    /* Text */
    --on-surface:       #dae2fd;
    --on-surface-dim:   #c2c6d6;
    --on-surface-muted: #8c909f;

    /* Borders */
    --border:           #1e2a3d;
    --border-focus:     #adc6ff;
    --border-variant:   #424754;

    /* Primary — Trust Blue */
    --primary:          #adc6ff;
    --primary-container:#4d8eff;
    --on-primary:       #002e6a;
    --primary-dim:      #005ac2;

    /* Secondary — Growth Emerald */
    --secondary:        #4edea3;
    --secondary-dim:    #00a572;
    --on-secondary:     #003824;

    /* Tertiary — Expense Coral */
    --tertiary:         #ffb2b7;
    --tertiary-dim:     #ff516a;
    --on-tertiary:      #67001b;

    /* Spacing */
    --sp-xs:  4px;
    --sp-sm:  8px;
    --sp-md:  16px;
    --sp-lg:  24px;
    --sp-xl:  32px;
    --sp-2xl: 48px;

    /* Radius */
    --r-sm:   6px;
    --r-md:   12px;
    --r-lg:   16px;
    --r-full: 9999px;

    /* Sidebar */
    --sidebar-w: 256px;

    /* Transitions */
    --t-fast:   150ms cubic-bezier(0.4,0,0.2,1);
    --t-normal: 250ms cubic-bezier(0.4,0,0.2,1);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg);
    color: var(--on-surface);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: opacity var(--t-fast); }
a:hover { opacity: 0.8; }

/* ---------- Typography ---------- */
.font-mono { font-family: 'JetBrains Mono', monospace; }

.text-display   { font-size: 48px; font-weight: 700; line-height: 56px; letter-spacing: -0.02em; }
.text-headline-lg { font-size: 32px; font-weight: 600; line-height: 40px; letter-spacing: -0.01em; }
.text-headline-md { font-size: 20px; font-weight: 600; line-height: 28px; }
.text-headline-sm { font-size: 16px; font-weight: 600; line-height: 24px; }
.text-body-lg   { font-size: 18px; font-weight: 400; line-height: 28px; }
.text-body-md   { font-size: 16px; font-weight: 400; line-height: 24px; }
.text-body-sm   { font-size: 14px; font-weight: 400; line-height: 20px; }
.text-label     { font-size: 12px; font-weight: 600; line-height: 16px; letter-spacing: 0.05em; text-transform: uppercase; }
.text-data      { font-family: 'JetBrains Mono', monospace; font-size: 14px; font-weight: 500; line-height: 20px; }

.text-muted     { color: var(--on-surface-muted); }
.text-dim       { color: var(--on-surface-dim); }
.text-primary   { color: var(--primary); }
.text-secondary { color: var(--secondary); }
.text-tertiary  { color: var(--tertiary); }
.text-success   { color: var(--secondary); }
.text-danger    { color: var(--tertiary); }

/* ---------- Layout ---------- */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface-low);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: var(--sp-lg) var(--sp-md);
    gap: var(--sp-sm);
    z-index: 100;
    overflow-y: auto;
    transition: transform var(--t-normal);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-sm) var(--sp-xl);
}

.sidebar-brand-icon {
    width: 40px; height: 40px;
    background: var(--primary-container);
    border-radius: var(--r-md);
    display: flex; align-items: center; justify-content: center;
    color: var(--on-primary);
    flex-shrink: 0;
}

.sidebar-brand-text h1 {
    font-size: 16px; font-weight: 700;
    color: var(--on-surface);
    line-height: 1.2;
}

.sidebar-brand-text p {
    font-size: 11px;
    color: var(--on-surface-muted);
    letter-spacing: 0.03em;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--on-surface-muted);
    padding: var(--sp-md) var(--sp-sm) var(--sp-xs);
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: 10px var(--sp-sm);
    border-radius: var(--r-md);
    color: var(--on-surface-dim);
    font-size: 14px;
    font-weight: 500;
    transition: all var(--t-fast);
    cursor: pointer;
    border: 1px solid transparent;
}

.sidebar-link:hover {
    background: var(--surface-high);
    color: var(--on-surface);
    border-color: var(--border);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--surface-high);
    color: var(--primary);
    border-color: var(--border);
}

.sidebar-link .material-symbols-outlined {
    font-size: 20px;
    font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
    flex-shrink: 0;
}

.sidebar-link.active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.sidebar-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    background: var(--primary-container);
    color: var(--on-primary);
    padding: 2px 8px;
    border-radius: var(--r-full);
}

.sidebar-footer {
    padding-top: var(--sp-lg);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: var(--sp-sm);
    border-radius: var(--r-md);
}

.sidebar-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border-variant);
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-avatar-placeholder {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-container);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    color: var(--on-primary);
    flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: var(--on-surface); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 11px; color: var(--on-surface-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Main Content ---------- */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: 64px;
    background: var(--surface-low);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 var(--sp-xl);
    gap: var(--sp-lg);
}

.topbar-title { font-size: 18px; font-weight: 600; color: var(--on-surface); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--sp-sm); }

/* ---------- Page Content ---------- */
.page-content {
    padding: var(--sp-xl);
    flex: 1;
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-lg);
    transition: border-color var(--t-fast), transform var(--t-fast);
}

.card:hover { border-color: var(--border-variant); }

.card-hover:hover {
    transform: translateY(-2px);
    border-color: var(--border-focus);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-md);
}

.card-title { font-size: 14px; font-weight: 600; color: var(--on-surface-dim); letter-spacing: 0.05em; text-transform: uppercase; }

/* Stat cards */
.stat-card { display: flex; flex-direction: column; gap: var(--sp-xs); }
.stat-value { font-family: 'JetBrains Mono', monospace; font-size: 28px; font-weight: 700; color: var(--on-surface); letter-spacing: -0.02em; }
.stat-label { font-size: 13px; color: var(--on-surface-muted); }
.stat-trend { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.stat-trend.up   { color: var(--secondary); }
.stat-trend.down { color: var(--tertiary); }

/* ---------- Bento Grid ---------- */
.bento { display: grid; gap: var(--sp-lg); }
.bento-3 { grid-template-columns: repeat(3, 1fr); }
.bento-4 { grid-template-columns: repeat(4, 1fr); }
.bento-2-1 { grid-template-columns: 2fr 1fr; }
.bento-span-2 { grid-column: span 2; }
.bento-span-3 { grid-column: span 3; }

/* ---------- Tables ---------- */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
}

table.vault-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.vault-table thead {
    background: var(--surface-mid);
}

.vault-table th {
    padding: 10px var(--sp-md);
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--on-surface-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.vault-table td {
    padding: 12px var(--sp-md);
    border-bottom: 1px solid var(--border);
    color: var(--on-surface);
    vertical-align: middle;
}

.vault-table tbody tr:last-child td { border-bottom: none; }

.vault-table tbody tr {
    transition: background var(--t-fast);
}

.vault-table tbody tr:hover {
    background: var(--surface-high);
}

/* Numeric columns */
.vault-table td.num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    text-align: right;
    white-space: nowrap;
}

/* Group row */
.vault-table tr.group-row td {
    background: var(--surface-mid);
    font-weight: 700;
    font-size: 12px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--on-surface-dim);
    padding: 8px var(--sp-md);
    border-top: 1px solid var(--border);
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--r-full);
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-primary   { background: rgba(173,198,255,0.12); color: var(--primary); border: 1px solid rgba(173,198,255,0.2); }
.badge-success   { background: rgba(78,222,163,0.12); color: var(--secondary); border: 1px solid rgba(78,222,163,0.2); }
.badge-danger    { background: rgba(255,178,183,0.12); color: var(--tertiary); border: 1px solid rgba(255,178,183,0.2); }
.badge-neutral   { background: var(--surface-high); color: var(--on-surface-dim); border: 1px solid var(--border); }
.badge-warning   { background: rgba(255,193,7,0.12); color: #ffc107; border: 1px solid rgba(255,193,7,0.2); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-xs);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 18px;
    border-radius: var(--r-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--t-fast);
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}

.btn:hover { transform: translateY(-1px); text-decoration: none; }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
}
.btn-primary:hover { background: #c9d8ff; color: var(--on-primary); opacity: 1; }

.btn-secondary {
    background: transparent;
    color: var(--on-surface);
    border-color: var(--border-variant);
}
.btn-secondary:hover { background: var(--surface-high); border-color: var(--on-surface-muted); }

.btn-danger {
    background: transparent;
    color: var(--tertiary);
    border-color: var(--tertiary-dim);
}
.btn-danger:hover { background: rgba(255,81,106,0.1); }

.btn-ghost {
    background: transparent;
    color: var(--on-surface-dim);
    border-color: transparent;
    padding: 8px;
}
.btn-ghost:hover { background: var(--surface-high); color: var(--on-surface); }

.btn-sm { font-size: 12px; padding: 5px 12px; }
.btn-lg { font-size: 15px; padding: 12px 24px; }

.btn .material-symbols-outlined { font-size: 18px; }

/* ---------- Inputs ---------- */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--on-surface-muted); }

.form-control {
    background: var(--surface-mid);
    border: 1px solid var(--border-variant);
    border-radius: var(--r-sm);
    padding: 10px 14px;
    color: var(--on-surface);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
    width: 100%;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(173,198,255,0.15);
}

.form-control::placeholder { color: var(--on-surface-muted); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-control.font-mono { font-family: 'JetBrains Mono', monospace; }

/* Form grid */
.form-grid { display: grid; gap: var(--sp-md); }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---------- Segmented Control (agrupación) ---------- */
.segmented {
    display: inline-flex;
    background: var(--surface-mid);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 3px;
    gap: 2px;
}

.segmented-btn {
    font-size: 13px;
    font-weight: 500;
    padding: 6px 16px;
    border-radius: 9px;
    border: none;
    background: transparent;
    color: var(--on-surface-dim);
    cursor: pointer;
    transition: all var(--t-fast);
    font-family: inherit;
}

.segmented-btn.active {
    background: var(--surface-highest);
    color: var(--on-surface);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.segmented-btn:hover:not(.active) { color: var(--on-surface); }

/* ---------- Flash Messages ---------- */
.flash { display: flex; align-items: flex-start; gap: var(--sp-sm); padding: var(--sp-md) var(--sp-lg); border-radius: var(--r-md); margin-bottom: var(--sp-md); font-size: 14px; }
.flash-success { background: rgba(78,222,163,0.1); border: 1px solid rgba(78,222,163,0.25); color: var(--secondary); }
.flash-error   { background: rgba(255,81,106,0.1); border: 1px solid rgba(255,81,106,0.25); color: var(--tertiary); }
.flash-info    { background: rgba(173,198,255,0.1); border: 1px solid rgba(173,198,255,0.25); color: var(--primary); }

/* ---------- FIFO Table ---------- */
.fifo-table td.gain  { color: var(--secondary); font-family: 'JetBrains Mono', monospace; }
.fifo-table td.loss  { color: var(--tertiary); font-family: 'JetBrains Mono', monospace; }

/* ---------- Drive Browser ---------- */
.drive-file-item {
    display: flex;
    align-items: center;
    gap: var(--sp-sm);
    padding: var(--sp-sm) var(--sp-md);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--t-fast);
    background: var(--surface);
}

.drive-file-item:hover { border-color: var(--primary); background: var(--surface-high); }
.drive-file-item.selected { border-color: var(--primary); background: rgba(173,198,255,0.08); }

.drive-icon { font-size: 24px; color: var(--primary); flex-shrink: 0; }
.drive-file-name { font-size: 13px; font-weight: 500; color: var(--on-surface); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drive-file-meta { font-size: 11px; color: var(--on-surface-muted); }

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(6,14,32,0.8);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity var(--t-normal);
}

.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border-variant);
    border-radius: var(--r-lg);
    width: min(600px, calc(100vw - 32px));
    max-height: 80vh;
    overflow-y: auto;
    padding: var(--sp-xl);
    transform: translateY(16px);
    transition: transform var(--t-normal);
}

.modal-backdrop.open .modal { transform: translateY(0); }

.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-lg); }
.modal-title { font-size: 18px; font-weight: 700; }

/* ---------- Custom Scrollbar ---------- */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface-low); }
::-webkit-scrollbar-thumb { background: var(--border-variant); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--on-surface-muted); }

/* ---------- Utility ---------- */
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-sm  { gap: var(--sp-sm); }
.gap-md  { gap: var(--sp-md); }
.gap-lg  { gap: var(--sp-lg); }
.mt-sm   { margin-top: var(--sp-sm); }
.mt-md   { margin-top: var(--sp-md); }
.mt-lg   { margin-top: var(--sp-lg); }
.mb-md   { margin-bottom: var(--sp-md); }
.mb-lg   { margin-bottom: var(--sp-lg); }
.w-full  { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .bento-3, .bento-4 { grid-template-columns: 1fr; }
    .bento-2-1 { grid-template-columns: 1fr; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .page-content { padding: var(--sp-md); }
}

/* ---------- Animations ---------- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: fadeInUp var(--t-normal) both; }

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.skeleton {
    background: linear-gradient(90deg, var(--surface-high) 25%, var(--surface-highest) 50%, var(--surface-high) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--r-sm);
}

/* ---------- Login Page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image:
        radial-gradient(ellipse at 20% 20%, rgba(77,142,255,0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 80%, rgba(78,222,163,0.04) 0%, transparent 60%);
}

.login-card {
    width: min(420px, calc(100vw - 32px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-2xl);
    text-align: center;
    animation: fadeInUp 0.4s both;
}

.login-logo {
    width: 64px; height: 64px;
    background: var(--primary-container);
    border-radius: var(--r-lg);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto var(--sp-lg);
    font-size: 32px;
    color: var(--on-primary);
}

.btn-google {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-sm);
    padding: 14px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-variant);
    background: var(--surface-high);
    color: var(--on-surface);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all var(--t-fast);
    font-family: inherit;
    margin-top: var(--sp-lg);
}

.btn-google:hover {
    background: var(--surface-highest);
    border-color: var(--primary);
    color: var(--on-surface);
    text-decoration: none;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}

.google-icon {
    width: 20px; height: 20px;
    flex-shrink: 0;
}
