:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #1baf7a;
}

* { box-sizing: border-box; }

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

/* Household name gate */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(11, 11, 11, 0.06);
  text-align: center;
}

.gate-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.gate-card .municipality-badge { margin: 0 0 16px; font-weight: 600; color: var(--accent); font-size: 0.85rem; }
.gate-card p { color: var(--text-secondary); margin: 0 0 20px; font-size: 0.9rem; }

#gateForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Language toggle — plain, small, top-right/top-of-card */
.lang-toggle {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-bottom: 4px;
}

.gate-card .lang-toggle { justify-content: center; margin-bottom: 12px; }

.lang-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--grid);
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 5px;
  cursor: pointer;
}

.lang-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

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

.headline {
  margin: 2px 0 4px;
  font-size: 1.05rem;
  color: var(--text);
}
.headline a { color: var(--accent); text-decoration: none; font-size: 0.82rem; margin-left: 4px; }
.headline a:hover { text-decoration: underline; }

header {
  padding: 24px 32px 8px;
}

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

.chart-summary {
  margin: -4px 0 12px;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

main {
  padding: 16px 32px 48px;
  max-width: 1200px;
  margin: 0 auto;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}

.field-action {
  justify-content: flex-end;
  flex-direction: row;
  align-items: center;
}

label {
  font-size: 0.8rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Field help tooltips — pure CSS, keyboard-accessible via focus */
.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--grid);
  color: var(--text-secondary);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
  flex: none;
}

.help:hover, .help:focus {
  background: var(--accent);
  color: var(--accent-ink);
  outline: none;
}

.help:hover::after, .help:focus::after {
  content: attr(data-tip);
  position: absolute;
  bottom: 135%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  width: 220px;
  white-space: normal;
  z-index: 30;
  box-shadow: 0 8px 20px rgba(11, 11, 11, 0.18);
}

.help:hover::before, .help:focus::before {
  content: "";
  position: absolute;
  bottom: 118%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--text);
  z-index: 30;
}

.readout {
  padding: 8px 10px;
  border: 1px solid var(--grid);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  background: var(--page);
}

select, input, button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

select:focus, input:focus {
  outline: none;
  border-color: var(--accent);
}

input:disabled {
  background: var(--page);
  color: var(--muted);
  cursor: not-allowed;
}

button {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 18px;
}

button:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--grid);
  margin-left: 8px;
}

#status { margin-left: 10px; color: var(--muted); font-size: 0.85rem; }

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.summary .stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}

.summary .stat .label { color: var(--muted); font-size: 0.78rem; }
.summary .stat .value { font-size: 1.3rem; font-weight: 600; margin-top: 4px; color: var(--text); }

.charts {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.chart-card h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  color: var(--text-secondary);
  font-weight: 500;
}

canvas { max-height: 340px; }

.error { color: #c0392b; font-size: 0.85rem; margin: 12px 0 0; }

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

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

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-view { background: rgba(42, 120, 214, 0.12); color: var(--accent); }
.badge-compute { background: rgba(27, 175, 122, 0.14); color: var(--good); }

.muted-row td { color: var(--muted); }

#dataTableCard, #yearlyTableCard { margin-top: 20px; }

/* ── Print / PDF export ── */
@media print {
  body { background: #fff; }
  .gate, #status, .btn-secondary, #recompute, .help { display: none !important; }
  .controls { break-inside: avoid; }
  .chart-card, .summary .stat { box-shadow: none; border: 1px solid #ccc; }
  .charts { gap: 12px; }
  .chart-card { break-inside: avoid; page-break-inside: avoid; }
  canvas { max-height: 260px; }
  table { font-size: 0.72rem; }
  th, td { padding: 4px 6px; white-space: normal; }
  main { padding: 0 8px; max-width: 100%; }
}
