@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  /* -- Control Room palette -- */
  --bg: #0c0e1a;            /* indigo-black */
  --bg-panel: #141729;      /* deep panel */
  --bg-panel-2: #1c2038;    /* raised panel */
  --line: #282d47;          /* hairline */
  --line-bright: #383e63;
  --accent: #7c5cff;        /* electric violet — primary */
  --accent-bright: #9579ff;
  --accent-dim: #4a3a99;
  --accent-soft: rgba(124, 92, 255, 0.16);
  --live: #38e0d4;          /* cyan — live / connected */
  --live-soft: rgba(56, 224, 212, 0.14);
  --rec: #ff3b3b;           /* record red — REC indicator / live status only */
  --rec-soft: rgba(255, 59, 59, 0.14);
  --danger: #ff5d7a;
  --danger-soft: rgba(255, 93, 122, 0.14);
  --text: #eceefb;
  --text-dim: #9098bd;
  --text-faint: #5e6589;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

/* ===========================================================================
   THEMES — switchable via <html data-theme="…">, chosen in the nav switcher.
   Default (no attribute) = the original "Control Room" violet.
   =========================================================================== */

/* Midnight — flat dark navy with a blue/cyan accent (design 1) */
:root[data-theme="midnight"] {
  --bg: #0a0e17;
  --bg-panel: #121829;
  --bg-panel-2: #1a2236;
  --line: #232c42;
  --line-bright: #324063;
  --accent: #2f6bff;
  --accent-bright: #5b8bff;
  --accent-dim: #21407a;
  --accent-soft: rgba(47, 107, 255, 0.16);
  --live: #22d3ee;
  --live-soft: rgba(34, 211, 238, 0.14);
  --text: #e7ecf6;
  --text-dim: #8893ab;
  --text-faint: #5b647e;
}

/* Daylight — clean light surface with an indigo accent (design 2) */
:root[data-theme="daylight"] {
  --bg: #f5f7fb;
  --bg-panel: #ffffff;
  --bg-panel-2: #f1f3f9;
  --line: #e6e9f1;
  --line-bright: #d6dbe8;
  --accent: #6366f1;
  --accent-bright: #7c7ff5;
  --accent-dim: #c3c6f7;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --live: #0ea5e9;
  --live-soft: rgba(14, 165, 233, 0.12);
  --rec: #ef4444;
  --rec-soft: rgba(239, 68, 68, 0.12);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.12);
  --text: #1a1f2e;
  --text-dim: #6b7280;
  --text-faint: #9aa1b2;
}

/* Aurora — modern flat graphite with an emerald accent. Calm neutral surfaces,
   high text contrast, soft accent tint; designed to feel clean and easy to use. */
:root[data-theme="aurora"] {
  --bg: #0d1117;
  --bg-panel: #161b22;
  --bg-panel-2: #212936;
  --line: #263041;
  --line-bright: #3a4658;
  --accent: #10b981;
  --accent-bright: #34d399;
  --accent-dim: #0f766e;
  --accent-soft: rgba(16, 185, 129, 0.15);
  --live: #22d3ee;
  --live-soft: rgba(34, 211, 238, 0.14);
  --rec: #f43f5e;
  --rec-soft: rgba(244, 63, 94, 0.14);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.14);
  --text: #e6edf3;
  --text-dim: #9aa5b4;
  --text-faint: #6b7688;
}

/* Obsidian Violet — premium near-black, violet→pink gradient accent. */
:root[data-theme="obsidian"] {
  --bg: #0a0a12; --bg-panel: #15151f; --bg-panel-2: #1e1e2d;
  --line: #26263a; --line-bright: #383854;
  --accent: #8b5cf6; --accent-bright: #ec4899; --accent-dim: #5b3aa6;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --live: #2dd4bf; --live-soft: rgba(45, 212, 191, 0.14);
  --rec: #ff4d6d; --rec-soft: rgba(255, 77, 109, 0.14);
  --danger: #ff4d6d; --danger-soft: rgba(255, 77, 109, 0.14);
  --text: #f4f2ff; --text-dim: #a29fc0; --text-faint: #6b6890;
}

/* Midnight Aurora — deep navy, cyan→blue gradient accent. */
:root[data-theme="nebula"] {
  --bg: #070d1a; --bg-panel: #101a2e; --bg-panel-2: #17253d;
  --line: #213152; --line-bright: #31456d;
  --accent: #22d3ee; --accent-bright: #3b82f6; --accent-dim: #1a5a8f;
  --accent-soft: rgba(34, 211, 238, 0.15);
  --live: #34d399; --live-soft: rgba(52, 211, 153, 0.14);
  --rec: #fb7185; --rec-soft: rgba(251, 113, 133, 0.14);
  --danger: #fb7185; --danger-soft: rgba(251, 113, 133, 0.14);
  --text: #e8f1ff; --text-dim: #8aa0c4; --text-faint: #5b6e90;
}

/* Emerald Noir — charcoal-green, emerald→lime gradient accent. */
:root[data-theme="emerald"] {
  --bg: #08120e; --bg-panel: #0f201a; --bg-panel-2: #163026;
  --line: #1e3a2e; --line-bright: #2c5443;
  --accent: #10b981; --accent-bright: #84cc16; --accent-dim: #0c7357;
  --accent-soft: rgba(16, 185, 129, 0.15);
  --live: #22d3ee; --live-soft: rgba(34, 211, 238, 0.14);
  --rec: #fb7185; --rec-soft: rgba(251, 113, 133, 0.14);
  --danger: #fb7185; --danger-soft: rgba(251, 113, 133, 0.14);
  --text: #e6f5ee; --text-dim: #8bb3a2; --text-faint: #5e7d6e;
}

/* Sunset — dark plum, orange→rose gradient accent. */
:root[data-theme="sunset"] {
  --bg: #140a12; --bg-panel: #221420; --bg-panel-2: #2e1a2a;
  --line: #3b2333; --line-bright: #542e44;
  --accent: #fb923c; --accent-bright: #f43f5e; --accent-dim: #a85a1f;
  --accent-soft: rgba(251, 146, 60, 0.15);
  --live: #38bdf8; --live-soft: rgba(56, 189, 248, 0.14);
  --rec: #ff4d6d; --rec-soft: rgba(255, 77, 109, 0.14);
  --danger: #ff4d6d; --danger-soft: rgba(255, 77, 109, 0.14);
  --text: #fceee9; --text-dim: #c49aa6; --text-faint: #8a6773;
}

/* Glass Light — clean light surface, indigo→purple gradient accent. */
:root[data-theme="glass"] {
  --bg: #eef1f8; --bg-panel: #ffffff; --bg-panel-2: #f4f6fc;
  --line: #e3e7f0; --line-bright: #d3d9e8;
  --accent: #6366f1; --accent-bright: #a855f7; --accent-dim: #c3c6f7;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --live: #0ea5e9; --live-soft: rgba(14, 165, 233, 0.12);
  --rec: #ef4444; --rec-soft: rgba(239, 68, 68, 0.12);
  --danger: #ef4444; --danger-soft: rgba(239, 68, 68, 0.12);
  --text: #1a1f33; --text-dim: #6b7288; --text-faint: #9aa1b5;
}

/* Cyber Neon — near-black, cyan→fuchsia gradient accent. */
:root[data-theme="neon"] {
  --bg: #0a0e14; --bg-panel: #111820; --bg-panel-2: #18222e;
  --line: #223040; --line-bright: #33475c;
  --accent: #06b6d4; --accent-bright: #d946ef; --accent-dim: #0a7d94;
  --accent-soft: rgba(6, 182, 212, 0.15);
  --live: #22d3ee; --live-soft: rgba(34, 211, 238, 0.14);
  --rec: #ff4d6d; --rec-soft: rgba(255, 77, 109, 0.14);
  --danger: #ff4d6d; --danger-soft: rgba(255, 77, 109, 0.14);
  --text: #e9f6fb; --text-dim: #86a0b0; --text-faint: #5a7183;
}

/* The flat themes drop the violet glow grid and the CRT scanline. */
:root[data-theme="midnight"] body,
:root[data-theme="daylight"] body,
:root[data-theme="aurora"] body,
:root[data-theme="obsidian"] body,
:root[data-theme="nebula"] body,
:root[data-theme="emerald"] body,
:root[data-theme="sunset"] body,
:root[data-theme="glass"] body,
:root[data-theme="neon"] body { background-image: none; }
:root[data-theme="midnight"] body::after,
:root[data-theme="daylight"] body::after,
:root[data-theme="aurora"] body::after,
:root[data-theme="obsidian"] body::after,
:root[data-theme="nebula"] body::after,
:root[data-theme="emerald"] body::after,
:root[data-theme="sunset"] body::after,
:root[data-theme="glass"] body::after,
:root[data-theme="neon"] body::after { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

* { box-sizing: border-box; }

/* Theme the root canvas too, not just <body>. Otherwise, when a page scrolls
   past its content (or on mobile overscroll bounce), the transparent <html>
   background shows the browser default — a white/black band that breaks the
   theme. Keeping it on :root means it also follows every data-theme. */
html { background: var(--bg); }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 1000px 600px at 80% -15%, rgba(124, 92, 255, 0.08), transparent 60%),
    radial-gradient(ellipse 700px 500px at 5% 110%, rgba(56, 224, 212, 0.05), transparent 55%),
    linear-gradient(rgba(143, 152, 200, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(143, 152, 200, 0.04) 1px, transparent 1px);
  background-size: auto, auto, 30px 30px, 30px 30px;
  background-attachment: fixed, fixed, scroll, scroll;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* CRT scanline overlay — the faint horizontal banding of a surveillance monitor.
   Kept very low-contrast so it reads as atmosphere, not noise. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.06) 3px
  );
  mix-blend-mode: multiply;
}
@media (prefers-reduced-motion: reduce) {
  body::after { display: none; }
}

a { color: var(--accent-bright); text-decoration: none; }
a:hover { text-decoration: underline; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb { background: var(--line-bright); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- */
/* Brand mark + topbar                                               */
/* ---------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 26px;
  background: linear-gradient(180deg, rgba(20, 23, 41, 0.95), rgba(20, 23, 41, 0.82));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text);
  font-size: 17px;
}
.brand-mark { width: 26px; height: 26px; flex-shrink: 0; border-radius: 7px; box-shadow: 0 2px 8px rgba(124,92,255,0.35); }
.brand span.sub { color: var(--text-faint); font-weight: 500; letter-spacing: 0.3px; }
.topbar nav a {
  margin-left: 20px; color: var(--text-dim); font-size: 13px; font-weight: 500;
  letter-spacing: 0.2px;
}
.topbar nav a:hover { color: var(--accent-bright); text-decoration: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 30px 24px 60px; }

/* ===========================================================================
   App shell — fixed left sidebar + slim topbar, injected by api.js on every
   logged-in page. The old per-page .topbar is hidden when the shell is on.
   =========================================================================== */
body.has-shell { padding-left: 234px; padding-top: 56px; }
body.has-shell > .topbar { display: none; }
body.has-demo-banner { padding-top: 96px; }

#demoBanner {
  position: fixed; top: 56px; left: 234px; right: 0; height: 40px; z-index: 69;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 0 14px; overflow: hidden; white-space: nowrap;
  background: rgba(255, 180, 84, 0.12); border-bottom: 1px solid rgba(255, 180, 84, 0.45);
  color: var(--text); font-size: 12.5px; font-weight: 500;
}
#demoBanner .demo-warn { color: #ffb454; font-weight: 700; animation: demoWarnPulse 2.2s ease-in-out infinite; }
@keyframes demoWarnPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }
#demoBanner .demo-note { color: var(--text-dim); }
#demoBanner a { color: var(--accent-bright); font-weight: 700; text-decoration: none; }
#demoBanner a:hover { text-decoration: underline; }
/* On narrower screens keep the warning + signup link; drop the secondary note. */
@media (max-width: 1280px) { #demoBanner .demo-note { display: none; } }
/* Phones: the remaining warning text alone still doesn't fit on one line at
   this width — let it wrap instead of silently clipping, and grow the
   reserved space below the topbar to match (fixed padding-top assumes a
   single-line banner otherwise, which would let wrapped text overlap the
   page content). */
@media (max-width: 480px) {
  #demoBanner { white-space: normal; height: auto; min-height: 40px; padding: 6px 14px; line-height: 1.35; text-align: center; }
  body.has-demo-banner { padding-top: 132px; }
}

#appSidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: 234px; z-index: 80;
  background: var(--bg-panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 14px 12px;
}
.side-logo {
  display: flex; align-items: center; gap: 11px; padding: 6px 8px 16px;
  font-family: var(--font-display); font-weight: 600; letter-spacing: 0.5px;
  color: var(--text); font-size: 16px; line-height: 1.05;
}
.side-logo .brand-mark { height: 26px; width: auto; display: block; }
.side-logo small { display: block; color: var(--text-faint); font-size: 9.5px; letter-spacing: 2.5px; font-weight: 600; }
.side-nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; flex: 1; margin-top: 4px; }
.side-nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--text-dim); font-size: 13.5px; font-weight: 500; text-decoration: none;
  transition: background .14s, color .14s;
}
.side-nav a .ico { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.side-nav a:hover { background: var(--bg-panel-2); color: var(--text); }
.side-nav a.active { background: var(--accent-soft); color: var(--accent-bright); font-weight: 600; }
.side-foot { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 8px; }
.side-storage { padding: 4px 8px 10px; }
.side-storage .ss-top { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.side-storage .ss-bar { height: 6px; border-radius: 4px; background: var(--bg-panel-2); overflow: hidden; }
.side-storage .ss-bar span { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.side-foot .who { font-size: 11.5px; color: var(--text-dim); padding: 2px 4px 8px; line-height: 1.45; }
.side-foot .who .who-link {
  display: flex; align-items: center; gap: 9px; padding: 5px 6px; border-radius: 9px;
  color: inherit; text-decoration: none;
}
.side-foot .who .who-link:hover { background: var(--bg-panel-2); }
.side-foot .who .who-meta { min-width: 0; }
.side-foot .who .who-meta strong { color: var(--text); font-weight: 600; display: block; font-size: 12.5px; word-break: break-all; }
.side-foot .who .who-meta .lvl-badge { margin-top: 3px; }

/* Account "level" pill — shown in the sidebar (the user's own status) and in
   the admin user table (everyone's status). One colour per tier. */
.lvl-badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; vertical-align: middle;
  font-size: 11px; font-weight: 600; line-height: 1.4; padding: 1px 8px; border-radius: 999px;
  border: 1px solid transparent;
}
.lvl-badge.lvl-demo    { color: #a78bfa; background: rgba(167,139,250,0.14); border-color: rgba(167,139,250,0.4); }
.lvl-badge.lvl-admin   { color: #eab308; background: rgba(234,179,8,0.12);  border-color: rgba(234,179,8,0.35); }
.lvl-badge.lvl-viewer  { color: var(--text-dim); background: var(--bg-panel-2); border-color: var(--line-bright); }
.lvl-badge.lvl-trial   { color: #38bdf8; background: rgba(56,189,248,0.12); border-color: rgba(56,189,248,0.35); }
.lvl-badge.lvl-expired { color: #ef4444; background: rgba(239,68,68,0.12);  border-color: rgba(239,68,68,0.35); }
.lvl-badge.lvl-paid    { color: #22c55e; background: rgba(34,197,94,0.12);  border-color: rgba(34,197,94,0.35); }
.who-avatar {
  width: 34px; height: 34px; flex-shrink: 0; padding: 0; cursor: pointer;
  border-radius: 50%; overflow: hidden; border: 1px solid var(--line-bright);
  background: var(--bg-panel-2); display: flex; align-items: center; justify-content: center;
}
.who-avatar:hover { border-color: var(--accent); }
.who-avatar img, .profile-avatar-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who-initials { font-weight: 700; color: var(--accent-bright); font-size: 12px; }
.profile-avatar-preview {
  width: 104px; height: 104px; margin: 4px auto 18px; border-radius: 50%; overflow: hidden;
  border: 1px solid var(--line-bright); background: var(--bg-panel-2);
  display: flex; align-items: center; justify-content: center;
}
.profile-avatar-preview .who-initials { font-size: 34px; }
.side-foot a.logout {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px;
  color: var(--text-dim); font-size: 13px; text-decoration: none;
}
.side-foot a.logout .ico { font-size: 15px; width: 20px; text-align: center; }
.side-foot a.logout:hover { background: var(--danger-soft); color: var(--danger); }

#appTopbar {
  position: fixed; top: 0; left: 234px; right: 0; height: 56px; z-index: 70;
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  background: var(--bg-panel); border-bottom: 1px solid var(--line);
}
#appTopbar .page-title { font-size: 15px; font-weight: 600; color: var(--text); font-family: var(--font-display); }
#appTopbar .crumb-link { color: var(--text-dim); text-decoration: none; }
#appTopbar .crumb-link:hover { color: var(--accent-bright); text-decoration: none; }
#appTopbar .bar-spacer { flex: 1; }
#appBarRight { display: flex; align-items: center; gap: 6px; }
.side-burger { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; line-height: 1; }

/* Global search — lives in every page's topbar. */
.global-search-wrap { position: relative; width: 340px; margin-left: 8px; }
.global-search-wrap input {
  width: 100%; padding: 7px 12px; font-size: 13px;
  background: var(--bg-panel-2); color: var(--text);
  border: 1px solid var(--line-bright); border-radius: var(--radius-sm);
}
.global-search-wrap input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.global-search-results {
  position: absolute; top: calc(100% + 6px); left: 0; width: 420px; z-index: 200;
  background: var(--bg-panel); border: 1px solid var(--line); border-radius: var(--radius-sm);
  max-height: 420px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.gs-section-label {
  padding: 8px 12px 4px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-faint);
}
.gs-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer;
  font-size: 13px; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.gs-item:hover, .gs-item.active { background: var(--bg-panel-2); }
.gs-item .gs-ico { font-size: 15px; flex-shrink: 0; }
.gs-item .gs-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.gs-item .gs-sub { color: var(--text-faint); }
.gs-empty { padding: 14px 12px; font-size: 13px; color: var(--text-dim); }

@media (max-width: 860px) {
  body.has-shell { padding-left: 0; }
  #appSidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,0.5); }
  body.sidebar-open #appSidebar { transform: translateX(0); }
  #appTopbar { left: 0; }
  #demoBanner { left: 0; }
  .side-burger { display: block; }
  #appTopbar .page-title { display: none; } /* not enough room for title + search on phones */
  .global-search-wrap { width: auto; flex: 1; max-width: 260px; margin-left: 6px; }
  .global-search-results { width: min(420px, 92vw); }
}

/* Phones: the topbar's right-side icon cluster (theme, language, gift,
   feedback) plus the search box and hamburger don't all fit at once — the
   theme switcher's text label is the single biggest item, so it's the first
   to go. The button stays fully usable (swatch still opens the dropdown). */
@media (max-width: 480px) {
  .theme-name, .theme-chevron { display: none; }
  #themeSwitchBtn { padding: 5px 7px; gap: 0; }
}

h1 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.3px;
  font-size: 30px;
  color: var(--text);
  margin: 0 0 4px;
}
h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}
.subtitle { color: var(--text-dim); margin: 0 0 8px; font-size: 14px; }

/* ---------------------------------------------------------------- */
/* Cards / grid                                                       */
/* ---------------------------------------------------------------- */
.card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.025) inset, 0 10px 30px rgba(0,0,0,0.22);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.entity-card {
  background: linear-gradient(180deg, var(--bg-panel), rgba(20, 23, 41, 0.6));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.entity-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--live));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .25s ease;
}
.entity-card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-3px);
  box-shadow: 0 14px 36px rgba(0,0,0,0.4), 0 0 0 1px var(--accent-soft);
}
.entity-card:hover::before { transform: scaleX(1); }
.entity-card h3 {
  margin: 0 0 8px; color: var(--text); font-size: 16px;
  font-weight: 600;
}
.entity-card .meta { color: var(--text-dim); font-size: 13px; line-height: 1.6; }

/* ---------------------------------------------------------------- */
/* Buttons / inputs                                                    */
/* ---------------------------------------------------------------- */
button, .btn {
  background: var(--bg-panel-2);
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
button:hover, .btn:hover { border-color: var(--accent); background: #232843; }
button:active, .btn:active { transform: scale(0.97); }
button.primary {
  background: linear-gradient(180deg, var(--accent-bright), var(--accent));
  border-color: var(--accent); color: #fff;
  font-weight: 600;
}
button.primary:hover { box-shadow: 0 6px 20px rgba(124,92,255,0.4); border-color: var(--accent-bright); }
button.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
button.danger:hover { background: var(--danger-soft); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
button.ghost:hover { background: var(--bg-panel-2); color: var(--text); border-color: var(--line); }
button.small { padding: 5px 11px; font-size: 12px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 14px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
label {
  display: block; font-size: 12px; font-weight: 500; color: var(--text-dim);
  letter-spacing: 0.2px;
  margin-bottom: 6px; margin-top: 14px;
}
label:first-child { margin-top: 0; }

.field-row { display: flex; gap: 12px; }
.field-row > div { flex: 1; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 18px 0; }
.toolbar .spacer { flex: 1; }

.empty-state {
  text-align: center; color: var(--text-dim); padding: 60px 20px;
  font-size: 14px;
}

/* ---------------------------------------------------------------- */
/* Modal                                                               */
/* ---------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 7, 15, 0.74);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
  animation: fadeIn .12s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-panel); border: 1px solid var(--line-bright); border-radius: var(--radius);
  padding: 24px; width: 440px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.05) inset;
}
.modal h3 { margin-top: 0; font-size: 18px; }
.modal-actions {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px;
  position: sticky; bottom: -24px;
  margin-left: -24px; margin-right: -24px; margin-bottom: -24px;
  padding: 16px 24px; background: var(--bg-panel);
  border-top: 1px solid var(--line-bright);
}

.hidden { display: none !important; }

/* Viewers are read-only — anything tagged .write-only (add/edit/delete
   controls) is hidden for them, rather than visible-but-403-on-click. */
body.viewer-readonly .write-only { display: none !important; }

.tag {
  display: inline-block; font-size: 10.5px; padding: 3px 10px; border-radius: 20px;
  background: var(--accent-soft); color: var(--accent-bright); border: 1px solid var(--accent-dim);
  letter-spacing: 0.3px; font-weight: 600;
}
.tag.live { background: var(--live-soft); color: var(--live); border-color: rgba(56,224,212,0.4); }

/* ---------------------------------------------------------------- */
/* Credential rows (click-to-reveal)                                  */
/* ---------------------------------------------------------------- */
.credential-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--line); gap: 10px;
}
.credential-row:last-child { border-bottom: none; }
.credential-row .cred-label {
  color: var(--text-dim); font-size: 12px; min-width: 90px;
  letter-spacing: 0.2px; font-weight: 500;
}
.credential-row .cred-value {
  font-family: var(--font-mono); font-size: 14px; flex: 1;
  letter-spacing: 0.5px; user-select: all; color: var(--text);
}
.credential-row .cred-actions { display: flex; gap: 4px; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); border-radius: 6px;
  width: 30px; height: 30px; padding: 0; font-size: 14px; color: var(--text-dim);
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent-bright); background: var(--accent-soft); }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th {
  color: var(--text-faint); font-weight: 600;
  font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--bg-panel-2);
  border: 1px solid var(--accent); color: var(--text); padding: 12px 18px;
  border-radius: var(--radius-sm); z-index: 2000; font-size: 13.5px;
  box-shadow: 0 10px 32px rgba(0,0,0,0.5);
  animation: toastIn .15s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------------------------------------------------------------- */
/* Viewfinder frame — signature motif                                  */
/* ---------------------------------------------------------------- */
.viewfinder-frame { position: relative; }
.vf-corner {
  position: absolute; width: 20px; height: 20px; pointer-events: none; z-index: 5;
  opacity: 0.5; transition: opacity .2s ease;
}
.viewfinder-frame:hover .vf-corner, .viewfinder-frame:focus-within .vf-corner { opacity: 1; }
.vf-tl { top: 8px; left: 8px; border-top: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.vf-tr { top: 8px; right: 8px; border-top: 2px solid var(--accent); border-right: 2px solid var(--accent); }
.vf-bl { bottom: 8px; left: 8px; border-bottom: 2px solid var(--accent); border-left: 2px solid var(--accent); }
.vf-br { bottom: 8px; right: 8px; border-bottom: 2px solid var(--accent); border-right: 2px solid var(--accent); }

/* Active-mode pulse — used only on toolbar buttons while a placement mode is on */
.pulse-dot {
  display: none; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; position: relative; top: -1px;
}
button.primary .pulse-dot {
  display: inline-block;
  background: #fff;
  animation: pulseDot 1.4s infinite;
}
@keyframes pulseDot {
  0% { box-shadow: 0 0 0 0 rgba(255,255,255,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); }
}

/* ---------------------------------------------------------------- */
/* DVR overlay — signature element                                    */
/* The REC dot + live timestamp mimic the overlay burned into footage */
/* ---------------------------------------------------------------- */
.dvr-status {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.5px;
}
.dvr-rec {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--rec);
  font-weight: 500;
}
.dvr-rec .rec-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--rec);
  box-shadow: 0 0 6px var(--rec);
  animation: recBlink 1.3s steps(1, end) infinite;
}
@keyframes recBlink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0.15; } }
.dvr-clock { color: var(--text-dim); }
.dvr-ch { color: var(--text-faint); }
@media (max-width: 720px) {
  .dvr-status .dvr-ch { display: none; }
}

/* Channel eyebrow — small monospace label like an NVR channel tag */
.ch-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 1px;
  color: var(--text-faint);
  text-transform: uppercase;
}

/* Status dot — online (green/live) vs idle */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.online { background: var(--live); box-shadow: 0 0 6px var(--live-soft); }
.status-dot.idle { background: var(--text-faint); }

/* Camera-feed framing for entity cards: a channel tag pinned top-right */
.entity-card .card-ch {
  position: absolute;
  top: 14px; right: 14px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--text-faint);
}
.entity-card .card-del {
  position: absolute; bottom: 12px; right: 12px;
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  border-radius: 6px; padding: 3px 8px; font-size: 13px; cursor: pointer; line-height: 1;
  opacity: 0; transition: opacity .15s, color .15s, border-color .15s;
}
.entity-card:hover .card-del { opacity: 1; }
.entity-card .card-del:hover { color: #ff6b6b; border-color: #ff6b6b; background: rgba(255,107,107,0.08); }

/* Device documentation photos (project editor modals) */
.device-photos {
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}
.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px; margin: 8px 0 10px;
}
.photo-cell {
  position: relative; border: 1px solid var(--line); border-radius: var(--radius-sm);
  overflow: hidden; background: var(--bg-panel-2);
}
.photo-cell img {
  display: block; width: 100%; height: 84px; object-fit: cover; cursor: zoom-in;
}
.photo-cell .photo-cap {
  width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent;
  color: var(--text-dim); font-size: 11px; padding: 4px 6px; box-sizing: border-box;
}
.photo-cell .photo-del {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; line-height: 20px;
  text-align: center; border: 0; border-radius: 6px; cursor: pointer;
  background: rgba(0,0,0,0.55); color: #fff; font-size: 13px;
}
.photo-cell .photo-del:hover { background: var(--danger); }
.photo-empty { color: var(--text-faint); font-size: 12.5px; padding: 6px 2px; }

/* Warranty status badge (properties panel + warranty page) */
.warranty-badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px;
  border-radius: 20px; letter-spacing: .2px;
}
.warranty-badge.valid   { background: rgba(52,199,89,0.16);  color: #34c759; }
.warranty-badge.soon    { background: rgba(255,179,64,0.18); color: #f0a500; }
.warranty-badge.expired { background: var(--danger-soft);    color: var(--danger); }

/* Custom date picker (dd/mm/yyyy display + pop-up calendar) */
.datepick { position: relative; }
.datepick-input { width: 100%; cursor: pointer; padding-left: 9px !important; padding-right: 34px !important; font-size: 12.5px; letter-spacing: 0; }
.datepick .dp-open, .datepick .dp-clear {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: transparent; border: 0; cursor: pointer; padding: 0;
  color: var(--text-dim); height: 22px; line-height: 22px; text-align: center;
}
.datepick .dp-open { right: 4px; width: 16px; font-size: 12px; }
.datepick .dp-open:hover { color: var(--accent-bright); }
.datepick .dp-clear { right: 19px; width: 14px; font-size: 10px; opacity: 0; transition: opacity .12s; }
.datepick.has-value .dp-clear { opacity: .55; }
.datepick .dp-clear:hover { opacity: 1; color: var(--danger); }

.dp-pop {
  position: fixed; z-index: 2100; width: 252px; box-sizing: border-box;
  background: var(--bg-panel); border: 1px solid var(--line-bright);
  border-radius: var(--radius); box-shadow: 0 10px 40px rgba(0,0,0,.45);
  padding: 10px; user-select: none;
}
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-title { font-size: 13.5px; font-weight: 600; color: var(--text); }
.dp-nav {
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  width: 28px; height: 28px; border-radius: 7px; cursor: pointer; font-size: 16px; line-height: 1;
}
.dp-nav:hover { border-color: var(--accent); color: var(--accent-bright); }
.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.dp-dow { margin-bottom: 4px; }
.dp-dowc { text-align: center; font-size: 11px; color: var(--text-faint); padding: 2px 0; }
.dp-day { text-align: center; font-size: 12.5px; padding: 6px 0; border-radius: 7px; cursor: pointer; color: var(--text); }
.dp-day:hover { background: var(--bg-panel-2); }
.dp-empty { visibility: hidden; cursor: default; }
.dp-day.today { box-shadow: inset 0 0 0 1px var(--line-bright); }
.dp-day.sel { background: var(--accent); color: #fff; }
.dp-foot { margin-top: 8px; text-align: center; }
.dp-today {
  background: transparent; border: 1px solid var(--line); color: var(--text-dim);
  padding: 4px 12px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.dp-today:hover { border-color: var(--accent); color: var(--accent-bright); }
