:root {
      --bg: #050816;
      --bg-elevated: rgba(15, 23, 42, 0.9);
      --card: rgba(15, 23, 42, 0.9);
      --accent: #22c55e;
      --accent-soft: rgba(34, 197, 94, 0.14);
      --accent-warn: #f97316;
      --accent-bad: #ef4444;
      --text-main: #e5e7eb;
      --text-muted: #9ca3af;
      --border-subtle: rgba(148, 163, 184, 0.25);
      --shadow-soft: 0 18px 40px rgba(15, 23, 42, 0.55);
      --radius-lg: 18px;
      --radius-pill: 999px;
    }

    * { box-sizing: border-box; }

    body {
      margin: 0;
      min-height: 100vh;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "Segoe UI", sans-serif;
      color: var(--text-main);
      background:
        radial-gradient(circle at top, #1e293b 0, transparent 55%),
        radial-gradient(circle at bottom, #0f172a 0, var(--bg) 60%);
      display: flex;
      justify-content: center;
    }

    .app-shell {
      width: 100%;
      max-width: 1100px;
      padding: 18px 14px 32px;
    }

    @media (min-width: 640px) {
      .app-shell { padding: 24px; }
    }

    .app-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 18px;
      gap: 12px;
    }

    .app-title {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .logo-pill {
      width: 40px;
      height: 40px;
      border-radius: var(--radius-pill);
      background: radial-gradient(circle at 30% 20%, #4ade80, #16a34a);
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 12px 30px rgba(34, 197, 94, 0.55);
      font-size: 22px;
    }

    .app-title h1 {
      margin: 0;
      font-size: 20px;
      letter-spacing: 0.04em;
    }

    .tag {
      padding: 6px 12px;
      border-radius: var(--radius-pill);
      font-size: 11px;
      text-transform: uppercase;
      letter-spacing: 0.09em;
      border: 1px solid rgba(148, 163, 184, 0.5);
      color: var(--text-muted);
      background: rgba(15, 23, 42, 0.8);
      white-space: nowrap;
    }

    .tag-live {
      border-color: rgba(34, 197, 94, 0.6);
      color: #bbf7d0;
      background: rgba(22, 163, 74, 0.18);
    }

    .tag-offline {
      border-color: rgba(239, 68, 68, 0.8);
      color: #fecaca;
      background: rgba(127, 29, 29, 0.28);
    }

    .status-bar {
      display: flex;
      gap: 8px;
      align-items: center;
      flex-wrap: wrap;
      justify-content: flex-end;
    }

    .app-main {
      display: flex;
      flex-direction: column;
      gap: 16px;
    }

    .card {
      border-radius: var(--radius-lg);
      background: var(--card);
      border: 1px solid var(--border-subtle);
      box-shadow: var(--shadow-soft);
      padding: 14px 14px 16px;
      backdrop-filter: blur(16px);
    }

    .card h2 {
      margin: 0 0 8px;
      font-size: 14px;
      text-transform: uppercase;
      letter-spacing: 0.12em;
      color: var(--text-muted);
    }

    .row {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      align-items: center;
      margin-bottom: 8px;
    }

    label {
      font-size: 12px;
      color: var(--text-muted);
      white-space: nowrap;
    }

    input, button {
      padding: 8px 10px;
      border-radius: 10px;
      border: 1px solid rgba(51, 65, 85, 0.9);
      background: #020617;
      color: var(--text-main);
      font-size: 13px;
    }

    button {
      cursor: pointer;
      background: #111827;
      transition: background 0.15s ease, transform 0.08s ease;
    }

    button:hover {
      background: #1f2937;
      transform: translateY(-1px);
    }

    button:active { transform: translateY(0); }

    .btn-accent {
      background: #22c55e;
      border-color: #22c55e;
      color: #022c22;
    }

    .btn-accent:hover { background: #16a34a; }

    .grow { flex: 1 1 180px; }

    video, iframe {
      width: 100%;
      height: 60vh;
      border: 0;
      border-radius: 16px;
      background: black;
      box-shadow: 0 18px 35px rgba(15, 23, 42, 0.8);
    }

    .pill {
      padding: 4px 10px;
      border-radius: var(--radius-pill);
      font-size: 12px;
      background: #111827;
      display: inline-block;
      white-space: nowrap;
      border: 1px solid rgba(51, 65, 85, 0.9);
      color: var(--text-muted);
    }

    .ok {
      background: rgba(22, 163, 74, 0.18);
      color: #bbf7d0;
      border-color: rgba(34, 197, 94, 0.7);
    }

    .warn {
      background: rgba(249, 115, 22, 0.18);
      color: #fed7aa;
      border-color: rgba(249, 115, 22, 0.7);
    }

    .bad {
      background: rgba(239, 68, 68, 0.18);
      color: #fecaca;
      border-color: rgba(239, 68, 68, 0.7);
    }

    .info {
      background: rgba(15, 23, 42, 0.9);
      color: var(--text-muted);
    }

    .hint {
      color: var(--text-muted);
      font-size: 12px;
      margin-top: 6px;
    }

    .small-label {
      font-size: 11px;
      color: var(--text-muted);
    }

    .section-title {
      margin: 4px 0 6px;
      font-size: 13px;
      color: var(--text-muted);
    }

    .chart-wrapper {
      margin-top: 4px;
      border-radius: 14px;
      background: radial-gradient(circle at top left, #0f172a, #020617);
      border: 1px solid rgba(30, 64, 175, 0.4);
      padding: 10px;
    }

    .status-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
      margin-top: 4px;
      font-size: 12px;
      color: var(--text-muted);
      flex-wrap: wrap;
    }

    .status-dot {
      width: 8px;
      height: 8px;
      border-radius: 999px;
      margin-right: 6px;
      background: #22c55e;
      box-shadow: 0 0 10px rgba(34, 197, 94, 0.8);
      display: inline-block;
    }

    .status-dot-bad {
      background: #ef4444;
      box-shadow: 0 0 10px rgba(239, 68, 68, 0.8);
    }

    .footer-note {
      margin-top: 10px;
      font-size: 11px;
      color: var(--text-muted);
      text-align: center;
      opacity: 0.7;
    }

    .events-list {
      margin-top: 4px;
      display: flex;
      flex-direction: column;
      gap: 6px;
      max-height: 260px;
      overflow-y: auto;
    }

    .event-item {
      display: flex;
      gap: 8px;
      align-items: flex-start;
      padding: 6px 8px;
      border-radius: 10px;
      background: rgba(15, 23, 42, 0.9);
      border: 1px solid rgba(31, 41, 55, 0.7);
    }

    .event-thumb {
      width: 54px;
      height: 54px;
      border-radius: 10px;
      object-fit: cover;
      background: black;
      flex-shrink: 0;
      cursor: zoom-in;
    }

    .event-meta {
      display: flex;
      flex-direction: column;
      gap: 2px;
      min-width: 0;
    }

    .event-title-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 6px;
    }

    .event-title {
      font-size: 13px;
      font-weight: 500;
      color: #e5e7eb;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .event-time {
      font-size: 11px;
      color: var(--text-muted);
      white-space: nowrap;
      flex-shrink: 0;
    }

    .event-message {
      font-size: 12px;
      color: var(--text-muted);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .event-badge {
      font-size: 10px;
      padding: 2px 6px;
      border-radius: 999px;
      border: 1px solid rgba(55, 65, 81, 0.9);
      text-transform: uppercase;
      letter-spacing: 0.08em;
      color: var(--text-muted);
    }

    .event-badge-battery {
      border-color: rgba(56, 189, 248, 0.7);
      color: #bae6fd;
    }

    .event-badge-deer {
      border-color: rgba(74, 222, 128, 0.8);
      color: #bbf7d0;
    }

    .event-badge-warn {
      border-color: rgba(249, 115, 22, 0.8);
      color: #fed7aa;
    }

    .event-badge-error {
      border-color: rgba(248, 113, 113, 0.9);
      color: #fecaca;
    }

    .lightbox {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.84);
      display: none;
      align-items: center;
      justify-content: center;
      padding: 18px;
      z-index: 9999;
    }
    .lightbox.open { display: flex; }
    .lightbox img {
      max-width: min(1100px, 96vw);
      max-height: 92vh;
      border-radius: 14px;
      box-shadow: 0 18px 45px rgba(0,0,0,0.65);
      background: #000;
    }
    .lightbox .hint {
      position: absolute;
      bottom: 14px;
      left: 0;
      right: 0;
      text-align: center;
      font-size: 12px;
      color: rgba(229, 231, 235, 0.85);
    }

    @media (max-width: 640px) {
      .app-shell { padding: 12px 10px 24px; }

      .app-header {
        flex-direction: column;
        align-items: center;
        gap: 10px;
      }

      .app-title h1 { font-size: 18px; }

      .status-bar { justify-content: center; }

      video, iframe { height: 40vh; }

      .card { padding: 10px 10px 12px; }

      .chart-wrapper { padding: 8px; }

      .events-list { max-height: 200px; }
    }


/* ===== Camera Tabs ===== */
.cam-tabs{
  display:flex;
  gap:10px;
  align-items:center;
  margin: 10px 0 14px;
  padding: 6px 6px;
  border-radius: 16px;
  background: rgba(2,6,23,0.35);
  border: 1px solid rgba(255,255,255,0.08);
  overflow-x:auto;
  scrollbar-width: thin;
}
.cam-tab{
  display:flex;
  align-items:center;
  gap:8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(15,23,42,0.55);
  color: rgba(229,231,235,0.95);
  font-weight: 600;
  font-size: 13px;
  cursor:pointer;
  user-select:none;
  white-space:nowrap;
}
.cam-tab:hover{ filter: brightness(1.08); }
.cam-tab.active{
  border-color: rgba(34,197,94,0.55);
  box-shadow: 0 0 0 2px rgba(34,197,94,0.12) inset;
}
.cam-tab .sub{
  font-weight: 500;
  font-size: 12px;
  opacity: 0.7;
}
.cam-tab.add{
  background: rgba(34,197,94,0.18);
  border-color: rgba(34,197,94,0.35);
  color: rgba(220,252,231,0.95);
}

/* ===== Modal ===== */
.modal{
  position: fixed;
  inset: 0;
  display:none;
  align-items:center;
  justify-content:center;
  background: rgba(0,0,0,0.55);
  z-index: 2000;
  padding: 18px;
}
.modal.open{ display:flex; }
.modal-card{
  width: min(560px, 96vw);
  background: rgba(2,6,23,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 18px;
  box-shadow: 0 12px 60px rgba(0,0,0,0.55);
  overflow:hidden;
}
.modal-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-title{
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 12px;
  color: rgba(229,231,235,0.9);
}
.icon-btn{
  border: 0;
  background: transparent;
  color: rgba(229,231,235,0.8);
  cursor:pointer;
  font-size: 16px;
  padding: 6px 8px;
  border-radius: 10px;
}
.icon-btn:hover{ background: rgba(255,255,255,0.06); }
.modal-body{ padding: 12px 14px; }
.form-row{ display:flex; flex-direction:column; gap:6px; margin-bottom: 12px; }
.hint{ font-size: 12px; color: rgba(229,231,235,0.6); }
.modal-footer{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.btn.secondary{
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  color: rgba(229,231,235,0.92);
}
.btn.secondary:hover{ filter: brightness(1.08); }

/* Prevent editing on display-only inputs */
input[readonly]{
  cursor: default;
}
input[readonly]:focus{
  outline: none;
  box-shadow: 0 0 0 2px rgba(34,197,94,0.18);
}

.cam-tab.manage{
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.12);
  color: rgba(229,231,235,0.92);
}
.manage-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding: 4px 0;
}
.manage-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(15,23,42,0.35);
  border-radius: 14px;
}
.manage-main{ display:flex; flex-direction:column; gap:2px; }
.manage-label{ font-weight:700; color: rgba(229,231,235,0.95); }
.manage-sub{ font-size: 12px; opacity: 0.75; }
.mono{ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }