/* Ledger — personal finance tracker
   Palette is semantic: green means money in, clay means money out. */

:root {
  --ink: #16262d;
  --ink-soft: #5a6b72;
  --ink-faint: #8a999f;
  --page: #eef1f2;
  --surface: #ffffff;
  --line: #dbe2e4;
  --shade: #16262d;
  --shade-hi: #24393f;
  --in: #2f6b52;
  --in-wash: #e4efe9;
  --out: #a9482f;
  --out-wash: #f6e7e1;
  --warn: #8a6a1f;
  --focus: #2f6b52;
  --radius: 6px;
  --sidebar-w: 244px;
  --gap: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: ui-sans-serif, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
a { color: var(--in); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.num, td.num, th.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: right;
  white-space: nowrap;
}
.pos { color: var(--in); }
.neg { color: var(--out); }

/* ---------- shell ---------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--shade);
  color: #dbe5e7;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: contain;
  padding: 20px 0 14px;
}

.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 0 18px 20px;
}
.brand-mark {
  width: 34px; height: 34px;
  flex: 0 0 34px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--in);
  color: #fff;
  font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; color: #fff; }
.brand-text small {
  color: #92a7ad;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav { display: flex; flex-direction: column; overflow-y: auto; flex: 1; }
.nav a {
  color: #c3d1d5;
  padding: 10px 18px;
  font-size: 14.5px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--shade-hi); color: #fff; text-decoration: none; }
.nav a.here {
  background: var(--shade-hi);
  color: #fff;
  border-left-color: var(--in);
  font-weight: 600;
}
.nav-heading {
  margin: 18px 18px 6px;
  font-size: 11.5px;
  color: #7f959b;
  letter-spacing: 0.04em;
  border-top: 1px solid #2c4249;
  padding-top: 14px;
}

.sidebar-foot { padding: 12px 18px 0; border-top: 1px solid #2c4249; }
.sidebar-foot .quiet {
  display: block;
  color: #a9bbc0;
  font-size: 13px;
  padding: 5px 0;
}
.db-chip {
  margin: 10px 0 0;
  font-size: 11px;
  color: #8fa5ab;
  border: 1px solid #2c4249;
  border-radius: 99px;
  padding: 2px 9px;
  display: inline-block;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 19px; flex: 1 1 auto; min-width: 0; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; min-width: 0; }
.topbar-actions:empty { display: none; }

.burger {
  display: none;
  width: 40px; height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 0 9px;
  cursor: pointer;
}
.burger span { display: block; height: 2px; background: var(--ink); border-radius: 2px; }

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12, 24, 28, 0.5);
  border: 0;
  z-index: 40;
}

.content { padding: var(--gap); flex: 1; }
.content > * + * { margin-top: var(--gap); }

.tabbar { display: none; }

/* ---------- flashes ---------- */

.flashes { padding: 12px var(--gap) 0; }
.flash {
  margin: 0 0 8px;
  padding: 10px 13px;
  border-radius: var(--radius);
  border-left: 3px solid var(--ink-soft);
  background: var(--surface);
  font-size: 14.5px;
}
.flash-success { border-left-color: var(--in); background: var(--in-wash); }
.flash-error { border-left-color: var(--out); background: var(--out-wash); }
.flash-info { border-left-color: var(--ink-soft); }

/* ---------- panels & metrics ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 15px; }
.panel-head a { font-size: 13px; }
.panel-body { padding: 15px; }
.panel-body > * + * { margin-top: 12px; }
.panel-empty { padding: 26px 15px; color: var(--ink-soft); text-align: center; }

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
}
.metric.lead { border-top: 3px solid var(--shade); }
.metric.income { border-top: 3px solid var(--in); }
.metric.expense { border-top: 3px solid var(--out); }
.metric h3 { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.metric .figure {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 4px;
  letter-spacing: -0.02em;
}
.metric .sub { font-size: 12.5px; color: var(--ink-faint); margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: var(--gap); }
.grid-2 > * { min-width: 0; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th {
  text-align: left;
  font-size: 12.5px;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f7f9f9; }
.row-actions { text-align: right; }
.row-actions > * { display: inline-flex; vertical-align: middle; }
.row-actions > * + * { margin-left: 8px; }

.tag {
  display: inline-block;
  font-size: 12px;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  white-space: nowrap;
}
.tag-income { color: var(--in); background: var(--in-wash); border-color: transparent; }
.tag-expense { color: var(--out); background: var(--out-wash); border-color: transparent; }
.tag-transfer { color: #40555e; background: #e7edef; border-color: transparent; }
.tag-admin { color: #4b3a75; background: #eae6f4; border-color: transparent; }
.tag-off { color: var(--out); background: var(--out-wash); border-color: transparent; }
.swatch {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: 7px;
  vertical-align: baseline;
}

/* ---------- forms ---------- */

.form { display: grid; gap: 14px; max-width: 620px; }
.form-row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=month], input[type=search], select, textarea {
  width: 100%;
  padding: 10px 11px;
  font: inherit;
  font-size: 16px; /* keeps iOS from zooming on focus */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
input[type=color] {
  width: 46px; height: 40px; padding: 2px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
}
textarea { min-height: 84px; resize: vertical; }
.hint { font-size: 12.5px; color: var(--ink-faint); margin: 4px 0 0; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14.5px; }
.check input { width: 18px; height: 18px; }
.check label { margin: 0; color: var(--ink); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 15px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.btn:hover { text-decoration: none; background: #f4f7f7; }
.btn-primary { background: var(--in); border-color: var(--in); color: #fff; }
.btn-primary:hover { background: #275a45; }
.btn-danger { color: var(--out); border-color: #e3c4b9; background: var(--out-wash); }
.btn-danger:hover { background: #f0d8cf; }
.btn-small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-link {
  border: 0; background: none; padding: 0; min-height: 0;
  color: var(--in); cursor: pointer; font-size: 13px;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}

/* ---------- bars, charts, misc ---------- */

.bar { height: 8px; background: #e3e9ea; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--in); border-radius: 99px; }
.bar.over > span { background: var(--out); }
.bar.close > span { background: var(--warn); }

.progress-row { display: grid; gap: 6px; }
.progress-row .labels {
  display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px;
}

.chart { width: 100%; height: auto; display: block; }
.legend { display: grid; gap: 7px; font-size: 13.5px; }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-item .num { margin-left: auto; }

.period-nav { display: flex; align-items: center; gap: 8px; min-width: 0; }
.period-nav .btn { flex: 0 0 auto; }
.period-nav input[type=month] { flex: 1 1 auto; min-width: 0; width: auto; }
.period-nav strong { font-size: 14.5px; min-width: 116px; text-align: center; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: center; }
.stack { display: grid; gap: 12px; }
.split { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.muted { color: var(--ink-soft); }
.tiny { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.notice {
  padding: 12px 14px;
  border-radius: var(--radius);
  border-left: 3px solid var(--warn);
  background: #fbf4e2;
  font-size: 14px;
}
.notice.bad { border-left-color: var(--out); background: var(--out-wash); }
.notice.good { border-left-color: var(--in); background: var(--in-wash); }

/* ---------- sign in ---------- */

.signin {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--shade);
}
.signin-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 10px;
  padding: 28px 26px;
}
.signin-card h1 { font-size: 22px; margin-bottom: 4px; }
.signin-card .form { max-width: none; }

/* ---------- error page ---------- */

.errorpage { display: grid; place-items: center; min-height: 60vh; text-align: center; }
.errorpage .code { font-size: 44px; font-weight: 600; color: var(--ink-faint); }

/* ---------- mobile ---------- */

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --gap: 13px; }

  .burger { display: flex; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    height: auto;              /* top/bottom define the box, not 100vh */
    max-height: 100dvh;
    z-index: 50;
    overflow-y: auto;          /* the whole panel scrolls, not just .nav */
    -webkit-overflow-scrolling: touch;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  /* a nested scroller inside a scroller is why the foot was unreachable */
  .nav { overflow: visible; flex: 0 0 auto; }
  .sidebar-foot { margin-top: auto; }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .scrim { display: block; }
  .nav a { padding: 13px 18px; }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    row-gap: 10px;
    column-gap: 12px;
  }
  .topbar h1 {
    font-size: 17px;
    grid-column: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-actions {
    grid-column: 1 / -1;
    width: 100%;
  }
  .topbar-actions .btn { min-height: 38px; }
  .period-nav { flex: 1 1 190px; }
  .topbar-actions > .btn { flex: 1 1 auto; }

  .metric .figure { font-size: 22px; }
  .form-row { grid-template-columns: 1fr; }

  /* tables become stacked records */
  table.stacked thead { display: none; }
  table.stacked, table.stacked tbody, table.stacked tr, table.stacked td {
    display: block;
    width: 100%;
  }
  table.stacked tr {
    border-bottom: 1px solid var(--line);
    padding: 11px 13px;
  }
  table.stacked tr:last-child { border-bottom: 0; }
  table.stacked tbody tr:hover { background: none; }
  table.stacked td {
    border: 0;
    padding: 2px 0;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    text-align: left;
  }
  table.stacked td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 12.5px;
    flex: 0 0 38%;
  }
  table.stacked td.num { text-align: right; justify-content: space-between; }
  table.stacked td.row-actions { justify-content: flex-start; padding-top: 8px; }
  table.stacked td.row-actions::before { content: none; }

  .content { padding-bottom: 78px; }

  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 30;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    padding: 10px 2px;
    text-align: center;
    font-size: 11.5px;
    color: var(--ink-soft);
  }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.here { color: var(--in); font-weight: 600; }
  .tabbar .tab-add {
    color: var(--in);
    font-weight: 600;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}

/* ---------- advisor ---------- */

.advisor-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: baseline;
  justify-content: space-between;
  margin: 0;
  padding: 11px 14px;
  font-size: 13.5px;
  color: #33474e;
  background: #e7edef;
  border-left: 3px solid var(--shade);
  border-radius: var(--radius);
}
.advisor-links { display: flex; gap: 14px; flex-wrap: wrap; }
