:root {
  color-scheme: light dark;
  --bg-page:         #f5f7fa;
  --bg-card:         #ffffff;
  --text-primary:    #1a1a2e;
  --text-secondary:  #555;
  --text-muted:      #888;
  --ring-bg:         #dde1e9;
  --border-color:    rgba(0,0,0,0.08);
  --border-subtle:   #e0e0e0;
  --bg-track:        #eee;
  --bg-chip:         #eef2f7;
  --badge-target-bg: #e8e8e8;
  --badge-target-fg: #555;
  --divider:         #f0f0f0;
  --target-line:     rgba(0,0,0,0.35);
  --color-positive:  #155724;
  --color-negative:  #c0392b;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-page:         #12141c;
    --bg-card:         #1e2130;
    --text-primary:    #e0e4f0;
    --text-secondary:  #9aa0b4;
    --text-muted:      #6b7280;
    --ring-bg:         #2c3040;
    --border-color:    rgba(255,255,255,0.06);
    --border-subtle:   #2c3040;
    --bg-track:        #2c3040;
    --bg-chip:         #1a2035;
    --badge-target-bg: #2c3040;
    --badge-target-fg: #9aa0b4;
    --divider:         #2c3040;
    --target-line:     rgba(255,255,255,0.35);
    --color-positive:  #4ade80;
    --color-negative:  #f87171;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  padding: 8px 12px;
}

#page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 12px;
}
h1 { font-size: 1.4rem; margin: 0; color: var(--text-primary); }


.card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 14px 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px var(--border-color);
}

/* Overview donut */
.donut-row {
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}
#view-controls:not([hidden]) {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 16px 0 20px;
}
.segmented-control {
  display: flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-track);
}
.segmented-control button {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.segmented-control button[aria-pressed="true"] {
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px var(--border-color);
}
.segmented-control button:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}
.segmented-control button:focus-visible {
  outline: 2px solid #4e79a7;
  outline-offset: 2px;
}
.donut-container {
  width: min(440px, 100vw);
}
.donut-container svg {
  width: 100%;
  height: auto;
  overflow: visible;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Per-slice cards */
.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 14px;
}
.card-title  { font-size: 1rem; font-weight: 600; flex-shrink: 0; }
.card-summary { font-size: 0.82rem; color: var(--text-secondary); text-align: right; }

/* Slice rows */
.slice-row { margin-bottom: 16px; }
.slice-row:last-child { margin-bottom: 0; }
.slice-row-children {
  padding-left: 12px;
  border-left: 2px solid var(--border-subtle);
  margin-left: 6px;
  margin-top: 10px;
}
.slice-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  margin-bottom: 5px;
  font-size: 0.85rem;
}
.slice-left  { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.slice-name  { font-weight: 500; }
.ticker-chip {
  font-size: 0.68rem;
  background: var(--bg-chip);
  color: #4e79a7;
  border-radius: 3px;
  padding: 1px 4px;
  font-weight: 600;
}
.slice-right { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; font-size: 0.78rem; color: var(--text-secondary); }

.diff-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
}
.over      { background: #d4edda; color: #155724; }
.under     { background: #f8d7da; color: #721c24; }
.on-target { background: var(--badge-target-bg); color: var(--badge-target-fg); }

/* Progress bar */
.bar-track {
  position: relative;
  height: 12px;
  background: var(--bg-track);
  border-radius: 6px;
  overflow: hidden;
}
.bar-actual {
  position: absolute;
  height: 100%;
  border-radius: 5px;
  transition: width 0.4s ease;
}
.bar-target-line {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: var(--target-line);
  border-radius: 1px;
}

/* Issues warning */
.warning-card {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: #7a5700;
}
.warning-card strong  { display: block; margin-bottom: 4px; }
.warning-card summary { color: #7a5700; }
.warning-card .unmatched-item { color: #7a5700; border-bottom-color: #ffe082; }

details { margin-top: 8px; }
summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 6px 0;
  user-select: none;
}
.unmatched-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  padding: 4px 0;
  border-bottom: 1px solid var(--divider);
  color: var(--text-secondary);
}

#account-bar { visibility: hidden; margin-left: auto; }
#account-select, #history-account-select {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.85rem;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  max-width: min(52vw, 360px);
}

/* Saved net worth history */
.history-card { max-width: 1100px; margin: 0 auto 16px; }
.history-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 20px; margin: 24px 0; }
.history-balance { font-size: clamp(1.7rem, 5vw, 2.4rem); font-weight: 700; margin: 4px 0; }
.history-change { font-size: 1.3rem; font-weight: 600; margin: 8px 0; }
.history-note { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; }
.history-positive { color: var(--color-positive); }
.history-negative { color: var(--color-negative); }
.history-ranges { width: fit-content; max-width: 100%; margin-bottom: 12px; }
.history-ranges button { min-width: 44px; }
.history-chart svg { display: block; width: 100%; height: auto; touch-action: pan-y; }
.history-grid { stroke: var(--border-subtle); stroke-width: 1; }
.history-axis { fill: var(--text-secondary); font-family: inherit; font-size: 12px; }
.history-line { fill: none; stroke: #4e79a7; stroke-width: 2.5; stroke-linejoin: round; }
.history-point { fill: #4e79a7; }
.history-guide { stroke: var(--text-muted); stroke-dasharray: 4 4; }
.history-marker { fill: var(--bg-card); stroke: #4e79a7; stroke-width: 3; }
.history-readout { text-align: center; font-size: 0.95rem; font-weight: 600; margin: 12px 0; min-height: 1.5em; }
.history-slider-label { display: block; font-size: 0.82rem; color: var(--text-secondary); }
.history-slider { width: 100%; min-height: 44px; accent-color: #4e79a7; cursor: pointer; }
.history-slider:focus-visible, .history-retry:focus-visible { outline: 2px solid #4e79a7; outline-offset: 2px; }
.history-table-details { margin-top: 20px; }
.history-table-details summary { min-height: 44px; display: list-item; padding: 12px 0; color: var(--text-primary); }
.history-table-scroll { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.history-table caption { text-align: left; padding: 8px 0; }
.history-table th, .history-table td { padding: 12px 8px; text-align: right; border-bottom: 1px solid var(--divider); white-space: nowrap; }
.history-table th:first-child, .history-table td:first-child { text-align: left; }
.history-footnote { margin-top: 20px; }
.history-warning { margin-top: 16px; }
.history-empty { padding: 32px 0; color: var(--text-secondary); line-height: 1.5; }
.history-retry { display: block; margin-top: 12px; min-height: 44px; padding: 8px 20px; border: 1px solid var(--border-subtle); border-radius: 7px; background: var(--bg-card); color: var(--text-primary); font: inherit; cursor: pointer; }
@media (max-width: 400px) {
  #page-header { gap: 8px; }
  .history-ranges button { padding: 8px; }
}

#loading { padding: 16px 0; display: none; }
.skeleton-donut-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.skeleton-donut {
  width: min(440px, 100vw);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 44px solid var(--ring-bg);
  box-sizing: border-box;
}
.skeleton-card {
  height: 64px; border-radius: 12px;
  background: var(--ring-bg);
  margin-bottom: 16px;
}
.skeleton-msg {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.skeleton-donut, .skeleton-card {
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}
@keyframes skeleton-pulse { 0%, 100% { opacity: 1 } 50% { opacity: 0.45 } }
#error   { color: #c0392b; padding: 20px; }
#signin-btn {
  display: none;
  margin: 40px auto;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #4285f4;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
