:root {
  --ink: #0e1a2b;
  --ink-2: #4a5568;
  --ink-3: #8a94a6;
  --bg: #f3f4f7;
  --card: #ffffff;
  --line: #e6e8ee;
  --accent: #1f5eff;
  --accent-soft: #e8efff;
  --ok: #1f9d5c;
  --ok-soft: #e4f6ec;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --bad: #c53030;
  --bad-soft: #fde8e8;
  --xero: #13b5ea;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, textarea, select { font: inherit; color: inherit; }
.screen { min-height: 100dvh; display: flex; flex-direction: column; padding-bottom: calc(176px + var(--safe-bot)); }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(14px + var(--safe-top)) 20px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  display: flex; align-items: center; gap: 12px;
}
.top h1 { font-size: 28px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; flex: 1; }
.top .back { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 6px 0; display: flex; align-items: center; gap: 2px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px; }

.wrap { padding: 4px 16px 0; display: flex; flex-direction: column; gap: 16px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.04em; margin: 8px 4px -6px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(14,26,43,.05); overflow: hidden; }
.pad { padding: 16px; }

/* Connection pill */
.conn { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); flex: none; }
.conn b { display: block; font-size: 15px; }
.conn span { font-size: 13px; color: var(--ink-2); }

/* Note box */
textarea.note {
  width: 100%; min-height: 190px; resize: none; border: 0; outline: 0; padding: 16px;
  font: 15px/1.45 ui-monospace, "SF Mono", Menlo, monospace; background: #fffdf5; color: #2d2a20;
}
.note-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--ink-2); }
.note-head button { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600; }

.hint { font-size: 13px; color: var(--ink-3); padding: 0 4px; display: flex; gap: 8px; align-items: flex-start; }

/* Buttons */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; border: 0; border-radius: 14px; padding: 16px; font-size: 17px; font-weight: 600; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.xero { background: var(--xero); color: #fff; }
.btn[disabled] { opacity: .45; }
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 12px 16px calc(12px + var(--safe-bot));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.dock .row { display: flex; gap: 8px; }
.dock .row .btn { flex: 1; }

/* Invoice list */
.list .item { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 13px; color: var(--ink-2); }
.item .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 15px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .03em; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; }
.badge.sent { background: var(--ok-soft); color: var(--ok); }
.badge.draft { background: #eef0f4; color: var(--ink-2); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }

/* Review */
.inv-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 16px 16px 12px; gap: 12px; }
.inv-head .ref { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.inv-head .to { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.fields { border-top: 1px solid var(--line); }
.field { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.field label { width: 96px; flex: none; font-size: 14px; color: var(--ink-2); }
.field input, .field select { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; text-align: right; padding: 2px 0; }
.field input:focus { color: var(--accent); }
.field.desc { align-items: flex-start; }
.field.desc input { text-align: left; }
.field.missing { background: var(--warn-soft); }
.totals { padding: 12px 16px 16px; font-variant-numeric: tabular-nums; }
.totals div { display: flex; justify-content: space-between; font-size: 15px; color: var(--ink-2); padding: 3px 0; }
.totals .grand { color: var(--ink); font-size: 20px; font-weight: 700; padding-top: 8px; margin-top: 6px; border-top: 1px solid var(--line); }
.alert { margin: 0 16px 12px; padding: 10px 12px; border-radius: 12px; font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.alert.warn { background: var(--warn-soft); color: #7a5214; }
.alert.bad { background: var(--bad-soft); color: #8f1d1d; }
.include { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 15px; }
.include input { width: 22px; height: 22px; accent-color: var(--accent); }
.card.skipped { opacity: .55; }

.meta { font-size: 13px; color: var(--ink-3); text-align: center; padding: 4px 0 0; }

/* Sign in */
.signin { justify-content: space-between; padding: calc(64px + var(--safe-top)) 24px calc(32px + var(--safe-bot)); background: var(--ink); color: #fff; }
.signin .logo { width: 72px; height: 72px; border-radius: 18px; }
.signin h1 { font-size: 34px; line-height: 1.1; letter-spacing: -0.02em; margin: 24px 0 10px; }
.signin p { color: #b8c3d6; font-size: 17px; margin: 0; max-width: 30ch; }
.signin .steps { margin: 36px 0 0; padding: 0; list-style: none; display: grid; gap: 14px; }
.signin .steps li { display: flex; gap: 12px; align-items: center; color: #dbe3f0; font-size: 16px; }
.signin .steps i { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.1); display: grid; place-items: center; font-style: normal; font-size: 14px; font-weight: 700; flex: none; }
.signin .fine { font-size: 13px; color: #8193ad; text-align: center; margin-top: 14px; }

/* Done */
.done { align-items: center; text-align: center; padding: calc(80px + var(--safe-top)) 24px 0; }
.done .tick { width: 84px; height: 84px; border-radius: 50%; background: var(--ok); display: grid; place-items: center; box-shadow: 0 0 0 12px var(--ok-soft); }
.done h1 { font-size: 28px; margin: 28px 0 8px; letter-spacing: -0.02em; }
.done p { color: var(--ink-2); margin: 0 0 24px; }
.done .card { width: 100%; text-align: left; }

/* Loading */
.thinking { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; flex: 1; color: var(--ink-2); padding: 40px; text-align: center; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

.toast { position: fixed; left: 16px; right: 16px; top: calc(12px + var(--safe-top)); background: var(--ink); color: #fff; border-radius: 14px; padding: 14px 16px; font-size: 15px; z-index: 20; }
.demo-tag { position: fixed; top: calc(6px + var(--safe-top)); right: 8px; font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--warn); background: var(--warn-soft); padding: 2px 6px; border-radius: 6px; z-index: 30; right: auto; left: 50%; transform: translateX(-50%); }

.field textarea { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; line-height: 1.35; resize: none; padding: 2px 0; text-align: right; }
.field .unit { color: var(--ink-3); font-size: 16px; flex: none; }
.field input[type=date]::-webkit-calendar-picker-indicator { opacity: .35; }

/* v2 */
.pill { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 7px 12px; font-size: 14px; font-weight: 600; flex: none; }
.pill.ghost { background: #eef0f4; color: var(--ink-2); }
.row-btns { display: flex; gap: 6px; }
button.avatar { border: 0; }
.steps-card p { margin: 0 0 12px; font-size: 15px; color: var(--ink-2); }
.steps-card ol { margin: 12px 0; padding-left: 20px; font-size: 15px; display: grid; gap: 8px; }
.steps-card code { font: 13px ui-monospace, Menlo, monospace; background: #eef0f4; padding: 1px 5px; border-radius: 5px; word-break: break-all; }
input.mono { width: 100%; font: 15px ui-monospace, Menlo, monospace; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fffdf5; }
.wrap a { color: var(--accent); }
.sug { border-bottom: 1px solid var(--line); background: #fafbfd; max-height: 300px; overflow-y: auto; }
.sug-head, .sug-empty { padding: 10px 16px; font-size: 13px; color: var(--ink-3); }
.sug-empty { color: var(--ink-2); font-size: 14px; }
.sug-opt { padding: 13px 16px; border-top: 1px solid var(--line); font-size: 16px; display: flex; justify-content: space-between; gap: 8px; align-items: center; cursor: pointer; }
.sug-opt:active { background: var(--accent-soft); }
.sug-tag { font-size: 12px; color: var(--warn); background: var(--warn-soft); padding: 2px 8px; border-radius: 999px; flex: none; }

/* v3: shared job list */
.live { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 3px 8px; border-radius: 999px; background: #eef0f4; }
.live.on { color: var(--ok); background: var(--ok-soft); }
.live.on::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 5px; vertical-align: 1px; }
.entries { display: flex; flex-direction: column; gap: 8px; }
.day { font-size: 13px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin: 10px 4px 0; }
.entry { text-align: left; border: 0; background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(14,26,43,.05); width: 100%; }
.entry:active { background: #f7f8fb; }
.entry-text { white-space: pre-wrap; word-break: break-word; font-size: 16px; line-height: 1.4; max-height: 9.8em; overflow: hidden; }
.entry-meta { font-size: 13px; color: var(--ink-3); margin-top: 8px; }
.entry-meta .wait { color: var(--warn); }
.empty { text-align: center; color: var(--ink-2); padding: 48px 16px; font-size: 16px; line-height: 1.5; }
.fold { border: 0; background: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 6px 4px; text-align: left; }
.edit { padding-bottom: 0; }
.editor { flex: 1; min-height: 50dvh; width: 100%; border: 0; outline: 0; resize: none; padding: 8px 20px 120px; font: 18px/1.45 -apple-system, BlinkMacSystemFont, system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.saved { margin-left: auto; font-size: 13px; color: var(--ink-3); }
.btn.danger { color: var(--bad); }
.linkbtn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 0; text-decoration: underline; }
.from { font-size: 13px; color: var(--ink-3); padding: 0 16px 10px; margin-top: -6px; }

/* extra charges */
.field.extra { gap: 8px; }
.field.extra .xdesc { text-align: left; flex: 1; }
.field.extra .xamt { flex: 0 0 72px; }
.xdel { border: 0; background: #eef0f4; color: var(--ink-2); width: 28px; height: 28px; border-radius: 50%; flex: none; }
.addx { border: 0; background: none; color: var(--accent); font-size: 15px; font-weight: 600; padding: 12px 16px; text-align: left; width: 100%; border-bottom: 1px solid var(--line); }
.line-preview { margin: 0 16px 12px; padding: 10px 12px; background: #f5f7fb; border-radius: 10px; font-size: 14px; line-height: 1.35; color: var(--ink); }
.line-preview span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 3px; }
.name-in { width: 100%; font-size: 17px; padding: 15px 16px; border-radius: 14px; border: 0; margin-bottom: 10px; background: rgba(255,255,255,.1); color: #fff; outline: none; }
.name-in::placeholder { color: #8193ad; }

/* live progress while the AI reads */
.progress { padding: calc(40px + var(--safe-top)) 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.prog-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; }
.prog-head span { font-size: 14px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; width: 2%; background: var(--accent); border-radius: 999px; transition: width .6s ease; }
.prog-sub { font-size: 14px; color: var(--ink-2); }
.prog-log { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.prog-log li { display: flex; gap: 10px; align-items: baseline; background: var(--card); border-radius: 12px; padding: 10px 12px; font-size: 14px; animation: pop .25s ease; }
.prog-log .ok { color: var(--ok); font-weight: 700; flex: none; }
.prog-log .t { flex: 1; min-width: 0; }
.prog-log .p { font-weight: 600; font-variant-numeric: tabular-nums; flex: none; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
@media (prefers-reduced-motion: reduce) { .prog-log li { animation: none; } .bar i { transition: none; } }
