/* Lab portal. System fonts only (no CDN). Light + dark via tokens; data-theme overrides the OS. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe3e8;
  --border-strong: #c6ccd4;
  --text: #1b2430;
  --text-2: #4d5a69;
  --text-3: #7b8794;
  --accent: #1f5fbf;
  --accent-hover: #184e9e;
  --accent-soft: #e6eefb;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --warn: #a15c00;
  --warn-soft: #fff4e0;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --code-bg: #eef1f5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #161c23; --surface-2: #1b222b; --border: #2a333e; --border-strong: #3a4552;
    --text: #e4e8ed; --text-2: #aab4bf; --text-3: #7f8b97; --accent: #5b9cff; --accent-hover: #7cb0ff;
    --accent-soft: #1b2b44; --accent-text: #0b1220; --ok: #4cc38a; --warn: #f0b450; --warn-soft: #3a2c12;
    --danger: #ff7a6e; --danger-soft: #3d1c1a; --code-bg: #1f2731;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1419; --surface: #161c23; --surface-2: #1b222b; --border: #2a333e; --border-strong: #3a4552;
  --text: #e4e8ed; --text-2: #aab4bf; --text-3: #7f8b97; --accent: #5b9cff; --accent-hover: #7cb0ff;
  --accent-soft: #1b2b44; --accent-text: #0b1220; --ok: #4cc38a; --warn: #f0b450; --warn-soft: #3a2c12;
  --danger: #ff7a6e; --danger-soft: #3d1c1a; --code-bg: #1f2731;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .divider:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn[disabled] { opacity: .5; cursor: default; }
.icon { width: 16px; height: 16px; flex: none; }

/* ---- top bar ---- */
.topbar { height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 12px 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .1px; min-width: 0; }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--text); color: var(--bg);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.brand small { color: var(--text-3); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.spacer { flex: 1; }
.timer { font: 600 15px/1 var(--mono); padding: 6px 10px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); font-variant-numeric: tabular-nums; min-width: 92px; text-align: center; }
.timer.low { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.timer.over { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.timer-label { color: var(--text-3); font-size: 12px; }

/* ---- split layout ---- */
.layout { display: flex; height: calc(100% - 48px); min-height: 0; }
.left { width: var(--left-w, 38%); min-width: 300px; max-width: 70%; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); min-height: 0; }
.divider { width: 6px; flex: none; cursor: col-resize; background: transparent; position: relative; margin-left: -3px; margin-right: -3px; z-index: 2; }
.divider::after { content: ""; position: absolute; inset: 0 2px; border-radius: 2px; transition: background .15s; }
.divider:hover::after, .divider.dragging::after { background: var(--accent); }
.right { flex: 1; display: flex; flex-direction: column; min-width: 320px; min-height: 0; }
body.dragging iframe { pointer-events: none; }
body.dragging { cursor: col-resize; user-select: none; }

/* ---- segmented control (left pane) ---- */
.seg { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); }
.seg button { position: relative; border: 0; background: none; padding: 8px 12px 10px; cursor: pointer; color: var(--text-2);
  font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 6px; }
.seg button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.seg button:hover { color: var(--text); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; line-height: 1; }
.badge.pop { animation: pop .4s ease; }
@keyframes pop { 0% { transform: scale(.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.panel { flex: 1; overflow: auto; padding: 16px 20px 24px; min-height: 0; }

/* ---- markdown ---- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h1 { font-size: 20px; margin: 0 0 12px; line-height: 1.3; }
.md h2 { font-size: 16px; margin: 22px 0 8px; padding-top: 4px; }
.md h3 { font-size: 14px; margin: 18px 0 6px; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .md-table { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { font: 12.5px/1.4 var(--mono); background: var(--code-bg); padding: 1px 5px; border-radius: 4px; }
.md pre { background: var(--code-bg); border-radius: 6px; padding: 10px 12px; overflow: auto; }
.md pre code { background: none; padding: 0; white-space: pre; }
.md blockquote { border-left: 3px solid var(--border-strong); margin-left: 0; padding: 2px 12px; color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md .md-table { overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md .al-right { text-align: right; } .md .al-center { text-align: center; }

/* ---- tasks ---- */
.task { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: var(--surface); overflow: hidden; }
.task-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.task-num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.task-title { font-weight: 600; flex: 1; }
.task-body { padding: 12px 14px 4px; }
.task.locked { opacity: .65; }
.task.locked .task-num { background: var(--border-strong); }
.task.new { animation: flash 1.6s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: none; } }
.empty { color: var(--text-3); text-align: center; padding: 40px 12px; }
.empty svg { width: 32px; height: 32px; margin-bottom: 8px; opacity: .6; }

/* ---- inbox ---- */
.msg { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; background: var(--surface); }
.msg.unread { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; font-size: 12px; color: var(--text-3); }
.msg-from { font-weight: 600; color: var(--text); font-size: 13px; }
.msg-receipt { margin-left: auto; }
.msg-receipt.read { color: var(--ok); }

/* ---- right pane tabs ---- */
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 6px 8px 0; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 42px; }
.tab { display: inline-flex; align-items: center; gap: 7px; height: 35px; padding: 0 14px; border: 1px solid transparent;
  border-bottom: 0; border-radius: 7px 7px 0 0; background: none; cursor: pointer; color: var(--text-2); font-weight: 500; margin-bottom: -1px; }
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab[aria-selected="true"] { background: var(--bg); color: var(--text); border-color: var(--border); }
.tab-actions { margin-left: auto; display: flex; gap: 4px; align-self: center; padding-bottom: 6px; }
.frames { flex: 1; position: relative; background: var(--bg); min-height: 0; }
.frames iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #1e1e1e; }
.frames iframe.light-bg { background: var(--surface); }
.frame-note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-3); }

/* ---- toast ---- */
.toast { position: fixed; right: 16px; bottom: 16px; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 12px 14px; z-index: 10;
  cursor: pointer; animation: slidein .25s ease; }
.toast b { display: block; margin-bottom: 2px; }
.toast p { margin: 0; color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---- login ---- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 28px; }
.login-card h1 { font-size: 20px; margin: 16px 0 4px; }
.login-card p.sub { margin: 0 0 20px; color: var(--text-2); }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.code-input { width: 100%; height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); font: 600 18px/1 var(--mono); letter-spacing: 2px; text-transform: uppercase; }
.login-card .btn { width: 100%; height: 40px; justify-content: center; margin-top: 14px; }
.alert { margin-top: 12px; padding: 8px 12px; border-radius: 6px; font-size: 13px; background: var(--danger-soft); color: var(--danger); }
.login-foot { margin-top: 20px; font-size: 12px; color: var(--text-3); }

/* ---- observe ---- */
.obs-section { border-bottom: 1px solid var(--border); padding: 14px 20px; }
.obs-section h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 0 0 10px; }
.composer textarea { width: 100%; min-height: 96px; resize: vertical; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: var(--surface); font: 13px/1.45 var(--mono); }
.composer .row, .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer input[type=text] { flex: 1; min-width: 120px; height: 32px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); }
.composer .row { margin-top: 8px; }
.hint { color: var(--text-3); font-size: 12px; }
.ro-banner { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 12px; color: var(--text-2);
  background: var(--surface); border-bottom: 1px solid var(--border); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.preview { border: 1px dashed var(--border-strong); border-radius: 6px; padding: 8px 10px; margin-top: 8px; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .left { width: 100% !important; max-width: none; min-width: 0; height: 45%; border-right: 0; border-bottom: 1px solid var(--border); }
  .divider { display: none; }
  .right { min-width: 0; }
  .brand small { display: none; }
}
.panel > .row { margin-bottom: 12px; }
.badge-neutral { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ---- help (candidate) and hints / chat (interviewer) ---- */
.seg { overflow-x: auto; scrollbar-width: none; }
.seg button { white-space: nowrap; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.modes button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; text-align: left;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: pointer; }
.modes button small { color: var(--text-3); font-size: 12px; }
.modes button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.modes button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.callout { border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px;
  margin-bottom: 12px; font-size: 13px; color: var(--text-2); }
.callout p { margin: 0 0 8px; } .callout p:last-child { margin-bottom: 0; }
.callout.warn { border-color: var(--warn); background: var(--warn-soft); color: var(--text); }
.callout.warn b { color: var(--warn); }
.thread { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.exchange { display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 92%; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--surface);
  white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble .md { white-space: normal; }
.bubble .msg-meta { margin-bottom: 2px; }
.bubble.mine { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.bubble.theirs { align-self: flex-start; }
.bubble.offer { align-self: flex-start; border-color: var(--accent); white-space: normal; }
.bubble.offer p { margin: 0 0 8px; }
.bubble.offer .cost { color: var(--warn); }
.bubble.hint-card { align-self: flex-start; border-color: var(--ok); box-shadow: inset 3px 0 0 var(--ok); white-space: normal; }
.bubble.waiting { align-self: flex-start; color: var(--text-2); display: flex; align-items: center; gap: 8px; white-space: normal; }
.bubble.reply { align-self: flex-start; color: var(--text-2); }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin 1s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.countdown { font-variant-numeric: tabular-nums; font-family: var(--mono); }
.empty.small { padding: 16px 8px; font-size: 13px; }
.code-input.small { width: auto; flex: 1; min-width: 160px; height: 34px; font-size: 14px; letter-spacing: 1px; }
.help .composer textarea { min-height: 64px; font-family: var(--font); font-size: 14px; }
.help .composer .row { margin-top: 6px; }
.hreq { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
.hreq.pending { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.hreq .row { margin-top: 8px; }
.hreq .msg-receipt b { color: var(--warn); }
.cand-text { margin: 4px 0 8px; padding: 6px 10px; border-left: 3px solid var(--border-strong); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.suggest { font-size: 13px; color: var(--text-2); }
.suggest-text { margin-top: 6px; padding: 8px 10px; border-radius: 6px; background: var(--code-bg); font-size: 13px; }
.suggest-text > :last-child { margin-bottom: 0; }
.sub-head { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 16px 0 8px; }
.settings { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; background: var(--surface-2); }
.settings .row + .row { margin-top: 8px; }
.settings label { font-weight: 500; }
.settings label.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.settings .hint { margin: 6px 0 0; }
select, input[type=number] { height: 32px; padding: 0 8px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; }
input[type=number] { width: 84px; }
select:focus-visible, .modes button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.picker select { flex: 1; min-width: 120px; }

/* Docs (team wiki) */
.docs { display: flex; flex-direction: column; gap: 12px; }
.docs-bar { display: flex; gap: 8px; align-items: center; position: sticky; top: -16px; background: var(--surface); padding: 4px 0 8px; z-index: 1; }
.docs-bar input { flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.docs-list { list-style: none; margin: 0; padding: 0; }
.docs-list li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.docs-list a { font-weight: 600; }

/* Chat (colleague channels) */
.chat { display: flex; flex-direction: column; gap: 10px; }
.chat-channels { display: flex; flex-direction: column; }
.chat-ch { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; text-align: left; border: 0; border-bottom: 1px solid var(--border);
  background: none; padding: 10px 4px; cursor: pointer; color: var(--text); font: inherit; }
.chat-ch:hover { background: var(--surface-2); }
.chat-ch-name { font-weight: 600; }
.chat-ch .hint { flex-basis: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-room { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.chat-head { display: flex; gap: 10px; align-items: flex-start; }
