:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --side: #efede8;
  --raised: #ffffff;
  --text: #1f1e1c;
  --muted: #6c6a65;
  --faint: #9a978f;
  --border: #e2dfd8;
  --border-strong: #cfcbc2;
  --hover: rgba(0, 0, 0, 0.045);
  --accent: #4d63e8;
  --accent-soft: rgba(77, 99, 232, 0.12);
  --accent-text: #ffffff;
  --user: #ebe9e3;
  --ok: #1f8a4c;
  --warn: #b26b00;
  --warn-soft: rgba(214, 140, 20, 0.13);
  --bad: #c2362f;
  --bad-soft: rgba(194, 54, 47, 0.1);
  --add-bg: rgba(31, 138, 76, 0.12);
  --add-text: #17693a;
  --del-bg: rgba(194, 54, 47, 0.11);
  --del-text: #a22d27;
  --code-bg: #f1efea;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 6px 24px rgba(0, 0, 0, 0.06);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1e;
    --panel: #232325;
    --side: #161617;
    --raised: #2a2a2d;
    --text: #ececec;
    --muted: #a2a1a6;
    --faint: #75747a;
    --border: #333336;
    --border-strong: #46464a;
    --hover: rgba(255, 255, 255, 0.06);
    --accent: #7b8cff;
    --accent-soft: rgba(123, 140, 255, 0.16);
    --accent-text: #0e1030;
    --user: #2e2e31;
    --ok: #4cc27f;
    --warn: #f0a63a;
    --warn-soft: rgba(240, 166, 58, 0.14);
    --bad: #ff6b62;
    --bad-soft: rgba(255, 107, 98, 0.12);
    --add-bg: rgba(76, 194, 127, 0.14);
    --add-text: #7ee2a8;
    --del-bg: rgba(255, 107, 98, 0.14);
    --del-text: #ff9a93;
    --code-bg: #19191b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
[hidden] { display: none !important; }

/* Layout */
#app { display: flex; height: 100dvh; }
#sidebar {
  width: 280px;
  flex: none;
  background: var(--side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 12px) 10px calc(env(safe-area-inset-bottom) + 10px);
  min-height: 0;
}
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
#scrim { display: none; }

/* Sidebar */
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 12px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; color: var(--accent-text); }
.brand-mark svg { width: 14px; height: 14px; }
.new-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 1px solid var(--border-strong); background: var(--raised); border-radius: 10px;
  padding: 8px 12px; font-weight: 550; text-align: left;
}
.new-btn:hover { border-color: var(--accent); }
.new-btn svg { width: 16px; height: 16px; }
.search {
  margin: 10px 0 6px; width: 100%; border: 1px solid transparent; background: var(--hover);
  border-radius: 9px; padding: 7px 10px; font-size: 14px; outline: none;
}
.search:focus { border-color: var(--border-strong); background: var(--raised); }
#session-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; -webkit-overflow-scrolling: touch; }
.group-label { font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; padding: 12px 8px 4px; }
.session-row {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  border-radius: 9px; padding: 7px 9px; margin: 1px 0; position: relative;
}
.session-row:hover { background: var(--hover); }
.session-row.active { background: var(--raised); box-shadow: 0 0 0 1px var(--border); }
.session-row .t { display: flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 500; overflow: hidden; }
.session-row .t span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-row .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.dot.running { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.dot.waiting { background: var(--warn); }
@keyframes pulse { 50% { opacity: 0.35; } }
.side-foot { font-size: 12px; color: var(--faint); padding: 8px 8px 0; display: flex; justify-content: space-between; gap: 8px; }
.empty-list { color: var(--muted); font-size: 13px; padding: 16px 8px; }

/* Top bar */
#topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 52px;
}
.icon-btn {
  border: 0; background: transparent; width: 36px; height: 36px; border-radius: 9px;
  display: grid; place-items: center; color: var(--muted); flex: none;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
#menu-btn { display: none; }
.title-wrap { flex: 1; min-width: 0; padding: 0 4px; }
#title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#subtitle { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill-btn {
  border: 1px solid var(--border); background: var(--raised); border-radius: 999px;
  padding: 5px 11px; font-size: 13px; display: flex; align-items: center; gap: 6px; color: var(--muted); flex: none;
}
.pill-btn:hover { color: var(--text); border-color: var(--border-strong); }
.pill-btn svg { width: 15px; height: 15px; }

/* Transcript */
#transcript { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#items { max-width: 800px; margin: 0 auto; padding: 18px 20px 28px; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; margin: 18px 0 14px; }
.msg-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 85%; }
.msg-thumb { display: block; max-width: min(220px, 60vw); max-height: 220px; border-radius: 14px; border: 1px solid var(--border); background: var(--code-bg); }
.file-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 100%; border: 1px solid var(--border); background: var(--panel);
  border-radius: 12px; padding: 7px 11px; font-size: 13.5px;
}
.file-chip svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-chip small { color: var(--muted); flex: none; font-size: 12px; }
.msg-user .bubble {
  background: var(--user); border-radius: 16px 16px 4px 16px; padding: 9px 14px; max-width: 85%;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant { margin: 8px 0; overflow-wrap: anywhere; }
.msg-assistant > :first-child { margin-top: 0; }
.msg-assistant > :last-child { margin-bottom: 0; }
.msg-assistant p { margin: 0 0 10px; }
.msg-assistant h2, .msg-assistant h3, .msg-assistant h4 { margin: 16px 0 6px; line-height: 1.3; }
.msg-assistant h2 { font-size: 18px; }
.msg-assistant h3 { font-size: 16px; }
.msg-assistant h4, .msg-assistant h5, .msg-assistant h6 { font-size: 15px; }
.msg-assistant ul, .msg-assistant ol { margin: 4px 0 10px; padding-left: 22px; }
.msg-assistant li { margin: 2px 0; }
.msg-assistant a { color: var(--accent); text-decoration: none; }
.msg-assistant a:hover { text-decoration: underline; }
.msg-assistant blockquote { margin: 8px 0; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--muted); }
.msg-assistant hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.msg-assistant code { font-family: var(--mono); font-size: 0.88em; background: var(--code-bg); border: 1px solid var(--border); border-radius: 5px; padding: 0.5px 4px; }
.code { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 8px 0 12px; background: var(--code-bg); }
.code-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.copy { border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.copy:hover { background: var(--hover); color: var(--text); }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; font: 13px/1.5 var(--mono); }
.msg-assistant .code code { background: none; border: 0; padding: 0; font-size: inherit; }
.table { overflow-x: auto; margin: 8px 0 12px; }
.table table { border-collapse: collapse; font-size: 14px; }
.table th, .table td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; vertical-align: top; }
.table th { background: var(--code-bg); font-weight: 600; }
.thinking { margin: 4px 0 8px; color: var(--muted); font-size: 13.5px; }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; user-select: none; }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary svg { width: 13px; height: 13px; transition: transform 0.15s; }
.thinking[open] summary svg { transform: rotate(90deg); }
.thinking .body { white-space: pre-wrap; border-left: 2px solid var(--border); padding: 4px 0 4px 12px; margin-top: 6px; max-height: 280px; overflow-y: auto; }
.model-tag { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* Tool rows */
.tool { margin: 3px 0; border-radius: 10px; }
.tool-row {
  display: flex; align-items: center; gap: 9px; width: 100%; border: 0; background: transparent;
  padding: 5px 8px; border-radius: 9px; text-align: left; color: var(--text); font-size: 14px; min-height: 32px;
}
.tool-row:hover { background: var(--hover); }
.tool-icon { width: 18px; height: 18px; flex: none; display: grid; place-items: center; color: var(--muted); }
.tool-icon svg { width: 16px; height: 16px; }
.tool-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-title .verb { font-weight: 550; }
.tool-sum { color: var(--muted); font-size: 12.5px; flex: none; font-variant-numeric: tabular-nums; }
.tool-sum .add { color: var(--add-text); }
.tool-sum .del { color: var(--del-text); }
.tool-chev { width: 14px; height: 14px; color: var(--faint); transition: transform 0.15s; flex: none; }
.tool.open .tool-chev { transform: rotate(90deg); }
.tool.error .tool-icon { color: var(--bad); }
.tool.denied .tool-title { color: var(--muted); text-decoration: line-through; }
.tool-body { margin: 2px 0 8px 27px; }
.tool-body pre, .out {
  margin: 0; font: 12.5px/1.5 var(--mono); background: var(--code-bg); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px; overflow: auto; max-height: 360px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.cmd { font: 12.5px/1.5 var(--mono); color: var(--muted); margin-bottom: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.cmd b { color: var(--text); font-weight: 500; }
.spin { width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Diffs */
.diff { font: 12.5px/1.5 var(--mono); border: 1px solid var(--border); border-radius: 9px; overflow: auto; max-height: 420px; background: var(--panel); }
.diff table { border-collapse: collapse; width: 100%; }
.diff td { padding: 0 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; vertical-align: top; }
.diff td.n { width: 1%; min-width: 38px; text-align: right; color: var(--faint); padding: 0 8px; user-select: none; white-space: nowrap; }
.diff tr.add { background: var(--add-bg); }
.diff tr.add td.c { color: var(--add-text); }
.diff tr.del { background: var(--del-bg); }
.diff tr.del td.c { color: var(--del-text); }
.diff tr.hunk td { color: var(--faint); background: var(--code-bg); padding-top: 2px; padding-bottom: 2px; }

/* Approval card */
.approval {
  border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 12px; padding: 10px 12px 12px; margin: 8px 0 10px;
}
.approval-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.approval-head svg { width: 16px; height: 16px; color: var(--warn); }
.approval .detail { margin-bottom: 10px; }
.approval .detail pre { max-height: 220px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  border: 1px solid var(--border-strong); background: var(--raised); border-radius: 9px; padding: 7px 14px; font-weight: 550; font-size: 14px;
}
.btn:hover { border-color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.deny-note { display: flex; gap: 8px; margin-top: 8px; }
.deny-note input { flex: 1; min-width: 0; border: 1px solid var(--border-strong); border-radius: 9px; padding: 7px 10px; background: var(--raised); font-size: 16px; }

.notice { text-align: center; color: var(--muted); font-size: 12.5px; margin: 10px 0; }
.notice details { display: inline; }
.notice summary { cursor: pointer; }
.notice .summary-text { text-align: left; white-space: pre-wrap; background: var(--code-bg); border-radius: 9px; padding: 10px 12px; margin-top: 6px; }
.error-box { border: 1px solid var(--bad); background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 8px 12px; margin: 10px 0; font-size: 14px; overflow-wrap: anywhere; }

/* Empty state */
.hero { max-width: 560px; margin: 12vh auto 0; padding: 0 20px; text-align: center; }
.hero h1 { font-size: 26px; letter-spacing: -0.02em; margin: 14px 0 6px; font-weight: 650; }
.hero p { color: var(--muted); margin: 0 0 18px; }
.hero .brand-mark { width: 44px; height: 44px; border-radius: 12px; margin: 0 auto; }
.kind-toggle { display: inline-flex; gap: 2px; padding: 3px; margin-top: 16px; border-radius: 11px; background: var(--hover); }
.kind-toggle button { border: 0; background: transparent; border-radius: 8px; padding: 5px 18px; font-size: 14px; font-weight: 550; color: var(--muted); }
.kind-toggle button.on { background: var(--raised); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.hero .brand-mark svg { width: 26px; height: 26px; }
.folder-big {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); background: var(--raised);
  border-radius: 12px; padding: 9px 14px; font-weight: 550; max-width: 100%;
}
.folder-big span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-big svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.suggestion { border: 1px solid var(--border); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 13.5px; color: var(--muted); }
.suggestion:hover { color: var(--text); border-color: var(--border-strong); }

#jump {
  position: absolute; right: 50%; transform: translateX(50%); bottom: 100%; margin-bottom: 10px;
  border: 1px solid var(--border); background: var(--raised); box-shadow: var(--shadow); border-radius: 999px;
  width: 34px; height: 34px; display: grid; place-items: center; color: var(--muted);
}
#jump svg { width: 17px; height: 17px; }

/* Dock: tasks, queue, status, composer */
#dock { position: relative; padding: 0 16px calc(env(safe-area-inset-bottom) + 12px); background: var(--bg); }
.dock-inner { max-width: 800px; margin: 0 auto; }
#tasks { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; margin-bottom: 8px; font-size: 13.5px; overflow: hidden; }
.tasks-head { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; padding: 7px 12px; text-align: left; color: var(--muted); font-size: 13px; }
.tasks-head b { color: var(--text); font-weight: 550; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tasks-head svg { width: 14px; height: 14px; transition: transform 0.15s; }
#tasks.open .tasks-head svg { transform: rotate(180deg); }
.task-list { list-style: none; margin: 0; padding: 0 12px 8px; display: none; max-height: 34vh; overflow-y: auto; }
#tasks.open .task-list { display: block; }
.task-list li { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; }
.task-list li.completed { color: var(--muted); text-decoration: line-through; }
.task-list li.in_progress { font-weight: 550; }
.tbox { width: 15px; height: 15px; border: 1.5px solid var(--border-strong); border-radius: 50%; flex: none; margin-top: 3px; display: grid; place-items: center; }
.task-list li.completed .tbox { background: var(--ok); border-color: var(--ok); }
.task-list li.completed .tbox::after { content: ""; width: 5px; height: 8px; border: solid #fff; border-width: 0 1.6px 1.6px 0; transform: translateY(-1px) rotate(45deg); }
.task-list li.in_progress .tbox { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
#queue { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.queued { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: 10px; padding: 6px 10px; }
.queued span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queued em { font-style: normal; font-size: 11.5px; color: var(--faint); flex: none; }
#status-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 0 4px 8px; }
#status-line.waiting { color: var(--warn); }
#status-line .model { color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#composer {
  border: 1px solid var(--border-strong); background: var(--panel); border-radius: 18px; box-shadow: var(--shadow);
  padding: 10px 10px 8px 14px; transition: border-color 0.15s;
}
#composer:focus-within { border-color: var(--accent); }
#composer.shell { border-color: var(--warn); }
#attachments { display: flex; gap: 8px; overflow-x: auto; padding: 4px 4px 10px 0; margin-top: -2px; }
#attachments.sending .att { opacity: 0.55; }
.att {
  position: relative; flex: none; width: 64px; height: 64px; border-radius: 11px; overflow: hidden;
  border: 1px solid var(--border); background: var(--code-bg); display: grid; place-items: center;
}
.att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att.pdf { width: auto; max-width: 230px; display: flex; align-items: center; gap: 8px; padding: 0 36px 0 11px; font-size: 13px; }
.att.pdf > svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.att.pdf > span:not(.spin) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.att.pdf small { color: var(--faint); flex: none; }
.att .spin { flex: none; }
.att-x {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0; padding: 0;
  background: rgba(0, 0, 0, 0.62); color: #fff; display: grid; place-items: center;
}
.att.pdf .att-x { top: 50%; transform: translateY(-50%); right: 8px; }
.att-x::before { content: ""; position: absolute; inset: -9px; }
.att-x svg { width: 12px; height: 12px; }
#attach-btn { width: 32px; height: 32px; margin-left: -6px; }
#attach-btn svg { width: 20px; height: 20px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); pointer-events: none; }
#send-btn .spin { border-color: rgba(255, 255, 255, 0.4); border-top-color: var(--panel); }
#input {
  display: block; width: 100%; border: 0; outline: none; background: transparent; resize: none;
  font-size: 16px; line-height: 1.45; max-height: 40vh; min-height: 24px; padding: 2px 0;
}
#input::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); background: transparent;
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px; color: var(--muted); max-width: 46vw; position: relative; flex: none;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip svg { width: 14px; height: 14px; flex: none; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip select { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; font-size: 16px; }
.chip.mode-auto { color: var(--warn); border-color: var(--warn); }
.spacer { flex: 1; }
.hint { font-size: 12px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
#send-btn {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; flex: none;
}
#send-btn:disabled { background: var(--border-strong); color: var(--panel); cursor: default; }
#send-btn svg { width: 17px; height: 17px; }
#send-btn.stop { background: var(--text); color: var(--bg); }
.cmd-menu { border: 1px solid var(--border); background: var(--raised); border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 8px; overflow: hidden; }
.cmd-menu button { display: flex; gap: 10px; width: 100%; border: 0; background: transparent; padding: 8px 12px; text-align: left; font-size: 14px; }
.cmd-menu button:hover, .cmd-menu button.sel { background: var(--hover); }
.cmd-menu b { font-family: var(--mono); font-weight: 500; }
.cmd-menu span { color: var(--muted); }

/* Sheets (folder picker, changes, menus) */
#sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.32); padding: 20px; }
.sheet {
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); width: min(640px, 100%); max-height: min(80dvh, 760px);
  display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border);
}
.sheet.wide { width: min(980px, 100%); }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 16px; border-bottom: 1px solid var(--border); }
.sheet-head h2 { margin: 0; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 12px 16px; -webkit-overflow-scrolling: touch; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px); border-top: 1px solid var(--border); }
.path-bar { font: 13px var(--mono); color: var(--muted); overflow-wrap: anywhere; margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.dir-list { display: flex; flex-direction: column; }
.dir-row { display: flex; align-items: center; gap: 10px; border: 0; background: transparent; padding: 8px 8px; border-radius: 8px; text-align: left; font-size: 14.5px; }
.dir-row:hover { background: var(--hover); }
.dir-row svg { width: 17px; height: 17px; color: var(--muted); flex: none; }
.dir-row span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-row small { color: var(--faint); }
.sheet-section { font-size: 11.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; margin: 12px 0 4px; }
.file-diff { margin-bottom: 14px; }
.file-diff summary { cursor: pointer; display: flex; gap: 8px; align-items: center; font: 13px var(--mono); padding: 6px 4px; list-style: none; }
.file-diff summary::-webkit-details-marker { display: none; }
.file-diff summary .p { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.file-diff .diff { max-height: none; }
.status-code { font: 600 11px var(--mono); border-radius: 5px; padding: 1px 5px; background: var(--hover); color: var(--muted); flex: none; }
.menu-list { display: flex; flex-direction: column; padding: 6px; }
.menu-list button { border: 0; background: transparent; text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 15px; }
.menu-list button:hover { background: var(--hover); }
.menu-list button.danger { color: var(--bad); }
.field { width: 100%; border: 1px solid var(--border-strong); border-radius: 10px; padding: 9px 12px; background: var(--raised); font-size: 16px; outline: none; }
.field:focus { border-color: var(--accent); }
.muted { color: var(--muted); }

/* Login */
#login { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card .brand-mark { width: 48px; height: 48px; border-radius: 13px; margin: 0 auto 14px; }
.login-card .brand-mark svg { width: 28px; height: 28px; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login-card .err { color: var(--bad); font-size: 13.5px; min-height: 20px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 110px); z-index: 70;
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}

/* Voice screen */
#voice {
  position: fixed; inset: 0; z-index: 55; background: var(--bg); display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 20px);
}
.voice-top { display: flex; align-items: center; justify-content: space-between; }
.voice-title { font-weight: 600; color: var(--muted); }
.voice-settings {
  align-self: center; width: min(420px, 100%); margin-top: 6px; padding: 12px 14px; border: 1px solid var(--border);
  background: var(--panel); border-radius: 14px; display: flex; flex-direction: column; gap: 10px; font-size: 14px;
}
.voice-settings label { display: flex; align-items: center; gap: 10px; }
.voice-settings select { flex: 1; min-width: 0; font-size: 16px; border: 1px solid var(--border-strong); border-radius: 9px; padding: 6px 8px; background: var(--raised); }
.voice-settings input[type="range"] { flex: 1; accent-color: var(--accent); }
.voice-settings .check input { accent-color: var(--accent); width: 18px; height: 18px; }
.voice-stage { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 28px; min-height: 0; }
#voice-orb {
  --level: 0; position: relative; width: min(52vw, 220px); aspect-ratio: 1; border: 0; padding: 0; border-radius: 50%;
  background: transparent; display: grid; place-items: center; -webkit-tap-highlight-color: transparent;
}
#voice-orb .orb-core {
  width: 100%; height: 100%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9fb0ff 0%, var(--accent) 45%, #2c3bb8 100%);
  box-shadow: 0 10px 40px rgba(77, 99, 232, 0.35);
  transform: scale(calc(0.86 + var(--level) * 0.3)); transition: transform 0.08s linear, filter 0.3s;
}
#voice-orb .orb-ring { position: absolute; inset: -14px; border-radius: 50%; border: 2px solid var(--accent); opacity: 0; }
#voice[data-phase="idle"] .orb-core { filter: saturate(0.55) brightness(0.95); }
#voice[data-phase="listening"] .orb-ring { opacity: 0.35; transform: scale(calc(1 + var(--level) * 0.25)); }
#voice[data-phase="transcribing"] .orb-core, #voice[data-phase="thinking"] .orb-core { animation: orb-think 1.4s ease-in-out infinite; }
#voice[data-phase="speaking"] .orb-core { animation: orb-speak 0.9s ease-in-out infinite; }
#voice[data-phase="speaking"] .orb-ring { opacity: 0.25; animation: orb-ring 1.8s ease-out infinite; }
@keyframes orb-think { 50% { transform: scale(0.8); filter: brightness(1.15); } }
@keyframes orb-speak { 0%, 100% { transform: scale(0.9); } 50% { transform: scale(0.97); } }
@keyframes orb-ring { from { transform: scale(0.95); opacity: 0.35; } to { transform: scale(1.25); opacity: 0; } }
#voice-status { color: var(--muted); font-size: 16px; text-align: center; max-width: 420px; min-height: 24px; padding: 0 8px; }
.voice-captions { width: min(640px, 100%); align-self: center; max-height: 34dvh; overflow-y: auto; text-align: center; }
.voice-captions p { margin: 0 0 10px; overflow-wrap: anywhere; }
#voice-you { color: var(--muted); font-size: 15px; }
#voice-you:not(:empty)::before { content: "You: "; color: var(--faint); }
#voice-reply { font-size: 17px; line-height: 1.5; }
body.voice-open { overflow: hidden; }
#send-btn.talk { background: var(--text); color: var(--bg); }

/* Phone */
@media (max-width: 820px) {
  #sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(86vw, 320px);
    transform: translateX(-102%); transition: transform 0.22s ease; box-shadow: var(--shadow);
  }
  body.side-open #sidebar { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.3); }
  #menu-btn { display: grid; }
  #topbar { padding-left: 6px; padding-right: 8px; }
  #items { padding: 12px 16px 24px; }
  #dock { padding: 0 10px calc(env(safe-area-inset-bottom) + 8px); }
  .pill-btn .label { display: none; }
  .pill-btn { padding: 7px 9px; }
  .hero { margin-top: 8vh; }
  .hint { display: none; }
  #sheet-wrap { align-items: flex-end; padding: 0; }
  .sheet, .sheet.wide { width: 100%; max-height: 88dvh; border-radius: 16px 16px 0 0; }
  .tool-body { margin-left: 4px; }
}
