:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1d2233;
  --muted: #6b7286;
  --line: #e3e6ef;
  --motion: #6c5ce7;
  --sound: #e17055;
  --ok: #00b894;
  --warn: #fdcb6e;
  --danger: #d63031;
  --lane: #f0f2f8;
  --shadow: 0 1px 3px rgba(20, 25, 50, .08), 0 4px 16px rgba(20, 25, 50, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c; --card: #1b1e29; --text: #e8eaf2; --muted: #9097ab; --line: #2b2f3e;
    --lane: #232736; --motion: #a29bfe; --sound: #fab1a0;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
main { max-width: 1100px; margin: 0 auto; padding: 0 16px 48px; display: grid; gap: 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.card { background: var(--card); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }

/* header */
.top { max-width: 1100px; margin: 0 auto; padding: 20px 16px; display: flex; gap: 16px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.brand { display: flex; gap: 12px; align-items: center; }
.logo { font-size: 34px; }
.conn { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.bad { background: var(--danger); }
.devices { display: flex; gap: 8px; flex-wrap: wrap; }
.device { background: var(--card); box-shadow: var(--shadow); border-radius: 12px; padding: 8px 12px; font-size: 13px; display: grid; gap: 4px; min-width: 210px; }
.device-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.meter { display: grid; grid-template-columns: 56px 1fr 52px; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.bar { height: 6px; border-radius: 3px; background: var(--lane); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; transition: width .4s; }
.bar.motion > i { background: var(--motion); }
.bar.sound > i { background: var(--sound); }

/* buttons & inputs */
.btn { border: 0; background: var(--motion); color: #fff; padding: 7px 12px; border-radius: 8px; cursor: pointer; font: inherit; font-size: 14px; }
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--lane); color: var(--text); }
.btn-light { background: #fff; color: #222; }
.btn.danger { color: var(--danger); }
input[type=date], .num { font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.num { width: 64px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; background: var(--lane); padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.seg { display: inline-flex; background: var(--lane); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 5px 10px; border-radius: 6px; cursor: pointer; font: inherit; font-size: 13px; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 6px 0 16px; }
.stat { background: var(--lane); border-radius: 10px; padding: 10px 12px; }
.stat-n { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.motion { background: var(--motion); }
.sw.sound { background: var(--sound); }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, 1fr); } }

/* timeline */
.tl-lanes { display: grid; grid-template-columns: 74px 1fr; row-gap: 8px; align-items: center; }
.tl-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tl-lane { position: relative; height: 40px; background: var(--lane); border-radius: 8px; overflow: hidden; }
.tl-lane .grid { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--line); }
.tl-lane .now { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ok); z-index: 2; }
.tl-lane .ev { position: absolute; bottom: 0; width: 3px; min-height: 6px; border-radius: 2px 2px 0 0; cursor: pointer; transform: translateX(-1px); opacity: .85; }
.tl-lane .ev:hover, .tl-lane .ev.sel { opacity: 1; outline: 2px solid var(--text); z-index: 3; }
#laneMotion .ev { background: var(--motion); }
#laneSound .ev { background: var(--sound); }
.tl-lane .ev.fresh { animation: pop 1.2s ease-out; }
@keyframes pop { 0% { transform: translateX(-1px) scaleY(2.2); filter: brightness(1.6); } 100% { transform: translateX(-1px); } }
.tl-axis { position: relative; height: 18px; font-size: 11px; color: var(--muted); }
.tl-axis span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.tl-window { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding-left: 74px; }
.tl-window input { flex: 1; }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; }

/* events list */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 560px; overflow: auto; }
.events li { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 8px; border-radius: 10px; background: var(--lane); }
.events li.sel { outline: 2px solid var(--motion); }
.events li.fresh { animation: flash 2s ease-out; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--warn) 60%, var(--lane)); } 100% { background: var(--lane); } }
.thumb { width: 64px; height: 48px; border-radius: 6px; object-fit: cover; background: var(--line); cursor: zoom-in; display: grid; place-items: center; font-size: 22px; }
.ev-title { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; color: #fff; }
.badge.motion { background: var(--motion); }
.badge.sound { background: var(--sound); }
.ev-meta { font-size: 12px; color: var(--muted); }
.ev-time { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); text-align: right; }
.empty { text-align: center; padding: 24px 0 8px; margin: 0; }

/* alert banner */
.alert { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px; padding: 12px 16px; color: #fff; background: var(--danger); animation: pulse 1s ease-in-out infinite alternate; }
.alert.motion { background: #5f4bd8; }
.alert.sound { background: #d35400; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.18); } }
.alert-icon { font-size: 28px; }
.alert-body { flex: 1; min-width: 0; }
.alert-title { font-weight: 700; font-size: 17px; }
.alert-sub { font-size: 13px; opacity: .9; }
.alert-snap { height: 52px; border-radius: 6px; }
.banner-warn { background: var(--warn); color: #3d2e00; padding: 8px 16px; text-align: center; font-weight: 600; font-size: 14px; }

dialog { border: 0; border-radius: 14px; padding: 12px; background: var(--card); color: var(--text); max-width: min(92vw, 900px); }
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog img { display: block; max-width: 100%; max-height: 75vh; border-radius: 8px; margin-bottom: 10px; }

/* login page */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 340px; display: grid; gap: 14px; padding: 24px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { font: inherit; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
.login .btn { padding: 10px; font-size: 15px; }
.login .btn:disabled { opacity: .6; cursor: wait; }
.login-error { margin: 0; color: var(--danger); font-size: 13px; }

/* live view */
.live-stage { position: relative; margin-top: 12px; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; max-height: 70vh; display: grid; place-items: center; }
.live-stage img { width: 100%; height: 100%; object-fit: contain; display: block; }
.live-stage:fullscreen { max-height: none; border-radius: 0; aspect-ratio: auto; }
.live-badge { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.55); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .05em; padding: 3px 8px; border-radius: 6px; display: flex; align-items: center; gap: 6px; }
.live-badge .rec { width: 8px; height: 8px; border-radius: 50%; background: #ff3b30; animation: pulse 1s ease-in-out infinite alternate; }
.live-msg { position: absolute; inset: auto 0 0 0; padding: 8px 12px; color: #fff; font-size: 13px; background: linear-gradient(transparent, rgba(0,0,0,.7)); }
.live-msg:empty { display: none; }
.live-stage.waiting .live-msg { inset: 0; display: grid; place-items: center; background: none; font-size: 15px; }
.select { font: inherit; font-size: 14px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); }
