/* Paleta: lód (tło), atrament fiordu (tekst), pomarańcz stacji (akcent, ostrzeżenia), głęboki fiord (linki).
   Ciemny motyw to noc polarna. */
:root {
  --ground: #e6edf0;
  --surface: #f6f9fa;
  --ink: #10222c;
  --muted: #566d7a;
  --line: #c3d1d8;
  --fjord: #0f4c5c;
  --orange: #d8481f;
  --shot: #0c1a21;
  --focus: #0f4c5c;
  --on-accent: #f6f9fa;
  --radius: 3px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0a151b;
    --surface: #102029;
    --ink: #dce8ed;
    --muted: #8ba3b0;
    --line: #223844;
    --fjord: #7cc1d3;
    --orange: #ff7a4d;
    --shot: #050c10;
    --focus: #7cc1d3;
    --on-accent: #06141a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1400px; margin: 0 auto; padding: 20px 20px 40px; outline: none; }
a { color: var(--fjord); }
img { max-width: 100%; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }

/* ---------- Nagłówek ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  flex-wrap: wrap;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand { text-decoration: none; color: var(--ink); display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: 30px; font-weight: 850; font-stretch: 118%; letter-spacing: -0.01em; }
.brand-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.top-status { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.pulse { margin: 0; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.pulse::before {
  content: "";
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fjord);
  flex: none;
}
.pulse.is-stale::before { background: var(--orange); }
.pulse.is-stale { color: var(--ink); }

.btn {
  font: inherit; font-size: 14px; font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px;
}
.btn:hover { border-color: var(--fjord); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-solid { background: var(--fjord); border-color: var(--fjord); color: var(--on-accent); }

/* ---------- Podgląd na żywo: mozaika ---------- */
.mosaic { display: grid; gap: 18px; grid-template-columns: 1fr; }
@media (min-width: 720px) {
  .mosaic { grid-template-columns: repeat(2, 1fr); }
  .frame:first-child { grid-column: span 2; }
}
@media (min-width: 1100px) {
  /* Pierwsza kamera zajmuje 2x2 pola, pozostałe cztery układają się obok niej. */
  .mosaic { grid-template-columns: repeat(4, 1fr); }
  .frame:first-child { grid-column: span 2; grid-row: span 2; }
}

.frame {
  display: flex; flex-direction: column;
  text-decoration: none; color: inherit;
  border-top: 3px solid var(--fjord); background: var(--surface);
}
.frame.is-stale { border-top-color: var(--orange); }
.frame.is-empty { border-top-color: var(--line); }
.shot { flex: 1 1 auto; position: relative; aspect-ratio: 16 / 9; min-height: 0; background: var(--shot); display: grid; place-items: center; overflow: hidden; }
.shot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.shot .none { color: var(--muted); font-size: 14px; padding: 16px; text-align: center; max-width: 36ch; }
.cap { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; padding: 10px 14px 12px; }
.cap-title { font-weight: 700; font-stretch: 105%; }
.cap-time { font-size: 14px; color: var(--muted); text-align: right; }
.cap-time strong { color: var(--ink); font-weight: 600; }
.frame:hover .cap-title { text-decoration: underline; text-underline-offset: 3px; }

.totals { margin: 22px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Galeria ---------- */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; padding: 0; list-style: none; }
.tabs a {
  display: block; padding: 7px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); font-size: 14px; font-weight: 600; background: var(--surface);
}
.tabs a[aria-current="page"] { background: var(--fjord); border-color: var(--fjord); color: var(--on-accent); }

.daybar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 0 0 18px; }
.daybar h1 { margin: 0 14px 0 0; font-size: 26px; font-weight: 800; font-stretch: 112%; letter-spacing: -0.01em; }
.daybar .count { color: var(--muted); font-size: 14px; margin-left: auto; }
.daybar input[type="date"], .daybar select {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; min-height: 36px;
}

.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.thumb {
  all: unset; box-sizing: border-box; cursor: pointer; display: block;
  background: var(--surface); border-top: 2px solid var(--line);
}
.thumb:hover { border-top-color: var(--fjord); }
.thumb:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.thumb .tshot { display: block; aspect-ratio: 16 / 10; background: var(--shot); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tt { display: block; padding: 5px 8px 7px; font-size: 13px; font-variant-numeric: tabular-nums; }

.more { display: flex; justify-content: center; margin: 24px 0 0; }
.empty { padding: 40px 0; color: var(--muted); max-width: 52ch; }
.empty strong { color: var(--ink); display: block; margin-bottom: 4px; font-size: 18px; }

/* ---------- Podgląd pojedynczego zdjęcia ---------- */
dialog#viewer {
  padding: 0; border: 0; background: var(--shot); color: #dce8ed;
  width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0;
}
dialog#viewer[open] { display: flex; flex-direction: column; }
dialog#viewer::backdrop { background: #000; }
.v-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; }
.v-title { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.v-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.v-bar .btn { color: #dce8ed; border-color: #38505c; }
.v-bar .btn:hover { border-color: #7cc1d3; }
.v-bar .btn-solid { background: #7cc1d3; border-color: #7cc1d3; color: #06141a; }
.v-speed { font-size: 13px; color: #9db3be; display: flex; align-items: center; gap: 6px; }
.v-speed select { font: inherit; font-size: 13px; background: #102029; color: #dce8ed; border: 1px solid #38505c; border-radius: var(--radius); padding: 5px 6px; }
.v-stage { flex: 1; min-height: 0; display: grid; grid-template-columns: 56px 1fr 56px; align-items: center; }
.v-stage img { width: 100%; height: 100%; object-fit: contain; min-height: 0; min-width: 0; }
.v-nav {
  font: inherit; font-size: 40px; line-height: 1; color: #dce8ed; background: transparent; border: 0;
  height: 100%; cursor: pointer;
}
.v-nav:hover { color: #7cc1d3; }
.v-nav:disabled { opacity: 0.25; cursor: default; }
.v-foot { padding: 6px 16px 14px; }
.v-foot input[type="range"] { width: 100%; accent-color: #7cc1d3; }
.v-hint { margin: 4px 0 0; font-size: 12px; color: #8aa0ac; }
@media (max-width: 600px) {
  .v-stage { grid-template-columns: 40px 1fr 40px; }
  .v-hint { display: none; }
}

/* ---------- Nawigacja ---------- */
.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a {
  display: block; padding: 7px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); font-size: 14px; font-weight: 600; background: transparent;
}
.nav a:hover { border-color: var(--fjord); }
.nav a[aria-current="page"] { background: var(--fjord); border-color: var(--fjord); color: var(--on-accent); }

/* ---------- Zaznaczanie w galerii ---------- */
.daybar .btn[aria-pressed="true"] { background: var(--fjord); border-color: var(--fjord); color: var(--on-accent); }
.thumb .tshot { position: relative; }
.thumb .tick, .thumb .disk { display: none; position: absolute; }
.grid.selecting .thumb .tick {
  display: block; left: 6px; top: 6px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid #fff; background: rgba(0, 0, 0, 0.35); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
}
.grid.selecting .thumb.is-picked { outline: 3px solid var(--fjord); outline-offset: -3px; }
.grid.selecting .thumb.is-picked .tick { background: var(--fjord); border-color: #fff; }
.grid.selecting .thumb.is-picked .tick::after {
  content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg);
}
.thumb.is-copied .disk {
  display: block; right: 6px; bottom: 6px; padding: 1px 7px; border-radius: 2px;
  font-size: 11px; font-weight: 700; background: var(--fjord); color: var(--on-accent);
}

.selbar {
  position: sticky; bottom: 0; z-index: 5; margin: 18px -20px -40px; padding: 12px 20px 14px;
  background: var(--surface); border-top: 2px solid var(--fjord);
  display: grid; gap: 8px;
}
.sel-sum { margin: 0; font-weight: 700; }
.sel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sel-msg { margin: 0; font-size: 14px; min-height: 1.4em; }
.sel-hint { margin: 0; font-size: 13px; color: var(--muted); }

/* ---------- Archiwum i kopiowanie ---------- */
.page-h { margin: 0 0 6px; font-size: 28px; font-weight: 800; font-stretch: 112%; letter-spacing: -0.01em; }
.lead { margin: 0 0 20px; color: var(--muted); max-width: 70ch; }
.panel {
  background: var(--surface); border: 1px solid var(--line); border-top: 2px solid var(--fjord);
  padding: 16px 18px 18px; margin: 0 0 18px;
}
.panel h2 { margin: 0 0 10px; font-size: 18px; font-weight: 750; font-stretch: 108%; }
.note { margin: 0 0 10px; font-size: 14px; color: var(--muted); max-width: 80ch; }
.note code { color: var(--ink); }
.sum { margin: 10px 0 0; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 12px; }
.toolbar-group { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.toolbar input[type="number"], .inline-form input {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--ground);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; min-height: 36px;
}
.toolbar input[type="number"] { width: 5.5em; }
.btn-danger { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-danger:hover { border-color: var(--ink); }
[data-theme="dark"] .btn-danger, .btn-danger:disabled { color: #fff; }
.linkbtn { font: inherit; color: var(--fjord); background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 0 0 8px; }
.inline-form label { font-size: 14px; font-weight: 600; }

.folderbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.folder-cur { margin: 0; }
.folder-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.folderbar .note { flex-basis: 100%; margin: 0; }

.tablewrap { overflow-x: auto; border: 1px solid var(--line); background: var(--ground); max-height: 60vh; overflow-y: auto; }
.matrix { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.matrix th, .matrix td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.matrix thead th { position: sticky; top: 0; z-index: 2; background: var(--surface); font-weight: 700; white-space: nowrap; }
.matrix tbody th { background: var(--surface); position: sticky; left: 0; z-index: 1; white-space: nowrap; font-weight: 600; }
.matrix thead th:first-child { left: 0; z-index: 3; }
.matrix label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.matrix input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--fjord); }
.c-none { color: var(--muted); text-align: center; }
.c-sum { text-align: right; white-space: nowrap; color: var(--muted); }
.c-cam { min-width: 9em; }
.cell { display: inline-flex; align-items: center; gap: 8px; }
.cell-n { font-weight: 700; }
.cell-sz { color: var(--muted); }
.c-chk { width: 1%; }
.chip {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 2px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--line); color: var(--ink);
}
.chip-ok { background: var(--fjord); border-color: var(--fjord); color: var(--on-accent); }
.chip-busy { border-color: var(--fjord); color: var(--fjord); }
.chip-warn { border-color: var(--orange); color: var(--orange); }
.chip-bad { background: var(--orange); border-color: var(--orange); color: #fff; }
.chip-live { border-color: var(--orange); color: var(--orange); }

progress { width: 100%; height: 10px; accent-color: var(--fjord); display: block; margin: 4px 0; }
.log { list-style: none; margin: 8px 0 0; padding: 0; max-height: 220px; overflow: auto; font-size: 13px; font-variant-numeric: tabular-nums; }
.log li { padding: 3px 0; border-bottom: 1px solid var(--line); white-space: pre-wrap; }
.log-ok { color: var(--ink); }
.log-warn { color: var(--orange); }
.log-bad { color: var(--orange); font-weight: 700; }
.confirm { margin: 10px 0 0; padding: 12px 14px; border: 2px solid var(--orange); background: var(--ground); }
.confirm p { margin: 0 0 10px; }

@media (max-width: 700px) {
  .selbar { margin-left: -20px; margin-right: -20px; }
  .nav { order: 3; width: 100%; }
}

.foot { padding: 18px 20px 28px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }
.foot p { margin: 0 auto; max-width: 1400px; }

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
