/* ============================================================
   Household Ledger - stylesheet
   Type: Bricolage Grotesque (display) / Instrument Sans (body)
         IBM Plex Mono (all money figures)
   ============================================================ */

:root {
  /* The blue app frame: top strip and sidebar */
  --frame-top: #2563C9;
  --frame-bot: #10306E;
  --frame-ink: #FFFFFF;
  --frame-ink-soft: rgba(255, 255, 255, .70);
  --frame-hover: rgba(255, 255, 255, .13);
  /* The white content panel */
  --bg: #F3F6FC;
  --surface: #FFFFFF;
  --surface-2: #F5F8FD;
  --ink: #16233A;
  --ink-soft: #5B6B85;
  --line: #E1E8F3;
  --accent: #1D4ED8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E8EEFC;
  /* Money colors stay green and red on white */
  --pos: #147A47;
  --pos-soft: #E2F3EA;
  --warn: #A0700F;
  --warn-soft: #FAF0DC;
  --neg: #C0362C;
  --neg-soft: #FBE7E4;
  --shadow: 0 1px 2px rgba(16, 35, 70, .05), 0 10px 30px rgba(16, 35, 70, .09);
  --radius: 14px;
  --panel-radius: 18px;
  --font-body: "Instrument Sans", system-ui, sans-serif;
  --font-display: "Bricolage Grotesque", var(--font-body);
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}
[data-theme="dark"] {
  --frame-top: #14294F;
  --frame-bot: #060F1F;
  --frame-ink: #EAF1FF;
  --frame-ink-soft: rgba(234, 241, 255, .60);
  --frame-hover: rgba(255, 255, 255, .09);
  --bg: #060F1F;
  --surface: #111C30;
  --surface-2: #17243B;
  --ink: #E3EAF6;
  --ink-soft: #92A3BE;
  --line: #24334E;
  --accent: #5B9BFF;
  --accent-ink: #06152E;
  --accent-soft: #16294A;
  --pos: #4FBF83;
  --pos-soft: #123024;
  --warn: #D9A950;
  --warn-soft: #33280F;
  --neg: #E8796C;
  --neg-soft: #3A1A17;
  --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 12px 34px rgba(0, 0, 0, .40);

}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--frame-bot);
  background-image: linear-gradient(160deg, var(--frame-top) 0%, var(--frame-bot) 62%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.45;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

h1, h2, h3 { font-family: var(--font-display); margin: 0; }
.money { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }
.muted { color: var(--ink-soft); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  box-shadow: 0 20px 60px rgba(4, 16, 40, .38);
  padding: 34px 30px 26px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.login-sub { color: var(--ink-soft); margin: 6px 0 0; font-size: 14px; }
.brand-mark {
  display: inline-block;
  width: 34px; height: 34px;
  border-radius: 10px;
  background:
    linear-gradient(150deg, #3B82F6 0%, #1D4ED8 55%, #10306E 100%);
  position: relative;
  margin-bottom: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
}
.brand-mark::after {
  content: "$";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  color: #05132C;
  line-height: 1;
}
.brand .brand-mark::after { font-size: 17px; }
.login-error {
  background: var(--neg-soft);
  color: var(--neg);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}
.login-theme-toggle {
  display: block;
  margin: 18px auto 0;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 12px;
  text-decoration: underline;
}
.login-wrap .login-brand h1 { color: var(--ink); }

/* ---------- Fields, buttons ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.check-line { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 14px; }
.check-line input { width: 17px; height: 17px; accent-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); }
.btn-danger { color: var(--neg); border-color: var(--neg); background: transparent; }
.btn-danger:hover { background: var(--neg-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- App layout ---------- */
/* The blue gradient on <body> is the frame. The sidebar sits on it
   transparently, and #main floats above it as a white panel, so blue
   shows along the top, right, and bottom edges. */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: 232px;
  flex-shrink: 0;
  background: transparent;
  border-right: none;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px 14px;
  color: var(--frame-ink);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.brand .brand-mark { width: 28px; height: 28px; border-radius: 9px; margin: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16.5px;
  letter-spacing: -.01em;
  color: var(--frame-ink);
}
#nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-btn {
  text-align: left;
  background: none;
  border: none;
  color: var(--frame-ink-soft);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 13px;
  border-radius: 9px;
}
.nav-btn:hover { background: var(--frame-hover); color: var(--frame-ink); }
.nav-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .16);
}
.sidebar-foot {
  display: flex;
  gap: 6px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, .16);
}
.foot-btn {
  flex: 1;
  background: none;
  border: 1px solid rgba(255, 255, 255, .24);
  border-radius: 8px;
  color: var(--frame-ink-soft);
  font-size: 12.5px;
  padding: 7px 0;
}
.foot-btn:hover { color: var(--frame-ink); background: var(--frame-hover); }

#main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border-radius: var(--panel-radius);
  margin: 14px 14px 14px 0;
  padding: 26px 30px 44px;
  box-shadow: 0 4px 30px rgba(5, 20, 50, .28);
  min-height: calc(100vh - 28px);
}
.loading { color: var(--ink-soft); padding: 40px 0; text-align: center; }

/* ---------- Page header ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h2 { font-size: 24px; font-weight: 700; letter-spacing: -.015em; }
.page-sub { color: var(--ink-soft); font-size: 13.5px; margin-top: 3px; }

/* ---------- Cards, grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h3 { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }

.stat { padding: 14px 16px; }
.stat .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); font-weight: 600; }
.stat .value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; margin-top: 4px; }
.stat .sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

/* ---------- Net worth hero (signature) ---------- */
.networth {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.networth .nw-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-soft); font-weight: 600; }
.networth .nw-value { font-family: var(--font-mono); font-size: 38px; font-weight: 600; letter-spacing: -.02em; margin: 4px 0 16px; }
.posbar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.posbar .seg { min-width: 3px; }
.posbar .seg-ret { background: var(--accent); }
.posbar .seg-goal { background: var(--pos); }
.posbar .seg-home { background: #7C5CD6; }
.posbar .seg-debt {
  background: repeating-linear-gradient(-45deg, var(--neg) 0 6px, color-mix(in srgb, var(--neg) 60%, var(--surface)) 6px 12px);
}
.poslegend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); }
.poslegend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl .row-actions { white-space: nowrap; text-align: right; }
.tbl .row-actions .btn { margin-left: 6px; }
.tbl tr.inactive { opacity: .55; }
.empty { color: var(--ink-soft); padding: 18px 4px; font-size: 14px; }

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
}
.pill-paid { background: var(--pos-soft); color: var(--pos); }
.pill-due { background: var(--warn-soft); color: var(--warn); }
.pill-auto { background: var(--accent-soft); color: var(--accent); }
.pill-type { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); }

/* ---------- Progress bars ---------- */
.progress { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--pos); border-radius: 99px; }
.progress > i.util-mid { background: var(--warn); }
.progress > i.util-high { background: var(--neg); }

/* ---------- Calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-title { font-family: var(--font-display); font-size: 18px; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-dow { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft); text-align: center; font-weight: 600; padding-bottom: 4px; }
.cal-cell {
  min-height: 86px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px;
  font-size: 12px;
}
.cal-cell.blank { background: transparent; border-style: dashed; opacity: .4; }
.cal-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-daynum { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.cal-cell.today .cal-daynum { color: var(--accent); font-weight: 600; }
.cal-item {
  border-radius: 6px;
  padding: 2px 6px;
  margin-bottom: 3px;
  font-size: 11.5px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-item.bill { background: var(--warn-soft); color: var(--warn); }
.cal-item.expense { background: var(--accent-soft); color: var(--accent); }
.cal-item.cc { background: var(--neg-soft); color: var(--neg); }
.cal-item.done { background: var(--pos-soft); color: var(--pos); text-decoration: line-through; }

/* ---------- Card tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  border-radius: 99px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Modal ---------- */
#modal-root:empty { display: none; }
.modal-back {
  position: fixed; inset: 0;
  background: rgba(10, 18, 20, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 460px;
  padding: 22px 24px;
}
.modal h3 { font-size: 17px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 22px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 99;
  box-shadow: var(--shadow);
}
#toast.err { background: var(--neg); color: #fff; }

/* ---------- Subscriptions ---------- */
.sub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
}
.sub-card {
  display: flex;
  align-items: center;
  gap: 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
}
.sub-card.inactive { opacity: .55; }
.logo-tile {
  flex-shrink: 0;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -.02em;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}
.logo-tile.has-logo { box-shadow: inset 0 0 0 1px var(--line); }
.logo-tile img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.sub-body { flex: 1; min-width: 0; }
.sub-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sub-meta {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.sub-cost { text-align: right; flex-shrink: 0; }
.sub-price { font-size: 16px; font-weight: 600; }
.sub-cycle { font-size: 11.5px; color: var(--ink-soft); font-weight: 400; margin-left: 1px; }
.sub-actions { margin-top: 6px; display: flex; gap: 5px; justify-content: flex-end; }

/* ---------- Danger zone (Backup > reset) ---------- */
.danger-zone {
  background: linear-gradient(150deg, #C0362C 0%, #8E211A 100%);
  border: 1px solid #8E211A;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-top: 22px;
  color: #FFFFFF;
}
[data-theme="dark"] .danger-zone {
  background: linear-gradient(150deg, #8E2A22 0%, #521310 100%);
  border-color: #6E1F19;
}
.danger-zone h3 {
  color: #FFFFFF;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}
.danger-zone .dz-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 7px;
  background: rgba(255, 255, 255, .18);
  font-size: 14px;
}
.danger-zone p { color: rgba(255, 255, 255, .92); font-size: 13.5px; margin: 0 0 8px; }
.danger-zone ul { color: rgba(255, 255, 255, .92); font-size: 13.5px; margin: 0 0 14px; padding-left: 20px; }
.danger-zone li { margin-bottom: 3px; }
.danger-zone .btn-reset {
  background: #FFFFFF;
  border: 1px solid #FFFFFF;
  color: #8E211A;
  font-weight: 700;
}
.danger-zone .btn-reset:hover { background: #FFEDEB; }
.modal.modal-danger { border: 2px solid var(--neg); }
.modal-danger h3 { color: var(--neg); }
.reset-warn {
  background: var(--neg-soft);
  color: var(--neg);
  border-radius: 9px;
  padding: 12px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.reset-warn b { display: block; margin-bottom: 4px; }
#reset-word { font-family: var(--font-mono); letter-spacing: .08em; text-transform: uppercase; }

/* ---------- Home projects ---------- */
.proj-list { display: flex; flex-direction: column; gap: 12px; }
.proj-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.proj-card.expanded { border-color: var(--accent); }
.proj-head { display: flex; align-items: center; gap: 14px; }
.proj-title { flex: 1; min-width: 0; }
.proj-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.proj-meta { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.proj-figs { text-align: right; flex-shrink: 0; }
.proj-spent { font-size: 17px; font-weight: 600; }
.proj-detail { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.proj-detail .card { background: var(--surface-2); box-shadow: none; }

/* Expanded loan row */
.loan-detail > td { background: var(--surface-2); padding: 16px 14px; }
.loan-detail .card { background: var(--surface); box-shadow: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  #app { flex-direction: column; }
  #sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 14px 14px 10px;
    border-right: none;
    border-bottom: none;
  }
  .brand { padding-bottom: 12px; }
  #nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 4px;
    padding-bottom: 4px;
  }
  .nav-btn { white-space: nowrap; padding: 8px 13px; }
  .sidebar-foot { border-top: none; padding-top: 8px; }
  .foot-btn { flex: 0 0 auto; padding: 7px 12px; }
  #main {
    margin: 0 8px 8px;
    padding: 18px 15px 40px;
    min-height: 0;
  }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .networth .nw-value { font-size: 30px; }
  .cal-cell { min-height: 64px; }
  .field-row { flex-direction: column; gap: 0; }
  .sub-grid { grid-template-columns: 1fr; }
  .proj-head { flex-wrap: wrap; }
  .proj-title { flex: 1 0 100%; }
  .proj-figs { text-align: left; }
}

@media (prefers-reduced-motion: no-preference) {
  .nav-btn, .btn, .tab-btn { transition: background .12s ease, color .12s ease; }
  .posbar .seg { transition: width .4s ease; }
}

/* ---------- Account page ---------- */
.sidebar-version {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--frame-ink-soft);
  padding-top: 8px;
  letter-spacing: .04em;
}
.qr-wrap {
  display: flex;
  justify-content: center;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  border: 1px solid var(--line);
}
.qr-wrap svg { width: 220px; height: 220px; }
.codes-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.codes-grid code {
  font-family: var(--font-mono);
  font-size: 15px;
  letter-spacing: .06em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  text-align: center;
}
.changelog { display: flex; flex-direction: column; gap: 10px; }
.cl-row {
  display: grid;
  grid-template-columns: 110px 90px 1fr;
  gap: 12px;
  align-items: baseline;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 13.5px;
}
.cl-row.current { border-color: var(--accent); background: var(--accent-soft); }
.cl-ver { font-weight: 600; }
.cl-date { font-size: 12px; }
@media (max-width: 900px) {
  .cl-row { grid-template-columns: 1fr; gap: 3px; }
  .codes-grid { grid-template-columns: 1fr; }
}
