:root {
  color-scheme: dark;
  --bg: #555556;
  --bg-deep: #3f3f40;
  --card: #2b2b2c;
  --card-head: #313132;
  --muted: #c8c8c8;
  --accent: #eb6d1e;
  --accent-dim: #a94d14;
  --ok: #4caf50;
  --warn: #f0ad4e;
  --err: #e05252;
  --text: #ffffff;
  --text-dim: #bcbcbc;
  --border: #4e4e4f;
  --border-strong: #6a6a6b;
  --shadow: rgba(0, 0, 0, 0.25);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.5rem 7.5rem 0.5rem 0.75rem;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  margin: 0;
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1.2;
}
.topbar .sub { font-size: 0.8rem; color: var(--text-dim); }
.spacer { flex: 1 1 auto; }
.nav { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.nav a {
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
}
.nav a:hover { background: rgba(255,255,255,0.08); }
.nav a.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }

body.menu-hidden .topbar,
body.menu-hidden .page-top { display: none !important; }

.menu-toggle {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 10000;
  padding: 0.4rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-weight: 700;
  backdrop-filter: blur(6px);
  cursor: pointer;
  opacity: 0.25;
  transition: opacity 0.25s ease;
}
.menu-toggle:hover { opacity: 1; }

/* ---------------- live-indikator ---------------- */
.live {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.dot {
  width: 9px; height: 9px; border-radius: 999px;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.6);
}
.dot.live-pulse { animation: pulse 2s infinite; }
.dot.off { background: var(--err); animation: none; }
.dot.stale { background: var(--warn); animation: none; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(76,175,80,0.55); }
  70%  { box-shadow: 0 0 0 8px rgba(76,175,80,0); }
  100% { box-shadow: 0 0 0 0 rgba(76,175,80,0); }
}

/* ---------------- knappar & fält ---------------- */
button, .btn, .btn-secondary, .btn-outline {
  cursor: pointer;
  padding: 0.45rem 0.7rem;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #111;
  font-weight: 700;
  font-size: 0.85rem;
  text-decoration: none;
  display: inline-block;
}
.btn-secondary { background: #999; color: #111; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: rgba(255,255,255,0.08); }
.btn-outline.on { border-color: var(--accent); color: var(--accent); font-weight: 800; }
button:disabled { opacity: 0.5; cursor: default; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #4a4a4b;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); }

.page-top { padding: 0.5rem 0.75rem; }
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.filter-form { display: flex; align-items: center; gap: 0.4rem; }
label { font-size: 0.85rem; color: var(--text-dim); }

/* ---------------- kort ---------------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card-head);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}
.card-head h2 { margin: 0; font-size: 1.05rem; }
.card-head .count { font-size: 0.75rem; color: var(--muted); }

/* ---------------- tabeller ---------------- */
.table-wrap { width: 100%; overflow-x: auto; }
table.results {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.95rem;
}
table.results thead th {
  position: sticky;
  top: 0;
  background: var(--card-head);
  border: 1px solid var(--border-strong);
  border-bottom: 2px solid var(--border-strong);
  z-index: 1;
  padding: 5px 4px;
}
table.results th, table.results td {
  padding: 4px;
  text-align: center;
  border: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
table.results tbody tr:nth-child(even) { background: #3a3a3b; color: #e3e3e3; }
table.results tbody tr:nth-child(odd)  { background: #2f2f30; }
table.results th.pos, table.results td.pos {
  width: 3.5ch;
  white-space: nowrap;
  overflow-wrap: normal;
  font-variant-numeric: tabular-nums;
}
table.results td.name { text-align: left; }
.club { color: var(--text-dim); font-size: 0.9em; }
.tiny { font-size: 0.75em; color: var(--muted); }
.dnf { color: var(--err); font-weight: 700; }

/* nya/aktuella rader */
tr.highlight td { background: var(--accent) !important; color: #111 !important; font-weight: 700; }
tr.highlight .club, tr.highlight .tiny { color: #3a1c05 !important; }
@keyframes flashin {
  from { background: #fff4e6; }
  to   { background: var(--accent); }
}
tr.flash td { animation: flashin 1.2s ease-out; }

/* ---------------- passeringsvy ---------------- */
.passings-wrap { padding: 0 0.75rem 3rem; }
table.passings { width: 100%; border-collapse: collapse; font-size: 1.05rem; table-layout: fixed; }
table.passings thead th {
  position: sticky; top: 0; background: var(--card-head);
  border: 1px solid var(--border-strong); padding: 6px 8px;
}
table.passings td { border: 1px solid var(--border); padding: 5px 8px; }
table.passings tbody tr:nth-child(even) { background: #3a3a3b; }
table.passings tbody tr:nth-child(odd)  { background: #2f2f30; }
table.passings td.runner { font-weight: 700; text-align: left; }
table.passings td.what { text-align: left; }
table.passings th.namn { width: 34%; text-align: left; }
table.passings td.time { font-variant-numeric: tabular-nums; text-align: center; }
.logo { position: fixed; right: 12px; bottom: 12px; max-height: 90px; opacity: 0.9; pointer-events: none; }

/* ---------------- masonry-grid ---------------- */
.grid { margin: 0 auto; padding: 0 0.5rem 2rem; }
.grid-item { margin-bottom: var(--gutter, 12px); }
@media (max-width: 640px) {
  .grid-sizer, .grid-item { width: 100% !important; }
}

/* ---------------- meddelanden ---------------- */
.empty {
  margin: 1rem 0.75rem;
  padding: 1rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  background: #4b4b4c;
}
.empty.small { font-size: 0.9rem; margin: 0; border: 0; background: transparent; }
.flash-msg {
  padding: 0.6rem 0.8rem; border-radius: 8px; margin: 0.5rem 0;
  background: #3d5a3d; border: 1px solid var(--ok); font-size: 0.9rem;
}
.flash-msg.err { background: #5a3d3d; border-color: var(--err); }
.warn-banner {
  margin: 0.5rem 0.75rem; padding: 0.6rem 0.8rem; border-radius: 8px;
  background: #5a4a2a; border: 1px solid var(--warn); font-size: 0.9rem;
}

/* ---------------- startsida ---------------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; padding: 1rem; }
.tile { display: block; text-decoration: none; color: var(--text); padding: 1rem; }
.tile:hover { border-color: var(--accent); }
.tile h3 { margin: 0 0 0.35rem; color: var(--accent); font-size: 1.1rem; }
.tile p { margin: 0; font-size: 0.85rem; color: var(--text-dim); }
.statgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; padding: 0 1rem 1rem; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; }
.stat .k { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.stat .v { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------- inställningar ---------------- */
.config-wrap { max-width: 1000px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.fieldgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 0.75rem; padding: 0.9rem; }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field .hint { font-size: 0.72rem; color: var(--muted); }
.field label.check { display: flex; align-items: center; gap: 0.4rem; color: var(--text); }
.field.wide { grid-column: 1 / -1; }
.sticky-save {
  position: sticky; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.9rem; background: var(--bg-deep);
  border: 1px solid var(--border); border-radius: var(--radius);
}
table.slides { width: 100%; border-collapse: collapse; }
table.slides td, table.slides th { padding: 4px; border-bottom: 1px solid var(--border); text-align: left; }
table.slides td:last-child { white-space: nowrap; }
table.slides button { padding: 0.3rem 0.5rem; }
table.slides input[type="text"] { width: 100%; }
.comp-results { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.comp-results div {
  padding: 0.4rem 0.6rem; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.85rem;
}
.comp-results div:hover { background: rgba(235,109,30,0.2); }
.comp-results .cid { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------------- byggare för rotatorbilder ---------------- */
.sb-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 2vh 2vw;
  backdrop-filter: blur(3px);
}
.sb {
  width: min(1200px, 100%);
  max-height: 96vh;
  display: flex; flex-direction: column;
}
.sb .card-head button { padding: 0.15rem 0.5rem; font-size: 1.1rem; line-height: 1; }
.sb-body {
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 1rem;
  padding: 1rem;
  overflow: auto;
}
@media (max-width: 900px) { .sb-body { grid-template-columns: 1fr; } }

.sb-form { display: flex; flex-direction: column; gap: 0.85rem; }
.sb-row { display: flex; flex-direction: column; gap: 0.35rem; }
.sb-row > label { font-size: 0.85rem; color: var(--text-dim); }
.sb-row.sb-inline { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.sb-row.sb-inline > label { display: flex; align-items: center; gap: 0.35rem; }
.sb-row .hint { font-size: 0.72rem; color: var(--muted); }
.sb-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.sb-chipbar { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.sb-chips {
  display: flex; flex-wrap: wrap; gap: 0.3rem;
  max-height: 210px; overflow: auto;
  padding: 0.5rem; border: 1px solid var(--border); border-radius: 8px; background: #3a3a3b;
}
.sb-chip {
  cursor: pointer; font-size: 0.78rem; font-weight: 600;
  padding: 0.25rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border-strong); background: #4a4a4b; color: var(--text);
}
.sb-chip:hover { border-color: var(--accent); }
.sb-chip.on { background: var(--accent); color: #111; border-color: var(--accent); }

.sb-preview { display: flex; flex-direction: column; gap: 0.5rem; min-width: 0; }
.sb-url { display: flex; align-items: baseline; gap: 0.5rem; min-width: 0; }
.sb-url code {
  flex: 1 1 auto; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 0.78rem; color: var(--accent);
  background: #3a3a3b; border: 1px solid var(--border); border-radius: 6px; padding: 0.3rem 0.5rem;
}
.sb-frame {
  position: relative; flex: 1 1 auto; min-height: 340px;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--bg);
}
/* Sidan renderas i 1600px bredd och skalas ned, som på en storbild. */
.sb-frame iframe {
  position: absolute; top: 0; left: 0;
  width: 1600px; height: 1000px; border: 0;
  transform: scale(0.42); transform-origin: top left;
}
@media (min-width: 1400px) { .sb-frame iframe { transform: scale(0.46); } }

.sb-foot {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.75rem 1rem; border-top: 1px solid var(--border); background: var(--card-head);
}
