:root {
  --bg: #f4f7f5;
  --surface: #ffffff;
  --surface-alt: #f8faf9;
  --text: #15211a;
  --muted: #5a6b61;
  --border: #dce5df;
  --primary: #1f7a53;
  --primary-soft: #e4f3eb;
  --shadow: 0 10px 28px rgba(21, 33, 26, 0.06);
}

[data-theme="dark"] {
  --bg: #0f1512;
  --surface: #17201b;
  --surface-alt: #1d2822;
  --text: #edf4ef;
  --muted: #98aa9f;
  --border: #2a3930;
  --primary: #3fb97e;
  --primary-soft: #1b3829;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.container {
  width: min(1240px, 94%);
  margin: 0 auto;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 0;
  flex-wrap: wrap;
}

.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.25;
}

.brand-sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.source-badge {
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.btn-secondary,
.btn-ghost {
  border-radius: 9px;
  padding: 8px 13px;
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.btn-secondary:hover,
.btn-ghost:hover {
  border-color: var(--primary);
}

.main-content {
  padding: 24px 0 42px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-primary {
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--surface) 60%, var(--primary-soft));
}

.kpi-label {
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 1.32rem;
  letter-spacing: -0.01em;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-group,
.seg-group {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 4px;
  gap: 4px;
  flex-wrap: wrap;
}

.tab-btn,
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.tab-btn.active,
.seg-btn.active {
  background: var(--primary);
  color: #fff;
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.checkbox-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.error-banner {
  background: #fdecec;
  color: #9e1c1c;
  border: 1px solid #f4b8b8;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 500;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.15fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 920px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.08rem;
}

.panel-sub {
  margin: 3px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.hint-badge {
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 4px 9px;
  border-radius: 999px;
}

.chart-stage {
  position: relative;
  width: min(420px, 100%);
  margin: 8px auto 4px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
}

#pie-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.pie-slice {
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
  transform-origin: 210px 210px;
}

.pie-slice.dimmed {
  opacity: 0.42;
}

.pie-slice.active {
  transform: scale(1.045);
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.2));
}

.slice-label {
  fill: #ffffff;
  font-size: 12px;
  font-weight: 700;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.donut-center {
  position: absolute;
  width: 44%;
  text-align: center;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.center-title {
  font-size: 0.78rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.center-value {
  font-size: 1.02rem;
}

.center-pct {
  font-size: 0.85rem;
  color: var(--primary);
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  text-align: left;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

th.num,
td.num {
  text-align: right;
  white-space: nowrap;
}

tbody tr {
  cursor: pointer;
  transition: background-color 0.14s ease;
}

tbody tr:hover,
tbody tr.active {
  background: var(--primary-soft);
}

.item-cell {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  margin-top: 5px;
  flex-shrink: 0;
}

.item-name {
  font-weight: 600;
}

.item-note {
  font-size: 0.78rem;
  color: var(--muted);
}

.pct-wrap {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 78px;
}

.pct-bar-bg {
  width: 74px;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.pct-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: #141c17;
  color: #f4f8f5;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 0.84rem;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  max-width: 280px;
}

.hidden {
  display: none !important;
}
