:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --line: #e2e0d8;
  --accent: #2456c7;
  --accent-text: #ffffff;
  --ok: #1f7a3d;
  --ok-bg: #e3f3e8;
  --warn: #8a5a00;
  --warn-bg: #fbefd5;
  --off: #7a2a2a;
  --off-bg: #f6e2e2;
  --chip: #eceae3;
  --radius: 10px;
  /* Map pin colours: reference dataviz palette slots 1-3 + neutral; validated all-pairs. */
  --lang-uk: #2a78d6; --lang-uk-ink: #ffffff;
  --lang-en: #eb6834; --lang-en-ink: #1d1d1b;
  --lang-de: #1baf7a; --lang-de-ink: #1d1d1b;
  --lang-other: #7a7974; --lang-other-ink: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161614;
    --surface: #1f1f1c;
    --text: #ecebe6;
    --muted: #a3a29b;
    --line: #34332e;
    --accent: #7ea2ff;
    --accent-text: #0d1430;
    --ok: #7fd79a;
    --ok-bg: #1d3325;
    --warn: #f2c66b;
    --warn-bg: #3a2f17;
    --off: #f0a3a3;
    --off-bg: #3b2222;
    --chip: #2b2a26;
    --lang-uk: #3987e5; --lang-en: #d95926; --lang-de: #199e70; --lang-other: #8f8e88;
    --lang-en-ink: #ffffff; --lang-de-ink: #ffffff; --lang-other-ink: #161614;
  }
}
:root[data-theme="dark"] {
  --bg: #161614; --surface: #1f1f1c; --text: #ecebe6; --muted: #a3a29b; --line: #34332e;
  --accent: #7ea2ff; --accent-text: #0d1430; --ok: #7fd79a; --ok-bg: #1d3325; --warn: #f2c66b;
  --warn-bg: #3a2f17; --off: #f0a3a3; --off-bg: #3b2222; --chip: #2b2a26;
  --lang-uk: #3987e5; --lang-en: #d95926; --lang-de: #199e70; --lang-other: #8f8e88;
  --lang-en-ink: #ffffff; --lang-de-ink: #ffffff; --lang-other-ink: #161614;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--surface); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; font-size: 14px; }
button:disabled { opacity: .5; cursor: default; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.top-row { display: flex; gap: 16px; align-items: center; justify-content: space-between; padding-top: 16px; padding-bottom: 16px; flex-wrap: wrap; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
/* Language switch: both languages visible, the current one highlighted. */
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.lang-switch button { border: 0; border-radius: 0; padding: 8px 12px; background: var(--surface); color: var(--muted); font-weight: 600; }
.lang-switch button + button { border-left: 1px solid var(--line); }
.lang-switch button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0; align-items: center; }
.filters input[type=search] { flex: 1 1 260px; min-width: 0; }
.filters input[type=search], .filters select, .field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.filters select { flex: 0 1 auto; max-width: 100%; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }

.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (max-width: 380px) { .list { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card.old { opacity: .78; }
.card h3 { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { background: var(--chip); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.badge { border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; }
.badge.active { color: var(--ok); background: var(--ok-bg); }
.badge.stale, .badge.paused, .badge.unknown { color: var(--warn); background: var(--warn-bg); }
.badge.closed { color: var(--off); background: var(--off-bg); }
.meta { margin: 0; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.meta b { color: var(--text); font-weight: 600; }
.desc { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.contacts { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; }
.contacts a { overflow-wrap: anywhere; }
.members { color: var(--muted); font-size: 13px; white-space: nowrap; }
details.src { font-size: 13px; color: var(--muted); }
details.src ul { margin: 4px 0 0; padding-left: 18px; }
details.src p { margin: 6px 0 0; }
.ico { display: inline-block; width: 1.5em; }
details.src a { overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.foot { color: var(--muted); font-size: 14px; padding-top: 32px; padding-bottom: 40px; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { margin: 0; font-size: 20px; }
.dlg-body { padding: 16px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.msg { margin: 0; font-size: 14px; }
.msg.err { color: var(--off); }
.msg.ok { color: var(--ok); }
.done { margin: 0; font-size: 17px; color: var(--ok); }
[hidden] { display: none !important; }

.field { display: grid; gap: 4px; }
.field > span { font-size: 14px; font-weight: 600; }
.field small { color: var(--muted); font-size: 13px; }
.field input, .field select, .field textarea { width: 100%; min-width: 0; }
.field textarea { min-height: 70px; resize: vertical; }
.field input:disabled { background: var(--chip); color: var(--muted); cursor: not-allowed; opacity: .6; }
.grid2 { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; min-width: 0; }
legend { font-size: 14px; font-weight: 600; padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.rep { display: grid; gap: 8px; }
.rep-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; padding: 10px; border: 1px dashed var(--line); border-radius: 8px; }
.mini { display: grid; gap: 2px; flex: 1 1 130px; min-width: 0; }
.mini.wide { flex-basis: 100%; }
.mini > span { font-size: 13px; color: var(--muted); }
.mini input, .mini select { width: 100%; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.rep-row > .del { flex: 0 0 auto; }

/* view tabs */
.views { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--line); }
.tab { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: transparent; padding: 8px 14px; color: var(--muted); font-weight: 600; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

/* map */
/* Background = the tiles' land colour (OSM #f2efe9, and its dark-filtered equivalent), so any pixel left
   between tiles at fractional zoom blends in instead of drawing a line. */
#map { height: min(70vh, 640px); border: 1px solid var(--line); border-radius: var(--radius); background: #f2efe9; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #map { background: #2a2a28; } }
:root[data-theme="dark"] #map { background: #2a2a28; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 0 4px; font-size: 14px; }
.leg { display: inline-flex; align-items: center; gap: 6px; }
.pin-wrap { background: none; border: 0; }
.pin { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--pin); color: var(--pin-ink);
  font: 700 11px/1 system-ui, sans-serif; border: 2px solid var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.35); }
.pin.old { opacity: .55; }
.pin.approx { border: 2px dashed var(--text); }
.pin-sm.approx { border-width: 1px; }
.pin-sm { width: 14px; height: 14px; border-width: 1px; box-shadow: none; }
.pin-uk { --pin: var(--lang-uk); --pin-ink: var(--lang-uk-ink); }
.pin-en { --pin: var(--lang-en); --pin-ink: var(--lang-en-ink); }
.pin-de { --pin: var(--lang-de); --pin-ink: var(--lang-de-ink); }
.pin-other { --pin: var(--lang-other); --pin-ink: var(--lang-other-ink); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); }
.leaflet-container { font: inherit; }
.leaflet-container a { color: var(--accent); }
.pop { display: grid; gap: 4px; font-size: 14px; }
.pop b { font-size: 15px; }
.pop-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); }
.pop-approx { color: var(--muted); font-size: 13px; }
.pop-links { display: flex; gap: 10px; align-items: center; margin-top: 4px; }
/* Dark map: invert each tile, not the whole tile pane. A filter on the pane plus fractional browser
   zoom left hairline seams between tiles; per tile they disappear. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #map .leaflet-tile-container img.leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }
}
:root[data-theme="dark"] #map .leaflet-tile-container img.leaflet-tile { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }

/* card highlighted after "Details" on the map */
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }
.card.flash { animation: flash 2s ease-out; }

/* Several clubs at one place: number in the middle, ring split by each club's language colour. */
.pin-multi { background: var(--surface); color: var(--text); border: 0; position: relative; font-size: 13px; }
.pin-multi::before { content: ""; position: absolute; inset: -1px; border-radius: 50%; padding: 4px; background: var(--ring);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; }
.pin-sm.pin-multi::before { padding: 3px; }
.pop-group { display: grid; gap: 8px; }
.pop-group > b { font-size: 13px; color: var(--muted); font-weight: 600; }
.pop-item { padding-top: 8px; border-top: 1px solid var(--line); }

/* Leaflet adds its own stylesheet after ours; #map raises specificity so these win in both themes. */
#map .leaflet-popup-content-wrapper, #map .leaflet-popup-tip { background: var(--surface); color: var(--text); }
#map .leaflet-popup-close-button { color: var(--muted); }
#map .leaflet-popup-close-button:hover { color: var(--text); }
#map .pop button { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
#map .leaflet-bar a { background: var(--surface); color: var(--text); border-bottom-color: var(--line); }
#map .leaflet-bar a:hover { background: var(--chip); }
#map .leaflet-bar { border-color: var(--line); }
#map .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--muted); }
#map .leaflet-control-attribution a { color: var(--accent); }
