:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #dde3ea;
  --text: #17202a;
  --muted: #5b6878;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --accent-soft: #e3ecfd;
  --danger: #dc2626;
  --ok: #16a34a;
  --ok-soft: #dcf5e4;
  --warn: #b45309;
  --warn-soft: #fdf0dc;
  --stage: #0b0e12;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #161c23; --surface-2: #1d252e; --line: #2a333d; --text: #e6edf3; --muted: #93a1b0;
    --accent: #3b82f6; --accent-soft: #172a4a; --danger: #ef4444; --ok: #22c55e; --ok-soft: #12301f;
    --warn: #f59e0b; --warn-soft: #34260e; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #161c23; --surface-2: #1d252e; --line: #2a333d; --text: #e6edf3; --muted: #93a1b0;
  --accent: #3b82f6; --accent-soft: #172a4a; --danger: #ef4444; --ok: #22c55e; --ok-soft: #12301f;
  --warn: #f59e0b; --warn-soft: #34260e; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
h3 { margin: 0 0 .5rem; }
code, pre, .id-input { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
a { color: var(--accent); }
.block { display: block; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }

/* top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px max(16px, calc((100vw - 1100px) / 2)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.brand-sub { color: var(--muted); font-weight: 500; }
.topnav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.who { color: var(--muted); font-size: .9rem; }

/* buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .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.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 30px; padding: 0 10px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0 4px; min-height: 0; font-weight: 500; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.row.spread { justify-content: space-between; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.optional { color: var(--muted); font-weight: 400; }
.hint, .fineprint { color: var(--muted); font-size: .82rem; font-weight: 400; margin: 0; }
.fineprint { margin-top: 16px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; min-height: 40px; width: 100%;
}
textarea { resize: vertical; }
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: .9rem; }
.id-input { font-size: 1.5rem; letter-spacing: .06em; padding: 10px 12px; }
.form-error { color: var(--danger); margin: 0; min-height: 0; font-size: .9rem; }
.form-error:empty { display: none; }
.error-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* cards & home */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 420px; margin: 48px auto; }
.muted-card { background: var(--surface-2); box-shadow: none; }
.muted-card p { color: var(--muted); margin: 0 0 12px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.lede { color: var(--muted); margin: 0 0 18px; }
.home {
  display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 20px;
  max-width: 1100px; margin: 32px auto; padding: 0 16px; align-items: start;
}
.connect-card { padding: 28px; }
.side-lists { display: flex; flex-direction: column; gap: 16px; }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-list li { display: flex; align-items: center; border-top: 1px solid var(--line); }
.device-list li:first-child { border-top: 0; }
.device-list .empty { color: var(--muted); padding: 8px 0; font-size: .9rem; }
.device {
  flex: 1; display: flex; gap: 10px; align-items: center; text-align: left; padding: 10px 4px;
  background: none; border: 0; color: inherit; font: inherit; cursor: pointer; border-radius: 6px; min-width: 0;
}
.device:hover { background: var(--surface-2); }
.device-text { display: flex; flex-direction: column; min-width: 0; }
.device-text small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; opacity: .6; }
.dot.on { background: var(--ok); opacity: 1; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin: 0 0 16px; }
.notice.ok { background: var(--ok-soft); }
.notice pre { white-space: pre-wrap; word-break: break-all; background: var(--surface); padding: 10px; border-radius: 6px; }

/* session */
.session { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--stage); color: #e6edf3; }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: 6px 10px; background: #161c23; border-bottom: 1px solid #2a333d; font-size: .85rem;
}
.tb-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.toolbar select { width: auto; min-height: 30px; padding: 3px 8px; background: #1d252e; color: #e6edf3; border-color: #2a333d; font-size: .82rem; }
.tb-btn {
  min-height: 30px; padding: 0 10px; border-radius: 6px; border: 1px solid #2a333d; background: #1d252e;
  color: #e6edf3; font: inherit; cursor: pointer; position: relative;
}
.tb-btn:hover:not(:disabled) { background: #26303b; }
.tb-btn:disabled { opacity: .4; cursor: not-allowed; }
.tb-btn.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.tb-btn.recording { background: #7f1d1d; border-color: #ef4444; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.chip { background: #1d252e; border: 1px solid #2a333d; border-radius: 999px; padding: 1px 9px; font-family: ui-monospace, Consolas, monospace; color: #93a1b0; }
.stats { color: #93a1b0; font-variant-numeric: tabular-nums; min-width: 12ch; }
.badge { position: absolute; top: -6px; right: -6px; background: #ef4444; color: #fff; border-radius: 999px; font-size: .7rem; padding: 0 5px; }
.session-body { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; overflow: auto; display: grid; place-items: start; min-width: 0; }
.stage.fit { overflow: hidden; place-items: center; }
.stage.dragging { outline: 3px dashed #3b82f6; outline-offset: -8px; }
#screen { display: block; outline: none; cursor: default; image-rendering: auto; touch-action: none; }
#screen.view-only { cursor: not-allowed; }
.remote-cursor {
  position: absolute; width: 14px; height: 14px; margin: -2px 0 0 -2px; pointer-events: none;
  border-left: 2px solid #fff; border-top: 2px solid #fff; transform: skew(-8deg);
  filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 1px #000);
}
.stage-overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(11, 14, 18, .82); z-index: 5; }
.overlay-card { background: #161c23; border: 1px solid #2a333d; border-radius: 12px; padding: 28px; max-width: 440px; text-align: center; }
.overlay-card p { color: #c3ccd6; }
.overlay-card .row { justify-content: center; margin-top: 14px; }
.overlay-card .btn { background: #1d252e; color: #e6edf3; border-color: #2a333d; }
.overlay-card .btn.primary { background: #3b82f6; border-color: #3b82f6; }
.overlay-card .btn.danger { color: #fca5a5; }
.sas-big { font: 700 2rem ui-monospace, Consolas, monospace; letter-spacing: .1em; color: #93c5fd; margin: 8px 0 0; }
.spinner { width: 32px; height: 32px; margin: 0 auto 8px; border: 3px solid #2a333d; border-top-color: #3b82f6; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
.drop-hint { position: absolute; inset: 24px; display: grid; place-items: center; font-weight: 600; pointer-events: none; background: rgba(37, 99, 235, .15); border-radius: 12px; }

.panel { width: 340px; max-width: 90vw; background: var(--surface); color: var(--text); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; }
.panel-body { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.chat-log { list-style: none; margin: 0; padding: 0; flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.chat-log li { background: var(--surface-2); border-radius: 10px; padding: 6px 10px; max-width: 85%; }
.chat-log li.mine { align-self: flex-end; background: var(--accent-soft); }
.chat-log small { color: var(--muted); }
.chat-log p { margin: 0; white-space: pre-wrap; word-break: break-word; }
.chat-form { display: flex; gap: 6px; }
.upload-zone { border: 2px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; }
.upload-zone p { margin: 0 0 8px; }
.upload-zone.dragging { border-color: var(--accent); background: var(--accent-soft); }
.transfers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.transfers li { font-size: .85rem; }
.transfer-head { display: flex; justify-content: space-between; gap: 8px; overflow: hidden; }
.transfer-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }
.browser-head { display: flex; gap: 8px; align-items: center; }
.browser-head code { font-size: .78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.file-list { list-style: none; margin: 0; padding: 0; }
.file {
  width: 100%; display: flex; gap: 8px; align-items: center; padding: 6px 6px; border: 0; background: none; color: inherit;
  font: inherit; font-size: .88rem; text-align: left; cursor: pointer; border-radius: 6px;
}
.file:hover { background: var(--surface-2); }
.file.dir .file-name { font-weight: 600; }
.file-icon { width: 1em; color: var(--muted); }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { color: var(--muted); }
.file-list .empty { color: var(--muted); padding: 6px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: .88rem; }
.info dt { color: var(--muted); }
.info dd { margin: 0; word-break: break-word; }

.menu {
  position: fixed; z-index: 30; background: #161c23; border: 1px solid #2a333d; border-radius: 8px; padding: 4px;
  display: flex; flex-direction: column; min-width: 240px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.menu button { text-align: left; background: none; border: 0; color: #e6edf3; padding: 8px 10px; border-radius: 6px; font: inherit; font-size: .88rem; cursor: pointer; }
.menu button:hover { background: #26303b; }
.menu .hint { padding: 6px 10px; color: #93a1b0; max-width: 260px; }

/* modal & toasts */
.modal-wrap { position: fixed; inset: 0; background: rgba(10, 14, 20, .55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { position: relative; background: var(--surface); color: var(--text); border-radius: 12px; padding: 24px; width: min(440px, 100%); box-shadow: var(--shadow); max-height: 90vh; overflow: auto; }
.modal-x { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; border: 0; background: none; color: inherit; font-size: 1.4rem; cursor: pointer; border-radius: 6px; }
.panel-head .modal-x { position: static; }
.modal-x:hover { background: var(--surface-2); }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: min(480px, calc(100vw - 32px)); }
.toast { background: #1f2937; color: #f9fafb; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); transition: opacity .4s; }
.toast.error { background: #991b1b; }
.toast.out { opacity: 0; }
.toast .btn.link { color: #93c5fd; }

/* admin */
.admin { max-width: 1200px; margin: 0 auto; padding: 20px 16px 48px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { display: flex; flex-direction: column; gap: 16px; }
.tab-body h2 { margin-top: 8px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head select { width: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td code { white-space: nowrap; }
td code.small { word-break: break-all; white-space: normal; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: .78rem; background: var(--surface-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.muted { color: var(--muted); }
.empty { color: var(--muted); }
.grid3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.toggle { display: flex; gap: 14px; align-items: flex-start; cursor: pointer; }
.toggle input { margin-top: 3px; flex: none; }
.toggle span { display: flex; flex-direction: column; }
.toggle small { color: var(--muted); }
.secret { font-size: 1.1rem; letter-spacing: .08em; background: var(--surface-2); padding: 10px 12px; border-radius: 8px; margin: 0; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }

@media (max-width: 760px) {
  .home { grid-template-columns: 1fr; margin-top: 16px; }
  .connect-card { padding: 20px; }
  .grid3 { grid-template-columns: 1fr; }
  .stats { display: none; }
  .panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 10; }
  .session-body { position: relative; }
}
