:root {
  color-scheme: light dark;
  --fg: #1a1a1a;
  --bg: #fafafa;
  --accent: #2a6f4b;
  --border: #ccc;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --chart-line: #2a78d6;
  --chart-tooltip-bg: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #e8e8e8;
    --bg: #16181a;
    --accent: #5fbf8e;
    --border: #444;
    --chart-grid: #2c2c2a;
    --chart-axis: #383835;
    --chart-muted: #898781;
    --chart-line: #3987e5;
    --chart-tooltip-bg: #232626;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

main {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.layout {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

@media (min-width: 900px) {
  .layout {
    flex-direction: row;
    align-items: flex-start;
  }

  .layout-form {
    flex: 0 0 340px;
  }

  .layout-output {
    flex: 1 1 auto;
    min-width: 0;
  }
}

.layout-output {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

h1 { font-size: 1.4rem; }

.disclaimer {
  font-size: 0.85rem;
  opacity: 0.75;
}

form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

label.inline {
  display: inline-flex;
  margin-right: 1rem;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
}

input, select {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font-size: 1rem;
}

button {
  padding: 0.75rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  cursor: pointer;
}

#result {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

#result.hidden { display: none; }

#result .price {
  font-size: 1.6rem;
  font-weight: bold;
  color: var(--accent);
}

#result.error {
  border-color: #c0392b;
  color: #c0392b;
}

#timeseries-section.hidden {
  display: none;
}

#timeseries-section h2 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

#timeseries-chart.error {
  color: #c0392b;
}

.chart-wrap {
  position: relative;
}

.price-chart {
  width: 100%;
  height: auto;
  display: block;
}

.chart-grid line {
  stroke: var(--chart-grid);
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--chart-muted);
  font-size: 11px;
}

.chart-boundary-line {
  stroke: var(--chart-axis);
  stroke-width: 1;
}

.chart-boundary-label {
  fill: var(--chart-muted);
  font-size: 11px;
}

.chart-line {
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-line-actual {
  stroke: var(--chart-line);
}

.chart-line-forecast {
  stroke: var(--chart-line);
  stroke-dasharray: 5 4;
  opacity: 0.75;
}

.chart-marker-ring {
  fill: var(--bg);
}

.chart-marker {
  fill: var(--chart-line);
}

.chart-marker-forecast {
  opacity: 0.85;
}

.chart-end-label {
  fill: var(--fg);
  font-size: 12px;
  font-weight: 600;
}

.chart-crosshair {
  stroke: var(--chart-axis);
  stroke-width: 1;
}

.chart-crosshair.hidden {
  display: none;
}

.chart-hit {
  fill: transparent;
  cursor: crosshair;
}

.chart-hit:focus {
  outline: 2px solid var(--chart-line);
}

.chart-tooltip {
  position: absolute;
  transform: translate(-50%, -115%);
  background: var(--chart-tooltip-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.chart-tooltip.hidden {
  display: none;
}

.chart-tooltip-value {
  font-weight: bold;
  font-size: 0.95rem;
  color: var(--fg);
}

.chart-tooltip-label {
  color: var(--fg);
  opacity: 0.8;
}

.chart-tooltip-note {
  color: var(--chart-muted);
  font-size: 0.72rem;
}

.chart-caption {
  font-size: 0.78rem;
  color: var(--chart-muted);
  margin: 0.5rem 0 0;
}

.chart-table-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: inherit;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
}

.chart-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.8rem;
}

.chart-table.hidden {
  display: none;
}

.chart-table th,
.chart-table td {
  text-align: right;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}

.chart-table th:first-child,
.chart-table td:first-child {
  text-align: left;
}

#municipality-map-section.hidden {
  display: none;
}

#municipality-map-section h2 {
  font-size: 1.05rem;
  margin-bottom: 0.5rem;
}

#municipality-map.error {
  color: #c0392b;
}

.muni-map {
  width: 100%;
  height: auto;
  display: block;
}

.muni-map-area {
  stroke: var(--bg);
  stroke-width: 0.5;
  cursor: pointer;
}

.muni-map-area-hover {
  stroke: var(--fg);
  stroke-width: 1.5;
}

.muni-map-nodata {
  fill: var(--chart-grid);
}

.muni-map-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--chart-muted);
}

.muni-map-legend-bar {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: linear-gradient(to right, rgb(33, 102, 172), rgb(247, 247, 247), rgb(178, 24, 43));
}
