/* ── Variables — Tema oscuro (default) ─────────────── */
:root {
    --bg:          #0b1628;
    --surface:     #122039;
    --surface2:    #1a2d4a;
    --surface3:    #213659;
    --border:      #2a4166;
    --border-light:#304e7a;

    --blue:        #2b7fff;
    --blue-dim:    #1d6eea;
    --blue-bg:     rgba(43,127,255,.13);

    --amber:       #f59e0b;
    --amber-bg:    rgba(245,158,11,.12);

    --green:       #22c55e;
    --green-bg:    rgba(34,197,94,.12);

    --teal:        #14b8a6;
    --teal-bg:     rgba(20,184,166,.12);

    --red:         #ef4444;
    --red-bg:      rgba(239,68,68,.12);

    --slate:       #7c9cbf;
    --slate-bg:    rgba(124,156,191,.1);

    --text:        #d4e3f7;
    --text-dim:    #8aaed4;
    --muted:       #5a7fa8;
    --subtle:      #3a5878;

    --radius:      10px;
    --radius-sm:   7px;
    --radius-xs:   4px;
    --shadow:      0 8px 32px rgba(0,0,0,.5);
    --shadow-sm:   0 2px 10px rgba(0,0,0,.3);

    --sidebar-w:   248px;
    --topbar-h:    56px;
    --transition:  .18s ease;
}

/* ── Tema claro ────────────────────────────────────── */
[data-theme="light"] {
    --bg:          #eef3fb;
    --surface:     #ffffff;
    --surface2:    #f0f5ff;
    --surface3:    #e2ecff;
    --border:      #c8d9f0;
    --border-light:#b0c8e8;

    --blue:        #1d6eea;
    --blue-dim:    #1558c8;
    --blue-bg:     rgba(29,110,234,.1);

    --amber:       #d97706;
    --amber-bg:    rgba(217,119,6,.1);

    --green:       #16a34a;
    --green-bg:    rgba(22,163,74,.1);

    --teal:        #0d9488;
    --teal-bg:     rgba(13,148,136,.1);

    --red:         #dc2626;
    --red-bg:      rgba(220,38,38,.1);

    --slate:       #4a6fa5;
    --slate-bg:    rgba(74,111,165,.1);

    --text:        #1a2d4a;
    --text-dim:    #2d4a6e;
    --muted:       #5a7fa8;
    --subtle:      #94aec8;

    --shadow:      0 8px 32px rgba(0,0,0,.12);
    --shadow-sm:   0 2px 10px rgba(0,0,0,.08);
}

/* ── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    display: flex;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Sidebar overlay (móvil) ───────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 90;
    backdrop-filter: blur(2px);
}

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition), background var(--transition), border-color var(--transition);
}
.sidebar-logo {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 18px; border-bottom: 1px solid var(--border);
}
.logo-mark {
    width: 38px; height: 38px; flex-shrink: 0;
    background: var(--blue); border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; box-shadow: 0 4px 14px rgba(43,127,255,.4);
}
.logo-name { font-size: 15px; font-weight: 700; color: var(--text); letter-spacing: -.3px; }
.logo-sub  { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }

.sidebar-nav { flex: 1; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--muted); font-size: 13.5px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
    border: none; background: none; width: 100%; text-align: left;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface2); color: var(--text-dim); }
.nav-item.active {
    background: var(--blue-bg); color: var(--blue);
    border-left: 3px solid var(--blue); padding-left: 9px;
}

.sidebar-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 8px;
}
.rate-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.rate-pill {
    font-size: 11px; font-weight: 700; padding: 3px 10px; border-radius: 20px;
}
.rate-in  { background: var(--green-bg); color: var(--green); }
.rate-out { background: var(--amber-bg); color: var(--amber); }

/* ── Theme toggle ──────────────────────────────────── */
.theme-toggle {
    display: flex; align-items: center; gap: 8px;
    width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--muted); font-size: 12px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
}
.theme-toggle:hover { border-color: var(--blue); color: var(--blue); }
.theme-toggle svg { width: 15px; height: 15px; flex-shrink: 0; }
.theme-toggle-label { flex: 1; text-align: left; }

/* ── Hamburger ─────────────────────────────────────── */
.hamburger {
    display: none;
    flex-direction: column; justify-content: center; gap: 5px;
    width: 38px; height: 38px;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: var(--radius-sm); cursor: pointer; padding: 9px;
    flex-shrink: 0;
}
.hamburger span {
    display: block; width: 100%; height: 2px;
    background: var(--text-dim); border-radius: 2px;
    transition: all var(--transition);
}

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

/* ── Topbar ────────────────────────────────────────── */
.topbar {
    height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
    padding: 0 24px; border-bottom: 1px solid var(--border);
    background: var(--surface); position: sticky; top: 0; z-index: 50;
    transition: background var(--transition), border-color var(--transition);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; color: var(--blue); }
.topbar-title { font-size: 15px; font-weight: 700; color: var(--text); }
.topbar-date  { font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ── Content ───────────────────────────────────────── */
.content { padding: 24px; flex: 1; max-width: 1400px; width: 100%; }

/* ── Sections ──────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; }
.section-header { margin-bottom: 22px; }
.section-header-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.section-title { font-size: 20px; font-weight: 700; letter-spacing: -.4px; }
.section-desc  { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ── Stat Cards ────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 14px; margin-bottom: 22px;
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px 18px 16px;
    position: relative; overflow: hidden;
    transition: background var(--transition), border-color var(--transition);
}
.stat-card::before {
    content: ''; position: absolute;
    top: 0; left: 0; right: 0; height: 3px;
    border-radius: var(--radius) var(--radius) 0 0;
}
.stat-card.blue::before  { background: var(--blue); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.green::before { background: var(--green); }
.stat-card.teal::before  { background: var(--teal); }
.stat-card.red::before   { background: var(--red); }
.stat-card.slate::before { background: var(--slate); }

.stat-icon { margin-bottom: 10px; }
.stat-card.blue  .stat-icon { color: var(--blue); }
.stat-card.amber .stat-icon { color: var(--amber); }
.stat-card.green .stat-icon { color: var(--green); }
.stat-card.teal  .stat-icon { color: var(--teal); }
.stat-card.red   .stat-icon { color: var(--red); }
.stat-card.slate .stat-icon { color: var(--slate); }

.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat-card.blue  .stat-value { color: var(--blue); }
.stat-card.amber .stat-value { color: var(--amber); }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.teal  .stat-value { color: var(--teal); }
.stat-card.red   .stat-value { color: var(--red); }
.stat-card.slate .stat-value { color: var(--text); }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ── Two-col ───────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ── Card ──────────────────────────────────────────── */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; margin-bottom: 18px;
    transition: background var(--transition), border-color var(--transition);
}
.card-header {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
    padding: 13px 18px; border-bottom: 1px solid var(--border);
    background: var(--surface2);
}
.card-title { font-size: 13.5px; font-weight: 700; letter-spacing: -.2px; }
.card-body  { padding: 20px; }

/* ── Tables ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: var(--surface2); }
th {
    padding: 10px 14px; text-align: left;
    font-size: 10.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
    white-space: nowrap;
}
td { padding: 11px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
tr:hover td { background: var(--blue-bg); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── Badges ────────────────────────────────────────── */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 9px; border-radius: 20px;
    font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-green  { background: var(--green-bg); color: var(--green); }
.badge-red    { background: var(--red-bg); color: var(--red); }
.badge-yellow { background: var(--amber-bg); color: var(--amber); }
.badge-blue   { background: var(--blue-bg); color: var(--blue); }
.badge-muted  { background: var(--slate-bg); color: var(--slate); }

/* ── Interest badges ───────────────────────────────── */
.interest-badge {
    display: inline-flex; align-items: center;
    font-size: 11.5px; font-weight: 700;
    padding: 3px 9px; border-radius: var(--radius-xs);
}
.interest-5  { background: var(--green-bg); color: var(--green); }
.interest-10 { background: var(--amber-bg); color: var(--amber); }

/* ── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer;
    border: none; transition: all var(--transition);
    white-space: nowrap; text-decoration: none;
}
.btn-primary {
    background: var(--blue); color: #fff;
    box-shadow: 0 4px 14px rgba(43,127,255,.3);
}
.btn-primary:hover { background: var(--blue-dim); }
.btn-ghost {
    background: transparent; color: var(--text-dim);
    border: 1px solid var(--border);
}
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.2); }
.btn-sm   { padding: 5px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Forms ─────────────────────────────────────────── */
.form-grid   { display: grid; gap: 15px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-group  { display: flex; flex-direction: column; gap: 5px; }
.form-label  { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.form-control {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: 10px 12px; font-size: 14px;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
    outline: none; width: 100%;
}
.form-control:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(43,127,255,.15); }
.form-control::placeholder { color: var(--subtle); }
select.form-control { cursor: pointer; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.filter-select { width: auto; font-size: 12px; padding: 7px 10px; }

/* ── Searchable dropdown ───────────────────────────── */
.dd-trigger {
    text-align: left; cursor: pointer;
    display: flex; justify-content: space-between; align-items: center;
    color: var(--text);
}
.dd-placeholder { color: var(--subtle); }
.dd-panel {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0;
    z-index: 200;
    background: var(--surface2); border: 1px solid var(--blue);
    border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.dd-search-wrap { padding: 8px; border-bottom: 1px solid var(--border); }
.dd-list { max-height: 220px; overflow-y: auto; }
.dd-opt { padding: 10px 14px; cursor: pointer; transition: background var(--transition); border-bottom: 1px solid var(--border); }
.dd-opt:last-child { border-bottom: none; }
.dd-opt:hover { background: var(--surface3); }
.dd-opt-name  { font-weight: 600; font-size: 13.5px; color: var(--text); }
.dd-opt-meta  { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.dd-opt-saldo { font-size: 12px; color: var(--amber); font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ── Search input ──────────────────────────────────── */
.search-input {
    background: var(--surface2); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius-sm);
    padding: 9px 12px; font-size: 13px; outline: none;
    flex: 1; max-width: 340px;
    transition: border-color var(--transition), background var(--transition);
}
.search-input:focus { border-color: var(--blue); }
.search-input::placeholder { color: var(--subtle); }

/* ── Modal ─────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.7);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    padding: 16px;
    /* Oculto por defecto */
    visibility: hidden; opacity: 0; pointer-events: none;
    transition: opacity .22s, visibility .22s;
}
.modal-overlay.open {
    visibility: visible; opacity: 1; pointer-events: auto;
}

.modal {
    background: var(--surface); border: 1px solid var(--border-light);
    border-radius: 14px; width: 100%; max-width: 540px;
    display: flex; flex-direction: column;
    max-height: calc(100dvh - 32px);
    box-shadow: var(--shadow);
    /* Animación de entrada — desktop */
    transform: translateY(24px) scale(.97);
    transition: transform .24s cubic-bezier(.22,1,.36,1),
                background var(--transition), border-color var(--transition);
}
.modal-lg { max-width: 620px; }
.modal-overlay.open .modal { transform: none; }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    background: var(--surface2); border-radius: 14px 14px 0 0;
    flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 700; }
.modal-body  { padding: 20px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-footer {
    padding: 14px 20px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap;
    background: var(--surface2); border-radius: 0 0 14px 14px;
    flex-shrink: 0;
}
.modal-close {
    background: none; border: none; color: var(--muted);
    cursor: pointer; font-size: 20px; padding: 2px 8px;
    border-radius: var(--radius-xs); transition: color var(--transition);
    line-height: 1; min-width: 32px; text-align: center;
}
.modal-close:hover { color: var(--text); }

/* ── Loan preview ──────────────────────────────────── */
.loan-preview {
    margin-top: 16px; background: var(--surface2);
    border-radius: 8px; padding: 14px;
    border: 1px solid var(--border); border-left: 3px solid var(--blue);
}
.total-row .detail-key { font-weight: 700; color: var(--text); }
.total-row .detail-val { font-size: 18px; color: var(--blue); }

/* ── Detail rows ───────────────────────────────────── */
.detail-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--muted); }
.detail-val { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Progress bar ──────────────────────────────────── */
.progress-bar { height: 7px; background: var(--surface2); border-radius: 4px; overflow: hidden; margin-top: 2px; }
.progress-fill { height: 100%; background: var(--blue); border-radius: 4px; transition: width .45s ease; }
.progress-fill.warn { background: var(--amber); }
.progress-fill.ok   { background: var(--green); }

/* ── Toast ─────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--surface); border: 1px solid var(--border-light);
    border-radius: var(--radius-sm); padding: 12px 16px;
    font-size: 13.5px; display: flex; align-items: center; gap: 10px;
    box-shadow: var(--shadow); min-width: 240px; max-width: 340px;
    animation: slideIn .22s ease; color: var(--text);
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.warn    { border-left: 3px solid var(--amber); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Empty state ───────────────────────────────────── */
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 36px; height: 36px; margin: 0 auto 10px; display: block; opacity: .35; }

/* ── Confirm dialog ────────────────────────────────── */
.confirm-icon {
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--red-bg); border: 2px solid rgba(239,68,68,.25);
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 4px; font-size: 24px;
    flex-shrink: 0;
}
.confirm-title {
    font-size: 17px; font-weight: 700; color: var(--text);
    margin-bottom: 8px; letter-spacing: -.3px;
}
.confirm-msg {
    font-size: 13.5px; color: var(--muted); line-height: 1.6;
}
.confirm-msg strong { color: var(--text); font-weight: 600; }
.confirm-warning {
    margin-top: 12px; padding: 10px 14px;
    background: var(--amber-bg); border: 1px solid rgba(245,158,11,.25);
    border-radius: var(--radius-sm); font-size: 12.5px; color: var(--amber);
    text-align: left;
}

/* ── Columnas ocultables en tabla ──────────────────── */
/* Uso: class="col-md" se oculta en tablet, "col-sm" en móvil */
.col-sm, .col-md { }   /* visible por defecto */

/* ══ RESPONSIVE ══════════════════════════════════════ */

/* Tablet ancha (≤ 1024px) */
@media (max-width: 1024px) {
    .col-md { display: none; }   /* Oculta columnas de tabla en tablet */
}

/* Tablet (≤ 900px) */
@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Móvil/Tablet (≤ 768px) */
@media (max-width: 768px) {
    /* ── Sidebar ── */
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
    .sidebar-overlay.open { display: block; }

    /* ── Layout ── */
    .main { margin-left: 0; }
    .hamburger { display: flex; }
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-date { display: none; }
    .content { padding: 10px; }

    /* ── Grids ── */
    .form-grid-2 { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .stat-value { font-size: 20px; }

    /* ── Sección header ── */
    .section-header-row { flex-direction: column; gap: 10px; }
    .section-header-row > .btn { width: 100%; justify-content: center; }

    /* ── Filtros / card-header ── */
    .card-header { flex-direction: column; align-items: stretch; gap: 8px; }
    .search-input { max-width: 100%; width: 100%; }
    .filter-select { width: 100%; }

    /* ── Columnas de tabla ocultas en móvil ── */
    .col-sm { display: none; }

    /* ── Botones en tabla ── */
    .btn-sm { padding: 7px 10px; font-size: 12px; }

    /* ── Modal: bottom sheet ── */
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
        /* El overlay mismo no hace scroll; el modal-body sí */
    }
    .modal {
        max-width: 100%;
        width: 100%;
        border-radius: 20px 20px 0 0;
        max-height: 92dvh;
        /* Animar desde abajo */
        transform: translateY(100%);
    }
    .modal-overlay.open .modal { transform: translateY(0); }
    .modal-header { border-radius: 20px 20px 0 0; padding: 18px 16px 14px; }
    .modal-footer { border-radius: 0; flex-direction: column-reverse; gap: 8px; }
    .modal-footer .btn { width: 100%; justify-content: center; }

    /* ── Toasts ── */
    .toast-container { bottom: 10px; right: 10px; left: 10px; }
    .toast { min-width: unset; max-width: 100%; font-size: 13px; }
}

/* Móvil (≤ 480px) */
@media (max-width: 480px) {
    .content { padding: 8px; }
    .section-title { font-size: 17px; }
    .stat-grid { grid-template-columns: 1fr 1fr; }
    td, th { padding: 9px 10px; }
}

/* Móvil muy pequeño (≤ 360px) */
@media (max-width: 360px) {
    .stat-grid { grid-template-columns: 1fr; }
}
