/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f0f2f5;
    color: #1a1a1a;
    -webkit-font-smoothing: antialiased;
}

/* ===== APP SHELL ===== */
#app { height: 100vh; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.page { display: none; flex: 1; flex-direction: column; overflow: hidden; position: absolute; inset: 0; background: #f0f2f5; }
.page.active { display: flex; z-index: 1; }
.page-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 90px; }

/* ===== HEADER ===== */
.hdr {
    background: linear-gradient(135deg, #0a3d10 0%, #1a7a2a 100%);
    color: #fff;
    padding: 14px 16px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 3px 10px rgba(0,0,0,.35);
    flex-shrink: 0;
    min-height: 58px;
    position: relative;
    z-index: 10;
}
.hdr h1 { flex: 1; font-size: 1.15rem; font-weight: 700; letter-spacing: -.2px; }
.hdr .ic-btn { background: rgba(255,255,255,.18); border: none; color: #fff; width: 34px; height: 34px; border-radius: 50%; font-size: .95rem; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.hdr .ic-btn:active { background: rgba(255,255,255,.32); }

/* ===== TOTALS BAR ===== */
.totals-bar {
    background: #12271a;
    display: flex;
    justify-content: space-around;
    padding: 10px 8px;
    flex-shrink: 0;
}
.t-item { text-align: center; flex: 1; }
.t-lbl { font-size: .67rem; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .4px; }
.t-val { font-size: .97rem; font-weight: 700; color: #fff; margin-top: 2px; }

/* ===== TABS ===== */
.tab-strip { display: flex; background: #0a3d10; padding: 0 12px; gap: 4px; flex-shrink: 0; }
.tab-btn { flex: 1; padding: 10px 8px; border: none; background: transparent; color: rgba(255,255,255,.6); font-size: .88rem; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; transition: all .2s; -webkit-tap-highlight-color: transparent; }
.tab-btn.active { color: #fff; border-bottom-color: #52c77b; background: rgba(255,255,255,.08); border-radius: 8px 8px 0 0; }

/* ===== FILTERS ===== */
.filter-wrap { display:flex; gap:6px; padding:8px 12px; overflow-x:auto; scrollbar-width:none; background:#fff; border-bottom:1px solid #e8e8e8; flex-shrink:0; }
.filter-wrap::-webkit-scrollbar { display:none; }
.filter-btn { white-space:nowrap; border:1.5px solid #d0d0d0; background:#f5f5f5; color:#555; border-radius:20px; padding:5px 13px; font-size:.8rem; font-weight:600; cursor:pointer; transition:background .15s,border-color .15s,color .15s; }
.filter-btn.active { background:#1a7a2a; color:#fff; border-color:#1a7a2a; }

/* ===== GASTO ITEMS ===== */
.gasto-item { display:flex; align-items:flex-start; gap:12px; padding:12px 16px; background:#fff; margin:4px 12px; border-radius:12px; box-shadow:0 1px 4px rgba(0,0,0,.07); }
.gi-icon { font-size:1.3rem; flex-shrink:0; width:32px; text-align:center; margin-top:2px; }
.gi-info { flex:1; min-width:0; }
.gi-label { font-size:.9rem; font-weight:600; color:#111; }
.gi-cat { display:inline-block; font-size:.65rem; font-weight:600; padding:2px 7px; border-radius:8px; background:#e8f5e9; color:#1a7a2a; margin-left:6px; vertical-align:middle; cursor:pointer; }
.gi-cat-deleted { display:inline-block; font-size:.65rem; font-weight:600; padding:2px 7px; border-radius:8px; background:#feecec; color:#c0392b; margin-left:6px; vertical-align:middle; }
.gi-notes { font-size:.78rem; color:#888; margin-top:2px; font-style:italic; }
.gi-by { font-size:.72rem; color:#aaa; margin-top:2px; }
.gi-right { text-align:right; flex-shrink:0; }
.gi-amount { font-size:.95rem; font-weight:700; color:#c0392b; }
.gi-date { font-size:.72rem; color:#aaa; margin-top:2px; }
.gi-actions { display:flex; gap:2px; justify-content:flex-end; margin-top:2px; }
.gi-del { background:none; border:none; color:#ff6b6b; font-size:1rem; cursor:pointer; padding:2px 4px; }
.gi-edit { background:none; border:none; color:#888; font-size:.9rem; cursor:pointer; padding:2px 4px; }

/* ===== PRESUPUESTO MENSUAL POR TIPO ===== */
#budget-bar { padding:10px 16px; background:#fff; border-bottom:1px solid #e8e8e8; flex-shrink:0; }
.budget-top { display:flex; justify-content:space-between; font-size:.78rem; color:#555; margin-bottom:6px; }
.budget-track { height:8px; background:#eee; border-radius:4px; overflow:hidden; }
.budget-fill { height:100%; border-radius:4px; transition:width .2s; }
.budget-fill.budget-ok { background:#1a7a2a; }
.budget-fill.budget-warn { background:#e6a417; }
.budget-fill.budget-over { background:#c0392b; }
.budget-msg { font-size:.75rem; margin-top:6px; font-weight:600; }
.budget-msg-over { color:#c0392b; }

/* ===== MÉTRICAS ===== */
.metric-row { display: flex; gap: 10px; padding: 0 12px; }
.metric-card { flex: 1; background: #fff; border-radius: 14px; padding: 14px 16px; box-shadow: 0 1px 5px rgba(0,0,0,.09); }
.metric-card.wide { margin: 0 12px; }
.mc-lbl { font-size: .72rem; color: #888; text-transform: uppercase; letter-spacing: .4px; }
.mc-info { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; margin-left: 4px; border-radius: 50%; background: #e0e0e0; color: #666; font-size: .68rem; font-weight: 700; cursor: pointer; vertical-align: middle; line-height: 1; }
.mc-info:active { background: #ccc; }
.mc-val { font-size: 1.15rem; font-weight: 800; color: #111; margin-top: 4px; }
.mc-val.big { font-size: 1.7rem; color: #1a7a2a; }
.mc-sub { font-size: .78rem; color: #999; margin-top: 6px; }

.chart-row { display: flex; align-items: flex-start; padding-left: 12px; }
.chart-yaxis { position: relative; flex-shrink: 0; width: 40px; height: 100%; }
.yaxis-tick { position: absolute; left: 0; right: 6px; text-align: right; font-size: .68rem; font-weight: 600; color: #999; transform: translateY(-50%); white-space: nowrap; }
.chart-scroll { flex: 1; min-width: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; padding: 4px 12px 0 0; }
.chart-svg { display: block; }
.chart-bar { fill: #1a7a2a; }
.chart-grid { stroke: #e8e8e8; stroke-width: 1; }
.chart-line-path { fill: none; stroke: #1a7a2a; stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart-area { fill: #1a7a2a; opacity: .13; }
.chart-dot { fill: #1a7a2a; stroke: #fff; stroke-width: 2; }
.chart-labels { display: flex; gap: 10px; margin-top: 6px; }
.chart-label { font-size: .74rem; font-weight: 700; color: #1a7a2a; text-align: center; flex-shrink: 0; white-space: nowrap; }
.chart-hint { font-size: .78rem; color: #888; text-align: center; padding: 10px 12px 2px; }

.catg-item { background: #fff; margin: 6px 12px; padding: 12px 14px; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.07); cursor: pointer; }
.catg-top { display: flex; align-items: center; gap: 8px; }
.catg-icon { font-size: 1.1rem; flex-shrink: 0; }
.catg-name { flex: 1; font-size: .88rem; font-weight: 600; color: #111; }
.catg-amount { font-size: .9rem; font-weight: 700; color: #1a7a2a; }
.catg-chevron { font-size: .7rem; color: #bbb; flex-shrink: 0; }
.catg-bar { height: 6px; background: #eee; border-radius: 3px; margin-top: 8px; overflow: hidden; }
.catg-bar-fill { height: 100%; background: #1a7a2a; border-radius: 3px; }
.catg-detalle { margin-top: 10px; padding-top: 10px; border-top: 1px solid #f0f0f0; }
.catg-detalle-item { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: .82rem; }
.catg-detalle-item:not(:last-child) { border-bottom: 1px dashed #f5f5f5; }
.catg-detalle-motivo { flex: 1; color: #444; }
.catg-detalle-fecha { color: #999; flex-shrink: 0; }
.catg-detalle-monto { font-weight: 700; color: #111; flex-shrink: 0; }

.tipo-select-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tipo-select-row .filter-btn { flex: 1; }

/* ===== SECTION TITLE ===== */
.section-title { padding: 14px 16px 5px; font-size: .69rem; color: #888; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }

/* ===== FAB ===== */
.fab {
    position: fixed; bottom: 22px; right: 18px;
    width: 56px; height: 56px; border-radius: 50%;
    background: linear-gradient(135deg, #0a3d10, #1a7a2a);
    color: #fff; border: none; font-size: 1.7rem;
    cursor: pointer; box-shadow: 0 5px 18px rgba(26,122,42,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 50; transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.9); box-shadow: 0 2px 10px rgba(26,122,42,.4); }

/* ===== MODAL ===== */
.overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 200;
    align-items: flex-end; backdrop-filter: blur(2px);
}
.overlay.open { display: flex; }
.modal {
    background: #fff; border-radius: 22px 22px 0 0; width: 100%;
    max-height: 92vh; overflow-y: auto; padding: 22px 18px 30px;
    animation: slideUp .28s cubic-bezier(.4,0,.2,1);
}
.modal-handle { width: 40px; height: 4px; background: #ddd; border-radius: 2px; margin: -10px auto 16px; }
@keyframes slideUp { from { transform: translateY(100%); opacity: .5; } to { transform: translateY(0); opacity: 1; } }
.modal h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 16px; color: #111; }

/* ===== FORMS ===== */
.fg { margin-bottom: 13px; }
.fg label { display: block; font-size: .78rem; color: #555; margin-bottom: 4px; font-weight: 600; }
.fg input, .fg select, .fg textarea {
    width: 100%; padding: 11px 13px; border: 1.5px solid #e0e0e0;
    border-radius: 11px; font-size: .93rem; background: #fafafa;
    outline: none; transition: border-color .2s, background .2s; color: #111;
    -webkit-appearance: none;
}
.fg input:focus, .fg select:focus, .fg textarea:focus { border-color: #1a7a2a; background: #fff; }
.fg .input-error { border-color: #e53935; background: #fff5f5; }
.fg textarea { resize: none; height: 72px; }
.fr { display: flex; gap: 10px; }
.fr .fg { flex: 1; }

/* ===== BUTTONS ===== */
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn { padding: 13px 18px; border-radius: 12px; border: none; font-size: .93rem; font-weight: 700; cursor: pointer; width: 100%; transition: opacity .15s, transform .1s; }
.btn:active { transform: scale(.97); opacity: .85; }
.btn-primary { background: linear-gradient(135deg, #0a3d10, #1a7a2a); color: #fff; }
.btn-secondary { background: #f0f0f0; color: #444; }
.btn-danger { background: #feecec; color: #c0392b; }
.btn-info { background: #e3f2fd; color: #1565c0; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 55px 24px; color: #ccc; }
.empty-state .es-icon { font-size: 3.2rem; margin-bottom: 12px; }
.empty-state .es-title { font-size: .95rem; color: #aaa; font-weight: 600; margin-bottom: 6px; }
.empty-state .es-sub { font-size: .83rem; color: #ccc; }

/* ===== TOAST ===== */
#toast {
    display: none; position: fixed; bottom: 85px; left: 50%; transform: translateX(-50%);
    background: rgba(30,30,30,.92); color: #fff; padding: 10px 20px; border-radius: 22px;
    font-size: .87rem; z-index: 999; white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0,0,0,.3); backdrop-filter: blur(4px);
}

/* ===== UPDATE BANNER ===== */
#update-banner {
    display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    background: #1a7a2a; color: #fff; padding: 10px 16px;
    align-items: center; justify-content: space-between; gap: 10px;
    font-size: .85rem; box-shadow: 0 2px 10px rgba(0,0,0,.2);
}
#update-banner button {
    background: #fff; color: #1a7a2a; border: none; border-radius: 16px;
    padding: 6px 14px; font-size: .82rem; font-weight: 700; cursor: pointer; flex-shrink: 0;
}

/* ===== CONFIRM DIALOG ===== */
#confirm-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.55); z-index: 300; align-items: center; justify-content: center;
}
#confirm-overlay.open { display: flex; }
.confirm-box {
    background: #fff; border-radius: 18px; padding: 22px 20px; width: calc(100% - 48px);
    max-width: 340px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.25);
}
.confirm-box .cb-icon { font-size: 2rem; margin-bottom: 8px; }
.confirm-box h3 { font-size: .97rem; font-weight: 700; margin-bottom: 6px; }
.confirm-box p { font-size: .85rem; color: #666; margin-bottom: 18px; }
.confirm-box .btn-row { flex-direction: row; }

/* ===== CATEGORÍAS ===== */
.cat-item { display:flex; align-items:center; gap:10px; padding:10px 14px; background:#fff; margin:4px 0; border-radius:10px; box-shadow:0 1px 4px rgba(0,0,0,.07); }
.cat-item-icon { font-size:1.2rem; width:26px; text-align:center; flex-shrink:0; }
.cat-item-name { flex:1; font-size:.9rem; font-weight:600; color:#111; }
.cat-item-info { flex:1; min-width:0; }
.cat-item-sub { font-size:.75rem; color:#888; margin-top:2px; }
.cat-item-sub a { color:#1a7a2a; font-weight:600; cursor:pointer; margin-left:6px; }

/* ===== SETTINGS SECTIONS ===== */
.settings-block { border-top: 1px solid #eee; margin-top: 18px; padding-top: 16px; }
.settings-block.no-border { border-top: none; margin-top: 0; padding-top: 0; }
.settings-block .sb-title { font-size: .75rem; font-weight: 700; color: #888; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.settings-block .sb-status { font-size: .85rem; color: #666; margin-bottom: 10px; }

/* ===== LOCK SCREEN ===== */
#lock-screen {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: linear-gradient(160deg, #072b0d 0%, #1a7a2a 100%);
    flex-direction: column; align-items: center; justify-content: center;
}
.lock-title { font-size: 1.5rem; font-weight: 800; color: #fff; letter-spacing: -.5px; }
.lock-sub { font-size: .88rem; color: rgba(255,255,255,.6); margin: 4px 0 32px; }
.pin-dots { display: flex; gap: 18px; margin-bottom: 32px; }
.pin-dots span {
    width: 15px; height: 15px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.5); background: transparent;
    transition: background .15s, border-color .15s;
}
.pin-dots span.filled { background: #fff; border-color: #fff; }
.pin-error { color: #ff8a80; font-size: .85rem; height: 20px; margin-bottom: 16px; text-align: center; }
.numpad { display: grid; grid-template-columns: repeat(3, 74px); gap: 13px; }
.numpad button {
    width: 74px; height: 74px; border-radius: 50%; border: none;
    background: rgba(255,255,255,.13); color: #fff;
    font-size: 1.45rem; font-weight: 600; cursor: pointer;
    transition: background .1s; -webkit-tap-highlight-color: transparent;
}
.numpad button:active { background: rgba(255,255,255,.3); }
.numpad button.np-del { font-size: 1.1rem; }
.numpad button.np-empty { background: transparent; pointer-events: none; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%,60%{transform:translateX(-9px)} 40%,80%{transform:translateX(9px)} }
.shake { animation: shake .35s ease; }

/* ===== LOGIN SCREEN ===== */
#login-screen { display:none; position:fixed; inset:0; background:linear-gradient(160deg,#072b0d,#1a7a2a); z-index:3000; flex-direction:column; align-items:center; justify-content:center; padding:24px; }
.login-box { background:#fff; border-radius:22px; padding:28px 22px; width:100%; max-width:360px; }
#login-error { color:#e53935; font-size:.85rem; text-align:center; margin-bottom:8px; display:none; }
