:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2128;
  --bg-sidebar: #010409;
  --bg-hover: rgba(177, 186, 196, 0.12);
  --bg-active: rgba(177, 186, 196, 0.2);
  --border: #30363d;
  --border-muted: #21262d;
  --fg: #e6edf3;
  --fg-muted: #8b949e;
  --fg-subtle: #6e7681;
  --accent: #2f81f7;
  --accent-fg: #4493f8;
  --accent-muted: rgba(56, 139, 253, 0.15);
  --success: #3fb950;
  --warning: #d29922;
  --warning-muted: rgba(187, 128, 9, 0.15);
  --danger: #f85149;
  --danger-muted: rgba(248, 81, 73, 0.12);
  --purple: #a371f7;
  --user-bubble: #1f2937;
  --code-bg: #161b22;
  --shadow: 0 8px 24px rgba(1, 4, 9, 0.6);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 300px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --bg-elev: #f6f8fa;
    --bg-elev-2: #eef1f4;
    --bg-sidebar: #f6f8fa;
    --bg-hover: rgba(208, 215, 222, 0.32);
    --bg-active: rgba(208, 215, 222, 0.6);
    --border: #d0d7de;
    --border-muted: #d8dee4;
    --fg: #1f2328;
    --fg-muted: #59636e;
    --fg-subtle: #818b98;
    --accent: #0969da;
    --accent-fg: #0969da;
    --accent-muted: rgba(84, 174, 255, 0.2);
    --success: #1a7f37;
    --warning: #9a6700;
    --warning-muted: rgba(212, 167, 44, 0.18);
    --danger: #d1242f;
    --danger-muted: rgba(255, 129, 130, 0.15);
    --purple: #8250df;
    --user-bubble: #eef2f7;
    --code-bg: #f6f8fa;
    --shadow: 0 8px 24px rgba(140, 149, 159, 0.3);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-fg); }
code, pre { font-family: var(--mono); }
.hidden { display: none !important; }
.muted { color: var(--fg-muted); }
.mono { font-family: var(--mono); }
svg.icon { width: 16px; height: 16px; fill: currentColor; flex: none; vertical-align: middle; }

/* ---------- layout ---------- */
.layout { display: flex; height: 100vh; height: 100dvh; width: 100%; }
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-muted);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  min-height: 0;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; position: relative; }
.backdrop { display: none; }

/* ---------- sidebar ---------- */
.sb-head { display: flex; align-items: center; gap: 6px; padding: 10px 10px 6px; }
.device-switch {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  padding: 6px 8px; text-align: left; font-weight: 600;
}
.device-switch:hover { background: var(--bg-hover); }
.device-switch .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-switch .chev { margin-left: auto; color: var(--fg-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-subtle); flex: none; }
.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--danger); }
.status-dot.busy { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: transparent; border: 1px solid transparent; color: var(--fg-muted);
  flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--fg); }
.icon-btn.active { color: var(--accent-fg); }

.new-session {
  margin: 4px 10px 8px;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--bg-elev); border: 1px solid var(--border); font-weight: 500;
}
.new-session:hover { background: var(--bg-elev-2); }
.search {
  margin: 0 10px 8px; padding: 7px 10px; border-radius: 8px;
  background: var(--bg); border: 1px solid var(--border); outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); }

.session-list { flex: 1; overflow-y: auto; padding: 0 6px 12px; -webkit-overflow-scrolling: touch; }
.group-head {
  display: flex; align-items: center; gap: 6px;
  width: 100%; background: none; border: 0; text-align: left;
  padding: 10px 8px 4px; color: var(--fg-muted); font-size: 12px; font-weight: 600;
}
.group-head .chev { transition: transform 0.15s; }
.group-head.collapsed .chev { transform: rotate(-90deg); }
.group-head .count { margin-left: auto; font-weight: 400; color: var(--fg-subtle); }
.session-row {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 8px; border-radius: 8px;
  background: none; border: 0; text-align: left; color: var(--fg);
  min-height: 40px;
}
.session-row:hover { background: var(--bg-hover); }
.session-row.active { background: var(--bg-active); }
.session-row .body { flex: 1; min-width: 0; }
.session-row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .meta { font-size: 12px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .badges { display: flex; align-items: center; gap: 4px; color: var(--fg-muted); }
.badge-attn { background: var(--warning); color: #000; border-radius: 10px; font-size: 11px; padding: 0 6px; font-weight: 600; }
.sb-foot {
  border-top: 1px solid var(--border-muted);
  padding: 8px 10px calc(8px + var(--safe-bottom));
  display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--fg-muted);
}
.sb-foot .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-list { padding: 24px 12px; color: var(--fg-muted); text-align: center; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-top)) 12px 8px;
  border-bottom: 1px solid var(--border-muted);
  min-height: 52px; background: var(--bg);
}
.topbar .menu-btn { display: none; }
.title-wrap { flex: 1; min-width: 0; }
.title-wrap .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-wrap .subtitle { font-size: 12px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { font-size: 12px; color: var(--warning); display: flex; align-items: center; gap: 4px; }

.banner {
  margin: 8px 12px 0; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-elev); font-size: 13px;
  display: flex; gap: 8px; align-items: flex-start;
}
.banner.warn { border-color: rgba(187, 128, 9, 0.5); background: var(--warning-muted); }
.banner.error { border-color: rgba(248, 81, 73, 0.5); background: var(--danger-muted); }

/* ---------- timeline ---------- */
.timeline {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 16px 16px 24px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.timeline-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.load-more { align-self: center; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px; padding: 4px 14px; font-size: 12px; color: var(--fg-muted); }
.msg { max-width: 100%; min-width: 0; }
.msg.user { align-self: flex-end; max-width: min(85%, 720px); }
.msg.user .bubble {
  background: var(--user-bubble); border: 1px solid var(--border-muted);
  border-radius: 16px 16px 4px 16px; padding: 8px 12px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .att { font-size: 12px; color: var(--fg-muted); margin-top: 2px; text-align: right; }
.msg.assistant { align-self: stretch; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; line-height: 1.3; }
.md h1 { font-size: 1.4em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.6em; }
.md li { margin: 2px 0; }
.md blockquote { margin: 0 0 10px; padding: 0 12px; border-left: 3px solid var(--border); color: var(--fg-muted); }
.md code { background: var(--bg-hover); padding: 0.1em 0.35em; border-radius: 5px; font-size: 0.9em; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.code-block { position: relative; margin: 0 0 10px; border: 1px solid var(--border-muted); border-radius: 8px; background: var(--code-bg); }
.code-block pre { margin: 0; padding: 12px; overflow-x: auto; font-size: 12.5px; line-height: 1.45; }
.code-block code { background: none; padding: 0; font-size: inherit; }
.code-lang { position: absolute; top: 4px; left: 10px; font-size: 11px; color: var(--fg-subtle); }
.code-block .code-lang + .copy-code + pre { padding-top: 22px; }
.copy-code {
  position: absolute; top: 4px; right: 4px; font-size: 11px; padding: 2px 8px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--fg-muted);
  opacity: 0.85;
}
.table-wrap { overflow-x: auto; margin: 0 0 10px; }
.md table { border-collapse: collapse; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; }
.md th { background: var(--bg-elev); }

details.tool, details.reasoning {
  border-radius: 8px; font-size: 13px; color: var(--fg-muted);
}
details.tool > summary, details.reasoning > summary {
  list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 4px 6px; border-radius: 6px; min-height: 30px;
}
details.tool > summary::-webkit-details-marker, details.reasoning > summary::-webkit-details-marker { display: none; }
details.tool > summary:hover, details.reasoning > summary:hover { background: var(--bg-hover); color: var(--fg); }
details > summary .sum-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details > summary .chev { transition: transform 0.15s; color: var(--fg-subtle); }
details[open] > summary .chev { transform: rotate(90deg); }
.tool-name { font-family: var(--mono); font-size: 11px; padding: 0 6px; border-radius: 10px; border: 1px solid var(--border); color: var(--fg-subtle); flex: none; }
.tool-body { margin: 4px 0 6px 28px; display: flex; flex-direction: column; gap: 6px; }
.tool-body pre {
  margin: 0; padding: 8px 10px; background: var(--code-bg); border: 1px solid var(--border-muted);
  border-radius: 6px; max-height: 320px; overflow: auto; font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--fg);
}
.tool-body .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--fg-subtle); }
.st-running { color: var(--accent-fg); }
.st-completed { color: var(--success); }
.st-failed { color: var(--danger); }
.reasoning .md { margin: 4px 0 6px 28px; font-size: 13px; color: var(--fg-muted); }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.notice { align-self: center; font-size: 12px; color: var(--fg-muted); padding: 2px 10px; border-radius: 10px; background: var(--bg-elev); max-width: 100%; overflow-wrap: anywhere; }
.notice.warning { color: var(--warning); }
.notice.error { color: var(--danger); background: var(--danger-muted); }
.task-complete { border: 1px solid rgba(46, 160, 67, 0.4); border-radius: 10px; padding: 10px 12px; background: rgba(46, 160, 67, 0.08); }
.task-complete .head { display: flex; align-items: center; gap: 6px; color: var(--success); font-weight: 600; margin-bottom: 6px; }
.plan-card { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: var(--bg-elev); font-size: 13px; }
.plan-card ul { margin: 4px 0 0; padding-left: 0; list-style: none; }
.plan-card li { display: flex; gap: 6px; align-items: baseline; }
.working { display: flex; align-items: center; gap: 8px; color: var(--fg-muted); font-size: 13px; padding: 4px 6px; }
.cursor::after { content: '▍'; animation: pulse 1s infinite; color: var(--accent-fg); }

.welcome { margin: auto; max-width: 560px; text-align: center; padding: 24px; color: var(--fg-muted); }
.welcome h2 { color: var(--fg); margin: 12px 0 6px; }
.logo { width: 48px; height: 48px; color: var(--fg); }

/* ---------- composer ---------- */
.composer-wrap {
  padding: 8px 12px calc(10px + var(--safe-bottom));
  padding-left: calc(12px + var(--safe-left));
  padding-right: calc(12px + var(--safe-right));
  background: var(--bg);
}
.composer-inner { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.perm-card {
  border: 1px solid rgba(187, 128, 9, 0.6); background: var(--warning-muted);
  border-radius: var(--radius); padding: 10px 12px;
}
.perm-card .head { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 4px; }
.perm-card pre {
  margin: 6px 0; max-height: 180px; overflow: auto; padding: 8px; border-radius: 6px;
  background: var(--code-bg); border: 1px solid var(--border-muted); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.perm-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 6px 14px; min-height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-elev); font-weight: 500;
}
.btn:hover { background: var(--bg-elev-2); }
.btn.primary { background: #238636; border-color: rgba(240, 246, 252, 0.1); color: #fff; }
.btn.primary:hover { background: #2ea043; }
.btn.accent { background: var(--accent); border-color: transparent; color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-muted); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.small { padding: 2px 10px; min-height: 28px; font-size: 12px; }

.composer {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev);
  display: flex; flex-direction: column;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); }
.composer textarea {
  border: 0; outline: none; resize: none; background: transparent;
  padding: 10px 12px 4px; min-height: 44px; max-height: 40vh; line-height: 1.45;
}
.attachments { display: flex; gap: 6px; padding: 6px 10px 0; flex-wrap: wrap; }
.attachments .att { position: relative; width: 52px; height: 52px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.attachments img { width: 100%; height: 100%; object-fit: cover; }
.attachments .rm { position: absolute; top: 1px; right: 1px; width: 18px; height: 18px; border-radius: 50%; border: 0; background: rgba(0,0,0,0.7); color: #fff; font-size: 12px; line-height: 18px; padding: 0; }
.composer-bar { display: flex; align-items: center; gap: 4px; padding: 4px 6px 6px; min-width: 0; }
.composer-bar .opts {
  display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  padding-right: 20px;
}
.composer-bar .opts::-webkit-scrollbar { display: none; }
.opt-select {
  appearance: none; -webkit-appearance: none;
  background: transparent; border: 1px solid transparent; border-radius: 8px;
  color: var(--fg-muted); padding: 4px 8px; font-size: 12.5px; max-width: 190px;
  text-overflow: ellipsis; flex: none;
}
.opt-select:hover { background: var(--bg-hover); color: var(--fg); }
.opt-select.mode-plan { color: var(--accent-fg); }
.opt-select.mode-autopilot { color: var(--purple); }
.opt-select.allow-on { color: var(--warning); }
.send-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 0; flex: none;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:disabled { background: var(--bg-active); color: var(--fg-subtle); cursor: default; }
.send-btn.stop { background: var(--fg); color: var(--bg); }
.composer-hint { font-size: 11px; color: var(--fg-subtle); text-align: center; }

/* ---------- new session ---------- */
.new-view { max-width: 720px; width: 100%; margin: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.new-view h2 { margin: 0; font-size: 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--fg-muted); font-weight: 600; }
.folder-row { display: flex; gap: 6px; }
.input {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--bg-elev); border-radius: 16px;
  padding: 3px 10px; font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip.active { border-color: var(--accent); color: var(--accent-fg); }

/* ---------- popover / modal ---------- */
.popover {
  position: fixed; z-index: 60; min-width: 240px; max-width: calc(100vw - 16px);
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px;
}
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: none; padding: 8px 10px; border-radius: 6px; min-height: 38px;
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item .sub { font-size: 12px; color: var(--fg-muted); }
.menu-item.selected { color: var(--accent-fg); }
.menu-sep { height: 1px; background: var(--border-muted); margin: 4px 0; }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 70; background: rgba(1, 4, 9, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  width: min(640px, 100%); max-height: min(86vh, 900px); display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border-muted); font-weight: 600; }
.modal-head .grow { flex: 1; }
.modal-body { padding: 12px 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 14px calc(10px + var(--safe-bottom)); border-top: 1px solid var(--border-muted); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--fg-muted); font-weight: 600; margin: 0 0 6px; }
.card { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elev); }
.dev-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border-muted); }
.dev-row:last-child { border-bottom: 0; }
.dev-row .body { flex: 1; min-width: 0; }
.dev-row .sub { font-size: 12px; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qr-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.qr-item { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--fg-muted); max-width: 200px; text-align: center; overflow-wrap: anywhere; }
.qr-item .qr { width: 168px; height: 168px; border-radius: 8px; overflow: hidden; background: #fff; }
.qr-item .qr svg { width: 100%; height: 100%; display: block; }
.token-row { display: flex; gap: 6px; align-items: center; }
.token-row code.cmd { white-space: normal; overflow-wrap: anywhere; text-overflow: clip; user-select: all; }
.token-row code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; padding: 6px 8px; border-radius: 6px; background: var(--bg-elev); border: 1px solid var(--border); font-size: 12px; }
.dir-list { display: flex; flex-direction: column; max-height: 50vh; overflow-y: auto; }
.dir-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 0; background: none; text-align: left; border-radius: 6px; min-height: 40px; }
.dir-item:hover { background: var(--bg-hover); }
.crumbs { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; color: var(--fg-muted); }

.toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); top: calc(10px + var(--safe-top)); display: flex; flex-direction: column; gap: 6px; width: min(420px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: none; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; box-shadow: var(--shadow); font-size: 13px; animation: toast-in 0.2s ease-out;
  display: flex; gap: 8px; align-items: flex-start;
}
.toast.error { border-color: rgba(248, 81, 73, 0.6); }
.toast.attn, .toast.clickable { pointer-events: auto; cursor: pointer; }
.toast.attn { border-color: rgba(187, 128, 9, 0.7); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ---------- login ---------- */
.login { height: 100vh; height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { font-size: 22px; margin: 4px 0 0; }
.login-card .input { text-align: center; font-family: var(--mono); }
.login-card .err { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- mobile ---------- */
/* Drawer layout: narrow screens, and short touch screens (phones in landscape). */
@media (max-width: 820px), (pointer: coarse) and (max-height: 520px) {
  .sidebar {
    position: fixed; z-index: 50; top: 0; bottom: 0; left: 0;
    width: min(86vw, 340px);
    transform: translateX(-102%); transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  .layout.drawer-open .sidebar { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(1, 4, 9, 0.55); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
  .layout.drawer-open .backdrop { opacity: 1; pointer-events: auto; }
  .topbar { padding-left: calc(6px + var(--safe-left)); padding-right: calc(6px + var(--safe-right)); }
  .topbar .menu-btn { display: inline-flex; }
  .timeline { padding: 12px 12px 16px; }
  .msg.user { max-width: 90%; }
  .composer-wrap { padding-top: 6px; }
  .composer-hint { display: none; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100%; max-height: 92dvh; border-radius: 16px 16px 0 0; border-bottom: 0; }
  .qr-item .qr { width: 148px; height: 148px; }
  .toasts { top: calc(60px + var(--safe-top)); }
}
/* Touch sizing: any coarse pointer (phones, tablets). */
@media (pointer: coarse) {
  .session-row { min-height: 48px; padding: 9px 10px; }
  .menu-item { min-height: 44px; }
  .icon-btn { width: 40px; height: 40px; }
  .send-btn { width: 40px; height: 40px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 34px; }
  .opt-select { max-width: 150px; padding: 6px 8px; font-size: 13px; }
  .composer-hint { display: none; }
  /* iOS zooms into inputs below 16px */
  input, textarea, .input, .search, .composer textarea { font-size: 16px; }
}
@media (hover: none) {
  .copy-code { opacity: 1; }
}

.code-input { font-family: var(--mono); letter-spacing: 0.4em; text-align: center; font-size: 20px !important; }
.totp-body { display: flex; flex-direction: column; gap: 8px; padding: 0 0 10px; }
.totp-body:empty { display: none; }
.totp-body a.btn { align-self: flex-start; text-decoration: none; color: inherit; }
