/* Load last. Theme colors only: assistant scrolling, viewport/keyboard safe areas,
   native [hidden], folded-content behavior and paused voice remain untouched. */
:root {
  --button-bg: #224e42;
  --button-fg: #ffffff;
  --expense: #79cbd9;
}
html[data-theme="light"] { color-scheme: light; }
html .primary { background: var(--button-bg); color: var(--button-fg); }
/* Native appearance picker: identical ergonomics in light and dark. */
html .theme-setting select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin-top: 8px;
  padding: 11px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #17191e;
  --paper: #202329;
  --ink: #e8eeec;
  --muted: #a1aea8;
  --line: #353b3d;
  --green: #91d5c3;
  --soft: #293631;
  --danger: #f1a28f;
  --button-bg: #12677b;
  --button-fg: #ffffff;
  --expense: #79cbd9;
  background: var(--bg);
  color: var(--ink);
}

/* An original sea-breeze cover, usable in both themes without child-DOM changes.
   Decoration sits below a dark veil and all content, including wrapped amounts. */
html .balance {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 220px;
  border-radius: 24px;
  background: #07576a;
  color: #fff;
}
html .balance > .balance-art {
  position: absolute;
  z-index: 0;
  right: -24px;
  bottom: -4px;
  width: min(108%, 540px);
  height: auto;
  max-width: none;
  opacity: .96;
  pointer-events: none;
  user-select: none;
}
html .balance::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(100deg, #07576a 8%, #07576af5 45%, #07576a75 68%, #07576a12 100%);
  pointer-events: none;
}
html .balance > :not(.balance-art) { position: relative; z-index: 2; }
html .balance .section-heading > span,
html .balance p,
html #app .balance .billing-range { color: #e1f0f1; }
html .balance p span, html .balance h1 small { color: #cce6e8; }
html .balance h1 {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: normal;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
html .balance input {
  background: #064555;
  color: #fff;
  border-color: #7cb7c4;
  color-scheme: dark;
  font-size: 16px;
  min-height: 44px;
  max-width: 100%;
}
html .balance input:focus { border-color: #d7f0ee; }
html .balance h1 { text-shadow: 0 1px 4px #064554; }
html .balance h1.balance-number-long { width: fit-content; padding-right: 6px; border-radius: 8px; background: #07576add; }

/* The :is(body, #theme-colors) specificity anchor beats existing #assistant-root,
   #settings-panel and #app rules, without !important or changing their layout. */
html[data-theme="dark"] body:is(body, #theme-colors) {
  background: var(--bg);
  color: var(--ink);
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .import-card, .dashboard-import, .monthly-chart, .ledger-fold,
  .category-tile, .entry-list, .draft, .assistant-review,
  .chat-transactions, .batch-learning, .chat-message p,
  .chat-message .copy-fold
) {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: none;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .modal, .sticky-actions, .assistant-page.chat-modal,
  .assistant-header, .assistant-compose
) { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .chat-message.user p, .chat-message.user .copy-fold,
  .chat-question, .batch-overview, .conversation-history,
  .category-tile.active, .chat-row.focused, .chart-empty, .chart-notice
) { background: var(--soft); color: var(--ink); border-color: #486157; }
/* Expanded long copy inherits its bubble rather than creating a second panel. */
html[data-theme="dark"] body:is(body, #theme-colors) .copy-fold > .copy-text {
  background: none;
  color: inherit;
  border: 0;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(input, textarea, select) {
  background: var(--paper);
  color: var(--ink);
  border-color: #515d5c;
  caret-color: var(--green);
  font-size: 16px;
}
html[data-theme="dark"] body:is(body, #theme-colors) input[type="checkbox"] {
  accent-color: var(--green);
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(input, textarea)::placeholder {
  color: var(--muted);
  opacity: 1;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(input, textarea, select):focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px #91d5c326;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(button, a, summary, input, textarea, select):focus-visible {
  outline-color: var(--green);
}
html[data-theme="dark"] body:is(body, #theme-colors) .primary {
  background: var(--button-bg);
  border-color: #4093a3;
  color: var(--button-fg);
}
html[data-theme="dark"] body:is(body, #theme-colors) .primary:hover {
  background: #17798e;
}
html[data-theme="dark"] body:is(body, #theme-colors) .secondary {
  background: var(--paper);
  color: var(--ink);
  border-color: #515d5c;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(.secondary:hover, .entry:hover, .close:hover) {
  background: #2b3438;
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .muted, .hint, footer, .brand small, .entry-info small, .entry-amount small,
  .memory-row small, .memory-info > small, .draft-fields label:not(.check),
  .draft-summary > small, .draft-expand-label, .chat-message > span,
  .chat-row small, .row-memory, .check, .paste-details, .preview,
  .loading, .setting p, .assistant-header p, .assistant-header small,
  .assistant-compose .hint, .batch-learning, .bounded-controls > span,
  .chart-report-stats, .chart-report-stats b, .chart-label,
  .chart-category-share, .chart-rank, .chart-period, .chart-footnote
) { color: var(--muted); }
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .empty h3, .category-tile span, .chart-category-name, .chart-heading h2,
  .draft-title, .entry-info strong
) { color: var(--ink); }
html[data-theme="dark"] body:is(body, #theme-colors) :is(
  .quiet:hover, .quiet.selected, .status, .refund,
  .copy-show, .copy-hide, .ledger-fold > summary,
  .dashboard-quick > summary, .setting > summary,
  .assistant-back, .assistant-reset, .assistant-review-toggle,
  .conversation-history > summary
) { color: var(--green); }
html[data-theme="dark"] body:is(body, #theme-colors) .quiet { color: var(--muted); }
html[data-theme="dark"] body:is(body, #theme-colors) .quiet:is(:hover, .selected) { color: var(--green); }
html[data-theme="dark"] body:is(body, #theme-colors) .notice {
  background: #373020;
  color: #eed6a1;
}
html[data-theme="dark"] body:is(body, #theme-colors) .notice.error {
  background: #3b2b2a;
  color: var(--danger);
}
html[data-theme="dark"] body:is(body, #theme-colors) :is(.form-error, .danger, .is-negative) {
  color: var(--danger);
}
html[data-theme="dark"] body:is(body, #theme-colors) .backdrop { background: #080c12b8; }
html[data-theme="dark"] body:is(body, #theme-colors) .toast {
  background: #293c3e;
  color: var(--ink);
  border: 1px solid #658386;
}
html[data-theme="dark"] body:is(body, #theme-colors) .loading span {
  border-color: var(--line);
  border-top-color: var(--green);
}

/* Chart tracks/markers have literal whites in the original SVG/CSS. Keep the
   original category colors (shared by segments, leaders, icons and rank bars). */
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-track {
  fill: var(--paper);
  stroke: var(--paper);
}
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-bar-track {
  background: #3b4348;
}
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-value-dot {
  color: #8a9b9c;
}
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-report-stats strong {
  color: var(--expense);
}
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-category-amount {
  color: var(--expense);
}
html[data-theme="dark"] body:is(body, #theme-colors) .monthly-chart .chart-category-amount.is-negative {
  color: var(--danger);
}
html[data-theme="dark"] body:is(body, #theme-colors) .entry-amount { color: var(--expense); }
html[data-theme="dark"] body:is(body, #theme-colors) .entry-amount.refund { color: var(--green); }
/* Reassert cover-specific input colors after the general dark form palette. */
html[data-theme="dark"] body:is(body, #theme-colors) .balance input {
  background: #064555;
  color: #fff;
  border-color: #7cb7c4;
}

/* Readability only: no display, overflow or scroll-height overrides. */
html body:is(body, #theme-colors) :is(
  .brand small, .hint, footer, .entry-info small, .entry-amount small,
  .loading small, .chat-message > span, .chat-row small, .row-memory,
  .chat-tools .quiet, .chat-modal > .hint, .chat-modal > .quiet,
  .memory-row small, .draft-summary > small, .draft-expand-label
) { font-size: 12px; }
html body:is(body, #theme-colors) :is(.chat-categories .secondary) { font-size: 14px; }
@media (max-width: 400px) {
  html .balance { min-height: 240px; }
  html .balance > .balance-art { right: -52px; width: 125%; opacity: .86; }
}
