/* Copied from design/fin-tokens.css (Claude Design, "Warm Ledger"). Edit tokens there first, then re-copy.
   Only change from the source: dark mode follows the OS (the @media block below). */
/* ==========================================================================
   Finances — design tokens + components ("Warm Ledger")
   Plain CSS custom properties. Light is default; dark via prefers-color-scheme
   or by putting .theme-dark / .theme-light on <html> (or any wrapper).
   Fonts: Inter (UI) + Inter Tight (display + money), Google Fonts.
   ========================================================================== */

:root, .theme-light {
  color-scheme: light;
  /* Surfaces */
  --bg: #F6F4EF;            /* page */
  --surface: #FFFEFB;       /* cards */
  --surface-2: #F1EEE7;     /* sunken: inputs on page, table header, track */
  --surface-3: #E8E4DB;     /* segmented track, hover */
  --border: #E5E0D6;        /* hairlines, card edges */
  --border-input: #958E80;  /* 3.2:1 on surface — WCAG 1.4.11 */
  /* Text */
  --text: #1D1B17;          /* 16.4:1 */
  --text-2: #57524A;        /* 7.0:1 on bg */
  --text-3: #6B655B;        /* 5.2:1 on bg — captions, meta */
  /* Action */
  --ink: #1D1B17;           /* primary button fill */
  --on-ink: #FFFEFB;
  --focus: #1D1B17;         /* focus ring is ink, never a hue */
  --link: #1D1B17;
  /* Money + status */
  --positive: #17734A;      /* 5.8:1 — always paired with "+" */
  --positive-bg: #E3F1E8;
  --warn-bg: #FBF0D9;
  --warn-border: #E7C57A;
  --warn-text: #6B4A0B;     /* 7.1:1 on warn-bg */
  --danger: #B4361F;
  --danger-bg: #FBE7E2;
  --rec: #C23B25;           /* recording mic; white icon 5.3:1 */
  --rec-ring: rgb(194 59 37 / .22);
  /* Entities — hue AND glyph shape; label always shown */
  --ent-aberdeen: #2A5FD0;  /* ● circle   5.7:1 */
  --ent-tcp: #C46A12;       /* ■ square   3.8:1 (graphics only) */
  --ent-personal: #8A4FB5;  /* ◆ diamond  5.4:1 */
  --ent-transfer: #8B857A;  /* ○ ring     3.6:1 (graphics only) */
  /* Charts */
  --chart-income: #3C9A6A;
  --chart-expense: #4A453E;
  --chart-grid: #E9E5DC;
  --chart-bar: #3C9A6A;
  /* Shadows */
  --sh-1: 0 1px 2px rgb(45 36 20 / .05);
  --sh-2: 0 1px 2px rgb(45 36 20 / .05), 0 8px 24px -10px rgb(45 36 20 / .14);
  --sh-3: 0 2px 4px rgb(45 36 20 / .06), 0 24px 48px -16px rgb(45 36 20 / .22);
  --sh-mic: 0 10px 28px -8px rgb(29 27 23 / .45);
}

.theme-dark {
  color-scheme: dark;
  --bg: #12110F;
  --surface: #1B1A17;
  --surface-2: #23211E;
  --surface-3: #2D2B27;
  --border: #2F2D29;
  --border-input: #6E685E;  /* 3.1:1 on surface */
  --text: #F2EFE8;
  --text-2: #B5AEA2;        /* 8.6:1 */
  --text-3: #958F84;        /* 5.4:1 on surface */
  --ink: #F2EFE8;
  --on-ink: #12110F;
  --focus: #F2EFE8;
  --link: #F2EFE8;
  --positive: #5CC08A;      /* 7.8:1 */
  --positive-bg: #15301F;
  --warn-bg: #2E2410;
  --warn-border: #6B5320;
  --warn-text: #F1D08A;
  --danger: #F08A74;
  --danger-bg: #3A1D16;
  --rec: #F06A50;           /* dark icon on it: 6.2:1 */
  --rec-ring: rgb(240 106 80 / .22);
  --ent-aberdeen: #6E9BFF;
  --ent-tcp: #F0A04B;
  --ent-personal: #C08BE6;
  --ent-transfer: #A39D92;
  --chart-income: #5CC08A;
  --chart-expense: #8C867B;
  --chart-grid: #2A2825;
  --chart-bar: #5CC08A;
  --sh-1: 0 0 0 1px rgb(255 255 255 / .02);
  --sh-2: 0 1px 0 rgb(255 255 255 / .03) inset, 0 12px 28px -12px rgb(0 0 0 / .6);
  --sh-3: 0 1px 0 rgb(255 255 255 / .04) inset, 0 28px 56px -18px rgb(0 0 0 / .7);
  --sh-mic: 0 10px 28px -8px rgb(0 0 0 / .7);
}

/* Follow the OS setting (same values as .theme-dark). */
@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) {
  color-scheme: dark;
  --bg: #12110F;
  --surface: #1B1A17;
  --surface-2: #23211E;
  --surface-3: #2D2B27;
  --border: #2F2D29;
  --border-input: #6E685E;  /* 3.1:1 on surface */
  --text: #F2EFE8;
  --text-2: #B5AEA2;        /* 8.6:1 */
  --text-3: #958F84;        /* 5.4:1 on surface */
  --ink: #F2EFE8;
  --on-ink: #12110F;
  --focus: #F2EFE8;
  --link: #F2EFE8;
  --positive: #5CC08A;      /* 7.8:1 */
  --positive-bg: #15301F;
  --warn-bg: #2E2410;
  --warn-border: #6B5320;
  --warn-text: #F1D08A;
  --danger: #F08A74;
  --danger-bg: #3A1D16;
  --rec: #F06A50;           /* dark icon on it: 6.2:1 */
  --rec-ring: rgb(240 106 80 / .22);
  --ent-aberdeen: #6E9BFF;
  --ent-tcp: #F0A04B;
  --ent-personal: #C08BE6;
  --ent-transfer: #A39D92;
  --chart-income: #5CC08A;
  --chart-expense: #8C867B;
  --chart-grid: #2A2825;
  --chart-bar: #5CC08A;
  --sh-1: 0 0 0 1px rgb(255 255 255 / .02);
  --sh-2: 0 1px 0 rgb(255 255 255 / .03) inset, 0 12px 28px -12px rgb(0 0 0 / .6);
  --sh-3: 0 1px 0 rgb(255 255 255 / .04) inset, 0 28px 56px -18px rgb(0 0 0 / .7);
  --sh-mic: 0 10px 28px -8px rgb(0 0 0 / .7);
}
}

:root {
  /* Type */
  --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Inter Tight", "Inter", ui-sans-serif, system-ui, sans-serif;
  --fs-money-xl: 44px;  /* hero figure (mobile 40) / lh 1.05 */
  --fs-money-lg: 32px;  /* KPI / lh 1.1 */
  --fs-money-md: 24px;  /* tile / lh 1.15 */
  --fs-h1: 28px;        /* screen title / lh 1.15 / -0.02em */
  --fs-h2: 19px;        /* card title / lh 1.3 */
  --fs-h3: 16px;
  --fs-body: 15px;      /* lh 1.5 */
  --fs-input: 16px;     /* never below 16 — iOS zoom */
  --fs-sm: 13px;        /* lh 1.4 */
  --fs-xs: 12px;        /* pills, axis labels */
  /* Space (4px base) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;
  /* Radius */
  --r-xs: 6px; --r-sm: 10px; --r-md: 12px; --r-lg: 18px; --r-xl: 24px; --r-pill: 999px;
  /* Sizes */
  --tap: 44px; --control-h: 48px; --mic: 88px; --mic-sm: 56px;
}

/* ---------- Base ---------- */
.fin { background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: var(--fs-body); line-height: 1.5; -webkit-font-smoothing: antialiased; }
.fin *, .fin *::before, .fin *::after { box-sizing: border-box; }
.fin h1, .fin h2, .fin h3, .fin p { margin: 0; }
.fin h1 { font-family: var(--font-display); font-size: var(--fs-h1); line-height: 1.15; font-weight: 600; letter-spacing: -0.02em; }
.fin h2 { font-family: var(--font-display); font-size: var(--fs-h2); line-height: 1.3; font-weight: 600; letter-spacing: -0.01em; }
.fin h3 { font-size: var(--fs-h3); font-weight: 600; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.sm { font-size: var(--fs-sm); line-height: 1.4; }
.xs { font-size: var(--fs-xs); line-height: 1.35; }
.eyebrow { font-size: var(--fs-xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "cv11" 1; }
.money { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; line-height: 1.05; }
.money-xl { font-size: var(--fs-money-xl); }
.money-lg { font-size: var(--fs-money-lg); }
.money-md { font-size: var(--fs-money-md); }
.money .cents { font-size: .55em; vertical-align: .62em; letter-spacing: 0; margin-left: 1px; color: var(--text-2); }
.pos { color: var(--positive); }
.fin a { color: var(--link); text-underline-offset: 3px; text-decoration-thickness: 1px; }
.fin a:hover { text-decoration-thickness: 2px; }
.fin svg.i { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.fin svg.i-sm { width: 16px; height: 16px; }

/* Focus: every interactive element */
.fin :focus-visible, .is-focus { outline: 2px solid var(--focus) !important; outline-offset: 2px; }

/* ---------- Card ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: var(--s-5); }
.card-lg { padding: var(--s-6); }
.card-flat { box-shadow: none; }
.card-sunken { background: var(--surface-2); border-color: transparent; box-shadow: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); margin-bottom: var(--s-4); }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }

/* ---------- Buttons ---------- */
.btn { appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--control-h); padding: 0 18px; border-radius: var(--r-md); border: 1px solid transparent; font: 600 15px/1 var(--font-ui); letter-spacing: -0.005em; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--ink); color: var(--on-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 88%, var(--bg)); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-input); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { min-height: var(--tap); padding: 0 14px; font-size: 14px; border-radius: var(--r-sm); }
.btn-lg { min-height: 56px; font-size: 16px; border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn[disabled], .btn.is-disabled { opacity: .45; cursor: not-allowed; }
.btn.is-loading { color: transparent; position: relative; }
.btn-link { appearance: none; background: none; border: 0; padding: 0 4px; min-height: var(--tap); font: 600 14px var(--font-ui); color: var(--text); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; cursor: pointer; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.input, .select, .textarea { width: 100%; min-height: var(--control-h); padding: 0 14px; border-radius: var(--r-md); border: 1px solid var(--border-input); background: var(--surface); color: var(--text); font: 400 var(--fs-input)/1.4 var(--font-ui); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-2); }
.textarea { padding: 12px 14px; min-height: 96px; resize: vertical; line-height: 1.5; }
.input-money { font: 600 28px/1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; min-height: 60px; padding-left: 34px; }
.affix { position: relative; display: block; }
.affix > .prefix { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--text-3); font: 600 22px var(--font-display); pointer-events: none; }
.select-wrap { position: relative; display: block; }
.select { appearance: none; -webkit-appearance: none; padding-right: 40px; cursor: pointer; }
.select-wrap > .chev { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--text-2); }
.field.is-invalid .input { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.field-error { font-size: var(--fs-sm); color: var(--danger); display: flex; gap: 6px; align-items: center; }
.input-ai { background: color-mix(in srgb, var(--warn-bg) 55%, var(--surface)); } /* field filled by "Fill in the details", until edited */

/* Checkbox */
.check { display: flex; align-items: flex-start; gap: 12px; min-height: var(--tap); padding: 10px 0; cursor: pointer; font-size: 15px; }
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--ink); cursor: pointer; }

/* ---------- Segmented control ---------- */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; background: var(--surface-3); border-radius: 14px; }
.seg > button { appearance: none; border: 0; background: transparent; min-height: 40px; padding: 0 12px; border-radius: 10px; font: 600 15px var(--font-ui); color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.seg > button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08), 0 0 0 1px var(--border); }
.seg-auto { grid-auto-columns: auto; display: inline-grid; }

/* ---------- Entity glyph (shape + color) ---------- */
.ent { display: inline-block; width: 10px; height: 10px; flex: none; }
.ent-aberdeen { background: var(--ent-aberdeen); border-radius: 50%; }
.ent-tcp { background: var(--ent-tcp); border-radius: 2px; }
.ent-personal { background: var(--ent-personal); transform: rotate(45deg) scale(.88); border-radius: 1.5px; }
.ent-transfer { border: 2px solid var(--ent-transfer); border-radius: 50%; }
.ent-lg { width: 14px; height: 14px; }
.ent-label { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }

/* Entity picker (Business) */
.picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.picker-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pick { appearance: none; position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 10px; min-height: 76px; padding: 12px; border-radius: var(--r-md); border: 1px solid var(--border-input); background: var(--surface); color: var(--text); text-align: left; font: 600 14px/1.2 var(--font-ui); cursor: pointer; }
.pick small { display: block; font-weight: 500; font-size: 12px; color: var(--text-3); margin-top: 2px; }
.pick[aria-pressed="true"] { border: 2px solid var(--ink); padding: 11px; background: var(--surface); box-shadow: var(--sh-2); }
.pick .tick { position: absolute; top: 9px; right: 9px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); color: var(--on-ink); display: none; place-items: center; }
.pick[aria-pressed="true"] .tick { display: grid; }

/* ---------- Pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px 0 7px; border-radius: var(--r-pill); font: 600 12px/1 var(--font-ui); white-space: nowrap; }
.pill svg { width: 13px; height: 13px; stroke: currentColor; fill: none; stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.pill-matched { background: var(--positive-bg); color: var(--positive); }
.pill-waiting { background: var(--warn-bg); color: var(--warn-text); }
.pill-logged { background: var(--surface-3); color: var(--text-2); }
.tag { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: var(--r-xs); background: var(--surface-3); color: var(--text-2); font: 600 11px/1 var(--font-ui); letter-spacing: .01em; }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--ink); color: var(--on-ink); font: 700 11px/1 var(--font-ui); font-variant-numeric: tabular-nums; }

/* ---------- Banner: AI "Check:" ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md); background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); font-size: 14px; line-height: 1.45; }
.banner strong { font-weight: 700; }
.banner .i { margin-top: 1px; }

/* ---------- Mic ---------- */
.mic { appearance: none; position: relative; width: var(--mic); height: var(--mic); border-radius: 50%; border: 0; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; box-shadow: var(--sh-mic); cursor: pointer; transition: transform .15s, background .2s; }
.mic svg { width: 34px; height: 34px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; position: relative; z-index: 1; }
.mic::before, .mic::after { content: ""; position: absolute; inset: 0; border-radius: 50%; pointer-events: none; }
.mic.is-rec { background: var(--rec); color: #fff; }
.theme-dark .mic.is-rec { color: var(--on-ink); }
@media (prefers-color-scheme: dark) { :root:not(.theme-light) .mic.is-rec { color: var(--on-ink); } }
.mic.is-rec::before { box-shadow: 0 0 0 10px var(--rec-ring); animation: micRing 1.6s ease-out infinite; }
.mic.is-rec::after { box-shadow: 0 0 0 22px color-mix(in srgb, var(--rec-ring) 45%, transparent); animation: micRing 1.6s .4s ease-out infinite; }
.mic-sm { width: var(--mic-sm); height: var(--mic-sm); box-shadow: var(--sh-2); }
.mic-sm svg { width: 24px; height: 24px; }
@keyframes micRing { 0% { transform: scale(.92); opacity: 1; } 100% { transform: scale(1.12); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .mic.is-rec::before, .mic.is-rec::after { animation: none; } }
.wave { display: flex; align-items: center; gap: 3px; height: 24px; }
.wave span { width: 3px; border-radius: 2px; background: var(--rec); }
.rec-status { display: inline-flex; align-items: center; gap: 8px; font: 600 14px var(--font-ui); color: var(--text); font-variant-numeric: tabular-nums; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rec); }

/* ---------- Progress ---------- */
.progress { height: 8px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--ink); }

/* ---------- Lists / tables ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font: 600 12px var(--font-ui); letter-spacing: .02em; color: var(--text-3); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table .input, .table .select { min-height: var(--tap); font-size: 14px; }

/* ---------- Charts (Chart.js reads these via getComputedStyle) ---------- */
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; }
.hbar-track { grid-column: 1 / -1; height: 10px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; }
.hbar-track > span { display: block; height: 100%; border-radius: inherit; }

/* ---------- App chrome ---------- */
.tabbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); padding: 6px 8px 8px; }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border-radius: var(--r-sm); font: 600 11px var(--font-ui); color: var(--text-3); text-decoration: none; position: relative; }
.tabbar a[aria-current="page"] { color: var(--text); }
.tabbar a .badge { position: absolute; top: 2px; left: calc(50% + 6px); height: 18px; min-width: 18px; font-size: 10px; }
.topnav { display: flex; gap: 4px; }
.topnav a { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: var(--r-sm); font: 600 14px var(--font-ui); color: var(--text-2); text-decoration: none; }
.topnav a[aria-current="page"] { background: var(--surface-3); color: var(--text); }
.mark { width: 32px; height: 32px; border-radius: 9px; background: var(--ink); color: var(--on-ink); display: grid; place-items: center; flex: none; }
.mark svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }
