/* Taurlandija tracker — stili.
   Mērķi: lasāms uz štāba projektora un uz telefona, bez atkarībām. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --line: #e2e5ea;
  --ink: #111827;
  --ink-soft: #5b6472;
  --accent: #ea580c;

  --s-gaida: #8a8f98;
  --s-prognoze: #3b82f6;
  --s-skrien: #16a34a;
  --s-kave: #f59e0b;
  --s-pazudis: #dc2626;
  --s-finisejis: #7c3aed;
  --s-dnf: #4b5563;

  --panel-w: 380px;
  --bar-h: 52px;
  --ctl-h: 44px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

#app {
  display: grid;
  grid-template-rows: var(--bar-h) auto 1fr var(--ctl-h);
  grid-template-areas: "bar" "fresh" "main" "ctl";
  height: 100%;
}

/* ------------------------------------------------------------------ josla */
#bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 10px; flex: 0 0 auto; }
.brand strong { font-size: 15px; white-space: nowrap; }
.clock {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink-soft);
}

.stats {
  display: flex;
  gap: 14px;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.stats::-webkit-scrollbar { display: none; }

.stat { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.stat b { font-variant-numeric: tabular-nums; font-size: 15px; }
.stat span { color: var(--ink-soft); font-size: 12px; }
.stat.warn b { color: var(--s-pazudis); }

.actions { display: flex; gap: 6px; flex: 0 0 auto; }

#search {
  width: 150px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: var(--bg);
}
#search:focus { outline: 2px solid var(--s-prognoze); outline-offset: -1px; }

button {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
button:hover { background: var(--bg); }

/* ------------------------------------------------------- datu svaigums */
.freshness {
  grid-area: fresh;
  padding: 6px 12px;
  background: #fef3c7;
  border-bottom: 1px solid #fcd34d;
  color: #78350f;
  font-size: 13px;
}
.freshness.bad { background: #fee2e2; border-bottom-color: #fca5a5; color: #7f1d1d; }

/* -------------------------------------------------------- karte + panelis */
main {
  grid-area: main;
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  min-height: 0;
}

#map { width: 100%; height: 100%; background: #dfe3e8; }

/* Rokturis kartes augstuma maiņai — tikai telefonā. */
.handle { display: none; }

#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}

#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  padding: 9px 4px;
  font-size: 13px;
  line-height: 1.2;
  /* Bez šī nozīmīte ietin otrā rindā un visa josla kļūst divreiz augstāka. */
  white-space: nowrap;
  color: var(--ink-soft);
}

#tabs .short { display: none; }
#tabs button.active {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 17px;
  margin-left: 5px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--s-pazudis);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 17px;
  text-align: center;
}
.badge.soft { background: var(--s-kave); }

.tab { flex: 1; overflow-y: auto; min-height: 0; }
.tab[hidden] { display: none; }

/* ------------------------------------------------------ KP izvēle */
.chooser {
  display: flex;
  gap: 5px;
  padding: 8px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
}
.chooser button { white-space: nowrap; font-size: 13px; }
.chooser button.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
  font-weight: 600;
}

/* ---------------------------------------------------------- saraksti */
.group-head {
  padding: 7px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  position: sticky;
  top: 0;
  z-index: 1;
}

.row {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:hover { background: var(--bg); }
.row.hi { background: #fff7ed; box-shadow: inset 3px 0 0 var(--accent); }

.bib {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: center;
  padding: 2px 0;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.who { min-width: 0; }
.who .nm { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .meta { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.eta { text-align: right; font-variant-numeric: tabular-nums; }
.eta .big { font-weight: 600; }
.eta .sub { font-size: 12px; color: var(--ink-soft); }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
}
.dot.gaida { background: var(--s-gaida); }
.dot.prognoze { background: var(--s-prognoze); }
.dot.skrien { background: var(--s-skrien); }
.dot.kave { background: var(--s-kave); }
.dot.pazudis { background: var(--s-pazudis); }
.dot.finisejis { background: var(--s-finisejis); }
.dot.dnf, .dot.nezinams { background: var(--s-dnf); }

.empty {
  padding: 22px 16px;
  color: var(--ink-soft);
  text-align: center;
  font-size: 13px;
}

.issue {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid var(--s-kave);
  font-size: 13px;
}
.issue.hard { border-left-color: var(--s-pazudis); }

.note {
  padding: 10px 12px;
  color: var(--ink-soft);
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

/* ---------------------------------------------------------- vadība */
#controls {
  grid-area: ctl;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
#controls::-webkit-scrollbar { display: none; }

.ctl { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 13px; color: var(--ink-soft); }
.ctl select { font: inherit; padding: 3px 6px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); }

#replaySlider { flex: 1 1 160px; min-width: 120px; accent-color: var(--accent); }
#replaySlider:disabled { opacity: 0.4; }

.replay-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 52px; }

.legend { display: flex; gap: 10px; font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.legend b { font-variant-numeric: tabular-nums; color: var(--ink); }
.legend .off { opacity: 0.35; }

/* --------------------------------------------------------- kļūdas ekrāns */
#fatal {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #1f2937;
}
#fatal[hidden] { display: none; }
.fatal-card {
  max-width: 560px;
  padding: 22px 24px;
  border-radius: 10px;
  background: var(--surface);
}
.fatal-card h2 { margin: 0 0 10px; font-size: 17px; }
#fatalMsg { margin: 0 0 12px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; word-break: break-word; }
.fatal-hint { margin: 0; color: var(--ink-soft); font-size: 13px; }

/* ------------------------------------------------------------- lielais ekrāns */
body.big { --panel-w: 460px; }
body.big #bar { --bar-h: 64px; }
body.big .brand strong, body.big .clock { font-size: 20px; }
body.big .stat b { font-size: 20px; }
body.big .row { padding: 11px 14px; }
body.big .who .nm { font-size: 16px; }

/* ----------------------------------------------------------------- telefons */
@media (max-width: 820px) {
  #app { grid-template-rows: auto auto 1fr auto; }

  /* Kartes augstums ir regulējams: telefonā svarīgākais ir saraksts. */
  main {
    grid-template-columns: 1fr;
    grid-template-rows: 34vh auto 1fr;
  }
  body[data-map-size="s"] main { grid-template-rows: 20vh auto 1fr; }
  body[data-map-size="l"] main { grid-template-rows: 58vh auto 1fr; }

  #panel { border-left: 0; border-top: 0; }

  .handle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 5px 0 6px;
    border: 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    background: var(--bg);
    border-radius: 0;
  }
  .handle .grip {
    width: 34px;
    height: 4px;
    border-radius: 2px;
    background: #b9c0ca;
  }
  .handle .hint { font-size: 11px; color: var(--ink-soft); }

  /* Galva: divas kompaktas rindas, nevis trīs augstas. */
  #bar { flex-wrap: wrap; gap: 6px; padding: 6px 10px; height: auto; }
  .brand { width: 100%; justify-content: space-between; }
  .brand strong { font-size: 14px; }
  .stats { gap: 11px; order: 3; width: 100%; }
  .stat b { font-size: 14px; }
  .stat span { font-size: 11px; }
  .actions { flex: 1; }
  #search { flex: 1; width: auto; min-width: 0; }

  /* Ciļņu josla: īsie apzīmējumi, mazāks fonts, nozīmīte blakus tekstam. */
  #tabs .full { display: none; }
  #tabs .short { display: inline; }
  #tabs button { padding: 8px 2px; font-size: 12px; }
  .badge { min-width: 15px; margin-left: 0; font-size: 10px; line-height: 15px; }

  /* Blīvākas rindas — telefonā katrs pikselis ir viena rinda vairāk. */
  .row { padding: 7px 10px; gap: 7px; grid-template-columns: 38px 1fr auto; }
  .who .nm { font-size: 14px; }
  .group-head { padding: 5px 10px; }
  .note { padding: 7px 10px; }

  /* Temps/replay telefonā ir paslēpti zem ⚙ — reti vajadzīgi, aizņem divas rindas. */
  #controls { display: none; }
  body.show-controls #controls {
    display: flex;
    height: auto;
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .legend { display: none; }
}
