:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-alt: #f3f5f7;
  --text: #14171c;
  --muted: #5d6876;
  --line: #e6e8ec;
  --line-strong: #d3d7de;
  --primary: #0c6e86;
  --primary-strong: #09566a;
  --primary-soft: #e7f4f8;
  --primary-text: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warn: #8a5a00;
  --warn-soft: #fff6e0;
  --ok: #0d7a3a;
  --ok-soft: #e7f6ec;
  --sidebar: #fbfbfc;
  --sidebar-text: #3d4856;
  --sidebar-muted: #6a7686;
  --sidebar-active: #e7f4f8;
  --sidebar-hover: #f0f2f5;
  --stage: #0c1116;
  --stage-line: #243041;
  --stage-text: #d5deea;
  --shadow-sm: 0 1px 1px rgba(16, 24, 40, 0.04);
  --shadow: 0 16px 40px rgba(16, 24, 40, 0.08);
  --ring: 0 0 0 3px rgba(12, 110, 134, 0.28);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 240px;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e12;
    --panel: #16191f;
    --panel-alt: #1d2129;
    --text: #eceef2;
    --muted: #9aa3b2;
    --line: #2a303a;
    --line-strong: #3a4250;
    --primary: #5ec8dc;
    --primary-strong: #8fd9e8;
    --primary-soft: #12323b;
    --primary-text: #062028;
    --danger: #ffb4ab;
    --danger-soft: #3b1814;
    --warn: #f3d48a;
    --warn-soft: #3a2e12;
    --ok: #8ee0ad;
    --ok-soft: #123222;
    --sidebar: #101318;
    --sidebar-text: #c5ccd6;
    --sidebar-muted: #8b95a5;
    --sidebar-active: #16343d;
    --sidebar-hover: #1b2028;
    --stage: #090d12;
    --stage-line: #2a3644;
    --stage-text: #d5deea;
    --shadow-sm: 0 1px 1px rgba(0, 0, 0, 0.35);
    --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
    --ring: 0 0 0 3px rgba(94, 200, 220, 0.32);
  }
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: var(--primary-soft);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  cursor: pointer;
  padding: 8px 14px;
  font-weight: 600;
  line-height: 1.3;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:hover {
  background: var(--panel-alt);
  border-color: var(--line-strong);
}

button:active {
  background: var(--panel-alt);
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

button.primary:hover,
button.primary:active {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  color: var(--primary-text);
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

button.ghost:hover {
  background: var(--panel-alt);
  color: var(--text);
}

button.danger {
  border-color: transparent;
  background: var(--danger-soft);
  color: var(--danger);
}

button.danger:hover {
  border-color: transparent;
  background: color-mix(in srgb, var(--danger) 16%, var(--danger-soft));
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 8px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.loadbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 80;
  overflow: hidden;
  background: var(--primary-soft);
  pointer-events: none;
}

.loadbar::before {
  content: "";
  display: block;
  height: 100%;
  width: 36%;
  background: var(--primary);
  animation: loadbar 1s ease-in-out infinite;
}

@keyframes loadbar {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(380%); }
}

/* ---------- App shell ---------- */

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 16px 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 8px 16px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-name {
  min-width: 0;
}

.brand .logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand .logo svg {
  width: 16px;
  height: 16px;
}

.nav {
  display: grid;
  gap: 2px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  font-weight: 600;
  padding: 8px 10px;
}

.nav button:hover {
  background: var(--sidebar-hover);
  color: var(--text);
  border-color: transparent;
}

.nav button.active {
  background: var(--sidebar-active);
  color: var(--primary);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.nav-label {
  min-width: 0;
}

.sidebar .foot {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 12px;
}

.sidebar .foot .server-chip {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--sidebar-muted);
  background: transparent;
}

.sidebar .foot button {
  width: 100%;
  background: transparent;
  color: var(--sidebar-text);
  border-color: var(--line);
}

.sidebar .foot button:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.content {
  min-width: 0;
  padding: 28px 32px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.userbox {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  min-width: 0;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
}

.userbox .who {
  display: grid;
  text-align: right;
  line-height: 1.25;
  min-width: 0;
}

.userbox .who strong {
  color: var(--text);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.userbox .who span:empty {
  display: none;
}

/* ---------- Auth screens ---------- */

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  align-items: safe center;
  justify-items: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(900px 420px at 12% -10%, color-mix(in srgb, var(--primary) 14%, transparent), transparent 60%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel .brand {
  margin: 0 0 20px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.025em;
  line-height: 1.25;
}

.login-panel > p {
  margin: 0 0 16px;
  color: var(--muted);
}

.login-panel .stack > button {
  width: 100%;
}

.agent-apk-download {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.agent-apk-checksum {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.agent-apk-checksum code {
  display: block;
  margin-top: 4px;
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 20px 0 10px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.qr-block {
  display: grid;
  justify-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-alt);
  padding: 16px;
  margin-bottom: 16px;
}

.qr-block img {
  width: 196px;
  height: 196px;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.qr-block .secret {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  word-break: break-all;
  text-align: center;
  color: var(--text);
}

.qr-block .hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin: 0;
}

.recovery-panel {
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: var(--radius);
  background: var(--warn-soft);
  padding: 16px;
  margin: 4px 0 16px;
}

.recovery-panel h3 {
  margin: 0 0 6px;
  font-size: 14px;
  letter-spacing: -0.01em;
}

.recovery-panel p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
}

.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.recovery-grid code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  text-align: center;
  color: var(--text);
}

/* ---------- Layout helpers ---------- */

.stack {
  display: grid;
  gap: 12px;
  /* Panels in a grid row stretch to the tallest sibling; keep fields packed
     at the top instead of spreading the extra height between rows. */
  align-content: start;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}

.grid > * {
  min-width: 0;
}

.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}

.panel h2 {
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.panel.stack > button.primary {
  margin-top: 2px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  min-width: 0;
}

.metric .value {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: var(--panel-alt);
}

td button,
.session-item > button {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 12px;
}

td button + button {
  margin-left: 6px;
}

td.row-actions {
  white-space: nowrap;
  text-align: right;
}

tr.row-disabled td {
  color: var(--muted);
}

/* ---------- Pills, notices, empty ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--muted);
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.3;
  white-space: nowrap;
}

.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }

.muted {
  color: var(--muted);
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
}

.server-chip {
  font-size: 12px;
  line-height: 1.45;
  word-break: break-all;
}

.login-panel .server-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.server-chip-url {
  min-width: 0;
  word-break: break-all;
}

.gap-top {
  margin-top: 16px;
}

.gap-top-sm {
  margin-top: 12px;
}

.messages {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  color: var(--muted);
  padding: 10px 12px;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.notice-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin-top: 2px;
}

.error {
  border-color: color-mix(in srgb, var(--danger) 28%, var(--line));
  background: var(--danger-soft);
  color: var(--danger);
}

.success {
  border-color: color-mix(in srgb, var(--ok) 28%, var(--line));
  background: var(--ok-soft);
  color: var(--ok);
}

.empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-alt);
}

.empty p {
  margin: 0;
  max-width: 42ch;
}

.empty-icon {
  width: 22px;
  height: 22px;
  opacity: 0.7;
}

.empty-inline {
  margin: 4px 0 0;
  font-size: 13px;
}

.empty-on-dark {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.16);
  color: var(--stage-text);
}

.empty-on-dark .muted {
  color: #93a3b8;
}

.device-summary {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-alt);
  padding: 14px 16px;
}

.device-summary > strong {
  display: block;
  margin-bottom: 10px;
}

.kv {
  display: grid;
  gap: 8px;
  margin: 0;
}

.kv div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
}

.kv dt {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.kv dd {
  margin: 0;
  min-width: 0;
  word-break: break-all;
}

/* ---------- Checkboxes ---------- */

.checkboxes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text);
  font-weight: 550;
  cursor: pointer;
  background: var(--panel);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.check:hover {
  border-color: var(--line-strong);
}

.check:has(input:checked) {
  border-color: color-mix(in srgb, var(--primary) 55%, var(--line));
  background: var(--primary-soft);
}

.check:has(input:focus-visible) {
  box-shadow: var(--ring);
}

.check input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

/* ---------- Viewer ---------- */

.viewer {
  display: grid;
  place-items: center;
  min-height: 240px;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius);
  background: var(--stage);
  color: var(--stage-text);
  text-align: center;
  padding: 20px;
}

.viewer-shell {
  display: grid;
  gap: 12px;
}

.viewer-stage {
  position: relative;
  aspect-ratio: 16 / 10;
  max-height: min(66vh, 560px);
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--stage-line);
  border-radius: var(--radius);
  background: var(--stage);
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.viewer-stage video,
.viewer-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.viewer-stage canvas:empty {
  display: none;
}

.viewer-overlay {
  position: absolute;
  left: 10px;
  top: 10px;
  max-width: calc(100% - 20px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(8, 12, 18, 0.78);
  color: var(--stage-text);
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.viewer-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.viewer-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.viewer-tools input {
  flex: 1 1 180px;
  width: auto;
  min-width: 0;
  max-width: none;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 148px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 13px;
}

.code {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
}

/* ---------- Session history ---------- */

.session-list {
  display: grid;
  gap: 8px;
}

.session-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 10px 12px;
}

.session-item:hover {
  border-color: var(--line-strong);
}

.session-item.active {
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  background: var(--primary-soft);
  box-shadow: inset 3px 0 0 var(--primary);
}

.session-item .grow {
  flex: 1;
  min-width: 0;
}

.session-item .meta {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Dialogs ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.48);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.modal > p {
  margin: -6px 0 12px;
  font-size: 13px;
}

.modal .messages {
  margin-bottom: 12px;
}

/* ---------- Operations ---------- */

.download-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

a.button-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

a.button-link:hover {
  background: var(--panel-alt);
}

a.button-link:focus-visible {
  outline: none;
  box-shadow: var(--ring);
  border-color: var(--primary);
}

.token-reveal {
  display: grid;
  gap: 10px;
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--line));
  border-radius: var(--radius);
  background: var(--warn-soft);
  padding: 16px;
}

.token-reveal h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  word-break: break-all;
}

.token-reveal p {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.token-reveal input {
  font-family: var(--mono);
  font-size: 12px;
}

/* ---------- Responsive ---------- */

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

  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: auto;
    width: 100%;
    z-index: 40;
    gap: 0;
    padding: 6px 8px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    border-right: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(16, 24, 40, 0.06);
  }

  .brand,
  .sidebar .foot {
    display: none;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
  }

  .nav button {
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    text-align: center;
    font-size: 11px;
    line-height: 1.2;
    min-height: 52px;
    border-radius: 10px;
    padding: 6px 2px;
  }

  .nav-label {
    white-space: nowrap;
  }

  .content {
    padding: 16px 16px calc(132px + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    margin-bottom: 16px;
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 20px;
  }

  .topbar .actions button {
    min-height: 40px;
  }

  .userbox .who {
    display: none;
  }

  .summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metric .value {
    font-size: 24px;
  }

  .span-4,
  .span-5,
  .span-6,
  .span-7,
  .span-8,
  .span-12 {
    grid-column: span 12;
  }

  .grid {
    gap: 12px;
  }

  .viewer-stage {
    aspect-ratio: 9 / 16;
    max-height: 62vh;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
  }

  .userbox {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 560px) {
  .login-wrap {
    padding: 16px;
    align-items: start;
  }

  .login-panel {
    padding: 20px;
  }

  .checkboxes,
  .recovery-grid {
    grid-template-columns: 1fr;
  }

  .kv div {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  table {
    min-width: 620px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loadbar::before {
    animation: none;
    width: 100%;
    transform: none;
  }

  button,
  input,
  select,
  textarea,
  .check,
  a.button-link {
    transition: none;
  }
}

/* Timestamps stay on one line; wide tables scroll inside their container. */
td.time {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
