/* ------------------------------------------------------------------
   styles.css — all the look-and-feel.
-------------------------------------------------------------------*/

:root {
  /* Clean, light palette */
  --bg: #f4f5f7;          /* light, clean page */
  --panel: #ffffff;       /* white panels */
  --ink: #1f2937;
  --ink-soft: #6b7280;
  --line: #e5e7eb;
  --brand: #3d5a80;       /* soft steel-blue top bar */
  --accent: #2563eb;      /* blue primary */
  --accent-dark: #1d4ed8;
  --green: #15803d;       /* money in (deposits) */
  --red: #b91c1c;         /* money out (withdrawals) */
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 14px;
  background: var(--brand); color: #fff;
  padding: 10px 18px; padding-top: max(10px, env(safe-area-inset-top));
  box-shadow: var(--shadow); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand-logo { width: 32px; height: 32px; flex-shrink: 0; display: block; border-radius: 50%; object-fit: cover; }
.brand span { color: #ffffff; }
.topbar-totals { margin-left: auto; display: flex; gap: 26px; }
.total { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.total-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #cbd5e1; }
.total-value { font-size: 17px; font-weight: 700; }
.total-value.neg { color: #fca5a5; }

.icon-btn {
  background: transparent; border: none; color: inherit;
  font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }
#menuBtn { display: none; }

/* ---- Layout ---- */
.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 300px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.nav { display: flex; flex-wrap: wrap; padding: 12px 12px 6px; gap: 6px; }
.nav-item {
  flex: 1 1 46%; padding: 8px 10px; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-soft);
  white-space: nowrap; text-align: center;
}
.nav-item.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.nav-item { position: relative; }
.nav-badge { display: inline-block; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 800; vertical-align: middle; }
.nav-badge[hidden] { display: none; }
.nav-item.active .nav-badge { background: #fff; color: var(--accent); }

.account-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.sidebar-empty { padding: 18px 12px; color: var(--ink-soft); font-size: 14px; }

.acct-group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 14px 8px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--ink-soft); font-weight: 700;
}
.acct-group-total { font-weight: 600; }

.acct-item {
  width: 100%; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 9px 10px; border: none; background: transparent;
  border-radius: 8px; cursor: pointer; text-align: left; font-size: 14px; color: var(--ink);
}
.acct-item:hover { background: #f3f4f6; }
.acct-item.active { background: #e0e7ff; }
.acct-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-item-bal { font-variant-numeric: tabular-nums; font-weight: 600; }
.acct-item-bal.neg, .neg { color: var(--red); }

.add-account-btn { margin: 10px; }

/* ---- Buttons ---- */
.primary-btn {
  background: var(--accent); color: #fff; border: none; padding: 10px 14px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.primary-btn:hover { background: var(--accent-dark); }
.ghost-btn {
  background: #fff; color: var(--ink); border: 1px solid var(--line);
  padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.ghost-btn:hover { background: #f9fafb; }
.danger-btn {
  background: #fff; color: var(--danger); border: 1px solid #fecaca;
  padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.danger-btn:hover { background: #fef2f2; }
.mini-btn {
  background: #f3f4f6; border: 1px solid var(--line); color: var(--ink-soft);
  padding: 4px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.mini-btn:hover { background: #e5e7eb; }
.mini-btn.danger { color: var(--danger); }

/* ---- Main panel ---- */
.main { flex: 1; overflow-y: auto; padding: 26px 30px; min-width: 0; }

.empty-state {
  max-width: 460px; margin: 8vh auto 0; text-align: center; color: var(--ink-soft);
}
.empty-icon, .register-placeholder-icon { font-size: 42px; }
.empty-state h2 { color: var(--ink); margin: 10px 0 6px; }
.empty-state p { margin: 0 0 18px; line-height: 1.5; }

/* Account detail */
.detail { max-width: 820px; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.detail-type { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); font-weight: 700; }
.detail-name { margin: 4px 0 2px; font-size: 26px; }
.detail-inst { color: var(--ink-soft); font-size: 14px; }
.detail-balance-box { text-align: right; }
.detail-balance-label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); font-weight: 700; }
.detail-balance { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.detail-balance.neg { color: var(--red); }
.detail-actions { display: flex; gap: 10px; margin: 18px 0; }
.detail-notes { background: #fffbeb; border: 1px solid #fde68a; padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 18px; }

.register-placeholder {
  margin-top: 8px; border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; color: var(--ink-soft); background: #fafafa;
}
.register-placeholder h3 { color: var(--ink); margin: 8px 0 6px; }
.register-placeholder p { margin: 0 auto; max-width: 460px; line-height: 1.5; }

/* ---- Register (transaction ledger) ---- */
.register-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px 0 12px; }
.register-bar h3 { margin: 0; font-size: 18px; }
.register-bar-btns { display: flex; gap: 8px; }
.reg-search { margin-bottom: 12px; }
.reg-search-input { width: 100%; }
.register-empty { border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px 20px; text-align: center; color: var(--ink-soft); background: #fafafa; }
.register-empty p { margin: 0 0 14px; }

.reg-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.reg-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-top: 1px solid var(--line); cursor: pointer; }
.reg-item:first-child { border-top: none; }
.reg-item:hover { background: #f3f4f6; }
.reg-day { width: 40px; flex-shrink: 0; text-align: center; line-height: 1.05; }
.reg-day-num { display: block; font-size: 22px; font-weight: 800; }
.reg-day-my { display: block; font-size: 10px; color: var(--ink-soft); font-weight: 700; letter-spacing: .3px; }
.reg-desc { flex: 1; min-width: 0; }
.reg-payee { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg-check { color: var(--ink-soft); font-weight: 600; font-size: 13px; }
.reg-cat { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg-memo { font-size: 12px; color: var(--ink-soft); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reg-figs { flex-shrink: 0; text-align: right; }
.reg-amt { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.reg-amt.out { color: var(--red); }
.reg-amt.in { color: var(--green); }
.reg-bal { font-size: 13px; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.reg-bal-lbl { color: var(--ink-soft); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; }
.reg-bal.neg { color: var(--red); }
.clr-btn { width: 24px; height: 24px; flex-shrink: 0; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; color: var(--green); font-weight: 800; cursor: pointer; line-height: 1; padding: 0; }
.clr-btn.on { background: #dcfce7; border-color: #86efac; }
.clr-btn.rec { background: #dbeafe; border-color: #93c5fd; color: var(--accent-dark); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input.readonly { background: #f3f4f6; color: var(--ink-soft); }

/* split editor */
.cat-section { margin-bottom: 14px; }
.split-toggle { margin-top: 2px; padding: 7px 12px; font-size: 13px; }
.split-head { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.split-row { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; background: #fafafa; }
.split-cat { width: 100%; margin-bottom: 6px; }
.split-memo { width: 100%; margin-bottom: 6px; }
.split-line2 { display: grid; grid-template-columns: 1fr 100px 30px; gap: 8px; align-items: center; }
.split-sign { padding: 9px 6px; }
.split-amt { text-align: right; }
.split-total { font-size: 14px; font-weight: 800; color: var(--ink); margin-top: 8px; }

/* ---- Scheduled screen ---- */
.sch-screen { max-width: 820px; }
.sch-section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-soft); font-weight: 700; margin: 18px 0 8px; }
.sch-section-title.due { color: var(--danger); }
.sch-bulk { margin-bottom: 8px; }
.sch-list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.sch-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer; }
.sch-item:first-child { border-top: none; }
.sch-item:hover { background: #f3f4f6; }
.sch-item.due { background: #fff7ed; }
.sch-item.due:hover { background: #ffedd5; }
.sch-main { flex: 1; min-width: 0; }
.sch-payee { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.sch-auto { background: #e0e7ff; color: var(--accent-dark); font-size: 10px; font-weight: 800; padding: 1px 6px; border-radius: 999px; letter-spacing: .4px; }
.sch-meta { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.sch-next { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.sch-item.due .sch-next { color: var(--danger); font-weight: 600; }
.sch-right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.sch-amt { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.sch-amt.out { color: var(--red); }
.sch-amt.in { color: var(--green); }
.sch-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.sch-enter { padding: 5px 12px; font-size: 13px; }

/* ---- Settings screen ---- */
.set-screen { max-width: 680px; }
.set-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.set-card h3 { margin: 0 0 8px; font-size: 17px; }
.set-text { margin: 0 0 14px; color: var(--ink-soft); font-size: 14px; line-height: 1.5; white-space: pre-line; }
.set-error { margin: 0 0 12px; color: var(--red); font-size: 13px; }
.set-btns { display: flex; flex-wrap: wrap; gap: 10px; }
.sync-status { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 10px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sync-dot.ok { background: var(--green); }
.sync-dot.busy { background: #d97706; }

/* ---- Reconcile screen ---- */
.rec-screen { max-width: 760px; }
.rec-controls { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.rec-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.rec-fig { flex: 1 1 160px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); }
.rec-fig-l { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); font-weight: 700; }
.rec-fig-v { display: block; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; }
.rec-diff.ok { background: #dcfce7; border-color: #86efac; }
.rec-diff.ok .rec-fig-v { color: var(--green); }
.rec-diff.off { background: #fef2f2; border-color: #fecaca; }
.rec-diff.off .rec-fig-v { color: var(--red); }
.rec-hint { font-size: 13px; color: var(--ink-soft); margin: 8px 0 12px; }
.rec-sort { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.rec-sort-l { font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.mini-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.rec-check { width: 26px; height: 26px; flex-shrink: 0; border-radius: 6px; border: 1.5px solid var(--line); background: #fff; color: var(--green); font-weight: 800; cursor: pointer; line-height: 1; padding: 0; }
.rec-check.on { background: #dcfce7; border-color: #86efac; }
.rec-lock { font-size: 12px; }
.rec-finish-row { margin-top: 16px; }
.rec-finish.disabled { opacity: .5; cursor: not-allowed; }

/* ---- Reports screen ---- */
.rep-screen { max-width: 760px; }
.rep-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 10px; }
.rep-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .4px; }
.rep-field .input { min-width: 150px; }
.rep-print { margin-left: auto; align-self: flex-end; }
.rep-scope { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
.rep-group { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden; }
.rep-group-head { display: flex; justify-content: space-between; align-items: center; padding: 11px 14px; background: #f9fafb; border-bottom: 1px solid var(--line); font-weight: 700; }
.rep-parent { font-size: 15px; }
.rep-rows { padding: 4px 0; }
.rep-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 14px 7px 26px; font-size: 14px; }
.rep-row:hover { background: #f9fafb; }
.rep-cat { color: var(--ink); }
.rep-amt { font-variant-numeric: tabular-nums; font-weight: 600; }
.rep-amt.in { color: var(--green); }
.rep-amt.out { color: var(--red); }
.rep-amt.subtotal { font-weight: 800; }
.rep-grand { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--brand); color: #fff; border-radius: var(--radius); font-size: 17px; font-weight: 800; margin-top: 4px; }
.rep-grand .rep-amt { color: #fff; }

@media print {
  .topbar, .sidebar, .rep-controls, #addAccountBtn { display: none !important; }
  .main { overflow: visible; padding: 0; }
  .layout { display: block; }
  .rep-group, .rep-grand { box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}

/* ---- Categories screen ---- */
.cat-screen { max-width: 820px; }
.screen-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.screen-header h1 { margin: 0 0 4px; font-size: 24px; }
.screen-sub { margin: 0; color: var(--ink-soft); font-size: 14px; max-width: 520px; line-height: 1.5; }

.cat-group { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; box-shadow: var(--shadow); overflow: hidden; }
.cat-parent { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: #f9fafb; border-bottom: 1px solid var(--line); }
.cat-parent .cat-name { font-weight: 700; }
.cat-parent-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.cat-children { padding: 4px 0; }
.cat-child { display: flex; align-items: center; gap: 10px; padding: 8px 14px 8px 26px; }
.cat-child:hover { background: #f9fafb; }
.cat-controls { display: flex; gap: 6px; margin-left: auto; }
.cat-empty { padding: 8px 26px; color: var(--ink-soft); font-size: 13px; font-style: italic; }
.tax-tag { background: #dcfce7; color: var(--green); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; }

/* ---- Forms ---- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field-hint { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.input {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; font-family: inherit; background: #fff; color: var(--ink);
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.15); }
textarea.input { resize: vertical; }
.checkbox-row { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.checkbox-row input { width: 17px; height: 17px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 50px rgba(0,0,0,.3); overflow: hidden; animation: pop .12s ease-out;
}
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header .icon-btn { color: var(--ink-soft); }
.modal-header .icon-btn:hover { background: #f3f4f6; }
.modal-body { padding: 18px; max-height: 64vh; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: #fafafa; }
.confirm-text { margin: 0; line-height: 1.5; }

/* ---- Mobile ---- */
@media (max-width: 800px) {
  #menuBtn { display: inline-block; }
  .topbar-totals { gap: 16px; }
  .total-value { font-size: 15px; }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
    transform: translateX(-102%); transition: transform .2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.2); padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; }
  .main { padding: 18px 16px; }
  .detail-header { flex-direction: column; }
  .detail-balance-box { text-align: left; }
}
