:root {
  --bg: #0f1420; --panel: #171e2e; --panel-2: #1f2840; --line: #2a3552;
  --text: #e8ecf5; --muted: #8e9ab5; --accent: #ef4b3f; --accent-2: #ff6a5c;
  --ok: #2fbf71; --warn: #f2b134; --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--accent-2); }
button, input { font: inherit; }
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 10px 16px; cursor: pointer; font-weight: 600;
}
button:hover { background: var(--accent-2); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
button.ghost:hover { background: var(--panel-2); }
button.small { padding: 6px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.muted { color: var(--muted); }
.error { color: #ff8a80; min-height: 1.3em; font-size: 14px; }

/* ---- Auth page ---- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 400px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; }
.brand img { width: 30px; height: 30px; }
.tabs { display: flex; gap: 6px; margin: 20px 0 4px; }
.tabs button { flex: 1; }
.card form button[type=submit] { width: 100%; margin-top: 18px; }

/* ---- Dashboard ---- */
header.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
header.top .who { display: flex; align-items: center; gap: 12px; font-size: 14px; }
main.dash { max-width: 1000px; margin: 0 auto; padding: 20px 16px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
section.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
section.box h2 { margin: 0 0 12px; font-size: 16px; }
.connect-row { display: flex; gap: 10px; }
.connect-row input { font-size: 22px; letter-spacing: 3px; font-variant-numeric: tabular-nums; }
.devices { display: grid; gap: 8px; }
.device {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--panel-2); border-radius: 10px;
}
.device .name { font-weight: 600; }
.device .meta { font-size: 12px; color: var(--muted); }
.device .grow { flex: 1; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #55607a; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.keybox { font-family: ui-monospace, Consolas, monospace; font-size: 20px; letter-spacing: 2px; background: var(--bg); padding: 8px 12px; border-radius: 8px; display: inline-block; }
table.log { width: 100%; border-collapse: collapse; font-size: 13px; }
table.log td, table.log th { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }

/* ---- Viewer ---- */
body.viewer { overflow: hidden; overscroll-behavior: none; }
.vbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10; height: 48px;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: rgba(15, 20, 32, .92); border-bottom: 1px solid var(--line);
}
.vbar .title { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage { position: fixed; top: 48px; left: 0; right: 0; bottom: 0; background: #000; touch-action: none; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; cursor: none; outline: none; }
.status {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  padding: 20px; color: var(--muted); pointer-events: none;
}
.status.hidden { display: none; }
.side {
  position: fixed; top: 48px; right: 0; bottom: 0; width: min(340px, 100%); z-index: 9;
  background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; transform: translateX(100%); transition: transform .2s;
}
.side.open { transform: none; }
.side .msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { background: var(--panel-2); padding: 8px 10px; border-radius: 10px; font-size: 14px; max-width: 90%; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: #3a2230; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; }
.side form { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.drop { margin: 10px; padding: 14px; border: 2px dashed var(--line); border-radius: 10px; text-align: center; font-size: 13px; color: var(--muted); cursor: pointer; }
.drop.hover { border-color: var(--accent); color: var(--text); }
#kbdInput { position: fixed; left: -1000px; top: 0; opacity: 0; width: 1px; height: 1px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 20; padding: 16px; }
.hidden { display: none !important; }

@media (max-width: 600px) {
  header.top { padding: 10px 14px; }
  .connect-row { flex-direction: column; }
  .vbar .label { display: none; }
}
