/* =====================================================================
   Income Manager — design system
   Mobile-first · flat (no gradients) · light & dark · accessible
   ===================================================================== */

:root {
  color-scheme: light;
  --brand: #0F766E;
  --brand-ink: #FFFFFF;
  --brand-soft: color-mix(in srgb, var(--brand) 10%, transparent);
  --brand-line: color-mix(in srgb, var(--brand) 35%, transparent);

  --bg: #F5F6F4;
  --surface: #FFFFFF;
  --surface-2: #F8F9F7;
  --surface-3: #EFF1EE;
  --border: #E2E5E1;
  --border-strong: #CDD2CC;
  --text: #15171A;
  --text-2: #52514E;
  --muted: #74736E;

  --income: #0E7A55;      /* text-safe green for amounts */
  --expense: #B42318;     /* text-safe red for amounts */
  --transfer: #175CD3;
  --reversal: #6E5BCE;
  --success: #067647;  --success-bg: #ECFDF3;
  --warning: #A15C07;  --warning-bg: #FFFAEB;
  --danger:  #B42318;  --danger-bg:  #FEF3F2;
  --info:    #175CD3;  --info-bg:    #EFF8FF;

  /* chart series (validated: see docs) */
  --c-income: #1baf7a;
  --c-expense: #eb6834;
  --c-net: #2a78d6;
  --c-grid: #EBECE9;
  --c-axis: #CFD1CC;
  --c-surface: #FFFFFF;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --sidebar: 248px;
  --topbar: 60px;
  --bottomnav: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
    --bg: #111211; --surface: #1A1A19; --surface-2: #20211F; --surface-3: #282926;
    --border: #2F302D; --border-strong: #42443F;
    --text: #F2F2F0; --text-2: #C3C2B7; --muted: #94938C;
    --income: #4FD1A1; --expense: #FF8A7A; --transfer: #7CB4FF; --reversal: #A99BFF;
    --success: #4FD1A1; --success-bg: #12271F; --warning: #F5B748; --warning-bg: #2A2112;
    --danger: #FF8A7A; --danger-bg: #2E1714; --info: #7CB4FF; --info-bg: #142033;
    --c-income: #199e70; --c-expense: #d95926; --c-net: #3987e5;
    --c-grid: #2A2B28; --c-axis: #3B3D38; --c-surface: #1A1A19;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
  --bg: #111211; --surface: #1A1A19; --surface-2: #20211F; --surface-3: #282926;
  --border: #2F302D; --border-strong: #42443F;
  --text: #F2F2F0; --text-2: #C3C2B7; --muted: #94938C;
  --income: #4FD1A1; --expense: #FF8A7A; --transfer: #7CB4FF; --reversal: #A99BFF;
  --success: #4FD1A1; --success-bg: #12271F; --warning: #F5B748; --warning-bg: #2A2112;
  --danger: #FF8A7A; --danger-bg: #2E1714; --info: #7CB4FF; --info-bg: #142033;
  --c-income: #199e70; --c-expense: #d95926; --c-net: #3987e5;
  --c-grid: #2A2B28; --c-axis: #3B3D38; --c-surface: #1A1A19;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 650; }
p { margin: 0 0 12px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: .9em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .amount, td.money { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mt-0 { margin-top: 0 } .mt-1 { margin-top: 8px } .mt-2 { margin-top: 16px } .mt-3 { margin-top: 24px }
.mb-1 { margin-bottom: 8px } .mb-2 { margin-bottom: 16px }
.gap-1 { gap: 8px } .gap-2 { gap: 16px }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack > * + * { margin-top: 16px; }
.pos { color: var(--income); } .neg { color: var(--expense); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Inline icons default to the text size; component rules below set explicit sizes. */
svg.icon { width: 1em; height: 1em; flex: none; vertical-align: -0.15em; }
.back-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; margin-bottom: 4px; }
.back-link svg { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
:root[data-theme="dark"] .btn-danger { color: #1A1A19; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-lg { min-height: 48px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-group { display: inline-flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- forms */
.form .field, .field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.field-error { font-size: 12.5px; color: var(--danger); margin-top: 4px; }
.req::after { content: " *"; color: var(--danger); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=search], input[type=tel], input[type=url], input:not([type]), select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.invalid input, .invalid select, .invalid textarea, input.invalid { border-color: var(--danger); }
input[type=color] { width: 48px; height: 40px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
input[type=file] { font: inherit; font-size: 14px; max-width: 100%; }
.input-group { display: flex; gap: 6px; align-items: stretch; }
.input-group > input { flex: 1; min-width: 0; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; font-size: 14px; pointer-events: none; }
.input-prefix > input { padding-left: 52px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); flex: none; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.form-section { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 12px; font-weight: 700; }
.amount-input { font-size: 30px !important; font-weight: 700; min-height: 60px !important; font-variant-numeric: tabular-nums; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-3); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  min-height: 38px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-weight: 600; font-size: 14px;
  color: var(--text-2); cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented button[data-type="income"][aria-pressed="true"] { color: var(--income); }
.segmented button[data-type="expense"][aria-pressed="true"] { color: var(--expense); }
.segmented button[data-type="transfer"][aria-pressed="true"] { color: var(--transfer); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); font: inherit; font-size: 13.5px; cursor: pointer; color: var(--text);
}
.chip[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--text); font-weight: 600; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* ---------------------------------------------------------------- alerts / badges */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-info    { background: var(--info-bg);    color: var(--info);    border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert a { color: inherit; font-weight: 600; text-decoration: underline; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-3); color: var(--text-2); white-space: nowrap; line-height: 1.6;
}
.badge svg { width: 12px; height: 12px; }
.badge-income   { background: color-mix(in srgb, var(--income) 13%, transparent);   color: var(--income); }
.badge-expense  { background: color-mix(in srgb, var(--expense) 12%, transparent);  color: var(--expense); }
.badge-transfer { background: color-mix(in srgb, var(--transfer) 12%, transparent); color: var(--transfer); }
.badge-reversal { background: color-mix(in srgb, var(--reversal) 14%, transparent); color: var(--reversal); }
.badge-success  { background: var(--success-bg); color: var(--success); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-danger   { background: var(--danger-bg); color: var(--danger); }
.badge-info     { background: var(--info-bg); color: var(--info); }

/* ---------------------------------------------------------------- app layout */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--border);
  display: none; flex-direction: column; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; min-height: var(--topbar); border-bottom: 1px solid var(--border); }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--brand); color: var(--brand-ink);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 17px; flex: none;
}
.brand img { width: 36px; height: 36px; object-fit: contain; border-radius: 8px; flex: none; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.2; }
.brand-org { font-size: 12px; color: var(--muted); }
.nav { padding: 10px; overflow-y: auto; flex: 1; }
.nav-group { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--text-2);
  font-weight: 550; font-size: 14px; text-decoration: none;
}
.nav a svg { width: 19px; height: 19px; flex: none; }
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--text); font-weight: 650; }
.nav a[aria-current="page"] svg { color: var(--brand); }
.nav .count { margin-left: auto; font-size: 11px; background: var(--danger); color: #fff; border-radius: 999px; padding: 0 6px; }
.sidebar-foot { padding: 10px 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar); display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: color-mix(in srgb, var(--surface) 92%, transparent); border-bottom: 1px solid var(--border);
  backdrop-filter: saturate(1.4) blur(8px);
}
.topbar h1 { font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .mobile-brand { display: flex; align-items: center; gap: 8px; }
.topbar .mobile-brand .brand-mark { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
.topbar .mobile-brand img { width: 30px; height: 30px; object-fit: contain; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.icon-btn {
  position: relative; width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn .dot-count {
  position: absolute; top: 5px; right: 4px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.conn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--success-bg); color: var(--success); border: 0; cursor: pointer; white-space: nowrap;
}
.conn::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conn.offline { background: var(--warning-bg); color: var(--warning); }
.conn.syncing { background: var(--info-bg); color: var(--info); }
.conn .conn-long { display: none; }

.main { padding: 16px 16px calc(var(--bottomnav) + 96px + var(--safe-b)); max-width: 1320px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h2 { font-size: 22px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

.offline-banner {
  display: none; padding: 9px 16px; background: var(--warning-bg); color: var(--warning); font-size: 13.5px; font-weight: 600;
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 25%, transparent); text-align: center;
}
body.is-offline .offline-banner { display: block; }

/* bottom navigation (mobile) */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; height: calc(var(--bottomnav) + var(--safe-b));
  padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(6, 1fr);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted);
  font-size: 11px; font-weight: 600; text-decoration: none;
}
.bottom-nav a svg { width: 22px; height: 22px; }
.bottom-nav a[aria-current="page"] { color: var(--brand); }

/* floating add button */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--bottomnav) + 16px + var(--safe-b)); z-index: 26;
  height: 56px; padding: 0 20px 0 16px; border-radius: 16px; border: 0; background: var(--brand); color: var(--brand-ink);
  font: inherit; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  box-shadow: var(--shadow-lg);
}
.fab svg { width: 24px; height: 24px; }
.fab-menu {
  position: fixed; right: 16px; bottom: calc(var(--bottomnav) + 84px + var(--safe-b)); z-index: 27;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 210px;
}
.fab-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; border: 0; background: transparent; border-radius: 10px;
  font: inherit; font-weight: 600; color: var(--text); cursor: pointer; text-align: left;
}
.fab-menu button:hover { background: var(--surface-3); }
.fab-menu .ico { width: 32px; height: 32px; border-radius: 9px; display: flex; align-items: center; justify-content: center; }
.fab-menu .ico svg { width: 18px; height: 18px; }
.fab-menu .ico.income { background: color-mix(in srgb, var(--income) 14%, transparent); color: var(--income); }
.fab-menu .ico.expense { background: color-mix(in srgb, var(--expense) 13%, transparent); color: var(--expense); }
.fab-menu .ico.transfer { background: color-mix(in srgb, var(--transfer) 13%, transparent); color: var(--transfer); }

@media (min-width: 1024px) {
  .sidebar { display: flex; }
  .shell { margin-left: var(--sidebar); }
  .bottom-nav, .topbar .mobile-brand { display: none; }
  .main { padding: 24px 28px 48px; }
  .topbar { padding: 0 28px; }
  .fab { bottom: 28px; right: 28px; }
  .fab-menu { bottom: 96px; right: 28px; }
  .conn .conn-long { display: inline; }
}
@media (max-width: 1023px) { .topbar h1.page-title { display: none; } }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; flex-wrap: wrap; }
.card-head h3 { font-size: 15px; font-weight: 650; }
.card-head .sub { font-size: 12.5px; color: var(--muted); }
.card-body { padding: 14px 16px 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
/* Grid/flex children must be allowed to shrink, or wide tables/charts push past the screen. */
.grid > *, .stack > *, .stats > * { min-width: 0; }
@media (min-width: 720px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } .grid.span-wide > .wide { grid-column: span 2; } .grid.cols-3-1 { grid-template-columns: 2fr 1fr; } }

/* stat tiles */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { padding: 14px 16px; }
.stat .label { font-size: 12.5px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .label .key { width: 10px; height: 10px; border-radius: 3px; }
.stat .value { font-size: 21px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .value small { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 3px; }
.stat .delta { font-size: 12px; font-weight: 600; margin-top: 2px; color: var(--muted); }
.stat .delta.good { color: var(--success); } .stat .delta.bad { color: var(--danger); }
.stat.hero { grid-column: 1 / -1; }
@media (max-width: 480px) {
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 18px; }
  .stat.hero .value { font-size: 28px; }
}
.stat.hero .value { font-size: 32px; }
@media (min-width: 900px) { .stat.hero { grid-column: span 2; } }
.stat-mini { display: flex; flex-direction: column; gap: 2px; }

/* ---------------------------------------------------------------- filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { width: auto; min-height: 38px; font-size: 14px; padding: 6px 10px; }
.filters .search { flex: 1 1 200px; }
.filters .search input { width: 100%; }
.preset-bar { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.preset-bar::-webkit-scrollbar { display: none; }
.preset-bar button {
  min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface);
  font: inherit; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.preset-bar button[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.filter-panel { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); padding: 14px; margin-bottom: 16px; }
.filter-panel .field { margin: 0; }
.filter-panel label { font-size: 12px; }
.filter-panel input, .filter-panel select { min-height: 38px; font-size: 14px; padding: 6px 10px; }
.loading-frame { opacity: .45; pointer-events: none; transition: opacity .15s; }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table th.r, .table td.r { text-align: right; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--border-strong); background: var(--surface-2); }
.table .sub { display: block; font-size: 12.5px; color: var(--muted); }
.table .cat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.amount { font-weight: 650; white-space: nowrap; }
.amount.income { color: var(--income); } .amount.expense { color: var(--expense); } .amount.transfer { color: var(--transfer); }
.is-reversed { text-decoration: line-through; text-decoration-color: var(--muted); opacity: .75; }

/* mobile transaction list */
.txn-list { list-style: none; margin: 0; padding: 0; }
.txn-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.txn-item:last-child { border-bottom: 0; }
.txn-item:hover { background: var(--surface-2); }
.txn-ico { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.txn-ico svg { width: 20px; height: 20px; }
.txn-ico.income { background: color-mix(in srgb, var(--income) 13%, transparent); color: var(--income); }
.txn-ico.expense { background: color-mix(in srgb, var(--expense) 12%, transparent); color: var(--expense); }
.txn-ico.transfer { background: color-mix(in srgb, var(--transfer) 12%, transparent); color: var(--transfer); }
.txn-ico.reversal { background: color-mix(in srgb, var(--reversal) 14%, transparent); color: var(--reversal); }
.txn-main { flex: 1; min-width: 0; }
.txn-title { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-meta { display: block; font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.txn-amt { text-align: right; flex: none; }
.txn-amt .amount { display: block; font-size: 14.5px; }
.txn-amt .txn-meta { font-size: 12px; }
.only-desktop { display: none; }
@media (min-width: 900px) { .only-desktop { display: block; } .only-mobile { display: none !important; } table.only-desktop { display: table; } }

.totals-bar { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 10px 14px; font-size: 13.5px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.totals-bar b { font-variant-numeric: tabular-nums; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--muted); flex-wrap: wrap; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; color: var(--border-strong); margin-bottom: 8px; }
.empty h3 { color: var(--text); font-size: 16px; margin-bottom: 6px; }

/* key/value list */
.kv { display: grid; grid-template-columns: minmax(110px, 38%) 1fr; gap: 8px 14px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* account rows */
.acct-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.acct-row:last-child { border-bottom: 0; }
.acct-ico { width: 36px; height: 36px; border-radius: 10px; background: var(--surface-3); color: var(--text-2); display: flex; align-items: center; justify-content: center; flex: none; }
.acct-ico svg { width: 18px; height: 18px; }

/* progress (budgets / meters) */
.meter { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--c-net) 16%, transparent); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--c-net); }
.meter.warning { background: color-mix(in srgb, #E8A100 20%, transparent); } .meter.warning > span { background: #D18E00; }
.meter.over { background: color-mix(in srgb, var(--danger) 18%, transparent); } .meter.over > span { background: var(--danger); }
.budget-line { padding: 10px 0; border-bottom: 1px solid var(--border); }
.budget-line:last-child { border-bottom: 0; }
.budget-line .row { justify-content: space-between; margin-bottom: 6px; font-size: 14px; }

/* insights */
.insights { list-style: none; margin: 0; padding: 0; }
.insights li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; align-items: flex-start; }
.insights li:last-child { border-bottom: 0; }
.insights .ins-ico { width: 26px; height: 26px; border-radius: 8px; flex: none; display: flex; align-items: center; justify-content: center; }
.insights .ins-ico svg { width: 15px; height: 15px; }
.ins-success { background: var(--success-bg); color: var(--success); }
.ins-warning { background: var(--warning-bg); color: var(--warning); }
.ins-danger { background: var(--danger-bg); color: var(--danger); }
.ins-info { background: var(--info-bg); color: var(--info); }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button, .tabs a {
  padding: 10px 14px; border: 0; background: none; font: inherit; font-weight: 600; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.tabs [aria-selected="true"] { color: var(--text); border-bottom-color: var(--brand); }

/* menu list (More page) */
.menu-list { list-style: none; margin: 0; padding: 0; }
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--border); color: var(--text);
  text-decoration: none; font: inherit; font-weight: 550; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; cursor: pointer; text-align: left;
}
.menu-list li:last-child a, .menu-list li:last-child button { border-bottom: 0; }
.menu-list a:hover, .menu-list button:hover { background: var(--surface-2); }
.menu-list svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.menu-list .chev { margin-left: auto; width: 16px; height: 16px; }

/* ---------------------------------------------------------------- modal / sheet */
.modal-root { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 14, .5); }
.modal {
  position: relative; width: 100%; max-height: 94vh; display: flex; flex-direction: column; background: var(--surface);
  border-radius: 18px 18px 0 0; box-shadow: var(--shadow-lg); padding-bottom: var(--safe-b);
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-foot .btn { flex: 1 1 auto; }
@media (min-width: 640px) {
  .modal-root { align-items: center; padding: 24px; }
  .modal { max-width: 560px; border-radius: 16px; max-height: 90vh; }
  .modal.wide { max-width: 860px; }
  .modal.narrow { max-width: 420px; }
  .modal-foot .btn { flex: 0 0 auto; }
}

/* toasts */
.toasts { position: fixed; z-index: 80; left: 12px; right: 12px; top: 12px; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 460px; width: 100%; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px;
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 550;
}
.toast .t-ico { width: 20px; height: 20px; flex: none; }
.toast.success .t-ico { color: #4FD1A1; } .toast.error .t-ico { color: #FF8A7A; } .toast.warning .t-ico { color: #F5B748; } .toast.info .t-ico { color: #7CB4FF; }
.toast button { margin-left: auto; background: none; border: 0; color: inherit; opacity: .7; cursor: pointer; font: inherit; }
@media (min-width: 1024px) { .toasts { left: auto; right: 24px; top: 72px; align-items: flex-end; } }

/* dropdown */
.dropdown { position: absolute; z-index: 40; min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; }
.dropdown a, .dropdown button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: none; border-radius: 8px;
  font: inherit; font-size: 14px; color: var(--text); cursor: pointer; text-align: left; text-decoration: none;
}
.dropdown a:hover, .dropdown button:hover { background: var(--surface-3); }
.dropdown svg { width: 17px; height: 17px; color: var(--muted); }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }
.dropdown .head { padding: 8px 10px; font-size: 13px; }

/* notifications list */
.notif { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.notif.unread { background: var(--brand-soft); }
.notif .n-title { font-weight: 650; font-size: 14px; }
.notif .n-msg { font-size: 13.5px; color: var(--text-2); }
.notif .n-time { font-size: 12px; color: var(--muted); }

/* update banner & install */
.banner {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--bottomnav) + 84px + var(--safe-b)); z-index: 50; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  font-size: 14px;
}
@media (min-width: 1024px) { .banner { bottom: 24px; left: calc(var(--sidebar) + 24px); right: auto; } }

/* ---------------------------------------------------------------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--c-grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--c-axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .val-label { fill: var(--text-2); font-size: 11px; font-weight: 600; font-family: var(--font); }
.chart .bar, .chart .seg, .chart .hit { cursor: default; }
.chart .bar:hover, .chart .seg:hover, .chart .bar.hover { filter: brightness(1.08); }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; opacity: .5; pointer-events: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12.5px; color: var(--text-2); margin-top: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.chart-legend i.line { height: 3px; width: 14px; border-radius: 2px; }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 8px 10px; font-size: 12.5px; min-width: 140px; color: var(--text); white-space: nowrap;
}
.chart-tip .tip-title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chart-tip .tip-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .tip-row b { font-variant-numeric: tabular-nums; }
.chart-tip .tip-row i { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-tip .tip-row span { color: var(--muted); }
.chart { container-type: inline-size; }
/* Doughnut + legend side by side only when the CARD is wide enough (not the screen). */
.donut-wrap { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: center; }
.donut-wrap > * { min-width: 0; }
@container (min-width: 440px) { .donut-wrap { grid-template-columns: 170px minmax(0, 1fr); } }
.donut-legend { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); }
.donut-legend li:last-child { border-bottom: 0; }
.donut-legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.donut-legend .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-legend .vl { font-variant-numeric: tabular-nums; font-weight: 600; }
.donut-legend .pc { color: var(--muted); width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.table-toggle { font-size: 12.5px; }

/* report view */
.report-paper { padding: 20px; }
.report-header { display: flex; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.report-header .org { display: flex; gap: 12px; align-items: center; }
.report-header img { max-height: 48px; max-width: 120px; object-fit: contain; }
.report-header h2 { font-size: 20px; }
.report-summary { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-bottom: 18px; }
.report-summary .rs { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); }
.report-summary .rs .l { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 650; }
.report-summary .rs .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.report-section { margin-top: 22px; }
.report-section h3 { font-size: 15px; margin-bottom: 10px; }
.report-signoff { display: none; }

/* ---------------------------------------------------------------- auth pages */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-wrap { width: 100%; max-width: 420px; }
.install-wrap { max-width: 620px; }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; justify-content: center; }
.auth-brand .brand-mark { width: 44px; height: 44px; font-size: 20px; border-radius: 12px; }
.auth-logo { width: 48px; height: 48px; object-fit: contain; }
.auth-app { font-weight: 750; font-size: 19px; }
.auth-org { font-size: 13px; color: var(--muted); }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px 22px; box-shadow: var(--shadow); }
.auth-title { font-size: 21px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 14px; margin-bottom: 18px; }
.auth-links { text-align: center; margin: 16px 0 0; font-size: 14px; }
.auth-tagline { text-align: center; color: var(--muted); font-size: 13px; margin-top: 18px; letter-spacing: .02em; }
.req { margin-bottom: 16px; font-size: 14px; }
.req summary { cursor: pointer; font-weight: 600; }
.req-list { list-style: none; padding: 8px 0 0; margin: 0; }
.req-list li { display: flex; gap: 8px; padding: 3px 0; }
.req-list li span { width: 18px; font-weight: 700; }
.req-list .ok span { color: var(--success); } .req-list .bad { color: var(--danger); } .req-list .warn span { color: var(--warning); }

/* boot / splash */
.boot { min-height: 70vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition: none !important; } }

/* ---------------------------------------------------------------- print */
@media print {
  /* A4 portrait by default; reports with wide tables switch to landscape (named page). */
  @page { size: A4 portrait; margin: 12mm 11mm 14mm;
    @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 8pt system-ui, sans-serif; color: #666; } }
  @page wide { size: A4 landscape; margin: 11mm 12mm 13mm;
    @bottom-right { content: "Page " counter(page) " of " counter(pages); font: 8pt system-ui, sans-serif; color: #666; } }
  /* Always print with the light palette, even when the screen is in dark mode. */
  html:root, html:root[data-theme] {
    color-scheme: light; --bg: #fff; --surface: #fff; --surface-2: #F8F9F7; --surface-3: #EFF1EE; --border: #E2E5E1; --border-strong: #CDD2CC;
    --text: #15171A; --text-2: #52514E; --muted: #74736E; --income: #0E7A55; --expense: #B42318;
    --c-income: #1baf7a; --c-expense: #eb6834; --c-net: #2a78d6; --c-grid: #EBECE9; --c-axis: #CFD1CC; --c-surface: #fff;
  }
  html, body { background: #fff !important; color: #000; font-size: 9pt; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .sidebar, .topbar, .bottom-nav, .fab, .fab-menu, .toasts, .banner, .offline-banner, .no-print, .filters, .filter-panel, .modal-root, #fab-host, .table-toggle { display: none !important; }
  .shell { margin: 0 !important; }
  .main { padding: 0 !important; max-width: none; }
  .card { border: 0; box-shadow: none; }
  a { color: inherit; text-decoration: none; }

  .report-paper { padding: 0; }
  /* The whole document switches page so no blank page is inserted before/after the report. */
  body:has(.report-paper.wide) { page: wide; }
  .report-header { padding-bottom: 8px; margin-bottom: 10px; break-inside: avoid; }
  .report-header h2 { font-size: 15pt; }
  .report-header img { max-height: 40px; }
  .report-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; break-inside: avoid; }
  .report-paper.wide .report-summary { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .report-summary .rs { padding: 5px 8px; border-radius: 6px; }
  .report-summary .rs .l { font-size: 6.5pt; }
  .report-summary .rs .v { font-size: 10.5pt; }
  .report-paper .alert { padding: 5px 8px; margin-bottom: 8px; }

  /* Sections flow continuously — only headings, charts and single rows are kept whole. */
  .report-section { margin-top: 12px; break-inside: auto; }
  .report-section h3 { font-size: 10.5pt; margin-bottom: 4px; break-after: avoid; }
  .report-paper .grid { gap: 10px; }
  .report-paper .grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-paper .chart, .report-paper .report-section:has(> .chart), .report-paper .report-section:has(> ul) { break-inside: avoid; }
  .donut-wrap { grid-template-columns: 105px minmax(0, 1fr); gap: 8px; }
  .donut-wrap > * { min-width: 0; }
  .donut-wrap svg { max-width: 105px !important; }
  .donut-legend { font-size: 7.5pt; }
  .donut-legend li { padding: 2px 0; }
  .donut-legend .pc { width: 36px; }
  .chart-legend { font-size: 7.5pt; margin-top: 4px; }

  .report-paper .table-wrap { overflow: visible; }
  .report-paper table.table { font-size: 8pt; width: 100%; }
  .report-paper .table th { font-size: 6.8pt; padding: 4px 5px; background: #F1F5F9 !important; }
  .report-paper .table td { padding: 3px 5px; line-height: 1.3; }
  .report-paper .table td.num, .report-paper .table td.date { white-space: nowrap; }
  .report-paper thead { display: table-header-group; }   /* column headings repeat on each page */
  .report-paper tfoot { display: table-row-group; }      /* the Total row prints once, at the end */
  .report-paper tr { break-inside: avoid; }
  .report-paper tfoot td { border-top: 1.5px solid #555; }

  .report-signoff { display: flex; gap: 28px; margin-top: 28px; font-size: 9pt; break-inside: avoid; }
  .report-signoff div { flex: 1; border-top: 1px solid #999; padding-top: 5px; }
}
