:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #5b6470;
  --border: #d8dce1;
  --accent: #1c4ed8;
  --accent-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2025;
    --text: #eceef1;
    --muted: #9aa3af;
    --border: #33383f;
    --accent: #5b8dfc;
    --accent-ink: #0b0f14;
  }
}
:root[data-theme="light"] {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #5b6470;
  --border: #d8dce1;
  --accent: #1c4ed8;
  --accent-ink: #ffffff;
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --card: #1d2025;
  --text: #eceef1;
  --muted: #9aa3af;
  --border: #33383f;
  --accent: #5b8dfc;
  --accent-ink: #0b0f14;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
}
.header-right { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
header nav { display: flex; gap: 18px; flex-wrap: wrap; }
header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}
header nav a:hover,
header nav a:focus-visible { color: var(--accent); }
header nav a[aria-current="page"] { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  min-height: 0;
}
.theme-toggle:hover,
.theme-toggle:focus-visible { color: var(--accent); border-color: var(--accent); }
.theme-toggle svg { display: none; width: 17px; height: 17px; }
.theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  .theme-toggle .icon-moon { display: none; }
  .theme-toggle .icon-sun { display: block; }
}
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

main { max-width: 640px; margin: 0 auto; padding: 24px 16px 64px; }
main, .info-section { scroll-margin-top: 64px; }
h1 { font-size: 1.35rem; margin-bottom: 4px; }
p.lead { color: var(--muted); margin-top: 0; }
.privacy {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 16px 0 24px;
  font-size: 0.9rem;
}
fieldset {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
legend { font-weight: 600; padding: 0 6px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 10px 0 4px; }
p.hint { font-size: 0.8rem; color: var(--muted); margin: 6px 0 0; }
select[multiple] { height: auto; }
input {
  width: 100%;
  padding: 12px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  /* 16px min stops iOS Safari auto-zooming the page on focus */
  font-size: 16px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute;
  z-index: 10;
  top: 100%;
  left: 0;
  right: 0;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 240px;
  overflow-y: auto;
}
.autocomplete-list li {
  padding: 10px 10px;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
}
.autocomplete-list li.active,
.autocomplete-list li:hover {
  background: var(--accent);
  color: var(--accent-ink);
}
.autocomplete-list li mark {
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}
.autocomplete-list .no-match {
  padding: 10px;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: default;
}
.autocomplete-list .no-match:hover { background: none; }

.row { display: flex; flex-wrap: wrap; gap: 10px; }
.row > div { flex: 1 1 130px; min-width: 0; }
.actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
button {
  font-size: 16px;
  padding: 12px 18px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
  min-height: 44px;
}
button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
  flex: 1 1 220px;
}
button.secondary { background: transparent; color: var(--muted); flex: 0 1 auto; }
#status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.9rem;
  min-height: 1.2em;
}
#status.error { color: #d1453b; }
#status.ok { color: #1a8a4a; }
#status.loading { color: var(--muted); }

/* Apple-style (iOS UIActivityIndicatorView) spinner: 12 fixed blades
   fading in sequence, rather than the whole shape rotating. */
/* SVG elements don't reliably honor the bare [hidden] attribute in every
   browser, so make it explicit rather than relying on the UA stylesheet. */
.spinner[hidden] { display: none; }
.spinner { color: var(--muted); flex: none; }
.spinner-blade {
  fill: currentColor;
  animation: spinner-fade 1.2s linear infinite;
}
.spinner-blade:nth-child(1) { animation-delay: -1.1s; }
.spinner-blade:nth-child(2) { animation-delay: -1s; }
.spinner-blade:nth-child(3) { animation-delay: -0.9s; }
.spinner-blade:nth-child(4) { animation-delay: -0.8s; }
.spinner-blade:nth-child(5) { animation-delay: -0.7s; }
.spinner-blade:nth-child(6) { animation-delay: -0.6s; }
.spinner-blade:nth-child(7) { animation-delay: -0.5s; }
.spinner-blade:nth-child(8) { animation-delay: -0.4s; }
.spinner-blade:nth-child(9) { animation-delay: -0.3s; }
.spinner-blade:nth-child(10) { animation-delay: -0.2s; }
.spinner-blade:nth-child(11) { animation-delay: -0.1s; }
.spinner-blade:nth-child(12) { animation-delay: 0s; }
@keyframes spinner-fade {
  0% { opacity: 1; }
  100% { opacity: 0.15; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner-blade { animation: none; opacity: 0.5; }
}
.info-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-top: 16px;
}
.info-section h2 { font-size: 1.05rem; margin: 0 0 4px; }
.info-section p { color: var(--text); }
.info-section details {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}
.info-section details:first-of-type { border-top: none; padding-top: 6px; }
.info-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
}
.info-section summary::marker { color: var(--accent); }
.info-section details p { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); }

.back-link { display: inline-block; margin-top: 20px; font-size: 0.9rem; }

footer { color: var(--muted); font-size: 0.8rem; margin-top: 24px; }
footer a { color: inherit; }

#map-wrap { max-width: 420px; margin: 8px auto 4px; touch-action: manipulation; }
#map-wrap svg { width: 100%; height: auto; display: block; }
#map-wrap path.county {
  stroke: var(--card);
  stroke-width: 1;
}
#map-wrap path.county.ineligible {
  fill: var(--border);
}
#map-wrap path.county.eligible {
  fill: #a9c4f5;
  cursor: pointer;
  transition: fill 0.12s ease;
}
@media (prefers-color-scheme: dark) {
  #map-wrap path.county.eligible { fill: #33538f; }
}
#map-wrap path.county.eligible:hover,
#map-wrap path.county.eligible:focus-visible {
  fill: #6f9aef;
  outline: none;
}
#map-wrap path.county.selected {
  fill: var(--accent);
}

/* Tappable county list — the primary way to select on touch screens,
   since the SVG shapes for small counties are hard to hit precisely
   with a finger. The map stays as a visual companion. */
#judete-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}
#judete-buttons button {
  font-size: 0.85rem;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
#judete-buttons button.selected {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}

#selected-judete {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
  min-height: 1.6em;
}
#selected-judete .chip {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
#selected-judete .empty {
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 460px) {
  main { padding: 16px 12px 48px; }
  .header-inner { padding: 10px 12px; }
  h1 { font-size: 1.2rem; }
  fieldset { padding: 12px; }
  .actions { flex-direction: column; }
  .actions button { width: 100%; }
}
