:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1f2630;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --live: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
button.icon { padding: 4px 8px; font-size: 13px; }

input[type=text], input[type=password] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; margin-top: 12px; }

/* ---- auth pages ---- */
.auth-wrap { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card p { margin: 0; color: var(--muted); font-size: 14px; }
.auth-card button { width: 100%; margin-top: 20px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .3px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 8px var(--danger); }

/* ---- dashboard ---- */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
header .actions { display: flex; gap: 8px; align-items: center; }
.layout-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.layout-toggle button { border: 0; border-radius: 0; background: transparent; padding: 6px 10px; }
.layout-toggle button.active { background: var(--panel-2); color: var(--accent); }

.alerts-wrap { position: relative; }
.alert-count, .detection-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px;
  padding: 0 6px; margin-left: 4px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 12px;
}
.alerts-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  width: 390px; max-height: 65vh; overflow-y: auto; padding: 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 16px 40px rgba(0,0,0,.5);
}
.alerts-dropdown-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }

main { padding: 20px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
@media (max-width: 800px) { .grid { grid-template-columns: 1fr !important; } }

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
}
.tile .video-box { position: relative; aspect-ratio: 16 / 9; background: #000; }
.tile video { width: 100%; height: 100%; object-fit: contain; display: block; }
.tile .overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 14px; text-align: center; padding: 20px; white-space: pre-line;
}
.tile .bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; gap: 8px; }
.tile .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .bar .tools { display: flex; gap: 6px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.live::before { background: var(--live); box-shadow: 0 0 6px var(--live); }
.badge.starting::before { background: var(--warn); }
.badge.error::before { background: var(--danger); }

.empty {
  text-align: center; color: var(--muted);
  border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 60px 20px;
}
.empty h2 { color: var(--text); margin-top: 0; }

/* ---- dialog ---- */
dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  width: min(480px, 92vw); padding: 24px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 4px; }
dialog .row { display: flex; justify-content: space-between; gap: 8px; margin-top: 22px; }
dialog .row .right { display: flex; gap: 8px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---- form extras ---- */
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
}
.row-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.row-2 > div:only-child { grid-column: 1 / -1; }
#fields-reolink .row-2:nth-of-type(2) { grid-template-columns: 1fr 1fr; }
.test-result {
  margin-top: 14px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); font-size: 13px; white-space: pre-line;
}
.test-result.ok { border-color: var(--live); }
.test-result.bad { border-color: var(--danger); color: var(--danger); }
button:disabled { opacity: .6; cursor: progress; }
dialog .row { flex-wrap: wrap; }

/* ---- tile click target ---- */
.tile .video-box { cursor: zoom-in; }

/* ---- focus view ---- */
body.no-scroll { overflow: hidden; }
.focus {
  position: fixed; inset: 0; z-index: 20;
  background: #000;
  display: flex; flex-direction: column;
}
.focus-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.focus-bar .name { font-weight: 600; }
.focus-bar .tools { display: flex; align-items: center; gap: 8px; }
.focus-bar .quality { font-size: 12px; color: var(--muted); margin-right: 4px; }
.focus-video { position: relative; flex: 1; min-height: 0; }
.focus-video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.focus-note {
  position: absolute; left: 16px; bottom: 16px; max-width: 70%;
  background: rgba(0,0,0,.7); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; color: var(--warn);
}

/* ---- detections ---- */
.nav-link { color: var(--text); text-decoration: none; font-size: 14px; padding: 8px 12px; border-radius: 8px; }
.nav-link:hover { background: var(--panel-2); }
.detection-button {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--text); background: var(--panel-2); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 14px; font-size: 14px;
}
.detection-button:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.detection-count {
  background: var(--accent); color: #fff; border-radius: 999px;
  padding: 0 7px; font-size: 12px; font-weight: 600; line-height: 18px;
}
.detection-button:hover .detection-count { background: #fff; color: var(--accent); }
.detections { max-width: 1400px; margin: 0 auto; display: grid; gap: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.panel h2 { margin: 0 0 12px; font-size: 18px; }
.status-panel { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.status-panel h2 { margin-bottom: 6px; }
.status-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.status-actions label.check { margin: 0; }
.status-actions select { width: auto; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; }
.filters input { width: 220px; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs .tab { background: var(--panel-2); }
.tabs .tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.alert-list { display: grid; gap: 8px; }
.alert-item {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 8px;
  text-align: left; color: inherit; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
}
.alert-item:hover { border-color: var(--accent); }
.alert-item.acked { opacity: .6; }
.alert-thumb { width: 64px; height: 40px; object-fit: cover; border-radius: 4px; background: #000; }
.alert-text { flex: 1; display: flex; flex-direction: column; }
.alert-play { color: var(--accent); font-size: 12px; white-space: nowrap; }
.object-grid, .sighting-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.object-card, .sighting-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.object-media { position: relative; }
.object-card img, .sighting-card img { width: 100%; height: 180px; object-fit: contain; display: block; background: #000; }
.object-remove {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff;
  border: 1px solid rgba(255, 255, 255, .4); font-size: 18px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
}
.object-remove:hover, .object-remove.confirming { background: var(--danger); border-color: var(--danger); }
.card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card-btn { flex: 1; min-width: 96px; padding: 7px 10px; font-size: 13px; border-radius: 6px; }
.card-btn:hover { border-color: var(--accent); color: var(--accent); }
.card-btn.saved { background: var(--accent); border-color: var(--accent); color: #fff; }
.object-body { padding: 10px; }
.object-title { display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.object-name { padding: 6px 8px !important; }
.identifier { font-size: 11px; color: var(--accent); white-space: nowrap; }
.sighting-card { padding-bottom: 10px; }
.sighting-card .hint { padding: 4px 10px 0; }
.no-image { height: 180px; display: grid; place-items: center; color: var(--muted); background: #000; }

/* ---- alert toasts ---- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 30; display: grid; gap: 8px; max-width: 360px; }
.toast { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--accent); border-left-width: 4px; border-radius: 8px; padding: 10px 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.toast span { flex: 1; font-size: 14px; }

/* ---- alert clip player ---- */
.clip-modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding: 20px; background: rgba(0, 0, 0, .75);
}
.clip-panel {
  width: min(720px, 100%); overflow: hidden;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0,0,0,.6);
}
.clip-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; }
.clip-panel video, .clip-still { width: 100%; max-height: 68vh; display: block; background: #000; }
.clip-still { height: auto; object-fit: contain; }
.clip-panel .hint { padding: 8px 12px 14px; }
