/* ==========================================================================
   Boop Web Helper — stylesheet
   Boop's own design language: warm cream ground, white cards, BoopOrange.
   ========================================================================== */

:root {
  --ground: #FFF8F0;
  --surface: #FFFFFF;
  --surface-2: #FBF1E6;
  --surface-3: #F4E7D8;
  --ink: #1A1512;
  --ink-2: #636366;
  --ink-3: #9A948E;
  --hair: #E9DCCD;
  --hair-strong: #D9C8B3;
  --accent: #F58E39;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(245, 142, 57, 0.14);
  --accent-soft-2: rgba(245, 142, 57, 0.24);
  --income: #4CAF50;
  --income-soft: rgba(76, 175, 80, 0.14);
  --expense: #E57373;
  --expense-soft: rgba(229, 115, 115, 0.14);
  --warn: #E0A030;
  --warn-soft: rgba(224, 160, 48, 0.16);
  --info-soft: rgba(66, 133, 244, 0.12);
  --info: #4285F4;
  --shadow: 0 1px 2px rgba(26, 21, 18, 0.04), 0 10px 30px rgba(26, 21, 18, 0.06);
  --shadow-lg: 0 24px 60px rgba(26, 21, 18, 0.18);
  --overlay: rgba(26, 21, 18, 0.35);
  --toast-bg: #1A1512;
  --toast-ink: #FFF8F0;
  --toast-action: rgba(255, 255, 255, 0.16);
  --radius: 18px;
  --radius-lg: 22px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --sidebar-w: 256px;
  --font: 'Nunito', 'SF Pro Rounded', ui-rounded, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #0A0A0A;
    --surface: #1C1C1E;
    --surface-2: #242224;
    --surface-3: #2E2B2C;
    --ink: #F2EBE4;
    --ink-2: #A8A19A;
    --ink-3: #6F6963;
    --hair: #2E2A28;
    --hair-strong: #3D3835;
    --accent: #FFAB66;
    --accent-ink: #1A1512;
    --accent-soft: rgba(255, 171, 102, 0.16);
    --accent-soft-2: rgba(255, 171, 102, 0.28);
    --income: #66BB6A;
    --income-soft: rgba(102, 187, 106, 0.18);
    --expense: #EF8A8A;
    --expense-soft: rgba(239, 138, 138, 0.18);
    --warn: #F0B54A;
    --warn-soft: rgba(240, 181, 74, 0.18);
    --info: #6FA3FF;
    --info-soft: rgba(111, 163, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
    --overlay: rgba(0, 0, 0, 0.55);
    --toast-bg: #F2EBE4;
    --toast-ink: #1A1512;
    --toast-action: rgba(0, 0, 0, 0.1);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --ground: #0A0A0A;
  --surface: #1C1C1E;
  --surface-2: #242224;
  --surface-3: #2E2B2C;
  --ink: #F2EBE4;
  --ink-2: #A8A19A;
  --ink-3: #6F6963;
  --hair: #2E2A28;
  --hair-strong: #3D3835;
  --accent: #FFAB66;
  --accent-ink: #1A1512;
  --accent-soft: rgba(255, 171, 102, 0.16);
  --accent-soft-2: rgba(255, 171, 102, 0.28);
  --income: #66BB6A;
  --income-soft: rgba(102, 187, 106, 0.18);
  --expense: #EF8A8A;
  --expense-soft: rgba(239, 138, 138, 0.18);
  --warn: #F0B54A;
  --warn-soft: rgba(240, 181, 74, 0.18);
  --info: #6FA3FF;
  --info-soft: rgba(111, 163, 255, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
  --overlay: rgba(0, 0, 0, 0.55);
  --toast-bg: #F2EBE4;
  --toast-ink: #1A1512;
  --toast-action: rgba(0, 0, 0, 0.1);
  color-scheme: dark;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.005em; }
h3 { font-size: 1.02rem; font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, pre, .mono { font-family: var(--mono); font-size: 0.86rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); }
.small { font-size: 0.86rem; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.num { font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

.skip-link { position: absolute; top: -100px; left: 12px; z-index: 300; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; font-weight: 700; }
.skip-link:focus { top: 12px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 22px 16px 18px;
  border-right: 1px solid var(--hair);
  background: var(--ground);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mascot { width: 44px; height: 44px; border-radius: 12px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 1.15rem; }
.brand-sub { font-weight: 600; font-size: 0.8rem; color: var(--ink-2); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  color: var(--ink-2); font-weight: 700; text-decoration: none;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav-icon { display: inline-flex; width: 20px; height: 20px; }
.nav-count { margin-left: auto; font-size: 0.75rem; font-weight: 800; color: var(--ink-3); background: var(--surface-3); padding: 1px 8px; border-radius: 999px; }
.nav-count:empty { display: none; }
.nav-item[aria-current="page"] .nav-count { background: var(--accent-soft-2); color: var(--accent); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 12px; padding: 0 4px; }
.theme-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; border-radius: 12px; border: 1px solid var(--hair);
  background: var(--surface); color: var(--ink); font-weight: 700;
}
.theme-toggle:hover { border-color: var(--hair-strong); }
.theme-icon { display: inline-flex; width: 18px; height: 18px; }
.privacy-line { display: flex; gap: 8px; align-items: flex-start; font-size: 0.78rem; color: var(--ink-2); line-height: 1.35; }
.privacy-icon { display: inline-flex; flex: none; width: 16px; height: 16px; margin-top: 1px; color: var(--accent); }
.privacy-icon svg { width: 16px; height: 16px; }
.sidebar-links { font-size: 0.78rem; color: var(--ink-3); }
.sidebar-links a { color: var(--ink-2); }

.main { padding: 36px 44px 80px; min-width: 0; }
.main:focus { outline: none; }
.screen { max-width: 1200px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head .lead { color: var(--ink-2); margin-top: 6px; max-width: 64ch; font-weight: 600; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { display: flex; align-items: center; gap: 8px; }
.card-tight { padding: 14px 16px; }
.card-flat { box-shadow: none; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 0.82rem; font-weight: 700; color: var(--ink-2); }
.stat-value { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 0.82rem; color: var(--ink-3); font-weight: 600; }

.callout { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--ink); border: 1px solid transparent; }
.callout .icon { color: var(--accent); flex: none; margin-top: 2px; }
.callout-info { background: var(--info-soft); }
.callout-info .icon { color: var(--info); }
.callout-warn { background: var(--warn-soft); }
.callout-warn .icon { color: var(--warn); }
.callout-danger { background: var(--expense-soft); }
.callout-danger .icon { color: var(--expense); }
.callout-ok { background: var(--income-soft); }
.callout-ok .icon { color: var(--income); }
.callout p { margin: 0; }
.callout p + p { margin-top: 6px; }
.callout strong { font-weight: 800; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 12px;
  border: 1px solid transparent; font-weight: 700; font-size: 0.95rem;
  background: var(--surface-2); color: var(--ink); white-space: nowrap;
  transition: background 0.15s var(--ease), transform 0.08s var(--ease), border-color 0.15s var(--ease), opacity 0.15s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn .icon { display: inline-flex; }
.btn .icon svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 18px rgba(245, 142, 57, 0.28); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.05); }
.btn-secondary { background: var(--surface); border-color: var(--hair); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--hair-strong); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--expense); color: #fff; }
.btn-danger:hover { background: var(--expense); filter: brightness(1.05); }
.btn-danger-soft { background: var(--expense-soft); color: var(--expense); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 0.86rem; border-radius: 10px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 1.08rem; border-radius: 16px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 10px; }
.btn-icon.btn-sm { width: 30px; height: 30px; }
.btn-block { width: 100%; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.chip-income { background: var(--income-soft); color: var(--income); }
.chip-expense { background: var(--expense-soft); color: var(--expense); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-ok { background: var(--income-soft); color: var(--income); }
.chip-tag { height: 22px; padding: 0 8px; font-size: 0.74rem; font-weight: 700; background: var(--surface-3); color: var(--ink-2); }
.chip-currency { font-family: var(--mono); font-weight: 600; letter-spacing: 0.02em; }
.chip-btn { cursor: pointer; border: 1px solid transparent; }
.chip-btn:hover { border-color: var(--hair-strong); }
.chip-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- Forms ---------- */
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--hair); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--hair-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft-2); }
.input::placeholder { color: var(--ink-3); }
.input[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--expense); }
.select { appearance: none; -webkit-appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23636366' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.input-sm, .select-sm { height: 34px; border-radius: 10px; font-size: 0.9rem; }
.input-mono { font-family: var(--mono); font-size: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 700; font-size: 0.88rem; color: var(--ink-2); }
.field-hint { font-size: 0.8rem; color: var(--ink-3); }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline .field-label { color: var(--ink); }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.checkbox { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.field-error { color: var(--expense); font-size: 0.82rem; font-weight: 700; }
.field-warn { color: var(--warn); font-size: 0.82rem; font-weight: 700; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { width: 42px; height: 26px; border-radius: 999px; background: var(--hair-strong); position: relative; transition: background 0.2s var(--ease); flex: none; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.2s var(--ease); }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--accent-soft-2); outline-offset: 2px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { height: 32px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--hair); border-radius: 14px; background: var(--surface); cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 3px; accent-color: var(--accent); }
.radio-card strong { display: block; font-weight: 800; }
.radio-card span { font-size: 0.82rem; color: var(--ink-2); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.swatch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.swatch:has(input:checked) { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.swatch:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Wallet cards ---------- */
.wallet-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.wallet-card {
  position: relative; display: flex; flex-direction: column; gap: 10px; min-height: 156px;
  padding: 18px; border-radius: var(--radius-lg); color: #fff; text-align: left;
  border: 0; box-shadow: var(--shadow); overflow: hidden; cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
  font-family: inherit;
}
.wallet-card::before { content: ''; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,0.18), rgba(0,0,0,0.06) 60%, rgba(0,0,0,0.14)); pointer-events: none; }
.wallet-card::after { content: ''; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; background: rgba(255,255,255,0.12); pointer-events: none; }
.wallet-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.wallet-card > * { position: relative; }
.wallet-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wallet-name { font-weight: 800; font-size: 1.08rem; text-shadow: 0 1px 2px rgba(0,0,0,0.15); }
.wallet-type { font-size: 0.74rem; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,0.22); backdrop-filter: blur(6px); white-space: nowrap; }
.wallet-balance { margin-top: auto; font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; text-shadow: 0 1px 2px rgba(0,0,0,0.15); }
.wallet-balance-label { font-size: 0.74rem; font-weight: 700; opacity: 0.9; }
.wallet-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.8rem; font-weight: 700; opacity: 0.95; }
.wallet-cap { font-family: var(--mono); font-size: 0.74rem; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,0.18); }
.wallet-meta { font-size: 0.78rem; font-weight: 700; opacity: 0.92; }
.wallet-excluded { position: absolute; top: 12px; right: 12px; }
.wallet-card.is-dark-text { color: #1A1512; }
.wallet-card.is-dark-text .wallet-name, .wallet-card.is-dark-text .wallet-balance { text-shadow: none; }
.wallet-card.is-dark-text .wallet-type { background: rgba(0,0,0,0.1); }
.wallet-card.is-dark-text .wallet-cap { background: rgba(0,0,0,0.08); }
.wallet-add {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 156px;
  border: 2px dashed var(--hair-strong); border-radius: var(--radius-lg); background: transparent;
  color: var(--ink-2); font-weight: 800; cursor: pointer; transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.wallet-add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.wallet-add .icon svg { width: 28px; height: 28px; }

.wallet-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: none; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--hair); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 700; }
.list-row .sub { font-size: 0.8rem; color: var(--ink-2); }
.list-row .amount { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }

.simple-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.simple-table th { text-align: left; font-size: 0.78rem; color: var(--ink-2); font-weight: 800; padding: 8px 10px; border-bottom: 1px solid var(--hair); }
.simple-table td { padding: 9px 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
.simple-table tr:last-child td { border-bottom: 0; }
.simple-table .num, .simple-table th.num { text-align: right; }

/* ---------- Empty state ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 48px 20px; text-align: center; color: var(--ink-2); }
.empty img { width: 96px; height: 96px; }
.empty p { font-weight: 700; max-width: 42ch; }
.empty-inline { padding: 20px; }
.empty-inline img { width: 64px; height: 64px; }

/* ---------- Data table (Transactions) ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.toolbar .input, .toolbar .select { width: auto; }
.toolbar .search { flex: 1 1 220px; min-width: 180px; position: relative; }
.toolbar .search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.toolbar .search .input { width: 100%; padding-left: 36px; }
.toolbar .date-range { display: inline-flex; align-items: center; gap: 6px; }
.toolbar .date-range .input { width: 150px; }

.bulk-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); font-weight: 700; }
/* An element carrying the hidden attribute stays hidden whatever display its class sets. */
[hidden] { display: none !important; }

.table-card { padding: 0; overflow: hidden; }
.table-wrap { overflow: auto; max-width: 100%; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; min-width: 1040px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--ink-2); font-size: 0.78rem; font-weight: 800;
  text-align: left; padding: 0; border-bottom: 1px solid var(--hair); white-space: nowrap;
}
.data-table thead th .sort-btn { display: flex; align-items: center; gap: 4px; width: 100%; height: 40px; padding: 0 10px; background: transparent; border: 0; color: inherit; font: inherit; font-weight: 800; text-align: left; }
.data-table thead th .sort-btn:hover { color: var(--ink); }
.data-table thead th[aria-sort] .sort-btn { color: var(--accent); }
.data-table thead th .sort-ind { font-size: 0.7rem; opacity: 0.8; }
.data-table thead th.plain { padding: 0 10px; height: 40px; }
.data-table tbody td { padding: 0; height: 42px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr.is-selected td { background: var(--accent-soft); }
.data-table tbody tr.is-new td { animation: rowIn 0.6s var(--ease); }
@keyframes rowIn { from { background: var(--accent-soft-2); } to { background: transparent; } }
.data-table .cell { display: block; padding: 0 10px; line-height: 42px; height: 42px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table td.editable .cell { cursor: text; }
.data-table td.editable:hover .cell { box-shadow: inset 0 0 0 1px var(--hair-strong); border-radius: 8px; }
.data-table td.is-editing { background: var(--surface); }
.data-table .cell-input { width: 100%; height: 42px; padding: 0 10px; border: 0; border-radius: 0; background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); font: inherit; color: inherit; }
.data-table .cell-input:focus { outline: none; }
.data-table select.cell-input { appearance: none; -webkit-appearance: none; }
.data-table .col-check { width: 40px; text-align: center; }
.data-table .col-check .checkbox { vertical-align: middle; }
.data-table .col-date { width: 118px; }
.data-table .col-type { width: 100px; }
.data-table .col-amount { width: 120px; }
.data-table .col-amount .cell { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; }
.data-table .col-amount .cell-input { text-align: right; }
.data-table .col-currency { width: 84px; }
.data-table .col-status { width: 60px; text-align: center; }
.data-table .col-actions { width: 44px; }
.data-table .col-note .cell { max-width: 220px; }
.data-table .cell-muted { color: var(--ink-3); font-style: italic; }
.data-table .cell-tags { display: flex; gap: 4px; align-items: center; height: 42px; padding: 0 10px; overflow: hidden; }
.data-table .row-delete { opacity: 0; }
.data-table tr:hover .row-delete, .data-table tr:focus-within .row-delete { opacity: 1; }

.issue-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; font-size: 0.74rem; font-weight: 800; cursor: help; }
.issue-badge.err { background: var(--expense-soft); color: var(--expense); }
.issue-badge.warn { background: var(--warn-soft); color: var(--warn); }
.issue-badge.ok { color: var(--income); background: transparent; }

.table-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--hair); background: var(--surface-2); font-size: 0.9rem; }
.sums { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.sums .sum { display: inline-flex; gap: 6px; align-items: baseline; font-weight: 700; }
.sums .sum b { font-weight: 800; font-variant-numeric: tabular-nums; }
.pager { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink-2); }

/* ---------- Drop zone / import ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 240px; padding: 32px; text-align: center;
  border: 2px dashed var(--hair-strong); border-radius: var(--radius-lg);
  background: var(--surface); transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone img { width: 84px; height: 84px; }
.dropzone h2 { font-size: 1.2rem; }
.dropzone p { color: var(--ink-2); font-weight: 600; }
.dropzone .formats { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.dropzone input[type="file"] { position: absolute; opacity: 0; width: 0; height: 0; }

.steps { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.step { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-weight: 800; font-size: 0.86rem; }
.step .n { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--surface-3); font-size: 0.78rem; }
.step.is-active { background: var(--accent-soft); color: var(--accent); }
.step.is-active .n { background: var(--accent); color: var(--accent-ink); }
.step.is-done { color: var(--income); }
.step.is-done .n { background: var(--income-soft); color: var(--income); }
.step-sep { width: 18px; height: 2px; background: var(--hair); border-radius: 2px; }

.source-badge { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 12px; background: var(--surface-2); font-weight: 700; }
.source-badge .icon { color: var(--accent); }

.mapper { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.sample-table { font-family: var(--mono); font-size: 0.78rem; }
.sample-table th { font-family: var(--font); }
.sample-table td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

details.disclosure { border: 1px solid var(--hair); border-radius: 12px; background: var(--surface); }
details.disclosure > summary { cursor: pointer; padding: 12px 14px; font-weight: 800; list-style: none; display: flex; align-items: center; gap: 8px; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::before { content: ''; width: 8px; height: 8px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(-45deg); transition: transform 0.15s; margin: 0 6px 0 2px; }
details.disclosure[open] > summary::before { transform: rotate(45deg); }
details.disclosure > .disclosure-body { padding: 0 14px 14px; }

.pre { margin: 0; padding: 14px 16px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--hair); overflow: auto; max-height: 420px; font-family: var(--mono); font-size: 0.82rem; line-height: 1.5; white-space: pre; color: var(--ink); }

.issue-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.issue-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 0.9rem; }
.issue-list li .icon { flex: none; margin-top: 1px; }
.issue-list li.err .icon { color: var(--expense); }
.issue-list li.warn .icon { color: var(--warn); }
.issue-list .raw { font-family: var(--mono); font-size: 0.76rem; color: var(--ink-3); word-break: break-all; }

/* ---------- Drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 100; animation: fadeIn 0.18s var(--ease); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); z-index: 101; background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slideIn 0.22s var(--ease); border-left: 1px solid var(--hair); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 12px; }
.drawer-body { flex: 1; overflow: auto; padding: 8px 22px 22px; display: flex; flex-direction: column; gap: 14px; }
.drawer-foot { display: flex; gap: 10px; align-items: center; padding: 14px 22px; border-top: 1px solid var(--hair); background: var(--surface); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Dialog ---------- */
dialog.dialog { border: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--ink); padding: 0; width: min(460px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog.dialog::backdrop { background: var(--overlay); }
.dialog-body { padding: 22px 24px 8px; display: flex; flex-direction: column; gap: 10px; }
.dialog-body p { color: var(--ink-2); font-weight: 600; }
.dialog-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px 22px; }

/* ---------- Toasts ---------- */
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px; border-radius: 14px; background: var(--toast-bg); color: var(--toast-ink); font-weight: 700; box-shadow: var(--shadow-lg); pointer-events: auto; animation: toastIn 0.22s var(--ease); max-width: 420px; }
.toast-msg { flex: 1; min-width: 0; }
.toast .icon { flex: none; }
.toast.ok .icon { color: var(--income); }
.toast.err .icon { color: var(--expense); }
.toast.warn .icon { color: var(--warn); }
.toast-action { border: 0; background: var(--toast-action); color: inherit; padding: 6px 10px; border-radius: 8px; font-weight: 800; }
.toast-close { border: 0; background: transparent; color: inherit; opacity: 0.7; padding: 4px; display: inline-flex; }
.toast.is-leaving { animation: toastOut 0.18s var(--ease) forwards; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(8px); opacity: 0; } }

/* ---------- Guide prose ---------- */
.prose { max-width: 76ch; }
.prose h2 { margin: 26px 0 8px; font-size: 1.3rem; }
.prose h3 { margin: 18px 0 6px; }
.prose p { margin: 0 0 10px; color: var(--ink); }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 4px 0; }
.prose code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--hair); font-size: 0.82em; }
.prose pre { margin: 10px 0 14px; }
.prose pre code { padding: 0; border: 0; background: transparent; font-size: inherit; }
.prose table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; font-size: 0.9rem; }
.prose th, .prose td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--hair); vertical-align: top; }
.prose th { font-size: 0.78rem; color: var(--ink-2); }
.prose .kbd { display: inline-block; padding: 1px 7px; border-radius: 6px; border: 1px solid var(--hair-strong); background: var(--surface-2); font-weight: 700; font-size: 0.86em; }
.guide-toc { display: flex; flex-wrap: wrap; gap: 8px; }
.guide-toc a { display: inline-flex; padding: 6px 12px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); font-weight: 700; font-size: 0.86rem; }
.guide-toc a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

/* ---------- Misc ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 0.9rem; }
.kv dt { color: var(--ink-2); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; }
.divider { height: 1px; background: var(--hair); margin: 4px 0; }
.error-panel { padding: 24px; border-radius: var(--radius); background: var(--expense-soft); border: 1px solid var(--expense); }
.error-panel pre { white-space: pre-wrap; }

.boot-error { max-width: 640px; margin: 40px auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .main { padding: 28px 28px 80px; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--hair); }
  .brand { padding: 0; }
  .nav { flex-direction: row; overflow-x: auto; gap: 2px; flex: 1 1 100%; order: 3; }
  .nav-item { padding: 8px 10px; font-size: 0.9rem; flex: none; }
  .nav-count { margin-left: 2px; }
  .sidebar-foot { margin-top: 0; margin-left: auto; flex-direction: row; align-items: center; gap: 12px; }
  .privacy-line { max-width: 220px; }
  .sidebar-links { display: none; }
  .theme-toggle { width: auto; }
  .theme-label { display: none; }
  .main { padding: 22px 18px 60px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
  .toast-region { left: 16px; right: 16px; }
}
