/* Styles for the EU-funds-in-Zagreb-budget report. Mobile-first (works down
   to ~320px). */

:root {
  --bg: #fdfcf7;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --border: #d9d6cc;
  --accent: #0369a1;
  --eu-51: #1e40af;   /* Izvor 5.1 — direct EU */
  --eu-56: #3b82f6;   /* Izvor 5.6 — ERDF/ESF */
  --eu-57: #fbbf24;   /* Izvor 5.7 — FSEU earthquake */
  --eu-58: #14b8a6;   /* Izvor 5.8 — NPOO/RRF */
  --total-line: #111;
  --prog-1: #1e40af;
  --prog-2: #3b82f6;
  --prog-3: #0ea5e9;
  --prog-4: #06b6d4;
  --prog-5: #14b8a6;
  --prog-6: #22c55e;
  --prog-7: #eab308;
  --prog-8: #f97316;
  --prog-9: #ef4444;
  --prog-10: #a855f7;
  --prog-other: #9ca3af;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

header, main {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px;
}

h1 { font-size: 1.7rem; margin: 0 0 .2em; line-height: 1.2; }
h2 { font-size: 1.3rem; margin-top: 2.5em; border-top: 1px solid var(--border); padding-top: 1em; }
h3 { font-size: 1.05rem; margin-top: 1.8em; }

.lede { font-size: 1.05rem; color: #333; max-width: 640px; }
.updated { color: var(--muted); font-size: .85rem; }

section { margin-bottom: 2em; }

/* Toolbar / toggles */
.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0 10px;
}
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: white;
}
.tab {
  border: 0;
  padding: 7px 12px;
  background: transparent;
  font-size: .9rem;
  color: #333;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.tab:last-child { border-right: 0; }
.tab.active {
  background: var(--accent);
  color: white;
}
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Chart container — keeps aspect reasonable on mobile */
.chart-box {
  position: relative;
  width: 100%;
  height: clamp(280px, 48vw, 440px);
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.legend-hint {
  font-size: .85rem;
  color: var(--muted);
  margin-top: 8px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: .9rem;
}
th, td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
th { background: #f3efe4; font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.small { font-size: .85rem; color: #333; }
.small ul, ul.small { padding-left: 20px; }
.small li { margin-bottom: .3em; }

/* Mandate comparison section */
#mandate-compare ol { padding-left: 24px; }
#mandate-compare ol li { margin-bottom: .5em; }

.mandate-stats {
  width: auto;
  min-width: 60%;
  font-size: .9rem;
  margin-top: 10px;
}
.mandate-stats th, .mandate-stats td { padding: 8px 12px; }
.mandate-stats th { text-align: center; }
.mandate-stats th .sub {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: .78rem;
  margin-top: 2px;
}
.mandate-stats td:first-child { color: #555; }
.mandate-stats td { text-align: center; font-variant-numeric: tabular-nums; }
.mandate-stats td:first-child { text-align: left; }
.mandate-stats.breakdown td:nth-child(2),
.mandate-stats.breakdown td:nth-child(3) { text-align: right; }
.mandate-stats.breakdown td:nth-child(4) { text-align: center; }

.key-finding {
  background: #f7f5ee;
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin-top: 12px;
  border-radius: 4px;
}
.key-finding p { margin: 0 0 .6em; }
.key-finding ul { margin: .4em 0 .8em; padding-left: 22px; }
.key-finding li { margin-bottom: .4em; }
.key-finding em { color: #333; }

@media (max-width: 560px) {
  .mandate-stats { min-width: 100%; font-size: .82rem; }
  .mandate-stats th, .mandate-stats td { padding: 6px 8px; }
  .key-finding { padding: 10px 12px; font-size: .9rem; }
}

/* Legend tables — shared base */
.legend-table { font-size: .88rem; table-layout: auto; }
.legend-table td { vertical-align: top; padding: 7px 8px; }
.legend-table thead th { white-space: nowrap; }
.legend-table td:first-child { white-space: nowrap; color: #111; width: 1%; }
.legend-table .hr-lang { display: block; color: var(--muted); font-size: .82rem; font-style: italic; margin-top: 2px; }

/* Fondovi i instrumenti — 4 cols: Kratica | Puni naziv | Razdoblje | Svrha */
.legend-table.fondovi td:nth-child(2) { width: 20%; }
.legend-table.fondovi td:nth-child(3) { color: #444; font-size: .82rem; width: 22%; }
.legend-table.fondovi td:nth-child(4) { color: #333; }

/* Izvori — 4 cols: Izvor | Naziv | Što uključuje (wide) | EU? (tiny) */
.legend-table.izvori td:nth-child(2) { width: 22%; white-space: nowrap; }
.legend-table.izvori td:nth-child(3) { color: #333; }
.legend-table.izvori td:nth-child(4) { width: 1%; white-space: nowrap; font-weight: 600; text-align: center; }
.legend-table.izvori td:nth-child(4):first-letter { color: var(--accent); }

/* Konto — 2 cols */
.legend-table.konto td:nth-child(2) { color: #333; }

/* Auto-populated programmes list */
#all-programmes {
  column-count: 2; column-gap: 20px;
  font-size: .82rem; color: #333;
  margin: 10px 0 20px;
}
#all-programmes .prog-row {
  break-inside: avoid;
  padding: 2px 0;
}
#all-programmes .prog-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 560px) {
  #all-programmes { column-count: 1; }
  .legend-table td:nth-child(3) { white-space: normal; }
  /* Allow horizontal scroll so reference tables don't truncate */
  .legend-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: .82rem;
  }
  .legend-table thead, .legend-table tbody, .legend-table tr { display: table; width: max-content; min-width: 100%; table-layout: auto; }
  .legend-table.fondovi td:nth-child(4),
  .legend-table.izvori td:nth-child(3) { white-space: normal; max-width: 320px; }
}

/* Narrow-screen tweaks */
@media (max-width: 420px) {
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.1rem; }
  .lede { font-size: .95rem; }
  .tab { padding: 6px 9px; font-size: .82rem; }
  th, td { padding: 5px 6px; font-size: .82rem; }
}

/* Projects table (per-project EU funds detail) */
#projects-table .cat-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .78rem;
  color: #666a73;
  white-space: nowrap;
}
#projects-table tfoot th {
  background: #f0ede6;
  border-top: 1.5px solid #d8d4ca;
}
#projects-table td:nth-child(3) {
  max-width: 380px;
}
