:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --text: #16191d;
  --muted: #5d6673;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --online: #16a34a;
  --offline: #9aa3ae;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --border: #2b323c;
    --text: #e6e9ee;
    --muted: #97a1ae;
    --accent: #4f8cff;
    --online: #22c55e;
    --offline: #5f6975;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.app { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; }
.brand svg { width: 22px; height: 22px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500;
}
.nav a[aria-current="page"] { color: var(--text); background: var(--surface-2); }
.nav a:hover { color: var(--text); }
.spacer { flex: 1; }
.who { color: var(--muted); font-size: 13px; }

.page { width: 100%; max-width: 1100px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 650; }
.page-head .sub { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.input {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
.input:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: grid; gap: 6px; font-weight: 500; }
label.field span { font-size: 13px; color: var(--muted); }

.login-wrap { flex: 1; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 360px; padding: 28px; display: grid; gap: 16px; }
.login h1 { margin: 0; font-size: 20px; }
.login p { margin: 0; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 1.2em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.group-row td { background: var(--surface-2); font-weight: 600; font-size: 13px; color: var(--muted); }
.name { font-weight: 600; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--offline); }
.dot.on { background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 20%, transparent); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 16px; border-bottom: 1px solid var(--border); }
.form-row .input { flex: 1 1 160px; }
.code { font-family: var(--mono); font-size: 15px; font-weight: 600; letter-spacing: 0.05em; }

.viewer { position: fixed; inset: 0; display: flex; flex-direction: column; background: #0b0d10; color: #e6e9ee; }
.viewer-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; flex-wrap: wrap;
  background: #151920; border-bottom: 1px solid #262c35;
}
.viewer-bar .btn, .viewer-bar .input { background: #1d232b; border-color: #2d3540; color: #e6e9ee; }
.viewer-bar .btn:hover { background: #262d37; }
.viewer-title { font-weight: 600; margin-right: 8px; }
.viewer-stats { font-family: var(--mono); font-size: 12px; color: #97a1ae; }
.viewer-stage { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; min-height: 0; }
.viewer-stage canvas {
  max-width: 100%; max-height: 100%; outline: none; background: #000;
  image-rendering: auto; touch-action: none;
}
.viewer-stage.actual canvas { max-width: none; max-height: none; }
.viewer-stage.actual { overflow: auto; align-items: flex-start; justify-content: flex-start; }
.viewer-overlay { position: absolute; inset: 56px 0 0; display: grid; place-items: center; pointer-events: none; }
.viewer-overlay .msg { background: rgba(21, 25, 32, 0.92); border: 1px solid #262c35; padding: 16px 22px; border-radius: 10px; pointer-events: auto; text-align: center; }
.viewer-stage.drop { outline: 3px dashed var(--accent); outline-offset: -12px; background: rgba(37, 99, 235, 0.08); }
.viewer-transfers {
  position: fixed; right: 12px; bottom: 12px;
  display: grid; gap: 6px; max-width: min(360px, calc(100vw - 24px));
  z-index: 50; pointer-events: none;
}
.transfer {
  background: rgba(21, 25, 32, 0.94); border: 1px solid #262c35; color: #e6e9ee;
  padding: 8px 12px; border-radius: 8px; font-family: var(--mono); font-size: 12px;
}
.transfer.done { border-color: var(--online); }
.transfer.cancelled { border-color: var(--danger); }

.toast {
  position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px));
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow);
  z-index: 100;
}

@media (max-width: 640px) {
  .nav { margin-left: 0; }
  .who { display: none; }
  .hide-sm { display: none; }
  th, td { padding: 10px; }
}
