:root {
  --bg: #111316;
  --panel: #1b1e23;
  --line: #2c3037;
  --text: #e6e8eb;
  --muted: #8b929c;
  --accent: #4ea1ff;
  --chmi: #4ea1ff;
  --sumava: #3ccf7a;
  --inpocasi: #b58cff;
  --direct: #ff5fa2;
  --rsd: #f2c94c;
  --webcamlive: #ff8a3d;
  --warn: #ffb547;
  --bad: #ff6b6b;
  --gap: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
}
button, select, input { font: inherit; color: inherit; }
button, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 4px 8px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--muted); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; }

header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
}
h1 { font-size: 16px; margin: 0; white-space: nowrap; }
nav { display: flex; gap: 4px; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#selCount { opacity: .8; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-left: auto; }
.controls label { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.controls label select { color: var(--text); }
.chk input { margin: 0; }

main { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; }
.view.active { display: flex; }

/* ---------- grid ---------- */
#view-grid { flex-direction: column; }
#grid {
  flex: 1; min-height: 0; display: grid; gap: var(--gap); padding: var(--gap);
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
}
.tile {
  position: relative; background: #000; overflow: hidden; border-radius: 4px;
  min-height: 0; cursor: zoom-in;
}
.tile img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: opacity .3s;
}
body.fit .tile img { object-fit: contain; }
.tile .cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 5px;
  background: linear-gradient(transparent, rgba(0,0,0,.75));
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
  font-size: 13px; text-shadow: 0 1px 2px #000; pointer-events: none;
}
.tile .cap b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .age { color: #ccc; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tile .age.old { color: var(--warn); }
.tile .age.dead { color: var(--bad); }
.tile .state {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); pointer-events: none;
}
.tile.loading::after {
  content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); animation: pulse 1s infinite;
}
@keyframes pulse { 50% { opacity: .2; } }
.tile.empty {
  border: 1px dashed var(--line); background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.tile.empty:hover { border-color: var(--accent); color: var(--accent); }
.tile.dragover { outline: 2px solid var(--accent); outline-offset: -2px; }
.tile[draggable=true] { cursor: grab; }
#hidden-note { margin: 0; padding: 2px 8px 6px; color: var(--muted); font-size: 12px; }

/* kompaktní mřížky: menší popisky */
#grid.dense .tile .cap { font-size: 11px; padding: 10px 5px 3px; }

/* ---------- výběr ---------- */
#map { flex: 1; min-width: 0; background: #222; }
aside {
  width: 340px; border-left: 1px solid var(--line); background: var(--panel);
  overflow-y: auto; padding: 10px 12px;
}
#search {
  width: 100%; padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--bg);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin: 8px 0; color: var(--muted); font-size: 13px; }
.legend button { margin-left: auto; font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.chmi { background: var(--chmi); }
.dot.sumava { background: var(--sumava); }
.dot.inpocasi { background: var(--inpocasi); }
.dot.direct { background: var(--direct); }
.dot.rsd { background: var(--rsd); }
.dot.webcamlive { background: var(--webcamlive); }
.legend label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.legend label input { margin: 0; }
aside h3 { font-size: 13px; margin: 14px 0 6px; color: var(--muted); font-weight: 600; }
aside h3 small { font-weight: 400; }
aside ol, aside ul { list-style: none; margin: 0; padding: 0; }
aside li {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 5px; cursor: pointer;
}
aside li:hover { background: rgba(255,255,255,.05); }
aside li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
aside li .src { font-size: 11px; color: var(--muted); }
#selected li { cursor: grab; }
#selected li .num { color: var(--muted); width: 1.6em; text-align: right; font-variant-numeric: tabular-nums; }
#selected li.over-limit .name { color: var(--muted); text-decoration: line-through; }
#selected li.dragover { box-shadow: inset 0 2px 0 var(--accent); }
#selected:empty::before { content: "Nic nevybráno – klikni na kameru v mapě nebo v seznamu."; color: var(--muted); font-size: 13px; }

/* leaflet popup */
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); border-radius: 8px; }
.leaflet-popup-tip { background: var(--panel); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.leaflet-popup-content { margin: 10px; width: 320px !important; }
.pop img { width: 100%; aspect-ratio: 4/3; object-fit: cover; background: #000; border-radius: 4px; display: block; }
.pop .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.pop .title { font-weight: 600; font-size: 14px; }
.pop .meta { color: var(--muted); font-size: 12px; }
.pop a { color: var(--accent); }
.pop label { display: flex; gap: 6px; align-items: center; cursor: pointer; font-weight: 600; }
.pop .others { margin-top: 6px; font-size: 12px; color: var(--muted); }
.pop .others button { font-size: 12px; padding: 1px 6px; margin: 2px 2px 0 0; }
.cam-marker {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 3px rgba(0,0,0,.6);
}
.cam-marker.chmi { background: var(--chmi); }
.cam-marker.sumava { background: var(--sumava); }
.cam-marker.inpocasi { background: var(--inpocasi); width: 11px; height: 11px; margin: 1px; border-width: 1.5px; }
.cam-marker.direct { background: var(--direct); }
.cam-marker.sel { width: 20px; height: 20px; margin: -3px; border-color: var(--warn); border-width: 3px; }

/* ---------- lightbox ---------- */
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
}
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-caption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 16px; text-align: center;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
}
.lb-caption a { color: var(--accent); }
#lightbox > button {
  position: absolute; background: rgba(0,0,0,.4); border: 0; font-size: 28px; line-height: 1;
  width: 48px; height: 48px; border-radius: 50%;
}
#lightbox button:hover { background: rgba(255,255,255,.15); }
.lb-close { top: 12px; right: 12px; }
.lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 12px; top: 50%; transform: translateY(-50%); }

/* ---------- mobil ---------- */
@media (max-width: 760px) {
  header { padding: 6px 8px; }
  .controls { margin-left: 0; }
  main { overflow-y: auto; }
  .view.active { height: auto; }
  #grid {
    grid-template-columns: repeat(var(--mcols), minmax(0, 1fr));
    grid-template-rows: none; grid-auto-rows: auto;
  }
  .tile { aspect-ratio: 4 / 3; }
  #view-pick { flex-direction: column; }
  #map { height: 60vh; flex: none; }
  aside { width: auto; border-left: 0; border-top: 1px solid var(--line); }
}

/* ---------- přihlášení ---------- */
.who { color: var(--muted); white-space: nowrap; }
.badge { background: var(--warn); color: #000; border-radius: 9px; padding: 0 6px; font-size: 12px; font-weight: 700; }
#auth {
  position: fixed; inset: 0; z-index: 3000; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#auth[hidden] { display: none; }
.auth-box {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 20px;
}
.auth-box h1 { font-size: 20px; margin: 0 0 14px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.auth-tabs .tab { flex: 1; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
#authForm input {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); font-size: 15px;
}
#authForm:not(.register) .reg-only { display: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 8px; font-weight: 600; }
#authMsg { margin: 0; min-height: 1.4em; font-size: 13px; }
#authMsg.err { color: var(--bad); }
#authMsg.ok { color: var(--sumava); }

/* ---------- správa uživatelů ---------- */
#view-users { overflow: auto; }
.users-wrap { padding: 16px; max-width: 1100px; width: 100%; }
.users-wrap h2 { margin: 0 0 4px; font-size: 18px; }
.hint { color: var(--muted); margin: 0 0 14px; }
#usersTable { width: 100%; border-collapse: collapse; }
#usersTable th, #usersTable td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
#usersTable th { color: var(--muted); font-weight: 600; font-size: 12px; }
#usersTable td.note { color: var(--muted); max-width: 320px; overflow-wrap: anywhere; }
#usersTable td.actions { white-space: nowrap; text-align: right; }
#usersTable td.actions button { margin-left: 4px; font-size: 12px; }
#usersTable tr.pending td { background: rgba(255,181,71,.08); }
.st-pending { color: var(--warn); font-weight: 600; }
.st-approved { color: var(--sumava); }
.st-rejected { color: var(--bad); }
@media (max-width: 760px) {
  #usersTable thead { display: none; }
  #usersTable tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  #usersTable td { display: block; border: 0; padding: 2px 4px; }
  #usersTable td.actions { text-align: left; }
}

/* odebrání kamery přímo z gridu */
.tile-remove {
  position: absolute; top: 6px; left: 6px; width: 28px; height: 28px; padding: 0;
  border-radius: 50%; border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 14px; line-height: 28px;
  opacity: 0; transition: opacity .15s;
}
.tile:hover .tile-remove, .tile-remove:focus-visible { opacity: 1; }
.tile-remove:hover { background: var(--bad); }
/* dotyková zařízení: křížek v gridu překáží → odebírá se v lightboxu */
@media (hover: none) { .tile-remove { display: none; } }
.lb-remove { margin-left: 8px; font-size: 13px; padding: 2px 8px; background: rgba(0,0,0,.4); border: 1px solid var(--line); border-radius: 6px; }
.lb-remove:hover { border-color: var(--bad); color: var(--bad); }
