/* Odinbook — the interface is monochrome on purpose.
   The only color anywhere is the color you assign to your own categories. */

:root {
  --bg: #000000;
  --ink: #ffffff;
  --ink-2: rgba(255, 255, 255, 0.62);
  --ink-3: rgba(255, 255, 255, 0.38);
  --ink-4: rgba(255, 255, 255, 0.20);
  --fill: rgba(255, 255, 255, 0.055);
  --fill-2: rgba(255, 255, 255, 0.10);
  --line: rgba(255, 255, 255, 0.09);
  --over: #ff453a;
  --in: #32d74b;
  --radius: 14px;
  --pad: 16px;
  --tabbar: 58px;

  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* Figures are always tabular so columns line up down the page. */
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ lock */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.lock-inner { width: 100%; max-width: 320px; text-align: center; }

.lock-mark {
  width: 46px; height: 46px;
  margin: 0 auto 22px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  position: relative;
}
.lock-mark::after {
  content: "";
  position: absolute; inset: 10px 10px auto 10px;
  height: 2px; background: var(--ink);
  box-shadow: 0 7px 0 var(--ink), 0 14px 0 var(--ink-4);
}

.lock-title { margin: 0 0 6px; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.lock-sub { margin: 0 0 26px; color: var(--ink-3); font-size: 14px; }

.lock-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  outline: none;
  margin-bottom: 12px;
}
.lock-input:focus-visible { border-color: var(--ink-2); }

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--ink);
  color: #000;
  border-radius: 12px;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.4; }

.lock-error { min-height: 20px; margin: 14px 0 0; color: var(--over); font-size: 13px; }

/* ------------------------------------------------------------------- app */

.app {
  max-width: 560px;
  margin: 0 auto;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 14px) var(--pad) 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 21px; font-weight: 600; letter-spacing: -0.015em; }

.actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 9px;
  color: var(--ink-2);
  font-size: 17px;
}
.icon-btn:active { background: var(--fill-2); color: var(--ink); }

.view { padding: 16px var(--pad) 28px; }

/* --------------------------------------------------------------- controls */

.segment {
  display: flex; gap: 3px; padding: 3px;
  background: var(--fill); border-radius: 10px;
}
.segment button {
  flex: 1; padding: 8px 4px;
  border-radius: 8px;
  font-size: 14px; font-weight: 500;
  color: var(--ink-3);
}
.segment button.on { background: var(--fill-2); color: var(--ink); }
.segment.compact { width: 84px; padding: 2px; }
.segment.compact button { padding: 5px 0; }
.segment.compact svg { width: 15px; height: 15px; fill: currentColor; display: block; margin: 0 auto; }

.pager {
  display: flex; align-items: center; justify-content: space-between;
  margin: 14px 0 16px;
  color: var(--ink-2);
}
.pager span { font-size: 14px; font-weight: 600; color: var(--ink); }
.pager button { width: 34px; height: 34px; font-size: 15px; }
.pager button:disabled { opacity: 0.2; }

/* ------------------------------------------------------------------ cards */

.card { background: var(--fill); border-radius: var(--radius); padding: 14px; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.card .label {
  display: block;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 7px;
}
.card .figure { font-size: 22px; font-weight: 600; }
.card .sub { font-size: 11.5px; color: var(--ink-3); margin-top: 5px; }

.stack { display: flex; flex-direction: column; gap: 10px; }

.section-label {
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-3);
  margin: 24px 0 10px;
}

/* ------------------------------------------------------------------- bars */

.bar { height: 6px; border-radius: 3px; background: var(--fill-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; }

/* ------------------------------------------------------------------- rows */

.rows { background: var(--fill); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 13px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.rows .row:last-child { border-bottom: 0; }
.row:active { background: var(--fill-2); }

/* The signature element: a category's color, carried everywhere it appears. */
.stripe { width: 4px; align-self: stretch; min-height: 30px; border-radius: 2px; flex: none; background: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.row .body { flex: 1; min-width: 0; }
.row .name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.row .amt { font-size: 15px; white-space: nowrap; }
.amt.in { color: var(--in); }
.amt.over { color: var(--over); }

.daygroup { margin-bottom: 14px; }
.dayhead { font-size: 11.5px; font-weight: 600; color: var(--ink-3); margin: 0 2px 7px; }

.chip {
  font-size: 10px; font-weight: 600; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 5px;
  background: var(--fill-2); color: var(--ink-2);
}
.repeat-glyph { color: var(--ink-3); font-size: 11px; }

/* --------------------------------------------------------------- plan row */

.planrow { display: block; width: 100%; padding: 13px; text-align: left; border-bottom: 1px solid var(--line); }
.rows .planrow:last-child { border-bottom: 0; }
.planrow:active { background: var(--fill-2); }
.planrow .top { display: flex; align-items: center; gap: 9px; margin-bottom: 9px; }
.planrow .top .name { flex: 1; font-size: 15px; font-weight: 500; }
.planrow .foot { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); margin-top: 7px; }

/* ------------------------------------------------------------------ chart */

.chartwrap { display: grid; place-items: center; padding: 6px 0 18px; }
.chartwrap svg { max-width: 260px; width: 100%; height: auto; }
.stackbar { width: 100%; height: 52px; border-radius: 8px; overflow: hidden; display: flex; margin: 26px 0; }
.stackbar > i { height: 100%; }
.total-figure { text-align: center; font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
.total-cap { text-align: center; font-size: 12px; color: var(--ink-3); margin: 3px 0 4px; }
.pct { font-size: 12px; color: var(--ink-3); width: 48px; text-align: right; flex: none; }
.footnote { font-size: 11.5px; color: var(--ink-3); padding: 11px 13px 13px; }

/* ------------------------------------------------------------------ empty */

.empty { text-align: center; padding: 54px 24px; }
.empty .glyph { font-size: 30px; color: var(--ink-4); margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; font-size: 16px; font-weight: 600; }
.empty p { margin: 0 auto; max-width: 260px; font-size: 14px; color: var(--ink-3); }
.empty .btn-primary { width: auto; padding: 11px 20px; margin-top: 18px; border-radius: 999px; }

/* ----------------------------------------------------------------- dialog */

.dialog-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 24px;
}

.dialog {
  width: 100%; max-width: 330px;
  background: #101010;
  border: 1px solid var(--line);
  border-radius: 17px;
  padding: 20px 18px 18px;
  animation: pop 0.16s ease-out;
}
@keyframes pop { from { transform: scale(0.96); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .dialog { animation: none; } }

.dialog h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.dialog p { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; }

.dialog-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.dialog-head .dot { width: 10px; height: 10px; }
.dialog-head .name { font-size: 13px; font-weight: 600; }

.dialog-ledger {
  margin: 14px 0 0;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 13px;
}
.dialog-ledger div { display: flex; justify-content: space-between; padding: 3px 0; color: var(--ink-2); }
.dialog-ledger div.total { color: var(--over); font-weight: 600; padding-top: 7px; }

.dialog-actions { display: flex; gap: 9px; margin-top: 18px; }
.dialog-actions button { flex: 1; padding: 12px 8px; border-radius: 11px; font-size: 14px; font-weight: 600; }
.btn-ok { background: var(--ink); color: #000; }
.btn-override { background: rgba(255, 69, 58, 0.13); color: var(--over); border: 1px solid rgba(255, 69, 58, 0.25); }
.btn-quiet { background: var(--fill-2); color: var(--ink); }

/* ------------------------------------------------------------------ debts */

/* A debt row carries two actions, so the row itself is a container and the
   tap-to-edit area is its own button beside the Paid shortcut. */
.row.debtrow { padding: 0; gap: 0; }
.debtmain {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 4px 11px 13px;
  text-align: left;
}
.debtmain:active { background: var(--fill-2); }
.debtmain .body { flex: 1; min-width: 0; }
.debtmain .name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.debtmain .meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.debtmain .amt { font-size: 15px; white-space: nowrap; }

.paybtn {
  flex: none; align-self: stretch;
  padding: 0 14px;
  font-size: 12.5px; font-weight: 600;
  color: var(--ink-2);
  border-left: 1px solid var(--line);
}
.paybtn:active { background: var(--fill-2); color: var(--ink); }

.amt.paid { color: var(--ink-3); }

.disclosure {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 13px 2px 11px;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 14px;
}
.disclosure .chev { font-style: normal; font-size: 11px; width: 10px; }
.disclosure .chip { letter-spacing: 0; }

/* Debts carry no per-record colour — overdue or not is the only distinction —
   so these live here rather than in a style attribute, which the page's CSP
   would refuse anyway. */
.stripe-neutral { background: #6E6E73; }
.stripe-over { background: var(--over); }
.figure.owed { color: var(--over); }

.field-flush { margin: 14px 0 0; }
.hint-block { margin-bottom: 14px; }
.hint-after { margin-top: 10px; }

/* ----------------------------------------------------------------- tabbar */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  max-width: 560px; margin: 0 auto;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  min-width: 0;
  height: var(--tabbar);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--ink-4);
}
.tab svg { width: 18px; height: 18px; fill: currentColor; }
.tab span { font-size: 9.5px; font-weight: 500; letter-spacing: -0.01em; white-space: nowrap; }
.tab.is-active { color: var(--ink); }

/* Row of small metadata pills under a recurring rule */
.pillrow { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 4px; }
.row.paused .name, .row.paused .amt { opacity: 0.45; }
.row.paused .stripe { opacity: 0.3; }

/* ------------------------------------------------------------------ sheet */

.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.6); backdrop-filter: blur(2px); }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-width: 560px; margin: 0 auto;
  max-height: 92dvh;
  display: flex; flex-direction: column;
  background: #0b0b0b;
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  animation: rise 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes rise { from { transform: translateY(100%); } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-grab { width: 34px; height: 4px; border-radius: 2px; background: var(--ink-4); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; }
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.sheet-btn { font-size: 15px; color: var(--ink-2); padding: 4px; }
.sheet-btn.strong { color: var(--ink); font-weight: 600; }
.sheet-btn:disabled { opacity: 0.35; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }

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

.field { margin-bottom: 16px; }
.field > label {
  display: block;
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 7px;
}
.input, select.input {
  width: 100%; padding: 12px 13px;
  background: var(--fill); border: 1px solid var(--line);
  border-radius: 11px; outline: none;
  appearance: none;
}
.input:focus-visible { border-color: var(--ink-2); }
.amount-input { font-variant-numeric: tabular-nums; font-size: 26px; text-align: center; padding: 16px 12px; }

.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 11px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 2px solid transparent; }
.swatch.on { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--ink); }

.danger { width: 100%; padding: 13px; margin-top: 6px; border-radius: 11px; background: rgba(255,69,58,0.12); color: var(--over); font-weight: 500; }
.btn-wide { width: 100%; padding: 13px; margin-top: 6px; border-radius: 11px; background: var(--fill-2); color: var(--ink); font-weight: 500; }
.hint { font-size: 12px; color: var(--ink-3); margin: -8px 0 16px; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed; z-index: 60;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
  padding: 10px 16px;
  background: var(--ink); color: #000;
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
}

/* ------------------------------------------------------------- desktop
   Above 900px the bottom tab bar becomes a left sidebar, sheets become
   centered modals, and hover states switch on. Layout only — the markup
   and the app logic are identical to mobile. */

@media (min-width: 900px) {

  .app {
    max-width: none;
    margin: 0;
    padding-left: 244px;
    padding-right: 24px;
    padding-bottom: 48px;
  }

  .topbar,
  .view {
    max-width: 760px;
    margin: 0 auto;
  }

  .topbar { padding: 26px 0 14px; }
  .topbar h1 { font-size: 25px; }
  .view { padding: 22px 0 40px; }

  /* Tab bar becomes a sidebar */
  .tabbar {
    top: 0; bottom: 0; right: auto;
    width: 220px;
    max-width: none;
    margin: 0;
    padding: 26px 14px;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .tabbar::before {
    content: "Odinbook";
    padding: 4px 12px 20px;
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -0.01em;
  }

  .tab {
    flex: none;
    height: 40px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 0 12px;
    border-radius: 9px;
  }
  .tab svg { width: 17px; height: 17px; }
  .tab span { font-size: 14px; font-weight: 400; letter-spacing: 0; }
  .tab.is-active { background: var(--fill); }
  .tab:hover { color: var(--ink); }

  /* Sheets become centered modals */
  .sheet {
    top: 50%; bottom: auto;
    left: 50%; right: auto;
    width: 460px; max-width: 460px;
    margin: 0;
    transform: translate(-50%, -50%);
    max-height: 78dvh;
    border: 1px solid var(--line);
    border-radius: 16px;
    animation: none;
  }
  .sheet-grab { display: none; }
  .sheet-head { padding: 16px 18px 12px; }
  .sheet-body { padding: 4px 20px 22px; }

  .toast { bottom: 28px; }

  .chartwrap svg { max-width: 300px; }

  /* Pointer affordances */
  .row:hover,
  .planrow:hover { background: var(--fill-2); }
  .icon-btn:hover { background: var(--fill-2); color: var(--ink); }
  .swatch:hover { transform: scale(1.08); }
  .segment button:hover { color: var(--ink); }
  .dialog-actions button:hover { filter: brightness(1.12); }
}

@media (min-width: 900px) and (prefers-reduced-motion: no-preference) {
  .swatch { transition: transform 0.12s ease; }
}
