/* ==========================================================================
   Receiptory — design system
   --------------------------------------------------------------------------
   Style:  Modern dark fintech SaaS — near-black forest-green surfaces,
           electric cobalt + mint accents, crisp borders, subtle glow,
           spacious layout. Light theme stays warm ivory, same accents.
           Dark cards carry an inset hairline highlight for crisp edges.
   Type:   Space Grotesk display for headlines & big numbers,
           Inter for UI text, tabular numerals for every amount.
           Both self-hosted from /fonts (no CDN, works offline).
   ========================================================================== */

/* --------------------------------------------------------------------------
   Self-hosted fonts (woff2, latin subset — bundled, never fetched remotely)
   -------------------------------------------------------------------------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/inter-400.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/inter-500.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("fonts/inter-600.woff2") format("woff2");
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/inter-700.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("fonts/space-grotesk-500.woff2") format("woff2");
}
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/space-grotesk-700.woff2") format("woff2");
}

:root {
  color-scheme: light;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-display: "Space Grotesk", "Inter", -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;

  /* Surfaces */
  --bg: #f8f6ef;
  --surface: #ffffff;
  --surface-sunken: #f4f1e8;
  --border: #e8e2d3;
  --border-strong: #868b7f;

  /* Ink */
  --forest: #143323;
  --text: #26362d;
  --text-strong: #143323;
  --muted: #5b6a61;

  /* Accents */
  --cobalt: #1d4ed8;
  --cobalt-hover: #1a43bd;
  --cobalt-soft: #e9eefd;
  --cobalt-text: #1d4ed8;
  --mint: #0e9f6e;
  --mint-soft: #e2f5ec;
  --sage: #ddebe1;
  --sage-strong: #c9e2d2;

  /* Status */
  --ok-soft: #ddebe1;
  --ok-text: #143323;
  --warn-soft: #fbf1dd;
  --warn-text: #8a5a12;
  --warn-border: #ebd9b4;
  --danger: #b42318;
  --danger-text: #b42318;
  --danger-soft: #fdecea;

  /* Component-specific tokens */
  --nav-active-bg: #143323;
  --nav-active-fg: #faf7f0;
  --btn2-bg: #ddebe1;
  --btn2-fg: #143323;
  --btn2-border: #c9e2d2;
  --toast-bg: #143323;
  --toast-fg: #faf7f0;
  --dot-idle: #d8d0c2;

  --focus: #1d4ed8;
  --glow-cobalt: 0 8px 24px -10px rgba(29, 78, 216, 0.5);
  --glow-mint: 0 8px 24px -10px rgba(14, 159, 110, 0.4);
  --card-ring: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --shadow-sm: 0 1px 2px rgba(20, 51, 35, 0.06);
  --shadow: 0 1px 2px rgba(20, 51, 35, 0.05), 0 16px 38px -18px rgba(20, 51, 35, 0.28);
  --shadow-raised: 0 2px 4px rgba(20, 51, 35, 0.07), 0 20px 44px -20px rgba(20, 51, 35, 0.33);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
}

[data-theme="dark"] {
  color-scheme: dark;

  /* Near-black forest-green surfaces */
  --bg: #050b08;
  --surface: #0a1410;
  --surface-sunken: #071009;
  --border: #24402f;
  --border-strong: #4a6c5d;

  --forest: #eaf1ec;
  --text: #cfdbd4;
  --text-strong: #f4faf6;
  --muted: #8fa398;

  /* Electric accents */
  --cobalt: #2f5cf6;
  --cobalt-hover: #3f6dff;
  --cobalt-soft: #12224d;
  --cobalt-text: #82a8ff;
  --mint: #3ddc97;
  --mint-soft: #0c2b1e;
  --sage: #10231b;
  --sage-strong: #1f3c30;

  /* Status */
  --ok-soft: #0c2b1e;
  --ok-text: #3ddc97;
  --warn-soft: #2e2513;
  --warn-text: #f0c66f;
  --warn-border: #4d4026;
  --danger: #f97066;
  --danger-text: #ff9c93;
  --danger-soft: #33191a;

  /* Component-specific tokens */
  --nav-active-bg: #2f5cf6;
  --nav-active-fg: #ffffff;
  --btn2-bg: #10231b;
  --btn2-fg: #dcefe4;
  --btn2-border: #4a6c5d;
  --toast-bg: #0e1f18;
  --toast-fg: #eaf1ec;
  --dot-idle: #4a6c5d;

  --focus: #3ddc97;
  --glow-cobalt: 0 8px 28px -8px rgba(47, 92, 246, 0.55);
  --glow-mint: 0 8px 28px -8px rgba(61, 220, 151, 0.35);
  --card-ring: inset 0 1px 0 rgba(184, 255, 222, 0.07);
  --shadow-sm: var(--card-ring), 0 1px 2px rgba(0, 0, 0, 0.5);
  --shadow: var(--card-ring), 0 1px 2px rgba(0, 0, 0, 0.5),
    0 20px 44px -22px rgba(0, 0, 0, 0.85);
  --shadow-raised: var(--card-ring), 0 2px 6px rgba(0, 0, 0, 0.55),
    0 26px 52px -24px rgba(0, 0, 0, 0.9);
}

/* --------------------------------------------------------------------------
   Base
   -------------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  transition: background-color 0.25s ease, color 0.25s ease;
}

/* Dark: faint cobalt + mint aurora so the near-black feels deep, not flat */
[data-theme="dark"] body {
  background:
    radial-gradient(1100px 560px at 88% -12%, rgba(47, 92, 246, 0.13), transparent 62%),
    radial-gradient(900px 520px at -12% 108%, rgba(61, 220, 151, 0.08), transparent 58%),
    var(--bg);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  color: var(--text-strong);
  line-height: 1.2;
  margin: 0 0 0.5em;
}

h2 {
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

p {
  margin: 0 0 0.75em;
}

a {
  color: var(--cobalt-text);
}

/* Amounts and anything numeric align in columns */
.num,
.stat-value,
td.num,
th.num,
.summary {
  font-variant-numeric: tabular-nums;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 60;
  background: var(--cobalt);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 12px;
}

:focus-visible {
  /* No border-radius override here: it would squash every field's own
     corner radius while focused. Outlines follow each element's radius. */
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[data-theme="dark"] :focus-visible {
  box-shadow: 0 0 20px -4px color-mix(in srgb, var(--focus) 55%, transparent);
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   Header & navigation
   -------------------------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

/* Dark: hairline highlight on the header edge keeps it crisp on near-black */
[data-theme="dark"] .app-header {
  box-shadow: 0 1px 0 rgba(184, 255, 222, 0.06), 0 14px 36px -28px rgba(0, 0, 0, 0.9);
}

.header-inner {
  max-width: 1140px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  color: var(--cobalt);
  font-size: 0.95rem;
  transform: translateY(-1px);
}

[data-theme="dark"] .brand-mark {
  color: var(--mint);
  text-shadow: 0 0 14px rgba(61, 220, 151, 0.6);
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-strong);
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
  padding: 4px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.nav-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.nav-btn:hover {
  color: var(--text-strong);
  background: color-mix(in srgb, var(--sage) 70%, transparent);
}

.nav-btn.is-active {
  background: var(--nav-active-bg);
  color: var(--nav-active-fg);
  box-shadow: var(--shadow-sm), 0 4px 16px -6px color-mix(in srgb, var(--nav-active-bg) 75%, transparent);
}

.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-strong);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--sage);
  border-color: var(--sage-strong);
}

.icon-btn:active {
  transform: scale(0.96);
}

[data-theme="light"] .icon-sun,
[data-theme="dark"] .icon-moon {
  display: none;
}

/* --------------------------------------------------------------------------
   Layout / views
   -------------------------------------------------------------------------- */

main {
  max-width: 1140px;
  margin: 0 auto;
  padding: 52px 28px 88px;
}

main:focus {
  outline: none;
}

.view > * + * {
  margin-top: 28px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .card {
  box-shadow: var(--shadow);
}

/* --------------------------------------------------------------------------
   Dashboard
   -------------------------------------------------------------------------- */

.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cobalt-text);
  margin-bottom: 10px;
}

/* Dark: mint eyebrow sets the electric-accent tone */
[data-theme="dark"] .eyebrow {
  color: var(--mint);
  text-shadow: 0 0 18px rgba(61, 220, 151, 0.35);
}

.headline {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--text-strong);
  margin: 0 0 14px;
  max-width: 16ch;
}

/* Dark: the hero headline tints cobalt → mint, like a fintech logotype */
[data-theme="dark"] .headline {
  background: linear-gradient(105deg, var(--text-strong) 12%, #a9c1ff 62%, var(--mint) 108%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 42px rgba(61, 220, 151, 0.18);
}

.lede {
  font-size: 1.05rem;
  color: var(--muted);
  max-width: 56ch;
  margin-bottom: 26px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 34px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 22px;
  margin-bottom: 30px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

[data-theme="dark"] .stat-card {
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border-strong);
}

/* Dark: stat cards pick up a soft cobalt glow on hover */
[data-theme="dark"] .stat-card:hover {
  box-shadow: var(--shadow), var(--glow-cobalt);
  border-color: color-mix(in srgb, var(--cobalt) 45%, var(--border));
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.stat-value {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-strong);
  line-height: 1.1;
  margin: 0 0 6px;
  word-break: break-word;
}

.stat-sub {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0;
}

.privacy-note {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--sage);
  border: 1px solid var(--sage-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.privacy-note p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 650;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--cobalt);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Dark: primary actions carry the electric cobalt glow */
[data-theme="dark"] .btn-primary {
  box-shadow: var(--glow-cobalt);
}

.btn-primary:hover:not(:disabled) {
  background: var(--cobalt-hover);
  box-shadow: 0 6px 18px -8px rgba(29, 78, 216, 0.55);
}

[data-theme="dark"] .btn-primary:hover:not(:disabled) {
  box-shadow: var(--glow-cobalt), 0 0 0 1px color-mix(in srgb, var(--cobalt) 60%, transparent);
}

.btn-secondary {
  background: var(--btn2-bg);
  color: var(--btn2-fg);
  border-color: var(--btn2-border);
}

.btn-secondary:hover:not(:disabled) {
  filter: brightness(0.97);
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--sage);
  color: var(--text-strong);
}

.btn-lg {
  font-size: 1rem;
  padding: 13px 24px;
  border-radius: 12px;
}

.btn-edit {
  background: transparent;
  color: var(--cobalt-text);
  border-color: var(--border-strong);
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-edit:hover:not(:disabled) {
  background: var(--cobalt-soft);
  border-color: var(--cobalt-text);
}

.btn-danger {
  background: transparent;
  color: var(--danger-text);
  border-color: var(--border-strong);
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger-text);
}

.btn-review {
  background: transparent;
  color: var(--warn-text);
  border-color: var(--warn-border);
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-review:hover:not(:disabled) {
  background: var(--warn-soft);
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field label {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text-strong);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 16px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="search"],
select {
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

[data-theme="dark"] input,
[data-theme="dark"] select {
  background: var(--surface-sunken);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

input:hover,
select:hover {
  border-color: var(--muted);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--cobalt);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cobalt) 25%, transparent);
}

/* Dark: focus rings glow against near-black */
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cobalt) 35%, transparent),
    0 0 18px -6px color-mix(in srgb, var(--cobalt) 80%, transparent);
}

input:disabled,
select:disabled {
  background: var(--surface-sunken);
  opacity: 0.6;
  cursor: not-allowed;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
  flex-wrap: wrap;
}

.hint {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 18px;
}

.confirm-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 16px 0 0;
}

/* Uncertain-field flag */
.flag {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--warn-text);
  background: var(--warn-soft);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  white-space: nowrap;
}

.field:has(.flag:not([hidden])) input,
.field:has(.flag:not([hidden])) select {
  border-color: var(--warn-text);
  background: var(--warn-soft);
}

[data-theme="dark"] .field:has(.flag:not([hidden])) input,
[data-theme="dark"] .field:has(.flag:not([hidden])) select {
  background: var(--surface-sunken);
}

/* --------------------------------------------------------------------------
   Upload: file drop, stepper, statuses
   -------------------------------------------------------------------------- */

.stepper {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 0 0 20px;
  padding: 0;
  counter-reset: step;
}

.step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  min-width: 0;
}

.step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: var(--dot-idle);
  color: var(--text-strong);
  font-size: 0.72rem;
  font-weight: 700;
  transition: background-color 0.2s ease;
}

.step-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.step.is-active {
  border-color: var(--cobalt);
  background: var(--cobalt-soft);
  color: var(--text-strong);
}

.step.is-active .step-dot {
  background: var(--cobalt);
  color: #fff;
  animation: pulse 1.4s ease-in-out infinite;
}

.step.is-done .step-dot {
  background: var(--forest);
  color: var(--bg);
}

[data-theme="dark"] .step.is-done .step-dot {
  background: var(--ok-text);
  color: #050b08;
  box-shadow: 0 0 12px -3px color-mix(in srgb, var(--mint) 85%, transparent);
}

.step.is-done {
  color: var(--text-strong);
  background: var(--surface);
  border-color: var(--sage-strong);
}

.step.is-error {
  border-color: var(--danger-text);
  background: var(--danger-soft);
  color: var(--danger-text);
}

.step.is-error .step-dot {
  background: var(--danger-text);
  color: #fff;
}

[data-theme="dark"] .step.is-error .step-dot {
  color: #1c0a09;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 92, 246, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(47, 92, 246, 0); }
}

.upload-row {
  display: flex;
  gap: 14px;
  align-items: stretch;
  flex-wrap: wrap;
}

.file-drop {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 22px 18px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.file-drop:hover {
  border-color: var(--cobalt);
  background: var(--cobalt-soft);
}

.file-drop:focus-within {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.file-drop input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-drop-title {
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text-strong);
}

.file-drop-types {
  font-size: 0.78rem;
  color: var(--muted);
}

.upload-row .btn {
  align-self: center;
}

.ai-status {
  font-size: 0.86rem;
  margin: 16px 0 0;
  padding-left: 18px;
  position: relative;
  color: var(--muted);
}

.ai-status::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.45em;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot-idle);
}

.ai-status.ok {
  color: var(--ok-text);
}

.ai-status.ok::before { background: var(--ok-text); }

.ai-status.warn {
  color: var(--warn-text);
}

.ai-status.warn::before { background: var(--warn-text); }

.ai-status.error {
  color: var(--danger-text);
}

.ai-status.error::before { background: var(--danger-text); }

.scan-status {
  font-size: 0.86rem;
  color: var(--cobalt-text);
  font-weight: 600;
  margin: 8px 0 0;
}

.scan-status:not([hidden])::before {
  content: "◍ ";
  animation: spin 1.1s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   Review: preview beside fields
   -------------------------------------------------------------------------- */

.review-split {
  display: grid;
  grid-template-columns: minmax(240px, 340px) 1fr;
  gap: 24px;
  margin-top: 22px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  align-items: start;
}

.doc-preview {
  margin: 0;
  position: sticky;
  top: 86px;
}

.preview-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.preview-box {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 160px;
  max-height: 420px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-box img {
  display: block;
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.preview-placeholder {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.preview-caption {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 8px 0 0;
  word-break: break-all;
}

.review-empty {
  font-size: 0.92rem;
  color: var(--muted);
  background: var(--surface-sunken);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 18px;
}

.review-banner {
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
  border: 1px solid transparent;
}

.review-banner.ok {
  background: var(--ok-soft);
  border-color: var(--sage-strong);
  color: var(--ok-text);
}

.review-banner.warn {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.review-banner.error {
  background: var(--danger-soft);
  border-color: var(--danger-text);
  color: var(--danger-text);
}

/* --------------------------------------------------------------------------
   Expense list: toolbar, table, chips
   -------------------------------------------------------------------------- */

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.list-header h2 {
  margin: 0;
}

.summary {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.field-search {
  flex: 1 1 200px;
  min-width: 170px;
}

.toolbar select {
  width: auto;
  min-width: 140px;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.check-chip:hover {
  border-color: var(--muted);
}

.check-chip:has(input:checked) {
  background: var(--cobalt-soft);
  border-color: var(--cobalt-text);
  color: var(--cobalt-text);
}

.check-chip input {
  accent-color: var(--cobalt);
  width: 15px;
  height: 15px;
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

#expense-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.93rem;
}

#expense-table thead {
  background: var(--surface-sunken);
}

#expense-table th,
#expense-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

#expense-table th {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

#expense-table td.num,
#expense-table th.num {
  text-align: right;
}

#expense-table tbody tr {
  background: var(--surface);
  transition: background-color 0.12s ease;
}

#expense-table tbody tr:hover {
  background: var(--surface-sunken);
}

#expense-table tbody tr:last-child td {
  border-bottom: 0;
}

#expense-table tbody tr.row-flagged td:first-child {
  box-shadow: inset 3px 0 0 var(--warn-text);
}

.th-sort {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 4px;
}

.th-sort:hover {
  color: var(--cobalt-text);
}

th.num .th-sort {
  flex-direction: row-reverse;
}

.sort-arrow {
  font-size: 0.85em;
  min-width: 0.9em;
  text-align: center;
}

th[aria-sort="ascending"] .th-sort,
th[aria-sort="descending"] .th-sort {
  color: var(--cobalt-text);
}

.merchant-name {
  font-weight: 650;
  color: var(--text-strong);
  /* Break unbroken strings (URLs, order numbers) instead of stretching
     the table cell sideways — `anywhere` counts toward min-content width. */
  overflow-wrap: anywhere;
}

.cell-merchant .chip-review {
  display: inline-block;
  margin-top: 5px;
}

/* Category chips — subtle, tinted per category */
.chip {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 650;
  line-height: 1.3;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--sage);
  color: var(--text);
  border: 1px solid transparent;
  white-space: nowrap;
}

.chip-review {
  background: var(--warn-soft);
  color: var(--warn-text);
  border-color: var(--warn-border);
}

.chip-meals { background: #fdf0e1; color: #8a5216; border-color: #f3ddc0; }
.chip-travel { background: #e7eefc; color: #1d4ed8; border-color: #cfdbf7; }
.chip-office-supplies { background: #ddebe1; color: #1f5136; border-color: #c6dfd0; }
.chip-software-subscriptions { background: #ede9fb; color: #5544c0; border-color: #dcd5f5; }
.chip-utilities { background: #e4f2f5; color: #0e6c85; border-color: #c9e4ea; }
.chip-rent-housing { background: #f6e9ea; color: #8f3a46; border-color: #ecd2d5; }
.chip-marketing { background: #fcebf3; color: #9c3a6b; border-color: #f4d4e4; }
.chip-shipping { background: #eef0ea; color: #4c5c33; border-color: #dde1d3; }
.chip-professional-services { background: #eef2f6; color: #3d5570; border-color: #dbe3ec; }
.chip-other { background: var(--surface-sunken); color: var(--muted); border-color: var(--border-strong); }

[data-theme="dark"] .chip {
  background: var(--sage);
  color: var(--text);
  border-color: var(--border-strong);
  filter: brightness(1.15) saturate(0.9);
}

[data-theme="dark"] .chip-review {
  background: var(--warn-soft);
  color: var(--warn-text);
  border-color: var(--warn-border);
  filter: none;
}

.actions-cell {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

td.actions-cell {
  text-align: right;
}

.empty-state {
  text-align: center;
  padding: 40px 20px 26px;
  color: var(--muted);
}

.empty-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 4px;
}

.empty-state .btn {
  margin-top: 12px;
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 40px));
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--toast-bg);
  color: var(--toast-fg);
  border: 1px solid color-mix(in srgb, var(--toast-fg) 18%, transparent);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-raised);
  animation: toast-in 0.25s ease;
}

.toast-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 50%;
  background: color-mix(in srgb, var(--toast-fg) 20%, transparent);
  font-size: 0.75rem;
}

.toast-error {
  background: var(--danger-soft);
  color: var(--danger-text);
  border-color: var(--danger-text);
}

.toast-error .toast-icon {
  background: var(--danger-text);
  color: #fff;
}

.toast.is-leaving {
  animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(8px); }
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */

.page-footer {
  border-top: 1px solid var(--border);
  padding: 22px 24px 34px;
}

.page-footer p {
  max-width: 1140px;
  margin: 0 auto;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .review-split {
    grid-template-columns: 1fr;
  }

  .doc-preview {
    position: static;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .header-inner {
    padding: 10px 14px;
    gap: 10px;
  }

  .brand-sub {
    display: none;
  }

  .app-nav {
    order: 3;
    width: 100%;
    margin-left: 0;
    overflow-x: auto;
  }

  .nav-btn {
    flex: 1;
    padding: 8px 7px;
    font-size: 0.85rem;
  }

  main {
    padding: 26px 14px 60px;
  }

  .card {
    padding: 18px;
    border-radius: 14px;
  }

  /* Expense table becomes readable cards */
  .table-wrap {
    border: 0;
    overflow: visible;
  }

  #expense-table,
  #expense-table tbody,
  #expense-table tr,
  #expense-table td {
    display: block;
    width: 100%;
  }

  #expense-table thead {
    display: none;
  }

  #expense-table tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  #expense-table tbody tr:hover {
    background: var(--surface);
  }

  #expense-table tbody tr.row-flagged {
    border-left: 4px solid var(--warn-text);
  }

  #expense-table tbody tr.row-flagged td:first-child {
    box-shadow: none;
  }

  #expense-table td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    text-align: left !important;
    padding: 5px 0;
    border-bottom: 0;
  }

  #expense-table td::before {
    content: attr(data-label);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    flex: none;
  }

  #expense-table td.cell-merchant {
    display: block;
    font-size: 1.05rem;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
  }

  #expense-table td.cell-merchant::before {
    display: none;
  }

  #expense-table td.cell-amount {
    border-top: 1px dashed var(--border);
    margin-top: 6px;
    padding-top: 9px;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-strong);
  }

  #expense-table td.actions-cell {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
  }

  #expense-table td.actions-cell::before {
    display: none;
  }

  .actions-cell .btn {
    flex: 1;
    min-width: 84px;
  }

  .stepper {
    flex-direction: column;
  }

  .hero-actions .btn {
    width: 100%;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar select,
  .field-search {
    width: 100%;
  }

  /* In the column layout a flex-basis would become a height — reset it */
  .field-search {
    flex: 0 0 auto;
  }

  .check-chip {
    justify-content: center;
  }

  .toast-region {
    right: 12px;
    left: 12px;
    bottom: 12px;
    max-width: none;
  }
}

/* ==========================================================================
   Extra pages: Insights · Budgets · History · Data · Settings · Help
   Every colour comes from the theme tokens, so light/dark both work.
   ========================================================================== */

.empty-inline {
  color: var(--muted);
  font-size: 0.92rem;
  margin: 0;
  padding: 6px 0;
}

/* --- Insights --- */

.insight-stats {
  margin-top: 4px;
}

.stat-card.mini {
  padding: 16px 18px;
}

.stat-card.mini .stat-value {
  font-size: 1.5rem;
}

.insight-block {
  margin-top: 26px;
}

.insight-heading {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 190px) 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 7px 0;
}

.bar-label {
  font-size: 0.88rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-track {
  height: 10px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--cobalt);
  border-radius: var(--radius-pill);
  transition: width 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
}

/* Dark: progress bars glow faintly, like a live balance meter */
[data-theme="dark"] .bar-fill,
[data-theme="dark"] .budget-fill {
  box-shadow: 0 0 14px -3px color-mix(in srgb, var(--cobalt) 90%, transparent);
}

[data-theme="dark"] .budget-fill.is-over {
  box-shadow: 0 0 14px -3px color-mix(in srgb, var(--danger-text) 80%, transparent);
}

.bar-value {
  font-size: 0.88rem;
  font-weight: 650;
  color: var(--text-strong);
}

.merchant-list {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.merchant-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: baseline;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
}

.merchant-row:last-child {
  border-bottom: 0;
}

.merchant-rank {
  color: var(--muted);
  font-size: 0.8rem;
}

.merchant-name-cell {
  font-weight: 650;
  color: var(--text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.merchant-amount {
  font-weight: 650;
  color: var(--text-strong);
}

/* --- Budgets --- */

.budget-form {
  margin-bottom: 18px;
  align-items: flex-end;
}

.budget-form .field {
  min-width: 150px;
}

.budget-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--surface-sunken);
  transition: border-color 0.2s ease;
}

.budget-item.is-over {
  border-color: var(--danger-text);
}

.budget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 9px;
}

.budget-name {
  font-weight: 650;
  color: var(--text-strong);
}

.budget-nums {
  font-size: 0.86rem;
  color: var(--muted);
}

.budget-remove {
  margin-left: 8px;
}

.budget-track {
  height: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

.budget-fill {
  height: 100%;
  background: var(--cobalt);
  border-radius: var(--radius-pill);
  transition: width 0.6s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.budget-fill.is-over {
  background: var(--danger-text);
}

.budget-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 7px;
}

.budget-item.is-over .budget-meta {
  color: var(--danger-text);
}

.btn-xs {
  font-size: 0.78rem;
  padding: 4px 10px;
}

/* --- History --- */

.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}

.history-row:last-child {
  border-bottom: 0;
}

.history-date {
  font-size: 0.84rem;
  color: var(--muted);
  white-space: nowrap;
}

.history-name {
  font-weight: 600;
  color: var(--text-strong);
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-ok {
  background: var(--ok-soft);
  color: var(--ok-text);
}

.chip-error {
  background: var(--danger-soft);
  color: var(--danger-text);
}

/* --- Data --- */

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 18px 0 22px;
}

.action-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  background: var(--surface-sunken);
}

.action-card h3 {
  margin: 0;
  font-size: 1rem;
}

.action-card p {
  margin: 0;
  flex: 1;
  font-size: 0.86rem;
  color: var(--muted);
}

.action-card .btn {
  align-self: flex-start;
}

.file-label {
  cursor: pointer;
}

.danger-zone {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  border: 1px solid var(--danger-text);
  background: var(--danger-soft);
  border-radius: 12px;
  padding: 16px 18px;
}

.danger-zone h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  color: var(--danger-text);
}

.danger-zone p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text);
  max-width: 56ch;
}

.danger-zone .btn-danger {
  background: var(--danger-text);
  color: var(--surface);
  border-color: transparent;
  padding: 10px 18px;
  font-size: 0.93rem;
}

.danger-zone .btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
  background: var(--danger-text);
}

/* --- Settings --- */

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-of-type {
  border-bottom: 0;
}

.settings-label h3 {
  margin: 0 0 2px;
  font-size: 1rem;
}

.settings-label p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.settings-row select {
  min-width: 210px;
  width: auto;
}

.settings-model {
  display: flex;
  gap: 10px;
  align-items: center;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.segment {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  padding: 7px 18px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.segment:hover {
  color: var(--text-strong);
}

.segment.is-active {
  background: var(--nav-active-bg);
  color: var(--nav-active-fg);
}

.storage-usage {
  margin: 0;
  font-weight: 650;
  color: var(--text-strong);
  font-size: 0.92rem;
}

/* --- Help --- */

.help-heading {
  font-size: 1rem;
  margin: 24px 0 10px;
}

.help-steps {
  margin: 0 0 18px;
  padding-left: 22px;
  font-size: 0.93rem;
  color: var(--text);
}

.help-steps li {
  margin-bottom: 8px;
}

.help-details {
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  background: var(--surface-sunken);
  overflow: hidden;
}

.help-details summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 650;
  font-size: 0.93rem;
  color: var(--text-strong);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  transition: background-color 0.15s ease;
}

.help-details summary::-webkit-details-marker {
  display: none;
}

.help-details summary:hover {
  background: var(--surface);
}

.help-details summary::after {
  content: "+";
  font-size: 1.15rem;
  line-height: 1;
  color: var(--cobalt-text);
  transition: transform 0.2s ease;
}

.help-details[open] summary {
  border-bottom: 1px solid var(--border);
}

.help-details[open] summary::after {
  transform: rotate(45deg);
}

.help-details > p,
.help-details > ul,
.help-details > .shortcut-list {
  margin: 0;
  padding: 12px 16px 16px;
  font-size: 0.9rem;
  color: var(--text);
}

.help-details ul {
  padding-left: 34px;
}

.help-details li {
  margin-bottom: 6px;
}

.shortcut-list p {
  margin: 6px 0;
}

kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 7px;
  color: var(--text-strong);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
}

/* --- Extra pages: responsive --- */

@media (max-width: 900px) {
  .action-grid {
    grid-template-columns: 1fr;
  }

  .insight-stats {
    grid-template-columns: 1fr;
  }

  .bar-row {
    grid-template-columns: minmax(90px, 130px) 1fr auto;
    gap: 10px;
  }

  .settings-row {
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: start;
  }

  .settings-row select {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 720px) {
  .budget-form .field {
    min-width: 0;
    width: 100%;
  }

  .history-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "name status" "date status";
    row-gap: 2px;
  }

  .history-name {
    grid-area: name;
  }

  .history-date {
    grid-area: date;
  }

  .history-row .chip {
    grid-area: status;
    align-self: center;
  }

  .merchant-row {
    grid-template-columns: auto 1fr;
    grid-template-areas: "rank name" "rank amount";
    row-gap: 2px;
  }

  .merchant-rank {
    grid-area: rank;
  }

  .merchant-name-cell {
    grid-area: name;
  }

  .merchant-amount {
    grid-area: amount;
  }

  .bar-row {
    grid-template-columns: 1fr auto;
    grid-template-areas: "label value" "track track";
    row-gap: 5px;
  }

  .bar-label { grid-area: label; }
  .bar-value { grid-area: value; }
  .bar-track { grid-area: track; }

  .danger-zone {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-model {
    flex-wrap: wrap;
  }

  .segmented {
    align-self: flex-start;
  }
}

/* Static hosted build: account sign-in is not enabled. */

#auth-screen { display: none !important; }

.auth-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 34px 32px 28px;
  box-shadow: var(--shadow);
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  margin-bottom: 18px;
}

.auth-title {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
}

.auth-tabs {
  margin: 16px 0 22px;
  align-self: flex-start;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-hint {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.78rem;
}

.auth-error {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--danger-text);
  background: var(--danger-soft);
  border: 1px solid var(--danger-text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
}

.auth-submit {
  margin-top: 4px;
}

.auth-note {
  margin: 20px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

/* Header chip: who is signed in + sign out */

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 12px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.user-chip-name {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text);
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .user-chip-name {
    display: none;
  }

  .user-chip {
    padding: 4px 6px;
  }

  .auth-card {
    padding: 26px 20px 22px;
  }
}

/* ==========================================================================
   Motion & interactivity
   Every animation below is neutralised by the prefers-reduced-motion
   block at the end of this file.
   ========================================================================== */

/* Section switches: a quick fade so navigation feels responsive */
.view:not([hidden]) {
  animation: view-in 0.22s ease both;
}

/* First-show reveals (the "will-reveal" class is added by ui.js) */
.will-reveal {
  opacity: 0;
}

.will-reveal.is-revealed {
  animation: reveal-up 0.55s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.stat-grid .stat-card.will-reveal.is-revealed:nth-child(2) {
  animation-delay: 0.08s;
}

.stat-grid .stat-card.will-reveal.is-revealed:nth-child(3) {
  animation-delay: 0.16s;
}

@keyframes reveal-up {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes view-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Expense rows: slide in when added, slide out when deleted */
.row-enter {
  animation: row-in 0.4s ease both;
}

.row-exit {
  animation: row-out 0.24s ease forwards;
  pointer-events: none;
}

@keyframes row-in {
  from { opacity: 0; transform: translateY(10px); }
}

@keyframes row-out {
  to { opacity: 0; transform: translateX(-14px) scale(0.98); }
}

/* Review panel: the split, the form, the banner and the preview all
   arrive together when extraction finishes */
.review-split:not([hidden]) {
  animation: rise-in 0.35s ease both;
}

#draft-form:not([hidden]) {
  animation: rise-in 0.4s 0.08s ease both;
}

.review-banner:not([hidden]) {
  animation: banner-in 0.3s ease both;
}

#preview-img:not([hidden]) {
  animation: preview-in 0.45s ease both;
}

@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
}

@keyframes banner-in {
  from { opacity: 0; transform: scale(0.98); }
}

@keyframes preview-in {
  from { opacity: 0; transform: scale(0.96); }
}

/* Stepper: smooth state changes and a pop when a step completes */
.step {
  transition: background-color 0.3s ease, border-color 0.3s ease,
    color 0.3s ease;
}

.step.is-done .step-dot {
  font-size: 0;
}

.step.is-done .step-dot::after {
  content: "✓";
  font-size: 0.72rem;
  animation: pop-in 0.3s ease;
}

@keyframes pop-in {
  from { transform: scale(0.4); opacity: 0; }
}

/* Theme toggle: the incoming icon swings in */
.icon-btn.is-spun .icon {
  animation: icon-spin 0.45s ease;
}

@keyframes icon-spin {
  from { transform: rotate(-120deg) scale(0.5); opacity: 0; }
}

/* Dashboard: clickable stat-card actions with a sliding arrow */
.stat-action {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--cobalt-text);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 650;
  padding: 8px 0 0;
  margin-top: 10px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
}

.stat-action:hover {
  text-decoration: underline;
}

.stat-action .arrow,
.btn .arrow {
  display: inline-block;
  transition: transform 0.2s ease;
}

.stat-action:hover .arrow,
.stat-action:focus-visible .arrow,
.btn:hover .arrow,
.btn:focus-visible .arrow {
  transform: translateX(4px);
}

/* A soft bump when a stat value changes */
.stat-value.is-updated {
  animation: value-bump 0.45s ease;
}

@keyframes value-bump {
  from { opacity: 0.35; transform: translateY(-5px); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
