:root {
  --bg: #121212; --bg2: #1a1a1a; --panel: #1f1f1f; --panel2: #262626; --line: #333; --line2: #444;
  --text: #ece8e1; --muted: #9b958c; --accent: #ce422b; --accent2: #e8603f; --ok: #5fb760; --warn: #e5a93b; --bad: #e0503c; --info: #4fa3e0;
  --radius: 10px; --shadow: 0 6px 24px rgba(0,0,0,.35);
  --font: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f0eb; --bg2: #ebe7e0; --panel: #fff; --panel2: #f6f3ee; --line: #ddd6cc; --line2: #c9c0b4;
    --text: #1f1b17; --muted: #6d655b; --shadow: 0 6px 24px rgba(60,40,20,.12); color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #f3f0eb; --bg2: #ebe7e0; --panel: #fff; --panel2: #f6f3ee; --line: #ddd6cc; --line2: #c9c0b4;
  --text: #1f1b17; --muted: #6d655b; --shadow: 0 6px 24px rgba(60,40,20,.12); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
.h1 { font-size: 28px; } .h2 { font-size: 20px; } .h3 { font-size: 16px; }
p { margin: 0 0 1em; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--bg2); color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 7px 10px; font: inherit; width: 100%; min-width: 0; }
textarea { min-height: 80px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.stack > * + * { margin-top: 12px; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card h3 { display: flex; align-items: center; gap: 8px; }
.card.narrow { max-width: 520px; margin: 0 auto; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }

.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 50%, transparent); }
.badge.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.connected, .dot.online { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dot.connecting, .dot.idle { background: var(--warn); }
.dot.error, .dot.disconnected { background: var(--bad); }
.dot.needs-address { background: var(--info); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }

/* landing */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.landing { max-width: 980px; margin: 0 auto; padding: 48px 16px; }
.hero { text-align: center; padding: 40px 0 24px; }
.hero h1 { font-size: clamp(30px, 6vw, 52px); letter-spacing: -.02em; }
.hero p { font-size: 17px; color: var(--muted); max-width: 640px; margin: 0 auto 28px; }
.steam-btn { display: inline-flex; align-items: center; gap: 10px; background: #171a21; color: #fff; padding: 12px 22px; border-radius: 10px; font-weight: 600; border: 1px solid #2a475e; font-size: 16px; }
.steam-btn:hover { background: #2a475e; text-decoration: none; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 32px; }
.features .card h3 { font-size: 15px; }
.features .card p { color: var(--muted); margin: 0; font-size: 13.5px; }

/* app shell */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--bg2); border-right: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; color: var(--text); }
.brand img { width: 28px; height: 28px; }
.side .section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 4px 0; }
.srv-link { display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px; color: var(--text); border: 1px solid transparent; }
.srv-link:hover { background: var(--panel); text-decoration: none; }
.srv-link.active { background: var(--panel); border-color: var(--line2); }
.srv-link .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-box { margin-top: auto; display: flex; align-items: center; gap: 10px; padding-top: 12px; border-top: 1px solid var(--line); }
.user-box img { width: 34px; height: 34px; border-radius: 6px; }
.main { padding: 20px 24px 60px; min-width: 0; }
.topbar { display: none; }
.server-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.server-head img.logo { width: 46px; height: 46px; border-radius: 8px; object-fit: cover; background: var(--panel2); }
.server-head .title { flex: 1; min-width: 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; scrollbar-width: thin; }
.tabs a { padding: 9px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

/* team */
.member { display: flex; align-items: center; gap: 12px; padding: 10px; border-bottom: 1px solid var(--line); }
.member img { width: 36px; height: 36px; border-radius: 6px; background: var(--panel2); }
.member .who { flex: 1; min-width: 0; }
.member .who b { display: block; }

/* chat */
.chat { display: flex; flex-direction: column; height: min(70vh, 720px); }
.chat-log { flex: 1; overflow-y: auto; padding: 10px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13.5px; }
.chat-log .msg { padding: 3px 0; word-wrap: break-word; }
.chat-log .msg .t { color: var(--muted); font-size: 11px; margin-right: 6px; font-family: var(--mono); }
.chat-log .msg .n { font-weight: 700; margin-right: 6px; }
.chat-log .msg.bot { opacity: .8; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }

/* devices */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.device { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.device.alarmed { border-color: var(--bad); }
.device .head { display: flex; align-items: center; gap: 8px; }
.device .head b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch { position: relative; width: 46px; height: 26px; border-radius: 99px; background: var(--line2); border: 0; cursor: pointer; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(20px); }
.items { display: flex; flex-wrap: wrap; gap: 4px; }
.items span { font-size: 12px; background: var(--panel2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; }

/* map */
.map-wrap { position: relative; height: min(78vh, 900px); background: #0b1f2a; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; touch-action: none; }
.map-wrap canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.map-wrap canvas.dragging { cursor: grabbing; }
.map-tools { position: absolute; top: 10px; left: 10px; display: flex; gap: 6px; flex-wrap: wrap; z-index: 2; }
.map-tools .btn { background: color-mix(in srgb, var(--panel) 92%, transparent); }
.map-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); max-width: 320px; z-index: 3; display: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* camera */
.cam-view { background: #000; border-radius: var(--radius); aspect-ratio: 16/9; display: flex; align-items: center; justify-content: center; overflow: hidden; border: 1px solid var(--line); outline: none; }
.cam-view:focus { border-color: var(--accent); }
.cam-view img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.pad { display: grid; grid-template-columns: repeat(3, 44px); gap: 6px; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--line2); border-left: 4px solid var(--accent); padding: 10px 12px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; animation: slide .2s ease-out; }
.toast.alarm { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

.steps { counter-reset: s; list-style: none; padding: 0; margin: 0; }
.steps > li { counter-increment: s; position: relative; padding: 0 0 18px 40px; }
.steps > li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.steps > li.done::before { content: "✓"; background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.feed { max-height: 420px; overflow-y: auto; }
.feed .it { padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; display: flex; gap: 8px; }
.feed .it .t { color: var(--muted); font-family: var(--mono); font-size: 11.5px; white-space: nowrap; padding-top: 2px; }
.console-out { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: var(--mono); font-size: 12.5px; min-height: 120px; max-height: 360px; overflow-y: auto; white-space: pre-wrap; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; height: 100vh; box-shadow: var(--shadow); max-width: 300px; }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--bg2); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px; }
  .map-wrap { height: 65vh; }
}
