/* Mobile-first, iPhone-optimized (safe-area aware), light + dark. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c1c1c;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #c52026;
  --accent-contrast: #ffffff;
  --vest: #2f6b37;
  --oest: #b0560a;
  --danger: #c52026;
  --shadow: 0 1px 2px rgba(16, 32, 48, 0.08);
}

:root[data-theme="dark"] {
  --bg: #0f141b;
  --surface: #1a222c;
  --surface-2: #232d39;
  --text: #e8eef5;
  --text-muted: #94a1b0;
  --border: #2b3644;
  --accent: #e0555c;
  --accent-contrast: #2a0a0c;
  --vest: #4a9b5b;
  --oest: #d98a3d;
  --danger: #e0645b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b;
    --surface: #1a222c;
    --surface-2: #232d39;
    --text: #e8eef5;
    --text-muted: #94a1b0;
    --border: #2b3644;
    --accent: #4f9df0;
    --accent-contrast: #06223f;
    --vest: #2fbf8a;
    --oest: #d98a3d;
    --danger: #e0645b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 12px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 12px);
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 2px 8px;
}
.logo {
  height: 20px;
  width: auto;
  min-width: 0;
  flex-shrink: 1;
  display: block;
}
.season-select {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 8px;
  min-width: 0;
  max-width: 100%;
  flex: none;
}
.season-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
}
.updated {
  flex: none;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 84px;
}
.refresh-btn {
  border: none;
  background: var(--surface-2);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.refresh-btn:active { transform: scale(0.94); }
.refresh-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Bottom navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  max-width: 460px;
  margin: 0 auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 0 7px;
  cursor: pointer;
}
.nav-tab .nav-icon {
  width: 28px;
  height: 28px;
}
.nav-tab.is-active {
  color: var(--accent);
}

/* Filters */
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filters .lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 6px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex: none;
}
.chips button.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

/* Aldersgruppe-chips + klubvælger på samme række */
.age-club-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.age-club-row .chips {
  flex: none;
}
.club-select {
  flex: 1;
  min-width: 120px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 28px 8px 10px;
  cursor: pointer;
  text-overflow: ellipsis;
}

/* På små skærme er der ikke plads til klubvælgeren ved siden af chips'ene,
   så den lægges på egen linje under aldersgrupperne. */
@media (max-width: 480px) {
  .age-club-row {
    flex-direction: column;
    align-items: stretch;
  }
  .club-select {
    flex: none;
    width: 100%;
  }
}

/* Filtrér-knap */
.filter-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.filter-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 9px;
  line-height: 1.4;
}

/* Dommer-filter: "Filtrér"-knap + søgefelt side om side */
.filter-bar { display: flex; gap: 8px; align-items: stretch; }
.filter-bar .filter-open { width: auto; flex: none; }
.filter-bar .search { flex: 1; width: auto; }

/* Række-checkliste (i bund-sheet) */
.division-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 2px;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.division-option:last-child { border-bottom: none; }
.division-option input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}

/* Bund-sheet */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(10, 12, 16, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  max-height: 85%;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet-grab {
  width: 36px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px auto 4px;
  flex: none;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 10px;
  flex: none;
}
.sheet-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.clear-btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
}
.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 16px 12px;
}
.sheet-body .lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 14px 0 6px;
}
.sheet-close {
  flex: none;
  margin: 6px 16px 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: none;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
}

.search {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  padding: 10px 14px;
  border-radius: 10px;
  outline: none;
}
.search:focus { border-color: var(--accent); }

/* Date group header */
.day-header {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg);
  padding: 8px 2px 6px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

/* Match card */
.match {
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.match-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.match-time {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(18px, 5.2vw, 24px);
  color: var(--accent);
}
.match-result {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: clamp(20px, 6vw, 26px);
  color: var(--text);
  letter-spacing: 0.01em;
}
.match-result.cancelled {
  font-size: 13px;
  color: var(--text-muted);
}
.match-result.no-result {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}
.team .forfeit-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  padding: 1px 6px;
  border-radius: 5px;
  letter-spacing: 0.02em;
}
.match-league {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex: none;
}
.badge.vest { background: color-mix(in srgb, var(--vest) 16%, transparent); color: var(--vest); }
.badge.oest { background: color-mix(in srgb, var(--oest) 16%, transparent); color: var(--oest); }

.stream-link {
  font-size: 16px;
  line-height: 1;
  text-decoration: none;
  flex: none;
  display: inline-block;
}
.stream-link:active { transform: scale(0.9); }

.match-head-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex: none;
}

.match-teams {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  margin: 2px 0 8px;
}
.team { display: flex; align-items: center; gap: 8px; font-size: clamp(20px, 6vw, 26px); }
.team .tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 5px;
}
.team.away { color: var(--text); }
.team-name {
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  line-height: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.team-name:active { opacity: 0.6; }

.match-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
}
.match-meta .venue {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  text-decoration: none;
}
.match-meta .venue:hover { text-decoration: underline; }
.match-meta .venue::before { content: "📍"; }
.match-refs {
  font-size: 13px;
  color: var(--text);
}
.match-refs .refs-label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.match-refs .refs-names { display: inline; }
.match-refs .ref-name {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: text-decoration-color 0.15s ease;
}
.match-refs .ref-name:hover,
.match-refs .ref-name:focus-visible {
  text-decoration-color: currentColor;
}

/* Referee card */
.referee {
  background: var(--surface);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.referee-head {
  display: flex;
  align-items: center;
  gap: 8px;
}
.referee-name { font-weight: 700; font-size: 16px; flex: 1; }
.referee-total { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.referee-breakdown {
  font-size: 12px;
  color: var(--text-muted);
  margin: 6px 0 10px;
}
.breakdown-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 2px 0;
  line-height: 1.4;
  cursor: pointer;
}
.breakdown-row .div-chev {
  width: 12px;
  font-size: 10px;
  flex: none;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.breakdown-row.is-open .div-chev { transform: rotate(90deg); }
.breakdown-row .div-name {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breakdown-row .div-dots {
  flex: 1 1 auto;
  border-bottom: 1px dotted var(--text-muted);
  opacity: 0.45;
  min-width: 8px;
}
.breakdown-row .div-count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex: none;
}
.breakdown-matches { margin: 2px 0 6px 18px; }
.breakdown-match {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 0;
  align-items: baseline;
  flex-wrap: wrap;
}
.breakdown-match .rm-date { flex: none; }
.breakdown-match .rm-teams {
  flex: 1 1 auto;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.breakdown-match .rm-teams.has-protocol { cursor: pointer; }
.breakdown-match .rm-teams.has-protocol:hover { text-decoration: underline; }
.breakdown-match .rm-result { flex: none; font-variant-numeric: tabular-nums; }
.breakdown-match .rm-result.forfeit { color: var(--accent); }
.breakdown-match .rm-result.muted { color: var(--text-muted); }
.breakdown-match .rm-med {
  flex: none;
  font: inherit;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.breakdown-match .rm-med:hover { text-decoration: underline; }
.breakdown-empty { font-size: 12px; color: var(--text-muted); padding: 3px 0; }
.referee.highlight { background: color-mix(in srgb, var(--accent) 12%, transparent); border-radius: 12px; transition: background 0.6s; }
.region-badge {
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.region-badge.vest {
  border-color: transparent;
  background: color-mix(in srgb, var(--vest) 16%, transparent);
  color: var(--vest);
}
.region-badge.oest {
  border-color: transparent;
  background: color-mix(in srgb, var(--oest) 16%, transparent);
  color: var(--oest);
}
.region-badge:active { transform: scale(0.95); }

/* "Klub"-mærkat på dommere der (også) dømmer klub-kampe */
.klub-badge {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
  flex: none;
}

/* Røde kort (udfoldelig tæller) */
.rcard {
  display: inline-block;
  width: 10px;
  height: 14px;
  background: var(--accent);
  border-radius: 2px;
  flex: none;
}
.redcard-row {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  margin: 10px 0 0;
  padding: 7px 10px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  border: 0;
  border-radius: 9px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  text-align: left;
}
.redcard-row .rcard { width: 11px; height: 15px; }
.redcard-chev {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.8;
}
.redcard-row[aria-expanded="true"] .redcard-chev { transform: rotate(180deg); }
.redcard-detail {
  margin: 6px 0 0;
  padding: 0 2px;
}
.redcard-match {
  display: flex;
  gap: 9px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.redcard-match:last-child { border-bottom: 0; }
.redcard-match .rcard { margin-top: 2px; }
.redcard-match-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.redcard-when { font-size: 11.5px; color: var(--text-muted); }
.redcard-teams { font-size: 13px; color: var(--text); font-weight: 600; }
.redcard-co { font-size: 11.5px; color: var(--text-muted); }
.redcard-protocol {
  align-self: flex-start;
  margin-top: 3px;
  border: none;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

/* State panels */
.state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.state-icon { font-size: 40px; margin: 0 0 8px; }
.state-ball {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  display: block;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.8s linear infinite;
}
.primary {
  border: none;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
}

.hidden { display: none !important; }

[hidden] { display: none !important; }

/* Kampprotokol */
.protocol-link {
  align-self: flex-start;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.protocol-link:active { transform: scale(0.97); }
.protocol-missing {
  align-self: flex-start;
  font-size: 11px;
  font-weight: 600;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  padding: 3px 8px;
  border-radius: 6px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  z-index: 2;
}
.modal-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
/* Fotoet er af et stående dokument; hvis billedet er liggende (bredere end højt),
   er det taget på siden og roteres 90° for at stå rigtigt. */
.modal-img.rotate-90 { transform: rotate(-90deg); }

/* Desktop: brug mere af skærmen i stedet for en smal mobil-kolonne. */
@media (min-width: 640px) {
  .app,
  .bottom-nav,
  .sheet {
    max-width: 760px;
  }
  .updated {
    max-width: none;
  }
}

/* ---------------------------------------------------------------------------
   Stillinger-fane (league standings)
   --------------------------------------------------------------------------- */
.stillinger-filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.sfl-row { display: flex; gap: 8px; align-items: stretch; }
.sfl-row .chips { flex: 1; }
.sdetail { flex: none !important; }

.stand-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 12px 6px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.stand-card.highlight {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-color: var(--accent);
  transition: background 0.6s, border-color 0.6s;
}
.stand-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.stand-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pulje-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin: 8px 0 2px;
}

.stand-scroll { overflow-x: auto; }
.stand { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.stand th {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-muted); text-align: right; padding: 5px 4px 4px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.stand th.hold { text-align: left; }
.stand th.pos, .stand th[colspan] { text-align: center; }
.stand td { text-align: right; padding: 6px 4px; color: var(--text); white-space: nowrap; }
.stand tbody tr:nth-child(even) { background: var(--surface-2); }
.stand .pos { color: var(--text-muted); width: 22px; text-align: center; }
.stand td.hold { text-align: left; font-weight: 600; max-width: 132px; padding: 0; }
.stand .team-link {
  display: block;
  width: 100%;
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  padding: 6px 4px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stand .team-link:active { opacity: 0.55; }
.stand .pts { font-weight: 800; color: var(--accent); }
.stand-det { min-width: 560px; }
