:root {
    --navy: #071A57;
    --blue: #103FD5;
    --sky: #67BAE4;
    --font: 'Poppins', sans-serif;
    --radius: 8px;
}

[data-theme="dark"] {
    --bg: #050f33;
    --surface: #071A57;
    --surface2: #0c2468;
    --border: rgba(103, 186, 228, 0.18);
    --border2: rgba(103, 186, 228, 0.08);
    --text: #f4f4f4;
    --text2: rgba(244, 244, 244, 0.7);
    --text3: rgba(244, 244, 244, 0.4);
    --inp-bg: rgba(255, 255, 255, 0.04);
    --inp-brd: rgba(103, 186, 228, 0.15);
    --inp-txt: #f4f4f4;
    --red: #f87171;
    --green: #4ade80;
    --amber: #fbbf24;
    --shadow: rgba(0, 0, 0, 0.35);
    --th-bg: rgba(103, 186, 228, 0.06);
    --th-bg-hover: rgba(103, 186, 228, 0.12);
}

[data-theme="light"] {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface2: #f1f5f9;
    --border: rgba(7, 26, 87, 0.12);
    --border2: rgba(7, 26, 87, 0.05);
    --text: #071A57;
    --text2: #4a5472;
    --text3: #8792b0;
    --inp-bg: #ffffff;
    --inp-brd: rgba(7, 26, 87, 0.18);
    --inp-txt: #071A57;
    --red: #d63c3c;
    --green: #0e9b58;
    --amber: #b07d1a;
    --shadow: rgba(7, 26, 87, 0.08);
    --th-bg: #f8fafc;
    --th-bg-hover: #e2e8f0;
}

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

html, body {
    height: 100vh;
    overflow: hidden;
    font-family: var(--font);
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    transition: background .3s, color .3s;
}

/* Grid Layout */
.app {
    display: grid;
    grid-template-rows: 56px 40px 1fr;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* ── BACKGROUND GLOWS ── */
.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.1;
    transition: opacity .3s;
}

[data-theme="light"] .glow {
    opacity: 0.03;
}

.glow-1 {
    top: -10%;
    right: 10%;
    width: 35vw;
    height: 35vw;
    background: var(--sky);
}

.glow-2 {
    bottom: -10%;
    left: 10%;
    width: 40vw;
    height: 40vw;
    background: var(--blue);
}

/* ── TOPBAR ── */
.topbar {
    background: linear-gradient(135deg, #071A57 0%, #103FD5 100%);
    border-bottom: 1px solid rgba(103,186,228,0.2);
    padding: 0 28px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}
.brand { display: flex; align-items: center; text-decoration: none; }
.logo-dark { display: block; }
.logo-light { display: none; }
[data-theme="light"] .logo-dark { display: none; }
[data-theme="light"] .logo-light { display: block; }
.topbar-title { font-size: 13px; font-weight: 500; color: rgba(255,255,255,0.6); margin-left: 12px; border-left: 1px solid rgba(103,186,228,0.25); padding-left: 16px; font-family: var(--font); }
.nav-links { display:flex; gap:6px; margin-left:auto; align-items:center; }
.nav-link { padding:5px 12px; border-radius:8px; border:1px solid rgba(103,186,228,0.3); background:transparent; color:rgba(255,255,255,0.7); font-size:11px; font-family: var(--font); font-weight:500; cursor:pointer; text-decoration:none; transition:all .15s; }
.nav-link:hover { background:rgba(103,186,228,0.15); color:#fff; border-color:rgba(103,186,228,0.6); }
.nav-link.active { background:rgba(103,186,228,0.2); color:#67BAE4; border-color:#67BAE4; }
.toggle-wrap { display:flex; align-items:center; gap:6px; color:rgba(255,255,255,.55); font-size:12px; margin-left:12px; font-family: var(--font); }
.toggle { width:40px; height:22px; background:rgba(255,255,255,.15); border:1px solid rgba(255,255,255,.2); border-radius:11px; cursor:pointer; position:relative; transition:background .25s; flex-shrink:0; }
.toggle::after { content:''; position:absolute; top:3px; left:3px; width:14px; height:14px; background:#fff; border-radius:50%; transition:transform .25s; }
[data-theme="light"] .toggle::after { transform:translateX(18px); }

[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.75); border-bottom: 1px solid rgba(7, 26, 87, 0.1); }
[data-theme="light"] .topbar-title { color: #555e7a; border-left-color: rgba(7, 26, 87, 0.15); }
[data-theme="light"] .nav-link { color: #555e7a; border-color: rgba(7, 26, 87, 0.2); }
[data-theme="light"] .nav-link:hover { background: rgba(7, 26, 87, 0.08); color: #071A57; border-color: rgba(7, 26, 87, 0.4); }
[data-theme="light"] .nav-link.active { background: rgba(16, 63, 213, 0.08); color: #103FD5; border-color: #103FD5; }
[data-theme="light"] .toggle-wrap { color: #555e7a; }
[data-theme="light"] .toggle { background: rgba(7, 26, 87, 0.15); border-color: rgba(7, 26, 87, 0.2); }

/* ── DATE TABS (BARRA AÑOS/MESES) ── */
.datetabs {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
}

.year-zone {
    display: flex;
    align-items: stretch;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}

.year-btn {
    padding: 0 16px;
    font-size: 11.5px;
    font-family: var(--font);
    font-weight: 600;
    color: var(--text3);
    cursor: pointer;
    border: none;
    background: none;
    border-right: 1px solid var(--border2);
    white-space: nowrap;
    display: flex;
    align-items: center;
    transition: color .15s, background .15s;
}

.year-btn:hover {
    color: var(--text2);
    background: rgba(103, 186, 228, 0.04);
}

.year-btn.active {
    color: #ffffff;
    background: rgba(16, 63, 213, 0.3);
    font-weight: 700;
}

[data-theme="light"] .year-btn.active {
    background: var(--blue);
    color: #ffffff;
}

.month-zone {
    display: flex;
    align-items: stretch;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
}

.month-zone::-webkit-scrollbar {
    display: none;
}

.month-btn {
    padding: 0 14px;
    font-size: 11px;
    font-family: var(--font);
    font-weight: 500;
    color: var(--text3);
    cursor: pointer;
    border: none;
    background: none;
    border-right: 1px solid var(--border2);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color .15s, background .15s;
}

.month-btn:hover {
    color: var(--text2);
    background: rgba(103, 186, 228, 0.04);
}

.month-btn.active {
    color: var(--sky);
    background: rgba(103, 186, 228, 0.08);
    font-weight: 600;
}

[data-theme="light"] .month-btn.active {
    color: var(--blue);
    background: rgba(16, 63, 213, 0.05);
}

.month-count {
    font-size: 9px;
    background: rgba(103, 186, 228, 0.15);
    color: var(--sky);
    padding: 1px 5px;
    border-radius: 8px;
    font-weight: 600;
}

[data-theme="light"] .month-count {
    background: rgba(16, 63, 213, 0.1);
    color: var(--blue);
}

/* Year separator inside month tabs (used in ALL-years mode) */
.month-year-sep {
    display: flex;
    align-items: center;
    padding: 0 10px 0 14px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--text3);
    opacity: 0.5;
    white-space: nowrap;
    border-right: 1px solid var(--border2);
    flex-shrink: 0;
}

.dtab-add {
    padding: 0 16px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text3);
    cursor: pointer;
    background: none;
    border: none;
    border-left: 1px solid var(--border);
    font-family: var(--font);
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    transition: color 0.15s, background 0.15s;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dtab-add:hover {
    color: var(--sky);
    background: rgba(103, 186, 228, 0.04);
}

[data-theme="light"] .dtab-add:hover {
    color: var(--blue);
    background: rgba(16, 63, 213, 0.04);
}

/* ── MAIN LAYOUT GRID ── */
.main {
    display: grid;
    grid-template-columns: 1fr 280px;
    overflow: hidden;
    min-height: 0;
    flex-shrink: 1;
}

@media (max-width: 900px) {
    .main {
        grid-template-columns: 1fr;
    }
    .right-panel {
        display: none !important; /* Hide panel on very narrow screens or adapt. We match librodiario desktop approach. */
    }
}

/* ── LEDGER TABLE PANEL (LEFT) ── */
.table-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border2);
    min-height: 0;
}

.panel-header {
    background: rgba(103, 186, 228, 0.03);
    border-bottom: 1px solid var(--border2);
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    flex-shrink: 0;
}

.ph-label {
    font-size: 9px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 600;
    user-select: none;
}

.ph-div {
    width: 1px;
    height: 14px;
    background: var(--border);
    opacity: 0.5;
}

.ph-stat {
    font-size: 11px;
    color: var(--text2);
}

.ph-stat b {
    font-weight: 600;
    color: var(--text);
}

/* ── KPI BAR ── */
.kpi-bar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: rgba(0, 0, 0, 0.05);
}

.kpi-bar.multimoneda {
    grid-template-columns: repeat(3, 1fr);
}

.kb-multivals {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-top: 4px;
}

.kb-mval {
    font-size: 11.5px;
    font-weight: 500;
    color: var(--text2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border2);
    padding-bottom: 3px;
}

.kb-mval:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.kb-mval span {
    font-weight: 700;
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
}

.kb-mval.green span {
    color: var(--green);
}

.kb-mval.red span {
    color: var(--red);
}

.kb-item {
    padding: 10px 16px;
    border-right: 1px solid var(--border2);
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.kb-item:last-child {
    border-right: none;
}

.kb-lbl {
    font-size: 9px;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: 600;
    user-select: none;
}

.kb-val {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}

.kb-val.green { color: var(--green); }
.kb-val.red { color: var(--red); }
.kb-val.sky { color: var(--sky); }

[data-theme="light"] .kb-val.sky {
    color: var(--blue);
}

.kb-sub {
    font-size: 10.5px;
    color: var(--text3);
    font-variant-numeric: tabular-nums;
    margin-top: 1px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── SCROLLABLE TABLE WRAP ── */
.tbl-wrap {
    overflow-y: auto;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--border2) transparent;
}

.tbl-wrap::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.tbl-wrap::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 5;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

thead tr {
    background: var(--th-bg);
    border-bottom: 1px solid var(--border2);
}

th {
    padding: 10px 16px;
    text-align: left;
    font-size: 9px;
    font-weight: 600;
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    white-space: nowrap;
    border-right: 1px solid var(--border2);
    user-select: none;
    transition: color .15s, background .15s;
}

th:last-child {
    border-right: none;
}

th.sortable {
    cursor: pointer;
}

th.sortable:hover {
    background-color: var(--th-bg-hover);
    color: var(--text);
}

th .sort-icon {
    font-size: 10px;
    margin-left: 3px;
    opacity: 0.5;
}

/* Inline Header Filters Row */
.tr-filters th {
    padding: 4px 8px;
    background: rgba(103, 186, 228, 0.02);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border2);
}

[data-theme="light"] .tr-filters th {
    background: rgba(7, 26, 87, 0.02);
}

.f-col {
    width: 100%;
    background: var(--inp-bg);
    border: 1px solid var(--inp-brd);
    border-radius: 4px;
    color: var(--inp-txt);
    font-family: var(--font);
    font-size: 10.5px;
    padding: 4px 8px;
    outline: none;
    transition: border-color .15s, background .15s;
    min-width: 0;
}

.f-col:focus {
    border-color: var(--sky);
}

[data-theme="light"] .f-col:focus {
    border-color: var(--blue);
}

.f-col::placeholder {
    color: var(--text3);
}

.f-col option {
    background: var(--surface);
    color: var(--text);
}

.f-clear {
    background: none;
    border: 1px solid rgba(248, 113, 113, 0.2);
    border-radius: 4px;
    color: var(--text3);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 8px;
    width: 100%;
    font-family: var(--font);
    transition: all .15s;
    text-align: center;
}

.f-clear:hover {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border-color: rgba(248, 113, 113, 0.4);
}

/* Body Rows */
tbody tr {
    border-bottom: 1px solid var(--border2);
    transition: background .1s;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background: rgba(103, 186, 228, 0.03);
}

[data-theme="light"] tbody tr:hover {
    background: rgba(7, 26, 87, 0.02);
}

td {
    padding: 10px 16px;
    color: var(--text2);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    border-right: 1px solid var(--border2);
}

td:last-child {
    border-right: none;
}

td.amount-val {
    font-weight: 600;
    font-family: monospace;
    font-size: 12.5px;
}

td.amount-val.green { color: var(--green); }
td.amount-val.red { color: var(--red); }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.badge-income {
    background: rgba(74, 222, 128, 0.1);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.badge-expense {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.badge-coin-pesos {
    background: rgba(74, 222, 128, 0.1);
    color: var(--green);
    border: 1px solid rgba(74, 222, 128, 0.2);
}

.badge-coin-mep {
    background: rgba(16, 63, 213, 0.1);
    color: var(--sky);
    border: 1px solid rgba(16, 63, 213, 0.2);
}

[data-theme="light"] .badge-coin-mep {
    color: var(--blue);
    background: rgba(16, 63, 213, 0.06);
    border-color: rgba(16, 63, 213, 0.15);
}

.badge-coin-ccl {
    background: rgba(251, 191, 36, 0.1);
    color: var(--amber);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

[data-theme="light"] .badge-coin-ccl {
    color: #b07d1a;
    background: rgba(251, 191, 36, 0.06);
    border-color: rgba(251, 191, 36, 0.2);
}

/* Action Delete Button */
.btn-delete {
    background: none;
    border: none;
    color: var(--text3);
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1;
    transition: all .15s;
    font-family: var(--font);
    outline: none;
}

.btn-delete:hover {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
}

/* ── RIGHT PANEL (SIDEBAR FORM) ── */
.right-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface2);
    border-left: 1px solid var(--border);
    min-height: 0;
}

.rp-header {
    padding: 12px 16px 10px;
    border-bottom: 1px solid var(--border2);
    flex-shrink: 0;
}

.rp-title {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--text3);
    font-weight: 600;
    user-select: none;
}

.form-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border2) transparent;
}

.form-scroll::-webkit-scrollbar {
    width: 4px;
}

.form-scroll::-webkit-scrollbar-thumb {
    background: var(--border2);
}

.field {
    margin-bottom: 12px;
}

.field label {
    display: block;
    font-size: 9px;
    color: var(--text3);
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 5px;
    user-select: none;
}

.field input, .field select {
    width: 100%;
    background: var(--inp-bg);
    border: 1px solid var(--inp-brd);
    border-radius: var(--radius);
    color: var(--inp-txt);
    font-family: var(--font);
    font-size: 12px;
    padding: 8px 10px;
    outline: none;
    transition: border-color .2s, background .2s;
}

.field input:focus, .field select:focus {
    border-color: var(--accent);
    background: rgba(103, 186, 228, 0.05);
}

[data-theme="light"] .field input:focus, [data-theme="light"] .field select:focus {
    border-color: var(--blue);
    background: rgba(16, 63, 213, 0.02);
}

.field input::placeholder {
    color: var(--text3);
}

.field select option {
    background: var(--surface2);
    color: var(--text);
}

[data-theme="light"] .field select option {
    background: #ffffff;
    color: var(--text);
}

.btn-primary {
    width: 100%;
    padding: 11px;
    background: linear-gradient(135deg, var(--sky) 0%, var(--blue) 100%);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: opacity .2s, transform .1s;
    letter-spacing: .3px;
}

.btn-primary:hover {
    opacity: .9;
}

.btn-primary:active {
    transform: scale(.99);
}

/* Secondary Button style */
.btn-cancel {
    width: 100%;
    padding: 9px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text2);
    font-family: var(--font);
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
    text-decoration: none;
}

.btn-cancel:hover {
    border-color: var(--accent);
    color: var(--text);
}

[data-theme="light"] .btn-cancel:hover {
    border-color: var(--blue);
}

/* Info Box inside modal/form */
.info-box {
    background: rgba(103, 186, 228, 0.05);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.info-box strong {
    color: var(--sky);
}

[data-theme="light"] .info-box strong {
    color: var(--blue);
}

/* ── SETTINGS MODAL ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(5, 15, 51, .85);
    z-index: 1000;
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    transition: opacity 0.3s;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 380px;
    overflow: hidden;
    box-shadow: 0 40px 80px rgba(0, 0, 0, .5);
}

.modal-hdr {
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border2);
    background: rgba(103, 186, 228, .03);
}

.modal-ttl {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.modal-bdy {
    padding: 20px 24px;
}

.modal-ftr {
    display: flex;
    gap: 8px;
    padding: 0 24px 20px;
}

.btn-ok {
    flex: 1;
    padding: 9px;
    background: linear-gradient(135deg, var(--sky), var(--blue));
    border: none;
    border-radius: var(--radius);
    color: white;
    font-family: var(--font);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}

.btn-ok:hover {
    opacity: .9;
}

/* ── FOOTER ── */
.footer {
    width: 100%;
    padding: 32px 24px;
    text-align: center;
    border-top: 1px solid var(--border);
    color: var(--text3);
    font-size: 11px;
    background: rgba(0, 0, 0, .05);
}

/* Toast Messages */
.toast-wrap {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 12.5px;
    font-weight: 500;
    min-width: 240px;
    animation: slideIn .2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
}

.toast.success {
    border-color: rgba(74, 222, 128, .4);
}

.toast.error {
    border-color: rgba(248, 113, 113, .4);
}

@keyframes slideIn {
    from { transform: translateX(16px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Animations */
.animate-slide-up {
    opacity: 0;
    transform: translateY(8px);
    animation: slideUp 0.4s cubic-bezier(0.1, 0.8, 0.2, 1) forwards;
}

@keyframes slideUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.hidden {
    display: none !important;
}

/* Edit row button */
.btn-edit-row {
    background: none;
    border: none;
    color: var(--text3);
    cursor: pointer;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 13px;
    line-height: 1;
    transition: all .15s;
    font-family: var(--font);
    outline: none;
    margin-right: 4px;
}

.btn-edit-row:hover {
    background: rgba(103, 186, 228, 0.1);
    color: var(--sky);
}

[data-theme="light"] .btn-edit-row:hover {
    color: var(--blue);
    background: rgba(16, 63, 213, 0.05);
}
