:root {
  color-scheme: light;
  --page-plane:     #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --gridline:       #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --highlight-band: rgba(235, 104, 52, 0.10);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page-plane:     #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --gridline:       #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --highlight-band: rgba(217, 89, 38, 0.14);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-plane:     #0d0d0d;
  --surface-1:      #1a1a19;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --gridline:       #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --highlight-band: rgba(217, 89, 38, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

@media (max-width: 640px) {
  .page {
    padding: 20px 12px 40px;
  }
}

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-secondary);
  margin: 0 0 24px;
  font-size: 0.9rem;
}

.theme-toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
}

.theme-toggle:hover {
  background: var(--gridline);
}

.controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 640px) {
  .controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    margin-bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }

  .field-label {
    display: none;
  }

  .field {
    width: 100%;
  }

  .date-nav {
    gap: 8px;
  }

  #date-select {
    font-size: 1rem;
    padding: 12px 36px 12px 14px;
    border-radius: 10px;
    border-color: var(--baseline);
  }

  .nav-btn {
    width: 48px;
    border-radius: 10px;
  }

  .page {
    padding-bottom: 92px;
  }
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  min-width: 0;
}

.field-label {
  color: var(--text-secondary);
}

.date-nav {
  display: flex;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
}

#date-select {
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 8px 34px 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background-color: var(--surface-1);
  color: var(--text-primary);
  min-width: 0;
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%2352514e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

#date-select:hover {
  background-color: var(--gridline);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) #date-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23c3c2b7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

:root[data-theme="dark"] #date-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23c3c2b7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.nav-btn {
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  width: 44px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  cursor: pointer;
}

.nav-btn:hover:not(:disabled) {
  background: var(--gridline);
}

.nav-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}


.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.chart-wrap {
  position: relative;
  height: 480px;
  width: 100%;
}

@media (max-width: 640px) {
  .chart-card {
    padding: 12px 4px 12px 8px;
    border-radius: 8px;
  }

  .chart-wrap {
    height: 300px;
  }
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.legend-chip.is-hidden {
  color: var(--text-muted);
  text-decoration: line-through;
  opacity: 0.6;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .chart-legend {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 10px -4px 0;
    padding: 0 4px 4px;
  }

  .legend-chip {
    font-size: 0.75rem;
    padding: 4px 9px;
  }
}

.chart-caption {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  margin: 12px 2px 0;
}

.highlight-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--highlight-band);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.table-view {
  margin-top: 20px;
}

.table-view summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 8px 0;
}

.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 8px;
}

#data-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#data-table th,
#data-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--gridline);
  text-align: right;
}

#data-table th:first-child,
#data-table td:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-1);
}

#data-table thead th {
  color: var(--text-secondary);
  font-weight: 500;
  background: var(--surface-1);
}
