:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2430;
  --line: #2b3440;
  --fg: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
  overscroll-behavior: none;
}

.hidden { display: none !important; }
/* Elements are hidden from script by setting .hidden as a property. That only
   works while no class gives them a display value: `.segmented` is a grid, and
   a class selector outranks the user agent's [hidden] rule. */
[hidden] { display: none !important; }
.grow { flex: 1 1 auto; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.center { text-align: center; }
.error { color: var(--danger); }
code { background: #21262d; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ── login ─────────────────────────────────────────────────────────────── */
.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}

.card h1 { margin: 0 0 4px; font-size: 24px; letter-spacing: .5px; }
.card .sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.card label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.card input[type=text], .card input[type=password] {
  width: 100%;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--fg);
  font-size: 15px;
}
.card input:focus { outline: none; border-color: var(--accent); }
.card .check { display: flex; align-items: center; gap: 8px; margin: 16px 0; color: var(--fg); font-size: 13px; }
.card .check input { width: auto; }
.card button {
  width: 100%;
  padding: 11px;
  background: var(--accent-2);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.card button:hover { background: var(--accent); }
.card button:disabled { opacity: .55; cursor: default; }
.hint { margin: 16px 0 0; color: var(--muted); font-size: 12px; }

/* ── layout ────────────────────────────────────────────────────────────── */
#deviceView, #sessionView { display: flex; flex-direction: column; height: 100%; }

.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.brand { font-weight: 700; letter-spacing: .5px; }
.title { font-weight: 600; }
.content { padding: 20px; overflow: auto; flex: 1 1 auto; }
.content h2 { font-size: 15px; font-weight: 600; margin: 0 0 14px; }

.pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: #1c3a26; }
.pill.bad { color: var(--danger); border-color: #3a1c1c; }
.pill.warn { color: var(--warn); border-color: #3a2f1c; }

button.ghost, button.danger {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
}
button.ghost:hover { border-color: var(--accent); }
button.danger { border-color: #4b1f1f; background: #2a1515; color: #ffb4b4; }
button.danger:hover { border-color: var(--danger); }

/* ── device grid ───────────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }

.device {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.device .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.device .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; flex: 0 0 auto; }
.device .dot.online { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.device .meta { color: var(--muted); font-size: 12px; word-break: break-all; }
.device button {
  margin-top: 6px;
  padding: 8px;
  border-radius: 8px;
  border: 0;
  background: var(--accent-2);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.device button:disabled { background: #30363d; color: var(--muted); cursor: not-allowed; }

/* ── session ───────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.toolbar label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.toolbar select {
  background: #0d1117;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #05070a;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}
.screen-wrap { position: relative; line-height: 0; }

#screen {
  display: block;
  max-width: 100%;
  background: #000;
  image-rendering: auto;
  cursor: none;
}
#screen.native { max-width: none; }

.cursor {
  position: absolute;
  width: 20px;
  height: 20px;
  pointer-events: none;
  z-index: 5;
  background-repeat: no-repeat;
  background-size: contain;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='20' height='20'><path d='M2 1 L2 16 L6 12 L9 18 L11.5 17 L8.5 11 L14 11 Z' fill='white' stroke='black' stroke-width='1.2'/></svg>");
  transform: translate(-2px, -1px);
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(5, 7, 10, .78);
  color: var(--fg);
  font-size: 14px;
}
.overlay.hidden { display: none; }
.spinner {
  width: 26px; height: 26px;
  border: 3px solid #30363d;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.statusbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 12px;
  flex: 0 0 auto;
}

/* ── toasts ────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  max-width: min(420px, 92vw);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  font-size: 13px;
}
.toast.warn { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

/* ── tabs ──────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin: 4px 0 18px; border-bottom: 1px solid var(--line); }
.tabs.inline { margin: 0; border-bottom: 0; }
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--fg); background: var(--panel-2); }
.tab.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
.tabs.inline .tab { border-bottom: 0; border-radius: 8px; padding: 6px 12px; }
.tabs.inline .tab.active { background: var(--panel-2); color: var(--fg); }

/* ── tables ────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { background: var(--panel-2); color: var(--muted); font-weight: 600; font-size: 12px; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.right, table.data th.right { text-align: right; }
table.data td.right button { margin-left: 6px; }

/* ── misc ──────────────────────────────────────────────────────────────── */
button.ghost.small { padding: 4px 9px; font-size: 12px; }
.danger-text { color: #ffb4b4; border-color: #4b1f1f; }
.danger-text:hover { border-color: var(--danger); }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.mt { margin-top: 26px; }
h2 .ghost.small { margin-left: 8px; vertical-align: middle; }
.inline-card { max-width: 420px; }
.inline-card button { width: auto; margin-top: 14px; }
.inline-card hr { border: 0; border-top: 1px solid var(--line); margin: 22px 0 6px; }
.inline-card .hint { margin-top: 10px; }

/* ══ authentication screen ═══════════════════════════════════════════════ */
/* The sign-in card is deliberately the most polished surface in the app: it
   is the first thing anyone sees, and the only screen a colleague who is not
   an administrator ever visits before the device list. */

.auth {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 20px;
}

/* Layered radial washes plus a faint grid, so the page has depth instead of
   being a flat black rectangle. */
.auth-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(880px 520px at 12% -12%, rgba(59, 130, 246, .22), transparent 62%),
    radial-gradient(760px 460px at 90% 4%, rgba(139, 92, 246, .17), transparent 64%),
    radial-gradient(680px 420px at 50% 112%, rgba(34, 197, 94, .10), transparent 62%),
    linear-gradient(180deg, #090d13 0%, #0d1117 55%, #090d13 100%);
}
.auth-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .030) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .030) 1px, transparent 1px);
  background-size: 46px 46px;
  -webkit-mask-image: radial-gradient(circle at 50% 38%, #000 0%, transparent 76%);
  mask-image: radial-gradient(circle at 50% 38%, #000 0%, transparent 76%);
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 404px;
  padding: 30px 30px 26px;
  border: 1px solid rgba(255, 255, 255, .075);
  border-radius: 18px;
  background: rgba(22, 27, 34, .84);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  backdrop-filter: blur(14px) saturate(1.1);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .06),
    0 24px 64px rgba(0, 0, 0, .55);
  animation: auth-in .42s cubic-bezier(.2, .7, .3, 1) both;
}
@keyframes auth-in {
  from { opacity: 0; transform: translateY(14px) scale(.986); }
  to   { opacity: 1; transform: none; }
}

/* ── brand ─────────────────────────────────────────────────────────────── */
.auth-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 22px; }
.auth-logo {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  color: #cfe3ff;
  background: linear-gradient(160deg, rgba(59, 130, 246, .32), rgba(139, 92, 246, .22));
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
}
.auth-logo svg { width: 27px; height: 27px; }
.auth-brand-text h1 { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: .4px; }
.auth-brand-text p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

/* ── segmented tabs ────────────────────────────────────────────────────── */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  margin-bottom: 22px;
  background: #0b0f15;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg-thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 9px;
  background: linear-gradient(180deg, #33405280, #232c3a);
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .07);
  transition: transform .28s cubic-bezier(.2, .7, .3, 1);
}
.segmented[data-active="register"] .seg-thumb { transform: translateX(100%); }
.seg-btn {
  position: relative;
  z-index: 1;
  padding: 9px 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: color .2s;
}
.seg-btn.active { color: var(--fg); }
.seg-btn:hover:not(.active) { color: #c3ccd8; }

/* ── fields ────────────────────────────────────────────────────────────── */
.auth-form .field { margin-bottom: 14px; }
.auth-form .field label {
  display: block;
  margin-bottom: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: #9aa6b4;
}
.auth-form .field label .opt { margin-left: 5px; font-size: 11.5px; font-weight: 400; color: #5b6675; }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: #5b6675;
  pointer-events: none;
  transition: color .18s;
}
.input-wrap:focus-within .input-icon { color: var(--accent); }

.input-wrap input {
  width: 100%;
  padding: 11px 46px 11px 38px;
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--fg);
  font-size: 14.5px;
  font-family: inherit;
  transition: border-color .18s, box-shadow .18s, background .18s;
}
.input-wrap input::placeholder { color: #4a5563; }
.input-wrap input:hover { border-color: #38424f; }
.input-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  background: #0f1620;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}

.reveal {
  position: absolute;
  right: 7px;
  padding: 5px 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.reveal:hover { color: var(--fg); background: rgba(255, 255, 255, .07); }

.auth-form .check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 0;
  font-size: 13px;
  color: #b8c2cf;
  cursor: pointer;
  user-select: none;
}
.auth-form .check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ── primary action ────────────────────────────────────────────────────── */
.primary {
  position: relative;
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .3px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .28);
  transition: transform .12s, box-shadow .2s, filter .2s;
}
.primary:hover:not(:disabled) { filter: brightness(1.08); box-shadow: 0 9px 24px rgba(37, 99, 235, .36); }
.primary:active:not(:disabled) { transform: translateY(1px); box-shadow: 0 3px 10px rgba(37, 99, 235, .30); }
.primary:disabled { opacity: .6; cursor: default; box-shadow: none; }

.btn-spin {
  display: none;
  width: 14px;
  height: 14px;
  margin-left: 8px;
  vertical-align: -2px;
  border: 2px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.primary.loading .btn-spin { display: inline-block; }

/* ── messages ──────────────────────────────────────────────────────────── */
.alert {
  margin: 16px 0 0;
  padding: 10px 13px;
  border: 1px solid rgba(239, 68, 68, .28);
  border-left: 3px solid var(--danger);
  border-radius: 9px;
  background: rgba(239, 68, 68, .10);
  color: #fca5a5;
  font-size: 13px;
  animation: auth-in .25s ease both;
}

.fineprint { margin: 14px 0 0; font-size: 12.5px; line-height: 1.65; color: #8a95a4; }

.auth-foot {
  position: relative;
  z-index: 1;
  margin: 20px 0 0;
  font-size: 12px;
  color: #6a7482;
}

@media (max-width: 460px) {
  .auth { padding: 24px 14px; }
  .auth-card { padding: 24px 20px 22px; border-radius: 16px; }
}
/* Short viewports (laptops, split screens): tighten the rhythm so the whole
   sign-up form fits without scrolling. */
@media (max-height: 760px) {
  .auth { padding: 20px 16px; }
  .auth-card { padding: 22px 24px 20px; }
  .auth-brand { margin-bottom: 15px; }
  .auth-brand-text p { display: none; }
  .segmented { margin-bottom: 15px; }
  .auth-form .field { margin-bottom: 10px; }
  .primary { margin-top: 14px; padding: 11px; }
  .fineprint { margin-top: 10px; }
  .auth-foot { margin-top: 12px; }
}
/* ══ admin: allocate an account ════════════════════════════════════════════ */
.card.inline-card.wide { max-width: 700px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid2 .field { margin-bottom: 14px; }
.grid2 input, .grid2 select {
  width: 100%;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--fg);
  font-family: inherit;
  font-size: 14px;
}
.grid2 input:focus, .grid2 select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, .16);
}
.grid2 label .opt { margin-left: 5px; font-size: 11.5px; font-weight: 400; color: #5b6675; }

/* The generated-password panel: shown once, after the account is created. */
.credential {
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid rgba(34, 197, 94, .3);
  border-radius: 10px;
  background: rgba(34, 197, 94, .07);
  animation: auth-in .25s ease both;
}
.credential .cred-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.credential .cred-row span { width: 42px; flex: 0 0 auto; color: var(--muted); font-size: 12.5px; }
.credential code {
  flex: 1 1 auto;
  padding: 6px 10px;
  background: #0d1117;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 14px;
  user-select: all;
}
.credential .fineprint { margin-top: 12px; }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; }
}