:root {
  --ink: #10130f;
  --paper: #ececdf;
  --panel: #171b16;
  --panel-2: #1e241d;
  --line: rgba(236, 236, 223, .13);
  --muted: #9ca393;
  --acid: #d5f25b;
  --orange: #ff8a4c;
  --red: #ff6b63;
  --green: #6ee7a1;
  --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: dark; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--ink); color: var(--paper); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { color: inherit; }
.noise { position: fixed; inset: 0; pointer-events: none; opacity: .22; z-index: -1; background-image: radial-gradient(rgba(255,255,255,.05) .7px, transparent .7px); background-size: 8px 8px; mask-image: linear-gradient(to bottom, black, transparent 70%); }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 72px; padding: 0 clamp(18px, 4vw, 64px); display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); backdrop-filter: blur(22px); background: rgba(16, 19, 15, .86); }
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; width: fit-content; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; background: var(--acid); color: var(--ink); border-radius: 6px; font-weight: 900; letter-spacing: -.08em; }
.brand b { display: block; letter-spacing: .16em; font-size: 13px; }
.brand small { color: var(--muted); font-size: 9px; letter-spacing: .24em; }
.top-actions { justify-self: end; display: flex; gap: 10px; align-items: center; }
.system-pill { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.system-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); box-shadow: 0 0 0 4px rgba(255,138,76,.12); }
.system-pill i.online { background: var(--green); box-shadow: 0 0 0 4px rgba(110,231,161,.12); }
.icon-button, .close-button { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: transparent; cursor: pointer; font-size: 20px; }
main { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 54px 0 80px; }
.workspace-bar { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 20px; margin: -18px 0 46px; padding: 13px; border: 1px solid var(--line); border-radius: 13px; background: linear-gradient(120deg,rgba(30,36,29,.96),rgba(17,21,16,.96)); box-shadow: var(--shadow); }
.workspace-back { min-height: 46px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--paper); cursor: pointer; }
.workspace-back:hover { border-color: var(--acid); color: var(--acid); }
.workspace-identity { min-width: 190px; padding: 0 8px; }
.workspace-identity span { display: block; margin-bottom: 3px; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .18em; }
.workspace-identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Georgia,"Times New Roman",serif; font-size: 20px; font-weight: 400; }
.workspace-nav { justify-self: end; display: flex; gap: 3px; padding: 4px; border: 1px solid var(--line); border-radius: 9px; }
.workspace-nav-link { border: 0; background: transparent; padding: 9px 14px; border-radius: 6px; color: var(--muted); cursor: pointer; transition: .2s ease; }
.workspace-nav-link:hover, .workspace-nav-link.active { background: var(--paper); color: var(--ink); }
.hero-row { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 48px; }
.eyebrow { margin: 0 0 9px; color: var(--acid); font-size: 10px; font-weight: 800; letter-spacing: .25em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 10px; max-width: 800px; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(42px, 6vw, 82px); line-height: .95; letter-spacing: -.055em; }
h2 { margin-bottom: 6px; font-family: Georgia, "Times New Roman", serif; font-weight: 400; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.04em; }
h3 { margin-bottom: 0; font-size: 18px; }
.lead, .muted { color: var(--muted); }
.lead { margin: 0; font-size: 16px; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 650; }
select, input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 8px; background: #11150f; color: var(--paper); padding: 0 13px; outline: none; }
select:focus, input:focus { border-color: var(--acid); box-shadow: 0 0 0 3px rgba(213,242,91,.1); }
.view { display: none; }
.view.active { display: block; animation: reveal .35s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(8px); } }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 52px; }
.metric { position: relative; overflow: hidden; min-height: 140px; padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.metric::after { content: ""; position: absolute; width: 90px; height: 90px; border-radius: 50%; right: -42px; bottom: -48px; background: var(--tone, var(--acid)); filter: blur(1px); opacity: .16; }
.metric-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .14em; }
.metric-value { display: block; margin-top: 25px; font-family: Georgia, serif; font-size: 36px; line-height: 1; }
.metric-note { display: block; margin-top: 8px; color: var(--muted); font-size: 11px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin: 0 0 22px; }
.section-heading .muted { margin: 0; max-width: 620px; }
.live-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-bottom: 52px; }
.live-card { overflow: hidden; border-radius: 14px; background: #050704; border: 1px solid var(--line); box-shadow: var(--shadow); }
.live-frame { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(135deg,#141a12,#050704); }
.live-frame img, .live-frame iframe { width: 100%; height: 100%; display: block; object-fit: cover; border: 0; }
.live-badge { position: absolute; left: 14px; top: 14px; padding: 6px 9px; border-radius: 5px; background: rgba(16,19,15,.76); backdrop-filter: blur(10px); font-size: 10px; letter-spacing: .16em; }
.live-badge::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--green); }
.live-meta { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 17px; }
.live-meta strong { font-size: 14px; }
.live-meta span { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.live-mode { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; }
.live-mode button { border: 0; border-radius: 5px; padding: 6px 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 10px; }
.live-mode button.active { color: var(--ink); background: var(--panel-2); }
.two-column { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.panel, .table-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.panel { padding: 22px; }
.panel-head { display: flex; align-items: start; justify-content: space-between; margin-bottom: 22px; }
.text-button { border: 0; background: transparent; color: var(--acid); cursor: pointer; }
.compact-event { display: grid; grid-template-columns: 56px 1fr auto; gap: 13px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.compact-event img { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; background: #080a07; }
.compact-event strong { display: block; font-size: 13px; }
.compact-event span { color: var(--muted); font-size: 11px; }
.event-time { font-variant-numeric: tabular-nums; }
.mqtt-state { color: var(--muted); font-size: 11px; }
.door-summary { display: grid; gap: 10px; }
.door-row { display: flex; justify-content: space-between; padding: 13px 0; border-top: 1px solid var(--line); }
.door-row span { color: var(--muted); font-size: 12px; }
.door-row b { font-size: 13px; text-align: right; }
.primary-button, .secondary-button { min-height: 44px; padding: 0 18px; border-radius: 7px; cursor: pointer; font-weight: 750; }
.primary-button { border: 1px solid var(--acid); background: var(--acid); color: var(--ink); }
.primary-button:hover { filter: brightness(1.06); transform: translateY(-1px); }
.secondary-button { border: 1px solid var(--line); background: transparent; }
.table-card { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 16px 18px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
th { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
tbody tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; gap: 7px; padding: 5px 8px; border-radius: 999px; background: rgba(110,231,161,.08); color: var(--green); font-size: 11px; }
.status.offline { color: var(--red); background: rgba(255,107,99,.08); }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.url-cell { max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.mini-button { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: transparent; cursor: pointer; }
.mini-button.danger:hover { color: var(--red); border-color: var(--red); }
.restart-note { margin-top: 14px; padding: 15px 18px; border-radius: 8px; background: rgba(255,138,76,.1); border: 1px solid rgba(255,138,76,.25); color: #ffc29f; }
.segmented { display: flex; padding: 3px; border: 1px solid var(--line); border-radius: 8px; }
.segmented button { padding: 7px 10px; border: 0; background: transparent; border-radius: 5px; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--paper); color: var(--ink); }
.event-feed { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.event-card { min-height: 220px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: 11px; }
.event-thumb { position: relative; height: 140px; background: #080a07; overflow: hidden; }
.event-thumb img { width: 100%; height: 100%; object-fit: cover; }
.event-type { position: absolute; left: 10px; top: 10px; padding: 5px 7px; background: rgba(16,19,15,.8); border-radius: 4px; font-size: 9px; letter-spacing: .13em; }
.event-body { padding: 15px; }
.event-body strong { display: block; margin-bottom: 5px; }
.event-body p { margin: 0; color: var(--muted); font-size: 11px; }
.event-body .event-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.upload-card { padding: 18px; min-height: 0; }
.upload-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; background: rgba(213,242,91,.1); color: var(--acid); margin-bottom: 24px; font-weight: 900; }
.recording-layout { display: grid; grid-template-columns: 330px 1fr; gap: 14px; }
.recording-form { display: grid; align-content: start; gap: 17px; }
.form-note { color: var(--muted); font-size: 11px; }
.video-stage { position: relative; min-height: 440px; display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: #050704; border: 1px solid var(--line); }
.video-stage video { width: 100%; height: 100%; max-height: 70vh; object-fit: contain; }
.video-placeholder { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; color: var(--muted); }
.video-placeholder b { color: var(--paper); margin-bottom: 7px; }
.device-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.device-card { padding: 22px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.device-card.active { border-color: rgba(213,242,91,.6); }
.device-card-top { display: flex; justify-content: space-between; align-items: start; }
.device-card h3 { margin: 15px 0 4px; }
.device-card code { color: var(--muted); font-size: 11px; word-break: break-all; }
.device-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin: 22px 0; }
.device-stats div { padding: 11px; background: var(--panel-2); border-radius: 7px; }
.device-stats span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.device-stats b { font-size: 16px; }
.location-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.location-card { min-height: 285px; display: flex; flex-direction: column; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg,rgba(28,34,25,.95),rgba(13,17,12,.98)); box-shadow: var(--shadow); }
.location-card.offline { opacity: .72; }
.location-status, .location-actions, .location-main { display: flex; align-items: center; }
.location-status { justify-content: space-between; }
.location-id { color: var(--muted); font-size: 9px; letter-spacing: .17em; }
.location-main { gap: 15px; margin: 28px 0 8px; }
.location-main h3 { margin: 0 0 5px; font-family: Georgia,"Times New Roman",serif; font-size: 25px; font-weight: 400; }
.location-main code { color: var(--muted); font-size: 10px; word-break: break-all; }
.location-mark { width: 52px; height: 52px; flex: 0 0 52px; display: grid; place-content: center; border-radius: 12px; background: var(--acid); color: #10130f; font-size: 15px; font-weight: 900; letter-spacing: .05em; }
.location-actions { gap: 8px; margin-top: auto; }
.location-actions button { flex: 1; white-space: nowrap; }
dialog { width: min(600px, calc(100% - 26px)); border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--paper); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(3,4,3,.75); backdrop-filter: blur(6px); }
.dialog-card { display: grid; gap: 17px; padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h2 { font-size: 32px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label small { font-weight: 400; color: #71786b; }
.dialog-warning { padding: 13px; background: rgba(255,138,76,.08); border: 1px solid rgba(255,138,76,.2); border-radius: 7px; color: #e9b493; font-size: 11px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 5px; }
.video-dialog { width: min(1100px, calc(100% - 26px)); }
.video-dialog-card { padding: 20px; }
.video-dialog video { width: 100%; max-height: 75vh; margin-top: 14px; background: #000; border-radius: 8px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: 440px; padding: 14px 18px; border-radius: 8px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow); transform: translateY(120px); opacity: 0; transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); color: #210807; }
.empty { grid-column: 1 / -1; padding: 45px 20px; border: 1px dashed var(--line); border-radius: 11px; text-align: center; color: var(--muted); }

@media (max-width: 1050px) {
  .workspace-bar { grid-template-columns: auto 1fr; }
  .workspace-nav { grid-column: 1 / -1; width: 100%; justify-content: stretch; }
  .workspace-nav-link { flex: 1; }
  .metric-grid { grid-template-columns: repeat(2,1fr); }
  .event-feed, .device-grid, .location-grid { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 760px) {
  main { width: min(100% - 24px, 1500px); padding-top: 34px; }
  .topbar { padding: 0 14px; }
  .system-pill { display: none; }
  .hero-row, .section-heading { align-items: stretch; flex-direction: column; }
  .metric-grid, .live-grid, .two-column, .recording-layout, .event-feed, .device-grid, .location-grid { grid-template-columns: 1fr; }
  .workspace-bar { display: flex; align-items: stretch; flex-direction: column; margin-top: -12px; }
  .workspace-nav { overflow-x: auto; }
  .workspace-nav-link { white-space: nowrap; }
  .field-row { grid-template-columns: 1fr; }
  h1 { font-size: 48px; }
  .video-stage { min-height: 260px; }
}
