[hidden] { display: none !important; }
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #6a7686;
  --line: #e2e7ed;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --ok: #2f9e44;
  --bad: #c92a2a;
  --head: #1c2430;
  --head-text: #ffffff;
}
/* Dark theme – Chrome's dark theme colours (background #202124, surfaces #292a2d) */
:root[data-theme="dark"] {
  --bg: #202124; --panel: #292a2d; --text: #e8eaed; --muted: #9aa0a6; --line: #3c4043;
  --accent: #ff8a3d; --accent-soft: #3a2a1e; --ok: #5bb974; --bad: #f28b82;
  --head: #35363a; --head-text: #e8eaed;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 24px; background: var(--head); color: var(--head-text);
}
.top h1 { margin: 0; font-size: 1.4rem; }
/* Competition name with a "back to all competitions" arrow button in front */
.title-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-text { min-width: 0; }
.home-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border: 1px solid rgba(255, 255, 255, .3); border-radius: 8px; color: inherit; text-decoration: none;
}
.home-btn svg { display: block; }
.home-btn:hover { background: rgba(255, 255, 255, .15); }
@media (max-width: 600px) { .home-btn { width: 34px; height: 34px; } .title-wrap { gap: 10px; } }
.meta { opacity: .75; font-size: .9rem; }
.top-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.updated { display: flex; align-items: center; gap: 8px; font-size: .85rem; opacity: .85; white-space: nowrap; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: #868e96; flex: none; }
.conn.on { background: var(--ok); animation: pulse 2.4s ease-in-out infinite; }
.conn.off { background: var(--bad); }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(47, 158, 68, .6); }
  70%  { box-shadow: 0 0 0 8px rgba(47, 158, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 68, 0); }
}
@media (prefers-reduced-motion: reduce) { .conn.on { animation: none; } }

.controls { display: flex; gap: 8px; }
.lang { display: flex; border: 1px solid rgba(255, 255, 255, .3); border-radius: 6px; overflow: hidden; }
.lang button {
  background: transparent; color: inherit; border: 0; padding: 3px 9px; font: inherit; font-size: .8rem;
  cursor: pointer; opacity: .7;
}
.lang button + button { border-left: 1px solid rgba(255, 255, 255, .3); }
.lang button[aria-pressed="true"] { background: rgba(255, 255, 255, .15); opacity: 1; font-weight: 600; }
@media (max-width: 600px) {
  .top { align-items: flex-start; }
  .updated { white-space: normal; text-align: right; }
}

.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px;
  padding: 20px 24px; margin: 0 auto;   /* full width – no max-width */
}
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .side { order: -1; }
}

/* Class grid */
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.cls {
  display: block; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; color: inherit; text-decoration: none; transition: border-color .15s;
}
.cls:hover { border-color: var(--accent); }
.cls .name { font-weight: 600; font-size: 1.05rem; display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.cls .count { color: var(--muted); font-size: .85rem; font-weight: 400; flex: none; }
.cls .sub { color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; gap: 6px; }
.cls .sub > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cls .radio { color: var(--accent); }

/* Class results */
.back { display: inline-block; margin-bottom: 10px; color: var(--accent); text-decoration: none; }
.cls-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.cls-head h2 { margin: 0; }
.cls-head .sub { color: var(--muted); }
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.club { color: var(--muted); }
/* Long names/clubs/teams: one line, cut with … (full text on hover) */
.cut, .nm { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.who .nm { max-width: 24em; }
td.club .cut { max-width: 18em; }
tr:last-child td { border-bottom: 0; }
tr.flash td { animation: flash 2.5s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: transparent; } }
.split .pl { color: var(--muted); font-size: .8rem; margin-left: 3px; }
.split.best, .split .best { color: var(--accent); font-weight: 600; }

/* Relay: team row, then one row per leg */
.relay tr.team-row td { font-weight: 600; border-top: 2px solid var(--line); }
.relay tr.team-row td.club, .relay tr.team-row .club-inline { font-weight: 400; }
.relay tr.leg-row td { border-bottom: 0; padding-top: 3px; padding-bottom: 3px; font-size: .9rem; }
.relay tr.leg-row td.who { padding-left: 22px; }
.relay tbody tr:first-child td { border-top: 0; }
.leg-no {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--line); color: var(--muted); font-size: .72rem; font-weight: 700;
}
.split .ctl { color: var(--muted); font-size: .72rem; margin-right: 4px; }
.status { color: var(--bad); }
.running { color: var(--ok); }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 30px 0; }

/* Latest finishers */
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section-head .back { margin-bottom: 0; }
.h-link { color: inherit; text-decoration: none; }
/* Clickable headers: "Classes | Clubs" on the overview */
.section-title.tabs { display: flex; gap: 16px; }
.tabs .tab { color: inherit; text-decoration: none; }
.section-title .tab { padding-bottom: 2px; border-bottom: 2px solid transparent; }
.section-title .tab:hover { color: var(--accent); }
.section-title .tab.active { color: var(--text); border-bottom-color: var(--accent); }
/* Relay leg selector: Overall | Leg 1 | Leg 2 ... */
.leg-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.leg-tabs .tab {
  padding: 3px 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel);
  font-size: .9rem; color: var(--muted);
}
.leg-tabs .tab:hover { border-color: var(--accent); color: var(--accent); }
.leg-tabs .tab.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
a.leg-no { text-decoration: none; }
a.leg-no:hover { background: var(--accent); color: #fff; }
/* Club results: one table per class */
.club-cls { margin: 16px 0 6px; font-size: 1.05rem; }
.club-cls:first-child { margin-top: 0; }
.club-cls a { color: var(--accent); text-decoration: none; }
.club-cls .sub { color: var(--muted); font-weight: 400; font-size: .85rem; }
.classes.clubs { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.clubs .cls .name { font-size: .98rem; }
.clubs .cls .name .cut { min-width: 0; }
.side h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: none; }
.h-link:hover { color: var(--accent); }
.h-link::after { content: " ›"; }
.filter {
  font: inherit; font-size: .9rem; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.cls-link { color: var(--accent); text-decoration: none; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover, th.sorted { color: var(--accent); }
.radio-table .pos { background: var(--ok); }
.side h2, .section-title { margin: 0 0 10px; font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.side h2 { letter-spacing: .01em; }   /* long Danish headers must fit with the › */
.latest { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.fact { min-width: 0; }   /* let long names shrink with … instead of widening the box */
.fact.radio-fact { border-left-color: var(--ok); }
.fact {
  display: block; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: 8px; color: inherit; text-decoration: none;
}
.fact.flash { animation: flash 2.5s ease-out; }
.fact .row1 { display: flex; justify-content: space-between; gap: 8px; }
.fact .who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fact .tag { background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 6px; font-size: .8rem; font-weight: 600; flex: none; }
/* Each fact box is always two lines: long names/clubs are cut with … instead of wrapping */
.fact .row2 { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85rem; }
.fact .row2 > span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fact .res { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; white-space: nowrap; flex: none;
  display: inline-flex; align-items: center; gap: 6px; }
/* Position as a round badge so it doesn't read as part of the time */
.pos {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; background: var(--accent); color: #fff; font-size: .75rem; font-weight: 700; line-height: 1;
}
.radio-fact .pos { background: var(--ok); }

/* Front page: competition list */
/* Desktop: finishers and radio punches stacked in one narrow column (each half the height, scrolling on its own),
   so the results get the width. Side by side only on very wide screens. */
@media (min-width: 901px) {
  body.has-radio .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  body.has-radio .side { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
  body.has-radio .side section { max-height: 100%; }
}
@media (min-width: 1900px) {
  body.has-radio .layout { grid-template-columns: minmax(0, 1fr) 600px; }
  body.has-radio .side { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: none; align-items: start; }
  body.has-radio .side section { max-height: calc(100vh - var(--head-h, 80px) - 40px); }
}

body.home .side { display: none; }
body.home .layout { grid-template-columns: minmax(0, 1fr); max-width: 900px; }
.page-title { margin: 0 0 4px; font-size: 1.2rem; }
/* Front page: title with the search box to the right (below it on phones) */
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.list-head .page-title { margin: 0; }
.search {
  flex: 0 1 320px; min-width: 0; font: inherit; font-size: .95rem; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
}
.search:focus { outline: none; border-color: var(--accent); }
@media (max-width: 600px) { .search { flex-basis: 100%; } }
.year { margin: 18px 0 8px; color: var(--muted); font-size: .9rem; letter-spacing: .04em; }
.competitions { display: grid; gap: 10px; }
.comp {
  display: block; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--accent); border-radius: 8px; color: inherit; text-decoration: none;
}
.comp:hover { border-color: var(--accent); }
.comp-date { color: var(--accent); font-size: .85rem; font-weight: 600; }
.live-badge {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--ok); color: #fff;
  font-size: .7rem; letter-spacing: .05em; vertical-align: 1px;
}
.comp-name { font-size: 1.1rem; font-weight: 600; }
.comp-sub { display: flex; justify-content: space-between; gap: 10px; color: var(--muted); font-size: .9rem; flex-wrap: wrap; }

/* Desktop: fixed layout – the page itself never scrolls. Header and side panel stay put;
   only the classes/results area scrolls, and each side list scrolls on its own if it's too long. */
@media (min-width: 901px) {
  body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  .top { flex: none; }
  .layout { flex: 1; min-height: 0; width: 100%; padding-bottom: 0; }
  /* main: fixed headings (back link, titles); only the [data-scroll] area inside scrolls */
  main { min-height: 0; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
  main > * { flex: none; }
  main > [data-scroll] { flex: 1 1 auto; min-height: 0; overflow-y: auto; margin-bottom: 20px; }
  main > .classes { align-content: start; }
  main > .table-wrap thead th { position: sticky; top: 0; z-index: 1; background: var(--panel); }
  /* room for the overlay scrollbar, so it never covers the last column's numbers */
  main > .table-wrap th:last-child, main > .table-wrap td:last-child { padding-right: 20px; }
  main > .classes, main > .scroll, main > .section-head, main > .club-results { padding-right: 12px; }
  /* no visible scrollbars on desktop – scroll with wheel/touchpad as usual */
  [data-scroll], .side .latest { scrollbar-width: none; }
  [data-scroll]::-webkit-scrollbar, .side .latest::-webkit-scrollbar { display: none; }
  .side { min-height: 0; height: 100%; padding-bottom: 20px; }
  .side section { display: flex; flex-direction: column; max-height: calc(100vh - var(--head-h, 80px) - 40px); min-height: 0; }
  .side .latest { overflow-y: auto; min-height: 0; }
}

/* ---------- Responsive: tablets and phones ---------- */
.club-inline { display: none; }
/* Relay leg: the team is always shown under the runner's name (no team column – keeps the table narrow) */
.leg-table .club-inline { display: block; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 24em; }
.leg-table td { padding-top: 4px; padding-bottom: 4px; }

@media (max-width: 900px) {
  /* Devices: the two lists stacked, each a swipeable strip */
  body.has-radio .layout { grid-template-columns: minmax(0, 1fr); }
  body.has-radio .side { display: block; }
  #radio-section { margin-top: 14px; }
  /* Latest finishers become a swipeable strip above the content */
  .latest { display: flex; align-items: flex-start; overflow-x: auto; gap: 10px; padding-bottom: 4px; scroll-snap-type: x mandatory; }
  .fact { flex: 0 0 240px; scroll-snap-align: start; }
}

@media (max-width: 600px) {
  body { font-size: 14px; }
  .top { padding: 10px 16px; flex-wrap: wrap; }
  .top h1 { font-size: 1.15rem; }
  .top-right { flex-direction: row-reverse; align-items: center; width: 100%; justify-content: space-between; }
  .lang button { padding: 6px 12px; }               /* bigger touch target */
  .layout { padding: 12px 16px; gap: 14px; }

  .classes { grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
  .classes.clubs { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .cls { padding: 10px; }

  .cls-head { flex-wrap: wrap; gap: 4px 10px; }
  th, td { padding: 6px 7px; }
  .col-club, .col-start { display: none; }           /* club moves under the name */
  td.who .nm, .club-inline { max-width: 55vw; }
  .club-inline { display: block; color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .relay tr.leg-row td.who { padding-left: 12px; }
  .split .pl { display: block; margin-left: 0; }
  .fact { flex-basis: 210px; }
}

/* Overlay scrollbar (desktop): thin, no space taken, only when there is more content */
.ovs-host { position: relative; }
@media (min-width: 901px) { .side .latest { padding-right: 10px; } }   /* room for the thumb next to the cards */
.ovs-thumb {
  position: absolute; width: 6px; border-radius: 3px; background: var(--muted);
  opacity: .35; z-index: 3; cursor: pointer; transition: opacity .2s, width .15s;
}
.ovs-host:hover .ovs-thumb, .ovs-thumb.active { opacity: .7; }
.ovs-thumb:hover { width: 8px; opacity: .85; }

/* ---------- Admin page (admin.html) ---------- */
.admin-main { width: 100%; max-width: 1100px; margin: 0 auto; padding: 20px 24px 40px; }
@media (min-width: 901px) { body.admin .admin-main { flex: 1; min-height: 0; overflow-y: auto; } }
@media (max-width: 600px) { .admin-main { padding: 12px 16px 32px; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
.card h2 { margin: 0 0 14px; font-size: 1.2rem; }
.form { display: flex; flex-direction: column; gap: 12px; max-width: 720px; }
.form.narrow { width: 100%; max-width: 380px; margin: 40px auto 0; }   /* fixed width, not shrink-to-content */
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.form input, .form select {
  font: inherit; font-size: .95rem; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.form input:focus, .form select:focus { outline: none; border-color: var(--accent); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form .row2 { grid-template-columns: 1fr; } }
.form p { margin: 0; }
.hint { color: var(--muted); font-size: .85rem; margin-top: -6px !important; }
.form-error { color: var(--bad); min-height: 1.2em; font-size: .9rem; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font: inherit; font-size: .9rem; padding: 7px 14px; border-radius: 8px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); display: inline-flex; align-items: center;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); color: #fff; }
.btn.danger { margin-left: auto; color: var(--bad); }
.btn.danger[data-armed] { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 3px 10px; font-size: .8rem; }
.btn:disabled { opacity: .6; cursor: default; }
td.actions { text-align: right; display: flex; gap: 6px; justify-content: flex-end; }
.link-btn { background: none; border: 0; color: inherit; font: inherit; font-size: .85rem; opacity: .85; cursor: pointer; text-decoration: underline; padding: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 4px 0; align-items: baseline; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; word-break: break-all; }
.kv .big { font-size: 1.6rem; font-weight: 700; color: var(--accent); }
body.admin .section-head { margin-bottom: 10px; align-items: center; }
body.admin .section-title { margin: 0; }
@media (max-width: 600px) { body.admin .col-status { display: none; } }
/* Admin event list: second row per event with the MeOS URL and public link */
body.admin tr.event-row td { border-bottom: 0; padding-bottom: 2px; }
body.admin tr.urls-row td { padding-top: 0; font-size: .82rem; white-space: normal; }
body.admin tr.urls-row td > span { display: inline-block; margin-right: 18px; word-break: break-all; }
body.admin .phone-only { display: none !important; }
@media (max-width: 600px) {
  body.admin .col-pwd { display: none; }
  body.admin tr.urls-row td > span.phone-only { display: inline-block !important; }
  body.admin tr.urls-row td > span { display: block; margin-right: 0; }
}
/* Date field: text input (yyyy-mm-dd) with a calendar button; the native picker sits invisibly under the button */
.date-field { position: relative; display: flex; }
.date-field input[name=date] { flex: 1; min-width: 0; padding-right: 40px; font-variant-numeric: tabular-nums; }
.date-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 32px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.date-btn:hover { color: var(--accent); background: var(--accent-soft); }
.date-native { position: absolute; right: 4px; bottom: 0; width: 32px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
