/* Agent Office — phone-first UI around the pixel office. Tokens first, components after. */

:root {
  color-scheme: dark;
  --bg: #0f1420;
  --surface: #171e2d;
  --surface-2: #1e2738;
  --surface-3: #283248;
  --text: #eef1f7;
  --text-muted: #9aa6bd;
  --border: #2c3650;
  --accent: #ffb341;
  --accent-contrast: #2a1700;
  --success: #46c774;
  --success-contrast: #06260f;
  --warning: #ffb341;
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.12);
  --claude: #e5835f;
  --codex: #3cc293;
  --focus: #8fb4ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef1f7;
    --surface: #ffffff;
    --surface-2: #f4f6fb;
    --surface-3: #e7ebf3;
    --text: #131a27;
    --text-muted: #566174;
    --border: #d9dfea;
    --accent: #f5a524;
    --accent-contrast: #2a1700;
    --success: #1f9d55;
    --success-contrast: #ffffff;
    --danger: #d64545;
    --danger-soft: rgba(214, 69, 69, 0.1);
    --claude: #c9603b;
    --codex: #17976c;
    --focus: #2f6bff;
    --shadow: 0 10px 30px rgba(20, 30, 50, 0.18);
  }
}

/* touch-action: manipulation stops iOS double-tap zoom everywhere (panning and scrolling still work). */
* { box-sizing: border-box; touch-action: manipulation; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { min-height: 100dvh; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
/* iOS zooms into any field with text smaller than 16px when it gets focus */
input, select, textarea { font-size: max(16px, 1em); }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, p { margin: 0; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); }
.ico { width: 20px; height: 20px; flex: none; }

.app { max-width: 540px; margin: 0 auto; min-height: 100dvh; position: relative; }

/* ---------- buttons ---------- */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px; border: 1px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; font-size: 16px; background: var(--surface-3); color: var(--text);
  transition: transform 120ms var(--ease), background-color 160ms var(--ease), opacity 160ms;
  touch-action: manipulation; user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-allow { background: var(--success); color: var(--success-contrast); }
.btn-deny { background: transparent; border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn.is-busy { opacity: 0.7; pointer-events: none; }
.link-btn { background: none; border: 0; padding: 10px 2px; color: var(--text-muted); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; min-height: 44px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; color: var(--text-muted);
  display: inline-grid; place-items: center; flex: none;
}
.icon-btn:active { background: var(--surface-3); }

/* ---------- join ---------- */
.join { min-height: 100dvh; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.join-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; padding: 28px 20px 22px; box-shadow: var(--shadow); }
.join-art { width: 288px; height: 120px; max-width: 100%; image-rendering: pixelated; display: block; margin: 0 auto 10px; }
.join h1 { font-size: 26px; text-align: center; letter-spacing: -0.01em; }
.join .lead { color: var(--text-muted); text-align: center; margin: 8px 0 20px; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 14px; color: var(--text-muted); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2);
  padding: 10px 14px; font-size: 16px; font-weight: 400; color: var(--text);
}
.field textarea { min-height: 120px; resize: vertical; line-height: 1.4; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.form-error { color: var(--danger); font-size: 14px; }
.hint { color: var(--text-muted); font-size: 13px; text-align: center; margin-top: 16px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-text { min-width: 0; }
.brand h1 { font-size: 17px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand p { font-size: 13px; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); flex: none; }
.live-dot[data-state="live"] { background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 22%, transparent); }
.live-dot[data-state="connecting"] { background: var(--warning); animation: pulse 1.2s infinite; }
.live-dot[data-state="offline"] { background: var(--danger); }
@keyframes pulse { 50% { opacity: 0.35; } }
.members { display: flex; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  color: #1b1405; background: var(--c, #8892a6); border: 2px solid var(--bg); margin-left: -8px; position: relative;
}
.avatar:first-child { margin-left: 0; }
.avatar.is-offline { filter: grayscale(0.9); opacity: 0.55; }
.avatar.is-online::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%; background: var(--success); border: 2px solid var(--bg); }

/* ---------- office ---------- */
.office-wrap { position: relative; overflow: hidden; background: #0b0f18; border-radius: 0 0 18px 18px; }
.office { display: block; width: 100%; image-rendering: pixelated; image-rendering: crisp-edges; touch-action: manipulation; }
.labels { position: absolute; inset: 0; pointer-events: none; }
.tag {
  position: absolute; left: 0; top: 0; pointer-events: auto; max-width: 104px;
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px 2px 4px; min-height: 18px;
  border-radius: 7px; border: 0; border-bottom: 2px solid var(--owner, #8892a6);
  background: rgba(14, 18, 30, 0.82); color: #f3f5fa; font-size: 10.5px; font-weight: 600; line-height: 1.2;
  white-space: nowrap; will-change: transform;
}
.tag span:last-child { overflow: hidden; text-overflow: ellipsis; }
/* app badge: C = Claude (orange), G = ChatGPT / Codex (teal) — same colours as the characters' shirts */
.tag-dot {
  width: 12px; height: 12px; border-radius: 3px; flex: none; display: inline-grid; place-items: center;
  font-size: 8.5px; font-weight: 800; line-height: 1; color: #fff; font-family: var(--mono);
}
.tag-claude { background: #e8743b; }
.tag-codex { background: #1f9e84; }
.tag.is-compact { font-size: 9.5px; padding: 1px 5px 1px 3px; min-height: 15px; opacity: 0.92; }
.tag.is-compact .tag-dot { width: 11px; height: 11px; font-size: 8px; }
.legend { display: flex; justify-content: center; gap: 14px; padding: 6px 12px 0; font-size: 12px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .tag-dot { width: 13px; height: 13px; font-size: 8.5px; }
.group-head { display: flex; align-items: center; gap: 6px; margin: 14px 4px 6px; font-size: 13px; font-weight: 700; color: var(--text-muted); }
.group-head:first-child { margin-top: 2px; }
.tag[data-status="waiting"] { background: #ffb341; color: #2a1700; }
.tag.is-selected { outline: 2px solid #fff; outline-offset: 1px; }
.office-empty {
  position: absolute; left: 12px; right: 12px; bottom: 12px; padding: 12px 14px; border-radius: 12px;
  background: rgba(14, 18, 30, 0.88); color: #eef1f7; font-size: 14px; display: grid; gap: 4px;
}

/* ---------- install hint ---------- */
.install-hint { margin: 10px 16px 0; padding: 12px; border-radius: 16px; background: var(--surface); border: 1px dashed color-mix(in srgb, var(--accent) 60%, var(--border)); display: grid; gap: 10px; }
.install-row { display: flex; align-items: flex-start; gap: 10px; }
.install-row .ico { margin-top: 2px; color: var(--accent); }
.install-row .grow { flex: 1; min-width: 0; }
.install-row .sub { font-size: 13px; color: var(--text-muted); }
.install-row .icon-btn { margin: -10px -8px -10px 0; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }

/* ---------- summary + tabs ---------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 14px 16px 2px; }
.stat { display: grid; gap: 2px; align-content: start; padding: 10px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.stat.is-alert { border-color: color-mix(in srgb, var(--warning) 60%, var(--border)); }
.stat-n { display: flex; align-items: center; gap: 7px; font-size: 22px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 12px; line-height: 1.3; color: var(--text-muted); font-weight: 600; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); flex: none; }
.dot-working { background: var(--success); }
.dot-waiting { background: var(--warning); }
.dot-idle { background: #7aa7ff; }
.dot-sleeping { background: #8a94a8; }
.dot-left { background: #555f73; }
.tabs { display: flex; gap: 4px; margin: 10px 16px 0; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.tab { flex: 1 1 0; min-width: 0; min-height: 40px; padding: 0 4px; border: 0; border-radius: 10px; background: transparent; color: var(--text-muted); font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: background-color 180ms var(--ease), color 180ms var(--ease); }
.tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); }
.panel { padding: 12px 16px 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.dock-spacer { height: calc(96px + env(safe-area-inset-bottom)); }
.empty { color: var(--text-muted); text-align: center; padding: 22px 10px; font-size: 14px; }

/* ---------- lists ---------- */
.row {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 10px 12px; min-height: 64px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: transform 120ms var(--ease);
}
.row:active { transform: scale(0.99); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; min-width: 0; }
.row-title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-act { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .time { font-size: 12px; color: var(--text-muted); flex: none; align-self: flex-start; padding-top: 2px; }
.row.is-waiting { border-color: color-mix(in srgb, var(--warning) 60%, var(--border)); }
.portrait { width: 44px; height: 44px; border-radius: 12px; background: #243049; image-rendering: pixelated; flex: none; }
.kind { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; flex: none; }
.kind-claude { background: color-mix(in srgb, var(--claude) 22%, transparent); color: var(--claude); }
.kind-codex { background: color-mix(in srgb, var(--codex) 22%, transparent); color: var(--codex); }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-muted); }

.feed-item { display: grid; grid-template-columns: 44px 1fr; gap: 10px; align-items: start; padding: 8px 2px; border-bottom: 1px solid var(--border); font-size: 14px; }
.feed-item:last-child { border-bottom: 0; }
.feed-item time { font-size: 12px; color: var(--text-muted); padding-top: 1px; font-variant-numeric: tabular-nums; }
.feed-item .who { font-weight: 700; }

.task-row .row-title .name { font-weight: 600; }

/* ---------- dock (primary action) ---------- */
.dock {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; width: 100%; max-width: 540px; z-index: 30;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.approval {
  background: var(--surface); border: 1px solid color-mix(in srgb, var(--warning) 55%, var(--border)); border-radius: 18px;
  padding: 12px; box-shadow: var(--shadow); display: grid; gap: 10px; animation: rise 260ms var(--ease);
}
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.approval.is-new { animation: rise 260ms var(--ease), flash 900ms var(--ease); }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px var(--warning); } }
.approval-head { display: flex; gap: 10px; align-items: center; }
.approval-head .portrait { width: 40px; height: 40px; }
.approval-title { font-weight: 700; font-size: 16px; }
.approval-meta { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.approval .code {
  margin: 0; font-family: var(--mono); font-size: 13px; line-height: 1.45; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; max-height: 96px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.approval.is-expanded .code { max-height: 42vh; }
.approval .note { font-size: 13px; color: var(--text-muted); }
.approval-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.approval-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.approval-count { font-size: 13px; font-weight: 700; color: var(--warning); background: none; border: 0; min-height: 40px; padding: 0 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); min-height: 40px; }
.check input { width: 20px; height: 20px; accent-color: var(--success); }
.deny-box { display: grid; gap: 8px; }
.deny-box textarea { width: 100%; min-height: 72px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); padding: 8px 10px; font-size: 15px; resize: vertical; }
.diff { display: grid; gap: 4px; }
.diff .old { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.diff .new { background: color-mix(in srgb, var(--success) 14%, transparent); }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(4, 7, 14, 0.55); z-index: 40; animation: fade 200ms var(--ease); }
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: 100%; max-width: 540px; z-index: 50;
  max-height: 92dvh; display: flex; flex-direction: column; background: var(--surface); border-radius: 22px 22px 0 0;
  border: 1px solid var(--border); border-bottom: 0; box-shadow: var(--shadow); animation: sheet-in 300ms var(--ease);
}
@keyframes sheet-in { from { transform: translate(-50%, 100%); } }
.sheet-handle { width: 40px; height: 5px; border-radius: 3px; background: var(--surface-3); margin: 8px auto 2px; flex: none; }
.sheet-body { overflow: auto; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; overscroll-behavior: contain; }
.sheet-head { display: flex; align-items: center; gap: 12px; }
.sheet-head h2 { font-size: 20px; line-height: 1.2; }
.sheet-head .grow { flex: 1; min-width: 0; }
.sheet-head .icon-btn { margin-right: -8px; }
.section { display: grid; gap: 8px; }
.section h3 { font-size: 13px; font-weight: 700; color: var(--text-muted); text-transform: none; letter-spacing: 0.01em; }
.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; display: grid; gap: 6px; font-size: 15px; }
.card pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: inherit; }
.big-portrait { width: 64px; height: 64px; border-radius: 16px; background: #243049; image-rendering: pixelated; flex: none; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.recent { display: grid; gap: 2px; font-size: 14px; }
.recent li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); list-style: none; }
.recent li:last-child { border-bottom: 0; }
.recent ul { margin: 0; padding: 0; }
.recent time { color: var(--text-muted); font-size: 12px; width: 40px; flex: none; font-variant-numeric: tabular-nums; padding-top: 2px; }
.actions { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: transparent; color: var(--text-muted); font-weight: 600; font-size: 14px; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.seg button[disabled] { opacity: 0.4; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); text-align: left; }
.choice[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.choice strong { display: block; font-size: 15px; }
.choice span { font-size: 13px; color: var(--text-muted); }
.machine-list { display: grid; gap: 8px; }
.machine { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); text-align: left; min-height: 56px; }
.machine[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.machine[disabled] { opacity: 0.5; }
.machine .grow { flex: 1; min-width: 0; }
.machine .sub { font-size: 13px; color: var(--text-muted); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background-color 160ms var(--ease); pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 180ms var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.setting { display: flex; align-items: center; gap: 12px; }
.setting .grow { flex: 1; min-width: 0; }
.setting .sub { font-size: 13px; color: var(--text-muted); }
.invite { display: flex; gap: 8px; align-items: center; }
.invite input { flex: 1; min-width: 0; min-height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 10px; font-family: var(--mono); font-size: 13px; }
.notice { font-size: 13px; color: var(--text-muted); background: var(--surface-2); border: 1px dashed var(--border); border-radius: 12px; padding: 10px 12px; }
.update-btn {
  position: fixed; z-index: 60; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 10px); transform: translateX(-50%);
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 0;
  background: var(--accent); color: var(--accent-contrast); font-size: 14px; font-weight: 600; box-shadow: var(--shadow); white-space: nowrap;
}
.update-btn .ico { width: 18px; height: 18px; }
.notice.is-warn { display: flex; gap: 10px; align-items: flex-start; border-style: solid; border-color: color-mix(in srgb, var(--warning) 55%, var(--border)); color: var(--text); line-height: 1.45; }
.notice.is-warn .ico { color: var(--warning); margin-top: 1px; }
.notice.is-warn code { word-break: break-all; }

/* ---------- give a task: app → chat (or a new chat) → message ---------- */
.app-pick { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.app-card {
  display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 14px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-weight: 700; font-size: 16px; text-align: left;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease);
}
.app-card .tag-dot { width: 26px; height: 26px; border-radius: 8px; font-size: 13px; }
.app-card.is-claude[aria-pressed="true"] { border-color: #e8743b; box-shadow: inset 0 0 0 1px #e8743b; background: color-mix(in srgb, #e8743b 12%, var(--surface-2)); }
.app-card.is-codex[aria-pressed="true"] { border-color: #1f9e84; box-shadow: inset 0 0 0 1px #1f9e84; background: color-mix(in srgb, #1f9e84 12%, var(--surface-2)); }
.app-card[disabled] { opacity: 0.4; }
.chat-list { display: grid; gap: 6px; max-height: min(330px, 42dvh); overflow-y: auto; overscroll-behavior: contain; padding: 1px; }
.chat-item {
  display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 8px 12px 8px 8px; border-radius: 16px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); text-align: left;
  transition: border-color 160ms var(--ease);
}
.chat-item[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chat-item[disabled] { opacity: 0.45; }
.chat-item .portrait { width: 44px; height: 44px; border-radius: 12px; }
.chat-item .grow { flex: 1; min-width: 0; display: grid; gap: 3px; }
.chat-item strong { font-size: 15px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .sub { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-item .check { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--accent-contrast); background: var(--accent); flex: none; opacity: 0; transform: scale(0.6); transition: opacity 140ms var(--ease), transform 180ms var(--ease); }
.chat-item .check .ico { width: 16px; height: 16px; }
.chat-item[aria-pressed="true"] .check { opacity: 1; transform: none; }
.chat-new-ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex: none; color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, var(--surface-3)); }
.folder-chips { flex-wrap: wrap; overflow: visible; }
.folder-chips .chip .ico { width: 16px; height: 16px; color: var(--text-muted); }
.folder-chips .chip.is-on .ico { color: var(--accent); }
.mode-help { margin-top: 6px; font-size: 13px; color: var(--text-muted); }
.notice code { font-family: var(--mono); background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }

/* ---------- files ---------- */
.code { margin: 0; font-family: var(--mono); font-size: 13px; line-height: 1.45; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
button.chip { min-height: 36px; }
.chip.is-on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.files-bar { display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 2px 4px; }
.crumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.crumbs::-webkit-scrollbar { display: none; }
.crumb { background: none; border: 0; color: var(--text); font-size: 14px; font-weight: 600; padding: 8px 6px; border-radius: 8px; display: inline-flex; align-items: center; min-height: 40px; }
.crumb:last-child { color: var(--accent); }
.crumb-sep { color: var(--text-muted); }
.file-list { display: grid; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; }
.file-list:empty { display: none; }
.file-list.is-loading { opacity: 0.6; }
.file-row { display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: 0; }
.file-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: none; border: 0; text-align: left; min-height: 56px; }
.file-main:active { background: var(--surface-2); }
.file-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-muted); flex: none; }
.file-ico.is-dir { color: var(--accent); }
.file-text { min-width: 0; display: grid; gap: 1px; }
.file-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--text-muted); }
.file-title { word-break: break-all; }
.code-view { margin: 0; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; max-height: 55dvh; overflow: auto; white-space: pre; tab-size: 2; }
.code-edit { width: 100%; min-height: 50dvh; font-family: var(--mono); font-size: 13px; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; resize: vertical; white-space: pre; overflow: auto; }
.file-img { max-width: 100%; max-height: 60dvh; border-radius: 12px; background: repeating-conic-gradient(#8883 0 25%, transparent 0 50%) 50% / 16px 16px; justify-self: center; }
.row-btns { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
a.btn { text-decoration: none; }
.cmd { user-select: all; -webkit-user-select: all; word-break: break-all; }
.spinner { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--text-muted); border-top-color: transparent; animation: spin 0.9s linear infinite; vertical-align: -1px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.office-empty .btn { justify-self: start; margin-top: 4px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(110px + env(safe-area-inset-bottom)); z-index: 60;
  max-width: min(92vw, 480px); padding: 10px 16px; border-radius: 12px; background: #f4f6fb; color: #121826;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); animation: rise 220ms var(--ease);
}
.toast.is-error { background: #ffdddd; color: #5c1111; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

@media (min-width: 560px) {
  .office-wrap { border-radius: 18px; margin: 0 12px; }
}

/* ---------- agents' replies (Markdown subset) ---------- */
.card.md { display: block; font-size: 15px; line-height: 1.5; word-break: break-word; }
.md p { margin: 0 0 8px; }
.md > :last-child { margin-bottom: 0; }
.md .md-h { font-weight: 700; margin-top: 6px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { font-family: var(--mono); font-size: 13px; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
.md .md-code { margin: 0 0 8px; font-family: var(--mono); font-size: 12.5px; line-height: 1.45; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; overflow-x: auto; white-space: pre; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.notice a { color: var(--accent); font-weight: 600; }
