:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #18202b;
  --panel-3: #1d2734;
  --line: #243041;
  --line-2: #2f3c50;
  --text: #e7edf4;
  --muted: #8d9aad;
  --faint: #5c6a7d;
  --accent: #38bdf8;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  color-scheme: dark;
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: #0d1218;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 32px; height: 32px; flex: none; }
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.line-info {
  color: var(--muted);
  font-size: 13px;
  padding-inline-start: 16px;
  border-inline-start: 1px solid var(--line);
}
.spacer { flex: 1; }
.seg {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
}
.seg button {
  background: transparent;
  border: 0;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--muted);
}
.seg button.active { background: var(--panel-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.clock { color: var(--muted); font-size: 13px; min-width: 70px; text-align: end; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  padding: 16px 20px 8px;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
}
.feed-col, .side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}
.hint, .hint-inline { color: var(--faint); font-size: 12px; font-weight: 400; }
.hint { margin: 10px 0 0; }

/* Feed */
.feed-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: #05080b;
  border: 1px solid var(--line);
}
.feed-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.feed-wrap.alarm { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger), 0 0 30px rgba(239, 68, 68, 0.25); }
.feed-wrap.flash::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 6px var(--danger);
  animation: flash 0.7s ease-out forwards;
  pointer-events: none;
}
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.cam-prompt {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  text-align: center;
  color: var(--muted);
  padding: 16px;
}
.cam-prompt p { margin: 0; }

/* Controls */
.drop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.drop {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 10px;
  cursor: pointer;
  text-align: start;
  transition: border-color 0.15s, background 0.15s;
}
.drop:hover { border-color: var(--line-2); background: var(--panel-3); }
.drop:active { transform: translateY(1px); }
.drop i {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex: none;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.drop i.clear { background: repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.4) 0 2px, transparent 2px 5px); }
.controls.disabled .drop, .controls.disabled #dumpBtn { opacity: 0.4; pointer-events: none; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.btn {
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
}
.btn:hover { background: var(--panel-3); }
.btn.primary { background: var(--accent); color: #04121c; border-color: transparent; font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; font-weight: 600; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text); font-size: 13px; }
.switch input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.steps { margin: 0; padding-inline-start: 20px; color: var(--muted); font-size: 13px; }
.steps li + li { margin-top: 4px; }

/* Status */
.status { display: flex; gap: 14px; align-items: center; transition: border-color 0.2s, background 0.2s; }
.stack {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 6px;
  background: #090c10;
  border-radius: 10px;
  border: 1px solid var(--line);
  flex: none;
}
.lamp { width: 18px; height: 18px; border-radius: 50%; background: #1d2530; }
.s-alarm .lamp.red { background: var(--danger); box-shadow: 0 0 14px var(--danger); animation: blink 0.9s steps(2, jump-none) infinite; }
.s-cal .lamp.amber { background: var(--warn); box-shadow: 0 0 14px var(--warn); }
.s-ok .lamp.green { background: var(--ok); box-shadow: 0 0 14px var(--ok); }
@keyframes blink { 50% { opacity: 0.35; } }
.status-text { flex: 1; min-width: 0; }
.status-text b { display: block; font-size: 16px; line-height: 1.35; }
.status-text span { color: var(--muted); font-size: 12.5px; }
.s-alarm { border-color: rgba(239, 68, 68, 0.6); background: linear-gradient(180deg, rgba(239, 68, 68, 0.14), rgba(239, 68, 68, 0.04)); }
.s-ok { border-color: rgba(34, 197, 94, 0.35); }

/* Settings */
.setting label { display: flex; justify-content: space-between; font-size: 13px; }
.setting input[type='range'] { width: 100%; accent-color: var(--accent); margin: 8px 0 0; }
.setting .hint { margin-top: 4px; }
.toggles { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; }

/* Metrics */
.kpi-big { display: flex; align-items: baseline; gap: 10px; }
.kpi-big .val { font-size: 34px; font-weight: 600; line-height: 1; }
.kpi-big .lab { color: var(--muted); font-size: 12.5px; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.kpi { background: var(--panel-2); border-radius: 8px; padding: 8px 4px; text-align: center; }
.kpi b { display: block; font-size: 18px; line-height: 1.2; }
.kpi span { font-size: 11.5px; color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.bad { color: var(--danger); }
.meta-line { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.meta-line b { color: var(--text); font-weight: 500; }
.types { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 12.5px; }
.types td { padding: 4px 0; vertical-align: middle; }
.types td:first-child { width: 42%; color: var(--muted); }
.types td:last-child { width: 56px; text-align: end; }
.bar { height: 6px; background: #1f2835; border-radius: 3px; overflow: hidden; margin-inline: 8px; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width 0.3s; }
.bar i.mid { background: var(--warn); }
.bar i.low { background: var(--danger); }

/* Tiers */
.tiers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tier {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 9px;
  cursor: pointer;
  text-align: start;
}
.tier:hover { border-color: var(--line-2); }
.tier b { font-size: 13.5px; }
.tier span { font-size: 11px; color: var(--muted); line-height: 1.35; }
.tier em { font-style: normal; font-size: 11px; color: var(--faint); margin-top: 2px; }
.tier.active { border-color: var(--accent); background: rgba(56, 189, 248, 0.1); box-shadow: inset 0 0 0 1px var(--accent); }
.tier.active em { color: #7dd3fc; }
.tier:disabled { opacity: 0.35; cursor: not-allowed; }

/* Extra sensor views */
.channels { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.ch { margin: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ch canvas { display: block; width: 100%; aspect-ratio: 4 / 3; background: #05080b; }
.ch figcaption { padding: 8px 12px; font-size: 12px; color: var(--muted); }
.ch figcaption b { color: var(--text); margin-inline-end: 6px; }

/* Comparison */
.cmp { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cmp th { font-weight: 600; color: var(--muted); font-size: 12px; padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.cmp th:first-child, .cmp td:first-child { text-align: start; }
.cmp td { padding: 5px 4px; text-align: center; border-bottom: 1px solid rgba(36, 48, 65, 0.5); }
.cmp td:first-child { color: var(--muted); }
.cmp .live { background: rgba(56, 189, 248, 0.08); }
.cmp th.live { color: #7dd3fc; }
.cmp tr.total td { font-weight: 600; border-bottom: 0; }
.cmp tr.total td:first-child { color: var(--text); }

/* Log */
.ev-note { font-size: 12px; color: #7dd3fc; text-align: center; padding: 4px; border-top: 1px dashed var(--line-2); border-bottom: 1px dashed var(--line-2); }
.log ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 440px; overflow-y: auto; }
.ev { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); }
.ev canvas, .ev .ico { width: 80px; height: 60px; border-radius: 6px; flex: none; }
.ev .ico { display: grid; place-items: center; background: #0e131a; color: var(--faint); font-size: 11px; border: 1px dashed var(--line-2); text-align: center; line-height: 1.3; }
.ev-body { min-width: 0; }
.ev-body b { display: block; font-size: 13px; font-weight: 600; }
.ev-body span { display: block; color: var(--muted); font-size: 12px; }
.gt { font-style: normal; font-size: 12px; }
.gt.ok { color: var(--ok); }
.gt.bad { color: var(--warn); }
.ev-alarm { border-color: rgba(239, 68, 68, 0.35); }
.ev-alarm.fresh { animation: fresh 1.2s ease-out; }
@keyframes fresh { from { background: rgba(239, 68, 68, 0.25); } }
.ev-miss b { color: var(--warn); }
.ev-buried b { color: var(--muted); }

.foot { max-width: 1440px; margin: 0 auto; padding: 4px 20px 28px; color: var(--faint); font-size: 12.5px; }
.foot p { margin: 6px 0; max-width: 900px; }
.foot b { color: var(--muted); }

/* Video mode */
.row.tight { margin-top: 0; }
.row.spread { justify-content: space-between; }
select.btn { appearance: auto; padding-block: 7px; }
.seek { display: flex; align-items: center; gap: 10px; margin: 12px 0 10px; }
.seek input { flex: 1; accent-color: var(--accent); }
.seek span { color: var(--muted); font-size: 12px; min-width: 96px; text-align: end; }
.feed-wrap.drawable #overlay { cursor: crosshair; touch-action: none; }
.feed-wrap.dragging { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.ev.seekable { cursor: pointer; }
.ev.seekable:hover { border-color: var(--line-2); }
.gt.seek { color: #7dd3fc; display: block; }
.controls .steps { margin-top: 12px; }

#vfile,
#video { position: fixed; width: 2px; height: 2px; opacity: 0; pointer-events: none; inset-inline-start: 0; top: 0; }

@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .line-info { display: none; }
  .foot { padding: 4px 16px 24px; }
}
@media (max-width: 480px) {
  .clock { display: none; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
  .kpi-big .val { font-size: 28px; }
}
