/* ============================================================
   FINOVA — personal finance, local & private
   Design system: ivory / blue / violet / green / amber
   Fraunces (display) + Plus Jakarta Sans (body/labels)
   ============================================================ */

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

:root {
  --bg:       #F9F8F6;
  --bg2:      #F2F0EC;
  --bg3:      #E8E5DF;
  --white:    #FFFFFF;
  --ink:      #1A1916;
  --ink2:     #2E2C28;
  --muted:    #7A7670;
  --muted2:   #A8A49E;

  --acc:      #2563EB;
  --acc2:     #1D4ED8;
  --acc-lt:   #EFF6FF;
  --acc-mid:  #BFDBFE;

  --suc:      #059669;
  --suc-lt:   #ECFDF5;

  --war:      #D97706;
  --war-lt:   #FFFBEB;

  --vio:      #7C3AED;
  --vio-lt:   #F5F3FF;

  --err:      #DC2626;
  --err-lt:   #FEF2F2;

  --bdr:      rgba(0,0,0,0.08);
  --bdr2:     rgba(0,0,0,0.05);

  --r:        20px;
  --r-sm:     12px;
  --r-xs:     8px;
  --shadow:   0 4px 24px rgba(0,0,0,0.06);
  --shadow-lg:0 12px 40px rgba(0,0,0,0.10);

  /* default category colors */
  --cat-groceries:  #059669;
  --cat-dining:     #D97706;
  --cat-transport:  #7C3AED;
  --cat-bills:      #2563EB;
  --cat-subs:       #4F46E5;
  --cat-entertain:  #DB2777;
  --cat-shopping:   #EA580C;
  --cat-health:     #0D9488;
  --cat-income:     #15803D;
  --cat-transfers:  #64748B;
  --cat-cash:       #78716C;
  --cat-other:      #A8A49E;
}

html, body {
  height: 100%;
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg2);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ── App shell ─────────────────────────────────────────── */
#app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar (desktop) */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--bdr);
  display: flex;
  flex-direction: column;
  padding: 28px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  padding: 0 6px 28px;
}

.brand-word {
  font-family: 'Fraunces', serif;
  font-size: 24px;
  font-weight: 300;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--acc2);
  line-height: 1;
}
.brand-word em { font-style: italic; color: var(--acc); }

.brand-tag {
  font-size: 10px;
  font-weight: 400;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 6px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--bg2); color: var(--ink); }
.nav-item.active { background: var(--acc-lt); color: var(--acc2); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  font-size: 10px;
  color: var(--muted2);
  letter-spacing: .06em;
  padding: 10px 12px 0;
  line-height: 1.6;
}

/* Main column */
.main {
  flex: 1;
  min-width: 0;
  padding: 40px 44px 100px;
  max-width: 1180px;
}

.view-header {
  margin-bottom: 28px;
}

.view-title {
  font-family: 'Fraunces', serif;
  font-size: 28px;
  font-weight: 300;
  color: var(--ink);
  letter-spacing: -.2px;
}
.view-title em { font-style: italic; color: var(--acc); }

.view-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

/* Mobile bottom nav */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--white);
  border-top: 1px solid var(--bdr);
  justify-content: space-around;
  align-items: center;
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 50;
}
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted2); font-size: 9px; font-weight: 600; letter-spacing: .04em;
  padding: 4px 10px;
}
.mobile-nav-item svg { width: 19px; height: 19px; }
.mobile-nav-item.active { color: var(--acc); }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 24px 16px 90px; max-width: 100%; }
  .mobile-nav { display: flex; }
}

/* ── Cards & primitives ────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
  padding: 22px;
}

.card-sm { border-radius: var(--r-sm); padding: 16px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; }
@media (max-width: 700px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-2 { grid-template-columns: 1fr; } }

.kpi-label {
  font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted2); margin-bottom: 6px;
}
.kpi-value {
  font-family: 'Fraunces', serif; font-size: 22px; font-weight: 400; color: var(--ink);
}
.kpi-value.pos { color: var(--suc); }
.kpi-value.neg { color: var(--err); }
.kpi-delta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.kpi-delta.up { color: var(--err); }
.kpi-delta.down { color: var(--suc); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: var(--r-sm); padding: 10px 18px;
  font-family: 'Fraunces', serif; font-style: italic; font-weight: 400; font-size: 13.5px;
  background: var(--acc); color: #fff;
}
.btn:hover { background: var(--acc2); }
.btn.secondary { background: var(--bg2); color: var(--ink); font-style: normal; font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 12.5px; }
.btn.secondary:hover { background: var(--bg3); }
.btn.danger { background: var(--err-lt); color: var(--err); font-style: normal; font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 12.5px; }
.btn.ghost { background: transparent; color: var(--muted); font-style: normal; font-weight: 600; font-family: 'Plus Jakarta Sans', sans-serif; font-size: 12px; padding: 8px 12px; }
.btn.ghost:hover { color: var(--ink); background: var(--bg2); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.small { padding: 7px 12px; font-size: 12px; }

.input, select.input {
  width: 100%;
  border: 1px solid var(--bdr);
  background: var(--white);
  border-radius: var(--r-xs);
  padding: 9px 11px;
  font-size: 13px;
  color: var(--ink);
}
.input:focus, select.input:focus { outline: none; border-color: var(--acc-mid); }
label.field-label {
  display: block; font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted2); margin-bottom: 6px;
}
.field { margin-bottom: 14px; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg2); border-radius: 20px; padding: 3px 10px;
  font-size: 10.5px; font-weight: 600; color: var(--muted);
}

.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px;
  font-size: 10px; font-weight: 700; letter-spacing: .03em;
}

.hr { height: 1px; background: var(--bdr); margin: 18px 0; border: none; }

.empty-state {
  text-align: center; padding: 48px 20px; color: var(--muted);
}
.empty-state .es-title {
  font-family: 'Fraunces', serif; font-style: italic; font-size: 17px; color: var(--ink2); margin-bottom: 6px;
}
.empty-state .es-sub { font-size: 12.5px; max-width: 340px; margin: 0 auto; line-height: 1.6; }

/* ── Tables ─────────────────────────────────────────────── */
table.txn-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.txn-table th {
  text-align: left; font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted2); padding: 0 10px 10px; border-bottom: 1px solid var(--bdr);
}
table.txn-table td { padding: 11px 10px; border-bottom: 1px solid var(--bdr2); vertical-align: middle; }
table.txn-table tr:last-child td { border-bottom: none; }
table.txn-table td.amt { text-align: right; font-family: 'Fraunces', serif; font-size: 13.5px; }
table.txn-table td.amt.neg { color: var(--ink); }
table.txn-table td.amt.pos { color: var(--suc); }
table.txn-table td.running { text-align: right; color: var(--muted); font-size: 11.5px; }
table.txn-table tr.txn-row:hover { background: var(--bg2); }

.cat-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 3px;
  border-radius: 20px; font-size: 11px; font-weight: 600;
}
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-chip.editable { cursor: pointer; border: 1px dashed transparent; }
.cat-chip.editable:hover { border-color: var(--bdr); }

/* ── Upload ────────────────────────────────────────────── */
.dropzone {
  border: 1.5px dashed var(--bdr);
  border-radius: var(--r);
  background: var(--white);
  padding: 46px 24px;
  text-align: center;
  transition: border-color .15s ease, background .15s ease;
}
.dropzone.drag { border-color: var(--acc); background: var(--acc-lt); }
.dropzone-icon {
  width: 52px; height: 52px; background: var(--acc-lt); border-radius: 14px;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
}
.dropzone-title { font-family: 'Fraunces', serif; font-size: 17px; font-style: italic; color: var(--ink); margin-bottom: 6px; }
.dropzone-desc { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-bottom: 18px; }
.fmt-row { display: flex; gap: 6px; justify-content: center; margin-bottom: 18px; }
.fmt-tag { background: var(--bg2); border-radius: 5px; padding: 4px 10px; font-size: 10.5px; font-weight: 700; color: var(--muted); letter-spacing: .05em; }

.priv-strip {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--suc-lt); border: 1px solid rgba(5,150,105,0.15); border-radius: var(--r-sm);
  padding: 12px 14px; margin-top: 16px; font-size: 12px; color: #065F46; line-height: 1.55;
}
.priv-strip.warn { background: var(--war-lt); border-color: rgba(217,119,6,0.2); color: #78350F; }
.priv-strip svg { flex-shrink: 0; margin-top: 1px; }

.map-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 10px; }
.map-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted2); padding: 6px 8px; }
.map-table td { padding: 6px 8px; border-top: 1px solid var(--bdr2); }

.import-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--bdr); border-radius: var(--r-sm); margin-bottom: 8px; background: var(--white);
}
.import-row .file-icon {
  width: 34px; height: 34px; border-radius: 9px; background: var(--acc-lt);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.import-row .file-name { font-size: 12.5px; font-weight: 600; }
.import-row .file-meta { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.import-row .file-status { margin-left: auto; font-size: 11px; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--bg3); border-radius: 20px; transition: .15s;
}
.switch .thumb {
  position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%;
  transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch input:checked + .track { background: var(--acc); }
.switch input:checked + .track .thumb { transform: translateX(16px); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(26,25,22,0.42); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: var(--white); border-radius: var(--r); padding: 26px; max-width: 420px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-title { font-family: 'Fraunces', serif; font-size: 18px; font-style: italic; margin-bottom: 8px; }
.modal-body { font-size: 13px; color: var(--muted); line-height: 1.6; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
#toast-stack { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--r-sm); font-size: 12.5px;
  box-shadow: var(--shadow-lg); max-width: 320px;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--suc); }
@media (max-width: 860px) { #toast-stack { left: 16px; right: 16px; bottom: 76px; } }

/* Category manager rows */
.cat-manage-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--bdr);
  border-radius: var(--r-sm); margin-bottom: 6px; background: var(--white);
}
.cat-manage-row .drag-handle { color: var(--muted2); cursor: grab; font-size: 13px; }
.cat-manage-row input.cat-name-input { border: none; background: transparent; font-size: 13px; font-weight: 600; flex: 1; }
.cat-manage-row input.cat-name-input:focus { outline: none; }

.rule-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--bdr2); font-size: 12px;
}
.rule-row:last-child { border-bottom: none; }
.rule-row .rule-pattern { font-family: 'IBM Plex Mono', monospace; background: var(--bg2); padding: 2px 7px; border-radius: 5px; font-size: 11px; }

/* Filter bar */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 18px;
}
.filter-bar .field { margin-bottom: 0; min-width: 130px; }
.filter-bar .field.grow { flex: 1; min-width: 180px; }

.progress-bar-bg { height: 5px; background: var(--bg2); border-radius: 3px; overflow: hidden; }
.progress-bar-fill { height: 5px; border-radius: 3px; }

/* Category row (breakdown lists) */
.cat {
  background: var(--white); border: 1px solid var(--bdr); border-radius: var(--r-sm);
  padding: 11px 12px; display: flex; align-items: center; gap: 11px;
}
.cat-orb {
  width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cat-body { flex: 1; min-width: 0; }
.cat-nm { font-size: 12px; font-weight: 600; color: var(--ink); margin-bottom: 2px; }
.cat-ct { font-size: 10.5px; color: var(--muted); }
.cat-bar-bg { height: 3px; background: var(--bg2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.cat-bar-fill { height: 3px; border-radius: 2px; }
.cat-r { text-align: right; flex-shrink: 0; }
.cat-amt { font-family: 'Fraunces', serif; font-size: 14.5px; font-weight: 400; color: var(--ink); }
.cat-pct { font-size: 10px; color: var(--muted); margin-top: 1px; }
.cat-click { cursor: pointer; }
.cat-click:hover { border-color: var(--acc-mid); }

.subs-list { display: flex; flex-direction: column; gap: 8px; }
.subs-row {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px; border: 1px solid var(--bdr);
  border-radius: var(--r-sm); background: var(--white);
}
.subs-row .subs-name { font-size: 12.5px; font-weight: 600; }
.subs-row .subs-meta { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.subs-row .subs-amt { margin-left: auto; font-family: 'Fraunces', serif; font-size: 14px; }

.tab-strip { display: flex; gap: 4px; background: var(--bg2); border-radius: var(--r-sm); padding: 3px; margin-bottom: 18px; width: fit-content; }
.tab-strip button {
  border: none; background: transparent; padding: 7px 14px; border-radius: 9px; font-size: 12px; font-weight: 600; color: var(--muted);
}
.tab-strip button.active { background: var(--white); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

.acct-swatch { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }

::selection { background: var(--acc-mid); }

.spin {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--bdr); border-top-color: var(--acc);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
