:root {
  --ink: #0C0A09;        /* header, darkest */
  --ink-2: #1C1917;
  --ink-3: #292524;
  --bg: #F5F5F4;
  --card: #FFFFFF;
  --line: #E7E5E4;
  --text: #0C0A09;
  --muted: #57534E;
  --gold: #A16207;       /* gold on light, 4.9:1 on white */
  --gold-hi: #D4A017;    /* gold on dark */
  --gold-soft: #FEF3C7;
  --ok: #15803D; --ok-soft: #DCFCE7;
  --warn: #B45309; --warn-soft: #FEF3C7;
  --bad: #B91C1C; --bad-soft: #FEE2E2;
  --info: #1D4ED8; --info-soft: #DBEAFE;
  --grey-soft: #E7E5E4;
  --r: 16px;
  --shadow: 0 1px 2px rgba(12,10,9,.06), 0 4px 16px rgba(12,10,9,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --display: 'Cormorant Garamond', Georgia, serif;
  --sans: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 var(--sans); overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold-hi); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg.i { width: 22px; height: 22px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar (darkest colour) ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--ink); color: #fff; padding: calc(var(--safe-t) + 12px) 16px 12px; display: flex; align-items: center; gap: 8px; min-height: 60px; }
.top h1 { font: 600 26px/1.1 var(--display); margin: 0; flex: 1; letter-spacing: .2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .iconbtn { color: #fff; }
.iconbtn { width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px; display: grid; place-items: center; cursor: pointer; }
.iconbtn:active { background: rgba(255,255,255,.12); }

main { padding: 16px 16px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; animation: fade .22s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- bottom tabs ---------- */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: var(--safe-b); }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 9px 0 8px; min-height: 58px; color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 600; }
.tabs a[aria-current="page"] { color: var(--gold); }
.tabs a[aria-current="page"] svg { stroke-width: 2.4; }

/* ---------- building blocks ---------- */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.dark { background: var(--ink-2); color: #fff; }
.card h2, .sec { font: 700 13px/1.2 var(--sans); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; }
.sec { margin: 22px 4px 10px; display: flex; justify-content: space-between; align-items: center; }
.sec a { text-transform: none; letter-spacing: 0; font-size: 14px; text-decoration: none; padding: 8px 0; }
.hello { font: 600 32px/1.1 var(--display); margin: 4px 4px 2px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 4px 14px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.one { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.tile { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; text-decoration: none; color: inherit; display: block; }
.tile.wide { grid-column: 1 / -1; }
.tile .k { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.tile .v { font: 700 22px/1.25 var(--sans); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .v.bad { color: var(--bad); }
.tile .v.ok { color: var(--ok); }

.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }
.item { display: flex; gap: 12px; align-items: center; padding: 14px 16px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 56px; cursor: pointer; background: none; width: 100%; text-align: left; border-left: 0; border-right: 0; border-bottom: 0; }
.item:first-child { border-top: 0; }
.item:active { background: var(--bg); }
.item .t { font-weight: 600; }
.item .d { color: var(--muted); font-size: 13.5px; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--grey-soft); color: var(--ink-3); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: #22C55E; box-shadow: 0 0 0 4px rgba(34,197,94,.2); }
.dot.run { background: var(--gold-hi); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.filters button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: 14px; font-weight: 600; white-space: nowrap; cursor: pointer; color: var(--muted); }
.filters button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- forms ---------- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink-3); }
input, select, textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; min-height: 48px; font-size: 16px; }
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px rgba(161,98,7,.15); }
.search { position: relative; margin-bottom: 12px; }
.search svg { position: absolute; left: 14px; top: 13px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 44px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px; border-radius: 12px; border: 0; font-weight: 700; cursor: pointer; text-decoration: none; background: var(--ink); color: #fff; transition: transform .12s, opacity .12s; }
.btn:active { transform: scale(.97); }
.btn.gold { background: var(--gold); }
.btn.line { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--bad); border: 1.5px solid var(--bad-soft); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.btns .btn { flex: 1; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--grey-soft); border-radius: 12px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; border-radius: 9px; min-height: 44px; font-weight: 600; font-size: 14px; cursor: pointer; color: var(--muted); padding: 4px 6px; }
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.hint { font-size: 13px; color: var(--muted); margin: -4px 2px 12px; }
.err { color: var(--bad); font-size: 14px; font-weight: 600; margin: 8px 2px; }
.lines .line { display: grid; grid-template-columns: 1fr 64px 110px 40px; gap: 6px; margin-bottom: 8px; }
.lines input { padding: 10px; }
.total { display: flex; justify-content: space-between; font-weight: 700; font-size: 18px; padding: 10px 2px; }
.fab { position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 9; box-shadow: 0 6px 20px rgba(12,10,9,.25); border-radius: 999px; }

/* ---------- Claude ---------- */
.ask { position: relative; }
.ask textarea { padding-right: 56px; }
.mic { position: absolute; right: 6px; top: 6px; color: var(--muted); }
.mic.on { color: var(--bad); animation: pulse 1s infinite; }
.out { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.55; }
.out code, .md code { background: var(--bg); border-radius: 6px; padding: 1px 5px; font-size: 13.5px; }
.bubble { border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.bubble.me { background: var(--ink-2); color: #fff; margin-left: 32px; }
.bubble.ai { background: var(--card); box-shadow: var(--shadow); margin-right: 8px; }
.bubble .meta { font-size: 12px; opacity: .7; margin-bottom: 4px; font-weight: 600; }

.md h1, .md h2, .md h3 { font: 700 16px/1.3 var(--sans); margin: 16px 0 6px; }
.md p { margin: 0 0 10px; }
.md ul { margin: 0 0 10px; padding-left: 20px; }
.md li { margin-bottom: 4px; }

/* ---------- lock screen ---------- */
.lock { min-height: 100vh; min-height: 100dvh; background: radial-gradient(120% 80% at 50% 0%, #292524 0%, var(--ink) 60%); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; padding-bottom: calc(24px + var(--safe-b)); }
.lock img { width: 72px; height: 72px; border-radius: 18px; }
.lock h1 { font: 600 32px/1.1 var(--display); margin: 16px 0 4px; }
.lock p { color: #A8A29E; margin: 0 0 26px; font-size: 14px; min-height: 21px; }
.lock p.e { color: #FCA5A5; }
.pins { display: flex; gap: 16px; margin-bottom: 34px; }
.pins i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #78716C; transition: background .15s, border-color .15s, transform .15s; }
.pins i.f { background: var(--gold-hi); border-color: var(--gold-hi); transform: scale(1.1); }
.pins.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; }
.pad button { width: 76px; height: 76px; border-radius: 50%; border: 0; background: rgba(255,255,255,.08); color: #fff; font: 500 28px var(--sans); cursor: pointer; display: grid; place-items: center; }
.pad button:active { background: rgba(212,160,23,.35); }
.pad button.ghost { background: transparent; font-size: 14px; font-weight: 600; }

/* ---------- invoice / receipt paper ---------- */
.paper { background: #fff; border-radius: 6px; box-shadow: var(--shadow); padding: 24px 20px; font-size: 14px; }
.paper .ph { display: flex; justify-content: space-between; gap: 12px; border-bottom: 3px solid var(--ink); padding-bottom: 14px; margin-bottom: 16px; }
.paper .brand { font: 700 24px/1.1 var(--display); }
.paper .kind { font: 700 22px/1 var(--sans); letter-spacing: .12em; color: var(--gold); text-align: right; }
.paper table { width: 100%; border-collapse: collapse; margin: 14px 0; }
.paper th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); padding: 6px 4px; }
.paper td { padding: 9px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.paper .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.paper .sum td { border: 0; padding: 4px; }
.paper .grand td { font-size: 17px; font-weight: 700; border-top: 2px solid var(--ink); }
.paper .foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); white-space: pre-wrap; }
.stamp { display: inline-block; border: 3px solid var(--ok); color: var(--ok); font-weight: 800; letter-spacing: .15em; padding: 4px 12px; border-radius: 8px; transform: rotate(-6deg); }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media print {
  body { background: #fff; }
  .top, .tabs, .noprint, #toast, .fab { display: none !important; }
  main { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; }
}
