/* M&G Books: ledger navy, gold accent, cool paper ground. Phone first (360 px and up), roomy on a computer, light and dark. */
:root {
  --bg: #F3F4F7; --surface: #FFFFFF; --surface2: #E9ECF2; --ink: #14213D; --muted: #5B6780; --line: #D8DDE8;
  --primary: #2A4D9B; --on-primary: #FFFFFF; --accent: #C98A12; --on-accent: #1B1405;
  --good: #1F8A5B; --warn: #B87800; --bad: #C2433A; --shadow: 0 1px 2px rgba(20,33,61,.08), 0 6px 18px rgba(20,33,61,.07);
  --bar: #BAC3D6; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0C1220; --surface: #151D2F; --surface2: #1E2740; --ink: #E8ECF5; --muted: #98A4BF; --line: #2A3550;
    --primary: #6C9BFF; --on-primary: #07122B; --accent: #E3A83A; --on-accent: #1B1405;
    --good: #4CC38A; --warn: #E3A83A; --bad: #EE6B60; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.3); --bar: #36456A; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding: env(safe-area-inset-top) 0 0; min-height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, .money { font-variant-numeric: tabular-nums; }
.app { max-width: 560px; margin: 0 auto; padding: 14px 16px calc(96px + env(safe-area-inset-bottom)); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.15; text-wrap: balance; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.top { display: flex; align-items: center; gap: 10px; margin: 2px 0 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .01em; flex: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
.top .sp { margin-left: auto; }
.top .who { margin-left: auto; font-size: 13px; color: var(--muted); min-width: 0; max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* cards and sections */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.card + .card, .card + .sec, .sec + .card, .sec + .sec { margin-top: 14px; }
.sec h2 { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin: 0 4px 8px; font-weight: 700; display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.sec h2 .r { text-transform: none; letter-spacing: 0; font-weight: 650; }
.hero { padding: 18px 18px 16px; }
.hero .lab { font-size: 13px; color: var(--muted); }
.hero .big { font-size: 42px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0 10px; max-width: 100%; }
.hero .big.neg { color: var(--bad); } .hero .big.pos { color: var(--good); }
.hero .big.m { font-size: 34px; } .hero .big.s { font-size: 29px; } .hero .big.xs { font-size: 24px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface2); border-radius: 14px; padding: 11px 13px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 650; }
.stat .v { font-size: 20px; font-weight: 800; letter-spacing: -.01em; margin-top: 2px; white-space: nowrap; }
.stat .v.sm { font-size: 17px; } .stat .v.xs { font-size: 14px; } .stat .v.xxs { font-size: 12px; }
p.small + .sec, .col > p.small + .sec { margin-top: 18px; }
.gauge { position: relative; height: 10px; border-radius: 99px; background: var(--surface2); overflow: hidden; }
.gauge i { position: absolute; inset: 0 auto 0 0; width: var(--w, 0%); border-radius: 99px; background: var(--primary); }
.gauge.good i { background: var(--good); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; background: var(--surface2); font-size: 12.5px; font-weight: 600; max-width: 100%; }
.pill b { font-weight: 800; }
.pill.good { color: var(--good); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }
button.pill { min-height: 44px; padding: 0 16px; border: 0; cursor: pointer; font: inherit; font-weight: 650; font-size: 13px; color: var(--primary); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.row2 { display: flex; align-items: center; gap: 12px; padding: 11px 2px; border-top: 1px solid var(--line); min-height: 56px; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.list li:first-child .row2, .row2.first { border-top: 0; }
.row2 .mid { flex: 1; min-width: 0; }
.row2 .t { display: block; font-weight: 600; overflow-wrap: anywhere; }
.row2 .s { display: block; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row2 .amt { font-weight: 700; flex: none; text-align: right; white-space: nowrap; }
.row2 .amt small { display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
.row2.empty .amt { color: var(--muted); font-weight: 600; }
.dot { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; background: var(--surface2); color: var(--primary); flex: none; }
.dot.ok { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.dot.todo { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.dot.pre { background: var(--surface2); color: var(--muted); }
.grp { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 16px 4px 6px; }
.grp b { font-size: 14px; } .grp span { font-size: 13px; color: var(--muted); }
.stamp { font-size: 12px; color: var(--muted); margin-top: 2px; }
.logrow { padding: 11px 2px; border-top: 1px solid var(--line); }
.logrow:first-child { border-top: 0; }
.logrow .a { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.logrow .a span:last-child { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.logrow .d { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

/* buttons, inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 650; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.accent { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn.small { min-height: 44px; padding: 0 14px; font-size: 14px; }
.txt { background: none; border: 0; color: var(--primary); font-weight: 650; min-height: 44px; min-width: 44px; padding: 0 6px; flex: none; white-space: nowrap; }
.txt.sm { font-size: 14px; }
.field { display: block; margin: 12px 0 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 5px; font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=search], select, textarea { width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 16px; }
input:focus-visible, button:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; min-height: 44px; border: 0; background: none; border-radius: 10px; font-weight: 650; color: var(--muted); padding: 0 6px; }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.switch { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); min-height: 56px; }
.switch:first-child { border-top: 0; }
.switch .tx { flex: 1; } .switch .tx b { display: block; font-weight: 600; } .switch .tx small { color: var(--muted); font-size: 13px; }
.switch input { appearance: none; width: 52px; height: 32px; border-radius: 99px; background: var(--bar); position: relative; flex: none; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked { background: var(--primary); } .switch input:checked::after { transform: translateX(20px); }
.note { background: var(--surface2); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.note.warn { border: 1px solid var(--warn); }
.banner { margin: 0 0 12px; padding: 11px 14px; border-radius: 12px; background: var(--surface2); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.banner.warn { border: 1px solid var(--warn); }
.linkbox { word-break: break-all; font-size: 13px; background: var(--surface2); padding: 10px 12px; border-radius: 10px; user-select: all; margin-top: 8px; }

/* cycle bar */
.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.nav button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 20px; flex: none; }
.nav button[disabled] { opacity: .35; }
.nav .c { text-align: center; min-width: 0; }
.nav h2 { font-size: 20px; }
.nav .l { font-size: 13px; color: var(--muted); margin-top: 2px; }
.navsub { display: flex; justify-content: center; gap: 8px; margin: 6px 0 14px; flex-wrap: wrap; }

/* bottom bar (a computer gets the same bar at the top) */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr 1fr 76px 1fr 1fr; align-items: center; max-width: 560px; margin: 0 auto; z-index: 5; }
.tabs button.t { background: none; border: 0; min-height: 52px; display: grid; place-items: center; gap: 2px; font-size: 12px; font-weight: 650; color: var(--muted); padding: 0; }
.tabs button.t svg { width: 24px; height: 24px; }
.tabs button.t[aria-current=page] { color: var(--primary); }
.fab { width: 64px; height: 64px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; margin: -26px auto 0; box-shadow: 0 6px 18px rgba(0,0,0,.28); }
.fab svg { width: 30px; height: 30px; }

/* sheets */
.sheet { position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(10px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet .in { max-width: 560px; margin: 0 auto; }
.sheet .bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; min-height: 48px; gap: 10px; }
.sheet .bar h2 { font-size: 18px; min-width: 0; overflow-wrap: anywhere; }
.amtbox { display: flex; align-items: baseline; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px 16px; }
.amtbox b { font-size: 30px; color: var(--muted); }
.amtbox input { border: 0; background: none; font-size: 40px; font-weight: 800; padding: 0; min-height: 56px; letter-spacing: -.02em; min-width: 0; width: 100%; }
.amtbox input:focus-visible { outline: 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 600; z-index: 40; max-width: calc(100% - 32px); box-shadow: var(--shadow); overflow-wrap: anywhere; }
.center { min-height: calc(100vh - 80px); display: flex; flex-direction: column; justify-content: center; gap: 14px; }
.center .logo { width: 72px; height: 72px; border-radius: 18px; }
.center h1 { font-size: 30px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.menu { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; min-height: 60px; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.menu + .menu { margin-top: 10px; }
.menu .tx { flex: 1; min-width: 0; } .menu .tx b { display: block; } .menu .tx small { color: var(--muted); font-size: 13px; }
.menu .ar { color: var(--muted); font-size: 20px; }
.rf { flex: none; width: 44px; height: 44px; padding: 4px; border: 0; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.rf svg { width: 36px; height: 36px; padding: 8px; box-sizing: border-box; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); }
.rf:active svg { background: var(--surface2); }
.rf.spin svg { animation: rfspin .9s linear infinite; }
@keyframes rfspin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .rf.spin svg { animation: none; } * { transition: none !important; } }
@media (max-width: 340px) { .brand span { display: none; } }

/* long names, long notes and big numbers must never push the page sideways */
html, body { overflow-x: clip; }
.app, .sheet, .toast { overflow-wrap: anywhere; }
.pill { max-width: 100%; }
.hero .row { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 14px; flex-wrap: wrap; }
.hero .row > span { min-width: 0; }

/* a computer: wider page, the bar moves to the top, two columns where it helps */
@media (min-width: 900px) {
  .app { max-width: 1040px; padding: 22px 28px 60px; }
  .tabs { position: sticky; top: 0; bottom: auto; max-width: 1040px; margin: 0 auto 14px; border: 1px solid var(--line); border-radius: 16px; padding: 4px 8px; grid-template-columns: 1fr 1fr auto 1fr 1fr; gap: 6px; z-index: 6; backdrop-filter: none; background: var(--surface); }
  .tabs button.t { grid-template-columns: auto auto; justify-content: center; gap: 8px; min-height: 48px; font-size: 14px; }
  .tabs button.t svg { width: 20px; height: 20px; }
  .fab { width: 46px; height: 46px; margin: 0 8px; box-shadow: none; }
  .fab svg { width: 22px; height: 22px; }
  .toast { bottom: 28px; }
  .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
  .cols > .col > .sec:first-child, .cols > .col > .card:first-child { margin-top: 0; }
  .cols .sec + .sec, .cols .card + .sec, .cols .sec + .card { margin-top: 14px; }
  .hero .big { font-size: 52px; }
  .sheet { background: color-mix(in srgb, var(--bg) 72%, #000); display: grid; place-items: start center; padding-top: 6vh; }
  .sheet .in { width: 560px; background: var(--bg); border-radius: 20px; padding: 18px 20px 24px; box-shadow: 0 18px 60px rgba(0,0,0,.35); }
  .center { min-height: 70vh; max-width: 460px; margin: 0 auto; }
}
