/* =========================================================
   Design system
   ========================================================= */
:root {
  /* Surfaces */
  --bg:         #0a0b0f;
  --surface:    #12141b;
  --surface-2:  #1a1d26;
  --surface-3:  #232732;
  --border:     #262b37;
  --border-2:   #30364456;

  /* Text */
  --text:       #edf0f5;
  --text-dim:   #c2c8d3;
  --muted:      #7a8396;

  /* Brand */
  --accent:     #ff385c;           /* Airbnb coral */
  --accent-2:   #ff6a85;
  --accent-soft: rgba(255,56,92,.12);

  /* Semantic */
  --pos:        #2ecc71;
  --pos-soft:   rgba(46,204,113,.14);
  --neg:        #ff5c6c;
  --neg-soft:   rgba(255,92,108,.14);
  --warn:       #ffb74d;
  --warn-soft:  rgba(255,183,77,.14);
  --info:       #5aa7ff;
  --info-soft:  rgba(90,167,255,.14);
  --violet:     #a78bfa;
  --violet-soft: rgba(167,139,250,.14);

  /* Radii & shadow */
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
  --shadow: 0 1px 0 rgba(255,255,255,.02) inset, 0 6px 24px rgba(0,0,0,.25);

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* =========================================================
   Reset-ish
   ========================================================= */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 800px at 80% -10%, rgba(255,56,92,.08), transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: .02em; }
p  { margin: 0; }
em { font-style: normal; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

main { max-width: 1180px; margin: 28px auto 64px; padding: 0 24px; }

/* =========================================================
   Topbar
   ========================================================= */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 14px 28px;
  background: linear-gradient(to bottom, rgba(18,20,27,.85), rgba(18,20,27,.7));
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; font-size: 16px; box-shadow: 0 4px 14px rgba(255,56,92,.35);
}
.brand-mark.lg { width: 48px; height: 48px; font-size: 22px; border-radius: 12px; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub  { font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  padding: 8px 14px; border-radius: 999px; color: var(--text-dim);
  font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tab.active {
  background: var(--accent-soft); color: var(--accent);
}
.icon-btn {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim);
  width: 36px; height: 36px; border-radius: 10px; cursor: pointer;
  display: grid; place-items: center; font-size: 15px;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--accent); }

/* =========================================================
   Page head
   ========================================================= */
.page-head {
  display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 16px;
  margin-bottom: 22px;
}
.eyebrow {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 6px;
}
.page-head p { max-width: 640px; margin-top: 8px; color: var(--muted); }
.month-nav { display: flex; gap: 8px; }

/* =========================================================
   Cards & sections
   ========================================================= */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}

/* Chart canvases: constrain height so they don't stretch to fill page */
.chart-wrap { position: relative; height: 280px; width: 100%; }
.chart-wrap.sm { height: 200px; }
.card > canvas { max-height: 280px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-bottom: 22px; }
.two-col > .card { margin-bottom: 0; }
@media (max-width: 860px) { .two-col { grid-template-columns: 1fr; } }

/* =========================================================
   KPI grid
   ========================================================= */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px;
}
.kpi-grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 920px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow);
}
.kpi::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.03), transparent 40%);
}
.kpi-label {
  font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
  margin-bottom: 10px;
}
.kpi-value {
  font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-bottom: 8px;
  line-height: 1.1; font-variant-numeric: tabular-nums;
}
.kpi-foot { font-size: 12px; color: var(--text-dim); }
.kpi-foot .muted { color: var(--muted); }

.kpi-earned  { box-shadow: var(--shadow), inset 3px 0 0 var(--pos); }
.kpi-spent   { box-shadow: var(--shadow), inset 3px 0 0 var(--neg); }
.kpi-net     { box-shadow: var(--shadow), inset 3px 0 0 var(--info); }
.kpi-burn    { box-shadow: var(--shadow), inset 3px 0 0 var(--warn); }
.kpi-annual  { box-shadow: var(--shadow), inset 3px 0 0 var(--violet); }

.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* =========================================================
   Progress bar
   ========================================================= */
.progress {
  height: 6px; background: var(--surface-2); border-radius: 999px; margin: 10px 0 6px; overflow: hidden;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--info), var(--pos));
  border-radius: 999px; transition: width .35s ease;
}

/* =========================================================
   Forms
   ========================================================= */
.tx-form { display: flex; flex-direction: column; gap: 14px; }
.form-head { margin-bottom: 4px; }
.form-head h2 { display: block; margin-bottom: 4px; font-size: 16px; }

.field { display: block; }
.field > span {
  display: block; font-size: 12px; letter-spacing: .04em; color: var(--muted);
  margin-bottom: 6px; font-weight: 500;
}
.field em.muted { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 4px; }
.field input, .tx-form input, .login-card input {
  width: 100%; padding: 11px 13px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--r-sm); font: inherit; transition: border-color .15s, background .15s;
}
.field input:focus, .tx-form input:focus, .login-card input:focus {
  outline: none; border-color: var(--accent); background: var(--surface-3);
}
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .row { grid-template-columns: 1fr; } }

/* Kind picker */
.kind-picker {
  border: none; padding: 0; margin: 4px 0;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.pill {
  position: relative; cursor: pointer; user-select: none;
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--r); padding: 12px 14px;
  transition: border-color .15s, background .15s, transform .15s;
  display: block;
}
.pill:hover { border-color: var(--border-2); transform: translateY(-1px); }
.pill input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.pill-title { display: block; font-weight: 600; font-size: 14px; }
.pill-sub   { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; letter-spacing: .02em; }

.pill-invest:has(input:checked)  { border-color: var(--violet); background: var(--violet-soft); }
.pill-invest:has(input:checked) .pill-title { color: var(--violet); }
.pill-cost:has(input:checked)    { border-color: var(--warn); background: var(--warn-soft); }
.pill-cost:has(input:checked) .pill-title   { color: var(--warn); }
.pill-income:has(input:checked)  { border-color: var(--pos); background: var(--pos-soft); }
.pill-income:has(input:checked) .pill-title { color: var(--pos); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  font: 500 14px/1 var(--font); cursor: pointer;
  transition: filter .15s, background .15s, border-color .15s;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent); color: white;
  box-shadow: 0 4px 14px rgba(255,56,92,.28);
}
.btn-primary:hover { filter: brightness(1.08); text-decoration: none; }
.btn-ghost {
  background: var(--surface-2); color: var(--text); border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-3); text-decoration: none; }
.btn.full { width: 100%; }

.link {
  background: none; border: none; color: var(--info); cursor: pointer;
  padding: 0; font: inherit; text-decoration: none;
}
.link:hover { text-decoration: underline; }
.link.danger { color: var(--neg); }
.link.small  { font-size: 12px; }

.inline { display: inline; }

/* =========================================================
   Tables & lists
   ========================================================= */
.ledger { width: 100%; border-collapse: collapse; }
.ledger th, .ledger td {
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-size: 14px; text-align: left; vertical-align: top;
}
.ledger th {
  color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
}
.ledger tr:last-child td { border-bottom: none; }
.ledger tr:hover td { background: rgba(255,255,255,.015); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.muted { color: var(--muted); }

.line-list { list-style: none; padding: 0; margin: 0; }
.line-list li {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--border);
}
.line-list li:last-child { border-bottom: none; }
.line-main strong { display: block; font-weight: 600; }
.line-side { text-align: right; }
.line-side .num { font-weight: 600; font-size: 15px; }

/* Tags */
.tag {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.tag-income      { background: var(--pos-soft); color: var(--pos); }
.tag-running_cost, .tag-cost { background: var(--warn-soft); color: var(--warn); }
.tag-investment  { background: var(--violet-soft); color: var(--violet); }
.tag-fixed       { background: var(--warn-soft); color: var(--warn); }
.tag-muted       { background: var(--surface-3); color: var(--muted); }

/* Chips (filters) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  padding: 6px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--text-dim); font-size: 13px;
  transition: background .15s, color .15s, border-color .15s;
}
.chip:hover { text-decoration: none; color: var(--text); border-color: var(--border-2); }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }

/* Empty states */
.empty {
  text-align: center; padding: 32px 16px; color: var(--muted); font-size: 14px;
  background: var(--surface-2); border-radius: var(--r); border: 1px dashed var(--border);
}
.empty a { color: var(--accent); }

/* =========================================================
   Login
   ========================================================= */
.login-wrap { display: grid; place-items: center; min-height: 72vh; }
.login-card {
  width: 360px; max-width: 92vw; padding: 32px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 8px; }
.login-brand h1 { font-size: 22px; }
.login-brand p { font-size: 13px; }

.error {
  background: var(--neg-soft); color: var(--neg);
  border: 1px solid rgba(255,92,108,.35);
  padding: 10px 14px; border-radius: var(--r-sm); font-size: 13px;
}

/* =========================================================
   Tables that overflow horizontally — wrap in this div
   to get a clean horizontal-scroll experience on mobile.
   ========================================================= */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Bleed slightly into card padding so the scroll cue is visible */
  margin: 0 -6px;
  padding: 0 6px;
}
.table-scroll .ledger { min-width: 520px; }
.table-scroll::-webkit-scrollbar { height: 6px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; }

/* =========================================================
   MOBILE / TABLET BREAKPOINTS
   ========================================================= */

/* Tablet & below */
@media (max-width: 860px) {
  main { margin: 18px auto 48px; padding: 0 16px; }
  h1 { font-size: 22px; }
  .card { padding: 18px; margin-bottom: 16px; border-radius: 14px; }
  .card-head { margin-bottom: 12px; }
  .page-head { margin-bottom: 16px; }
  .kpi { padding: 16px; }
  .kpi-value { font-size: 24px; }
  .kpi-label { margin-bottom: 8px; }

  /* Topbar: brand + scrollable tabs + logout fit on one row */
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand-mark { width: 28px; height: 28px; font-size: 14px; border-radius: 8px; }
  .brand-name { font-size: 14px; }
  .brand-sub { display: none; }

  .tabs {
    margin-left: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    max-width: calc(100vw - 160px); /* leave room for brand + logout */
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex-shrink: 0; padding: 6px 12px; font-size: 13px; }

  .month-nav .btn { padding: 8px 12px; font-size: 13px; }
}

/* Phones */
@media (max-width: 560px) {
  main { padding: 0 12px; }
  h1 { font-size: 20px; }
  .eyebrow { font-size: 10px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; }

  .card { padding: 16px; border-radius: 12px; }
  .card-head { flex-wrap: wrap; row-gap: 4px; }

  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; }
  .kpi-foot { font-size: 11px; }

  /* Forms become single-column */
  .row { grid-template-columns: 1fr; gap: 10px; }
  .kind-picker { grid-template-columns: 1fr; gap: 6px; }
  .pill { padding: 12px 14px; }
  .pill-title { font-size: 14px; }

  /* Form inputs slightly more padded for touch */
  .field input, .login-card input { padding: 12px 14px; font-size: 16px; /* prevents iOS zoom-on-focus */ }

  /* Filter chips wrap nicely */
  .chips { gap: 6px; }
  .chip { padding: 6px 12px; font-size: 12px; }

  /* Line list (income/fixed-cost rows) — keep amount on its own visual line if needed */
  .line-list li { gap: 8px; padding: 10px 0; }
  .line-side .num { font-size: 14px; }

  /* Login card: full width with a little breathing room */
  .login-card { width: 100%; padding: 24px; }
  .login-brand h1 { font-size: 20px; }

  /* Charts: shorter so they don't dominate small screens */
  .chart-wrap { height: 240px; }
  .chart-wrap.sm { height: 180px; }
}

/* Very narrow phones (<= 380px) */
@media (max-width: 380px) {
  .topbar { padding: 8px 10px; gap: 8px; }
  .tabs { max-width: calc(100vw - 130px); }
  .brand-name { font-size: 13px; }
  .icon-btn { width: 32px; height: 32px; }
  .kpi-value { font-size: 20px; }
  h1 { font-size: 18px; }
}
