/* viewer/style.css — Beam viewer: mobile-first dark UI shared by index.html and session.html.
   No inline styles anywhere (CSP default-src 'self' forbids them); toggle visibility with the
   `hidden` attribute or classes. */

:root {
  --bg: #0b1220;
  --bg-2: #111a2c;
  --card: #141f33;
  --card-2: #1a2740;
  --line: #24324d;
  --text: #e6edf7;
  --muted: #8ea0bd;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --accent-text: #04121c;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --pad: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
body.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.95em; }
code { background: var(--bg-2); padding: 1px 6px; border-radius: 6px; }
h1 { font-size: 1.35rem; margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.02rem; margin: 0 0 10px; font-weight: 600; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.error { color: var(--danger); font-size: 0.92rem; margin: 6px 0 10px; }
.empty { color: var(--muted); padding: 24px 8px; text-align: center; }
b { font-weight: 600; }

/* top bar ------------------------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) var(--pad) 8px;
  background: rgba(11, 18, 32, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  min-height: 52px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 1.1rem; flex: 1; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 7px;
  background: linear-gradient(135deg, var(--accent) 0%, #818cf8 100%);
  position: relative; display: inline-block;
}
.brand-mark::after {
  content: ""; position: absolute; left: 7px; top: 5px; width: 0; height: 0;
  border-left: 9px solid var(--bg); border-top: 6px solid transparent; border-bottom: 6px solid transparent;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  appearance: none; background: transparent; border: 0; color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-2); }
.icon-btn svg { width: 22px; height: 22px; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--muted); flex: 0 0 auto; }
.dot.online, .dot.dot-authed { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.18); }
.dot.offline, .dot.dot-closed { background: #5b6b86; }
.dot.dot-connecting, .dot.dot-open { background: var(--warn); }

/* banner ------------------------------------------------------------------------------- */
.banner {
  background: #3b2f12; color: #fde68a; border-bottom: 1px solid #6b5416;
  padding: 8px var(--pad); font-size: 0.9rem; text-align: center;
}
.banner.info { background: #12304a; color: #bae6fd; border-color: #1e4f76; }
.banner.danger { background: #4a1616; color: #fecaca; border-color: #7f1d1d; }

/* layout ------------------------------------------------------------------------------- */
.main {
  flex: 1; width: 100%; max-width: 560px; margin: 0 auto;
  padding: var(--pad) var(--pad) calc(var(--pad) + var(--safe-b));
}
.view { animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.row-between h1 { margin: 0; }
.steps { margin: 0 0 14px; padding-left: 20px; color: var(--muted); }
.steps li { margin-bottom: 6px; }

/* forms -------------------------------------------------------------------------------- */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 0.86rem; color: var(--muted); margin-bottom: 5px; }
input[type="text"], input[type="password"], input[type="url"], textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; outline: none; min-height: 44px;
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18); }
input:disabled, button:disabled { opacity: 0.6; cursor: not-allowed; }

.btn {
  appearance: none; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--card-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 16px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: background 0.12s, transform 0.05s;
}
.btn:hover { background: #21304c; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: transparent; color: var(--danger); border-color: #5a2323; }
.btn.danger:hover { background: #2a1414; }
.btn.small-btn { padding: 8px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.ghost { background: transparent; }
form .btn.primary { width: 100%; margin-top: 4px; }
.row .btn.primary, .dlg .btn.primary { width: auto; margin-top: 0; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.25); border-top-color: currentColor;
  animation: spin 0.8s linear infinite; display: inline-block;
}
.btn:not(.primary) .spinner { border-color: rgba(255, 255, 255, 0.2); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; margin-bottom: 10px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 44px; height: 26px; border-radius: 13px; background: #33425f; position: relative; flex: 0 0 auto;
  transition: background 0.15s;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; transition: transform 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.3); }

/* lists -------------------------------------------------------------------------------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.list.compact { gap: 6px; }
.device {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
}
.device .device-name { font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.device .device-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .device-meta { color: var(--muted); font-size: 0.82rem; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device .device-actions { display: flex; gap: 6px; align-items: center; }
.device.offline .device-name { color: var(--muted); }
.badge { font-size: 0.7rem; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #1f3a52; color: #7dd3fc; text-transform: uppercase; letter-spacing: 0.04em; }
.badge.unpaired { background: #2b2b3d; color: #a5b4fc; }
.key-row {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.key-row .key-name { font-weight: 600; }
.key-row .key-dev { color: var(--muted); font-size: 0.78rem; }

/* enrollment code ---------------------------------------------------------------------- */
.code-box { text-align: center; padding: 14px 0 12px; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(1.5rem, 7vw, 2.2rem); letter-spacing: 0.08em; font-weight: 700;
  user-select: all; -webkit-user-select: all;
  padding: 10px; background: var(--bg-2); border-radius: 12px; border: 1px dashed var(--line);
}
.code.expired { color: var(--muted); text-decoration: line-through; }

/* camera ------------------------------------------------------------------------------- */
.camera { position: relative; width: 100%; aspect-ratio: 1 / 1; background: #000; border-radius: 12px; overflow: hidden; margin-bottom: 12px; }
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camera-frame {
  position: absolute; inset: 12%; border: 2px solid rgba(56, 189, 248, 0.8); border-radius: 12px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35); pointer-events: none;
}

/* toast + dialogs ---------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%);
  background: #1e293b; color: var(--text); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 50; max-width: min(92vw, 480px); font-size: 0.92rem;
}
.toast.ok { border-color: #1d5c47; }
.toast.error { border-color: #7f1d1d; color: #fecaca; }
.dlg {
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; width: min(92vw, 420px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.dlg::backdrop { background: rgba(0, 0, 0, 0.55); }
.dlg h2 { margin-bottom: 8px; }
.dlg p { color: var(--muted); }

/* session page (viewer/session.html, W09) ---------------------------------------------- */
body.session { background: #000; overflow: hidden; }
.session .stage { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: #000; touch-action: none; }
.session .stage video { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; display: block; }
.session .overlay { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; }
.session .overlay.no-cursor, .session .stage.no-cursor video, .session .stage.no-cursor .overlay { cursor: none; }
.session .virtual-cursor { position: absolute; width: 18px; height: 18px; pointer-events: none; display: none; }
.session .virtual-cursor.visible { display: block; }
.session .hud {
  position: fixed; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); z-index: 20;
  background: rgba(0, 0, 0, 0.6); color: #d1fae5; font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace;
  padding: 6px 8px; border-radius: 8px; pointer-events: none; white-space: pre;
}
.session .toolbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); z-index: 30;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
  background: rgba(15, 23, 42, 0.85); border: 1px solid var(--line); border-radius: 14px; padding: 6px 8px;
  max-width: calc(100vw - 16px); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.session .toolbar.collapsed { padding: 4px; }
.session .toolbar .btn { padding: 6px 10px; min-height: 36px; font-size: 0.85rem; }
.session .toolbar .btn.active { background: var(--accent); color: var(--accent-text); }
.session .toolbar select { min-height: 36px; padding: 6px 8px; width: auto; }
.session .modbar { display: flex; gap: 6px; }
.session .hidden-input {
  position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0.01; font-size: 16px;
  border: 0; padding: 0; margin: 0; resize: none; overflow: hidden;
}
.session .session-banner {
  position: fixed; top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); z-index: 40;
  background: rgba(30, 41, 59, 0.95); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 0.92rem; max-width: min(92vw, 520px); text-align: center;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center;
}
.session .session-banner.danger { border-color: #7f1d1d; }
.session .tap-to-start {
  position: fixed; inset: 0; z-index: 35; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.7); color: var(--text); font-size: 1.1rem; cursor: pointer;
}
:fullscreen body.session, body.session:fullscreen { background: #000; }
:fullscreen .session .toolbar { bottom: 10px; }

@media (min-width: 720px) {
  .main { padding-top: 28px; }
  h1 { font-size: 1.5rem; }
}
@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
  .spinner { animation-duration: 1.5s; }
}
