*,
*::before,
*::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, label { font: inherit; color: inherit; touch-action: manipulation; }

.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;
}

.icon { display: block; flex-shrink: 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding:
    max(20px, env(safe-area-inset-top))
    max(var(--gap), env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(var(--gap), env(safe-area-inset-left));
  display: grid;
  /* minmax(0, 1fr): never let intrinsic widths (inputs) stretch the column past the screen */
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: var(--card-pad);
}

.field-label {
  display: block;
  padding: 0;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* ---------- Summary ---------- */

.summary { padding: 4px 4px 0; }
.summary p { margin: 0; }

.summary-label { color: var(--text-muted); font-size: 14px; }

.summary-total {
  margin: 4px 0 0 !important;
  font: 700 clamp(34px, 11.5vw, 48px)/1.1 var(--font-num);
  overflow-wrap: anywhere;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.text-ok { color: var(--text-ok); }
.text-over { color: var(--text-over); }

/* ---------- Month budget ---------- */

.budget { display: grid; gap: 8px; }
.budget-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; }
.budget-label { font-size: 14px; color: var(--text-muted); white-space: nowrap; }
.budget-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.budget-scale { font-weight: 400; color: var(--text-muted); }
.budget-meta { font-size: 13px; color: var(--text-muted); }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- Progress (shared) ---------- */

.progress-row { display: flex; align-items: center; gap: 10px; }

.progress {
  flex: 1;
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-raised);
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--level-fill);
  transition: width 0.3s ease;
}

.progress-pct {
  min-width: 3.2em;
  text-align: right;
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--level-text);
}

.level-ok { --level-fill: var(--accent-ok); --level-text: var(--text-ok); }
.level-warn { --level-fill: var(--accent-warn); --level-text: var(--text-warn); }
.level-high { --level-fill: var(--accent-high); --level-text: var(--text-high); }
.level-over { --level-fill: var(--accent-over); --level-text: var(--text-over); }

/* ---------- Form ---------- */

.expense-form { display: grid; gap: 18px; }

.amount-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: clamp(64px, 19vw, 76px);
  padding: 0 clamp(14px, 4.5vw, 18px);
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--divider);
  transition: border-color 0.15s;
}

.amount-field:focus-within { border-color: var(--border-focus); }

.amount-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: 600 clamp(28px, 9vw, 36px)/1 var(--font-num);
  font-variant-numeric: tabular-nums;
}

.amount-input::placeholder { color: var(--placeholder); }

.amount-currency { font-size: 26px; font-weight: 500; color: var(--text-muted); }

.category-picker { border: 0; margin: 0; padding: 0; min-width: 0; }

.category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--grid-gap);
}

.category-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  min-height: clamp(76px, 23vw, 88px);
  padding: 10px 4px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--divider);
  cursor: pointer;
  text-align: center;
  user-select: none;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.category-option:active { transform: scale(0.97); }

.category-option:has(input:checked) {
  border-color: var(--tone);
  background: color-mix(in srgb, var(--tone) 12%, var(--bg));
}

.category-option:has(input:focus-visible) { outline: 2px solid var(--tone); outline-offset: 2px; }

.category-name {
  max-width: 100%;
  font-size: clamp(11.5px, 3.5vw, 13.5px);
  line-height: 1.2;
  color: var(--text);
  overflow-wrap: anywhere;
  hyphens: auto;
}

.category-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--tone);
  background: color-mix(in srgb, var(--tone) 18%, transparent);
}

.tone-gray { --tone: var(--tone-gray); }
.tone-brown { --tone: var(--tone-brown); }
.tone-orange { --tone: var(--tone-orange); }
.tone-yellow { --tone: var(--tone-yellow); }
.tone-green { --tone: var(--tone-green); }
.tone-blue { --tone: var(--tone-blue); }
.tone-purple { --tone: var(--tone-purple); }
.tone-pink { --tone: var(--tone-pink); }
.tone-red { --tone: var(--tone-red); }

.date-input {
  display: block;
  width: 100%;
  min-width: 0;
  height: var(--tap);
  margin: 0;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--divider);
  background: var(--bg);
  font-size: 16px; /* >=16px prevents iOS zoom on focus */
  line-height: var(--tap);
  -webkit-appearance: none;
  appearance: none;
}

/* iOS Safari centers date value and ignores height without these */
.date-input::-webkit-date-and-time-value { text-align: left; margin: 0; }
.date-input::-webkit-datetime-edit { padding: 0; }

.btn-primary {
  width: 100%;
  height: 60px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--on-primary);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.3; cursor: default; }

.form-status {
  min-height: 20px;
  margin: -8px 0 0;
  font-size: 13px;
  text-align: center;
  color: var(--text-ok);
}

.form-status.is-error { color: var(--text-over); }

/* ---------- Transactions ---------- */

.section-title {
  margin: 0 4px 6px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tx-list { list-style: none; margin: 0; padding: 0; }

.tx-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--divider);
}

.tx-row:last-child { border-bottom: 0; }

.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-time { font-size: 13px; color: var(--text-muted); }

.tx-amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.tx-remove {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  margin-right: -6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.tx-remove:hover, .tx-remove:focus-visible { color: var(--text-over); background: var(--surface); }

.tx-empty { margin: 8px 4px; color: var(--text-muted); font-size: 14px; }



/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -8px -6px -12px 4px;
}

.topbar-title { font-size: 13px; font-weight: 500; color: var(--text-muted); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.icon-btn:hover, .icon-btn:focus-visible { color: var(--text); background: var(--surface); }
.icon-btn:active { background: var(--surface-raised); }
.icon-btn-spacer { width: 44px; flex-shrink: 0; }

/* ---------- Dialogs ---------- */

body:has(dialog[open]) { overflow: hidden; }

dialog { color: var(--text); }

dialog.screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  overflow-y: auto;
  overscroll-behavior: contain;
}

dialog.screen::backdrop { background: var(--bg); }

.screen-inner {
  max-width: 480px;
  margin: 0 auto;
  padding:
    max(12px, env(safe-area-inset-top))
    max(var(--gap), env(safe-area-inset-right))
    max(32px, env(safe-area-inset-bottom))
    max(var(--gap), env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.screen-header {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 -10px;
}

.screen-title {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
}

.screen-sub { margin: 0 4px; font-size: 14px; color: var(--text-muted); }

dialog.sheet {
  width: 100%;
  max-width: 480px;
  max-height: min(92dvh, 92vh);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  overflow: hidden;
}

dialog.sheet::backdrop { background: var(--backdrop); }

.sheet-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  max-height: min(92dvh, 92vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px var(--card-pad) max(20px, env(safe-area-inset-bottom));
}

.sheet-header {
  position: sticky;
  top: -8px;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -8px calc(var(--card-pad) * -1) 0;
  padding: 8px calc(var(--card-pad) - 10px) 0 var(--card-pad);
  background: var(--surface);
}

.sheet-title { margin: 0; font-size: 17px; font-weight: 600; }

/* ---------- Form controls ---------- */

.field { display: grid; gap: 0; min-width: 0; margin: 0; padding: 0; border: 0; }
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.field-error { min-height: 0; font-size: 12.5px; color: var(--text-over); }
.field-error:not(:empty) { margin-top: 6px; }
.field-hint { margin: -8px 0 0; font-size: 12.5px; line-height: 1.4; color: var(--text-muted); }
.field .field-hint { margin: 6px 0 0; }

.text-input {
  width: 100%;
  min-width: 0;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 16px; /* prevents iOS zoom */
  outline: 0;
  transition: border-color 0.15s;
}

.text-input:focus { border-color: var(--border-focus); }
.text-input:disabled { color: var(--text-muted); }
.text-input::placeholder { color: var(--text-faint); }

.money-input { position: relative; display: block; }
.money-input .text-input { padding-right: 34px; font-variant-numeric: tabular-nums; }
.money-suffix {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}

.icon-option { cursor: pointer; }

.icon-tile {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--divider);
  background: var(--bg);
  color: var(--text-muted);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.icon-option:has(input:checked) .icon-tile {
  color: var(--tone);
  border-color: var(--tone);
  background: color-mix(in srgb, var(--tone) 16%, var(--bg));
}

.icon-option:has(input:focus-visible) .icon-tile { outline: 2px solid var(--text); outline-offset: 2px; }

.tone-row { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: clamp(4px, 1.5vw, 10px); }
.tone-option { display: grid; place-items: center; cursor: pointer; }

.tone-swatch {
  display: block;
  width: 100%;
  max-width: 34px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--tone);
  box-shadow: inset 0 0 0 2px var(--surface);
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.tone-option:has(input:checked) .tone-swatch { border-color: var(--text); }
.tone-option:has(input:focus-visible) .tone-swatch { outline: 2px solid var(--text); outline-offset: 2px; }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: var(--tap);
  border: 1px dashed var(--border-dashed);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary:active { background: var(--surface); }

.btn-danger {
  width: 100%;
  height: 48px;
  margin-top: -8px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-over);
  font-weight: 500;
  cursor: pointer;
}

.btn-danger:active { background: color-mix(in srgb, var(--accent-over) 12%, transparent); }

/* ---------- Category list ---------- */

.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-list li + li .cat-row { border-top: 1px solid var(--divider); }

.cat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 12px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.cat-row:active { background: var(--surface); }

.cat-main { flex: 1; min-width: 0; display: grid; gap: 6px; }

.cat-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cat-name { min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-amount { flex-shrink: 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cat-scale { font-weight: 400; color: var(--text-muted); }
.cat-meta { font-size: 12.5px; color: var(--text-muted); }
.cat-chevron { color: var(--text-faint); }

/* ---------- Top bar actions ---------- */

.topbar-actions { display: flex; align-items: center; gap: 2px; }

/* ---------- Emoji ---------- */

.emoji { display: block; line-height: 1; font-family: var(--font-emoji); }

.emoji-field { position: relative; display: block; }

.emoji-preview {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--tone) 18%, transparent);
  font: 22px/1 var(--font-emoji);
  pointer-events: none;
}

.emoji-preview:empty { display: none; }
.emoji-input { font-family: var(--font-emoji), var(--font); }
.emoji-field:has(.emoji-preview:not(:empty)) .emoji-input { padding-left: 52px; color: transparent; caret-color: var(--text); }

.emoji-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}


.icon-grid { margin-top: 10px; transition: opacity 0.15s; }
.icon-grid.is-muted { opacity: 0.35; }

/* ---------- Category picker: view switch + list view ---------- */

.picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.picker-header .field-label { margin: 0; }

.view-switch {
  display: flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--divider);
}

.view-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.view-btn[aria-pressed="true"] { background: var(--surface-raised); color: var(--text); }
.view-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 1px; }

.category-grid.is-list { grid-template-columns: minmax(0, 1fr); gap: 6px; }

.category-grid.is-list .category-option {
  flex-direction: row;
  justify-content: flex-start;
  gap: 12px;
  min-height: 52px;
  padding: 8px 12px;
  text-align: left;
}

.category-grid.is-list .category-icon { width: 32px; height: 32px; }

.category-grid.is-list .category-name {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Global ---------- */

[hidden] { display: none !important; }

.boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---------- Auth ---------- */

.auth { display: grid; gap: 16px; padding-top: 8vh; }
.auth-head { text-align: center; }
.auth-title { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; text-align: center; }
.auth-sub { margin: 6px 0 0; color: var(--text-muted); font-size: 14px; }

.auth-note {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--primary) 14%, var(--surface));
  font-size: 14px;
  line-height: 1.4;
}

.auth-form { display: grid; gap: 14px; }
.auth-error { margin: 0; min-height: 0; font-size: 13.5px; color: var(--text-over); }
.auth-error:empty { display: none; }
.auth-error.is-info { color: var(--text-ok); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--divider);
}

.segmented button {
  height: 40px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
}

.segmented button[aria-selected="true"] { background: var(--surface-raised); color: var(--text); }

/* ---------- Avatars & authors ---------- */

.avatar {
  --avatar-size: 20px;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 50%;
  background: color-mix(in srgb, var(--tone) 24%, var(--surface));
  color: var(--tone);
  font-size: calc(var(--avatar-size) * 0.5);
  font-weight: 700;
  line-height: 1;
}

.tx-meta { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13px; color: var(--text-muted); }
.tx-author { display: inline-flex; align-items: center; gap: 5px; min-width: 0; }
.tx-author > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Account sheet ---------- */

.member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.member-row { display: flex; align-items: center; gap: 12px; }
.member-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-tag {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 12px;
}

.invite-hint { margin: 0 0 10px !important; }
.invite-box { display: grid; gap: 10px; }
.invite-link { font-size: 14px; color: var(--text-muted); }
.invite-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.invite-actions:has(> [hidden]) { grid-template-columns: 1fr; }

.btn-compact { height: 46px; font-size: 15px; }
.btn-secondary.btn-compact { border-style: solid; }

.account-email { margin: 0; font-size: 13px; color: var(--text-muted); text-align: center; }

/* ---------- Import banner ---------- */

.banner { display: grid; gap: 12px; border: 1px solid color-mix(in srgb, var(--primary) 45%, transparent); }
.banner-text { margin: 0; font-size: 14px; line-height: 1.4; }
.banner-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- Analytics ---------- */

.analytics { gap: 14px; }

.period-picker { display: grid; gap: 10px; }

.period-tabs { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.period-tabs button { height: 36px; padding: 0 2px; font-size: clamp(12px, 3.6vw, 14px); }

.period-nav { display: flex; align-items: center; justify-content: space-between; margin: -4px -10px; }
.period-nav .icon-btn:disabled { opacity: 0.25; cursor: default; background: transparent; }
.period-label { flex: 1; text-align: center; font-weight: 600; font-size: 16px; }

.period-range .date-input { height: 48px; line-height: 48px; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { display: grid; gap: 4px; align-content: start; min-width: 0; }
.stat-main { grid-column: 1 / -1; gap: 6px; }
.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value {
  font: 600 clamp(16px, 5vw, 19px)/1.2 var(--font-num);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-value-lg { font-size: clamp(28px, 9vw, 36px); font-weight: 700; letter-spacing: -0.02em; }
.stat-value.is-muted { color: var(--text-faint); font-weight: 500; }

.chart { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.chart-title { margin: 0; font-size: 15px; font-weight: 600; }
.chart-caption { font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.chart-caption-key { color: var(--text-muted); }
.chart-caption-value { font-weight: 600; }
.chart-empty { margin: 0; padding: 24px 0; text-align: center; font-size: 14px; color: var(--text-muted); }

/* Donut */
.donut { position: relative; width: min(220px, 62vw); aspect-ratio: 1; margin: 0 auto; }
.donut-svg { display: block; width: 100%; height: 100%; }
.donut-track { fill: none; stroke: var(--surface-raised); }
.donut-slice { fill: none; stroke: var(--tone); cursor: pointer; transition: opacity 0.2s; }
.donut-slice.is-dim { opacity: 0.22; }
.donut-center {
  position: absolute;
  inset: 22%;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  pointer-events: none;
}
.donut-label { max-width: 100%; font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-value { font: 700 clamp(17px, 5.4vw, 21px)/1.2 var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.donut-sub { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }

.legend { list-style: none; margin: 0 -4px; padding: 0; }
.legend-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 6px 4px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: opacity 0.2s;
}
.legend-row:active { background: var(--surface-raised); }
.legend-row.is-dim { opacity: 0.4; }
.legend-icon { width: 30px; height: 30px; }
.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-pct { min-width: 2.6em; text-align: right; font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.legend-amount { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Bars */
.bars { display: grid; gap: 6px; }
.bars-plot {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--bars), minmax(0, 1fr));
  align-items: end;
  height: 140px;
  border-bottom: 1px solid var(--divider);
}
.bar-col {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 100%;
  padding: 0 clamp(1px, 0.6vw, 3px);
  border: 0;
  background: transparent;
  cursor: pointer;
}
.bar {
  display: block;
  width: 100%;
  max-width: 28px;
  border-radius: 4px 4px 1px 1px;
  background: var(--chart-bar);
  transition: height 0.3s ease, opacity 0.2s;
}
.bar.is-soft { opacity: 0.45; }
.bar.is-dim { opacity: 0.25; }
.bar.is-future { opacity: 0.15; }
.bars-avg {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--text-faint);
  pointer-events: none;
}
.bars-axis { display: grid; grid-template-columns: repeat(var(--bars), minmax(0, 1fr)); }
.bar-label {
  overflow: visible;
  white-space: nowrap;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Overspend ---------- */

.cat-row.is-over {
  margin: 4px 0;
  padding: 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent-over) 9%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-over) 45%, transparent);
}
.cat-row.is-over .cat-amount { color: var(--text-over); }
.cat-list li + li .cat-row.is-over,
.cat-list li:has(.is-over) + li .cat-row { border-top-color: transparent; }

.over-badge {
  flex-shrink: 0;
  padding: 1px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--accent-over) 16%, transparent);
  color: var(--text-over);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.legend-row.is-over { background: color-mix(in srgb, var(--accent-over) 9%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-over) 40%, transparent); }
.legend-row.is-over .legend-amount { color: var(--text-over); }
.legend-row + .legend-row, .legend li + li { margin-top: 2px; }

/* ---------- Overspend card (dashboard) + AI insight ---------- */

.over-card {
  display: grid;
  gap: 10px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-over) 45%, transparent);
  background: color-mix(in srgb, var(--accent-over) 6%, var(--surface));
}
.over-head { display: flex; align-items: center; justify-content: space-between; }
.over-title { font-size: 14px; font-weight: 600; color: var(--text-over); }

.over-list { list-style: none; margin: 0 -6px; padding: 0; }
.over-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 4px 6px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.over-item:active { background: color-mix(in srgb, var(--accent-over) 10%, transparent); }
.over-icon { width: 30px; height: 30px; }
.over-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.over-amount { font-weight: 600; color: var(--text-over); font-variant-numeric: tabular-nums; white-space: nowrap; }

.ai-insight {
  display: grid;
  gap: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--divider);
}
.ai-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--chart-bar);
}
.ai-text { margin: 0; font-size: 14.5px; line-height: 1.45; display: grid; gap: 6px; transition: opacity 0.2s; }
.ai-insight.is-loading .ai-text { opacity: 0.6; }

.skeleton {
  display: block;
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-raised) 25%, color-mix(in srgb, var(--text) 12%, var(--surface-raised)) 50%, var(--surface-raised) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.2s ease-in-out infinite;
}
.skeleton.is-short { width: 60%; }
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- PDF export button ---------- */

.pdf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 36px;
  margin-right: 6px;
  padding: 0 12px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.pdf-btn:active:not(:disabled) { background: var(--surface-raised); }
.pdf-btn:disabled { cursor: progress; color: var(--text-muted); }
.pdf-btn .spinner { display: none; }
.pdf-btn.is-busy .pdf-btn-icon { display: none; }
.pdf-btn.is-busy .spinner { display: block; }

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.6s; } }
