/* ISLA Console — Claude-style visual language.
 *
 * Two rules drive most of this file:
 *   1. Warm greys, never pure white or pure black. The page is paper, the sidebar is card.
 *   2. Type does the hierarchy. The display serif appears only where Claude uses it
 *      (greeting, brand), and body copy stays at a comfortable measure.
 */

:root {
  --bg: #faf9f5;
  --bg-elevated: #ffffff;
  --sidebar: #f0eee6;
  --sidebar-active: #e6e3d8;
  --text: #1f1e1d;
  --text-muted: #6f6c64;
  --text-faint: #93908a;
  --border: #e4e1d6;
  --border-strong: #d3cfc2;
  --accent: #c96442;
  --accent-soft: #f4e6e0;
  --user-bubble: #ffffff;
  --code-bg: #f4f2ea;
  --danger: #b4423a;
  --ok: #3f7d54;
  --shadow: 0 1px 2px rgba(31, 30, 29, .05), 0 8px 24px rgba(31, 30, 29, .06);
  --radius: 14px;
  --font-body: "Styrene B", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-display: "Tiempos Text", "Copernicus", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, ui-serif, serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 272px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* The theme is an explicit attribute, resolved before first paint by an inline script.
 * A media query alone cannot express "system, until the user picks something else". */
:root[data-theme="dark"] {
    --bg: #262623;
    --bg-elevated: #2f2f2b;
    --sidebar: #1f1e1b;
    --sidebar-active: #33332e;
    --text: #f2f0e9;
    --text-muted: #a5a29a;
    --text-faint: #7e7b74;
    --border: #3b3a35;
    --border-strong: #4a4942;
    --accent: #d97757;
    --accent-soft: #3a2b26;
    --user-bubble: #33332e;
    --code-bg: #1c1c19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15.5px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- gate */

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-card {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 34px 28px 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}

.gate-mark { color: var(--accent); display: flex; justify-content: center; }
.gate-card h1 {
  margin: 2px 0 0;
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 500;
  letter-spacing: .01em;
}
.gate-sub { margin: 0 0 6px; color: var(--text-muted); font-size: 14px; }
.gate-card input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.gate-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.gate-error { margin: 0; min-height: 18px; color: var(--danger); font-size: 13px; }

.btn-primary {
  padding: 11px 18px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 500;
  transition: filter .15s, transform .08s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active { transform: scale(.985); }
.btn-primary:disabled { opacity: .55; cursor: default; }

.btn-secondary {
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  font-weight: 500;
}
.btn-secondary:hover { background: var(--sidebar); }

/* ---------------------------------------------------------------- shell */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 12px 12px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 6px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: .04em;
}
.brand svg { color: var(--accent); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--sidebar-active); color: var(--text); }
.close-sidebar { display: none; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .03);
  transition: background .15s;
}
.new-chat:hover { background: var(--sidebar-active); }
.new-chat svg { color: var(--accent); }

.threads {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 12px -4px;
  padding: 0 4px;
  scrollbar-width: thin;
}
.threads::-webkit-scrollbar { width: 6px; }
.threads::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.thread-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 9px;
  color: var(--text-muted);
  font-size: 14px;
  text-align: left;
  transition: background .12s, color .12s;
}
.thread-item:hover { background: var(--sidebar-active); color: var(--text); }
.thread-item.active { background: var(--sidebar-active); color: var(--text); font-weight: 500; }
.thread-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-item .del {
  opacity: 0;
  color: var(--text-faint);
  padding: 2px;
  border-radius: 5px;
  flex: none;
}
.thread-item:hover .del { opacity: 1; }
/* Touch devices never fire :hover, so an opacity-only affordance would be unreachable. */
@media (pointer: coarse) {
  .thread-item .del { opacity: .5; }
}
.thread-item .del:hover { color: var(--danger); background: var(--bg); }
.thread-item .live {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.4s ease-in-out infinite;
  flex: none;
}
.threads-empty { padding: 10px; color: var(--text-faint); font-size: 13px; }

.sidebar-foot {
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.account { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.dot.up { background: var(--ok); }
.dot.down { background: var(--danger); }
.account-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.account-text strong { font-size: 12.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-text span { font-size: 11.5px; color: var(--text-faint); }

.meter { padding: 0 4px; display: flex; flex-direction: column; gap: 5px; }
.meter-label { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-faint); }
.meter-track { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: var(--accent); border-radius: 2px; transition: width .4s; }

.text-btn {
  align-self: flex-start;
  padding: 4px;
  color: var(--text-faint);
  font-size: 12.5px;
  border-radius: 6px;
}
.text-btn:hover { color: var(--text); }

/* ---------------------------------------------------------------- main */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 52px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
  flex: none;
}
.topbar-spacer { flex: 1; }
.open-sidebar { display: none; }

.model-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 13px;
  color: var(--text-muted);
  transition: border-color .15s, color .15s;
}
.model-chip:hover { border-color: var(--border-strong); color: var(--text); }

.usage-chip {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--code-bg);
  color: var(--text-faint);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.model-menu {
  position: absolute;
  top: 52px;
  left: 14px;
  z-index: 30;
  width: min(320px, calc(100vw - 28px));
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 60vh;
  overflow-y: auto;
}
.model-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  text-align: left;
}
.model-option:hover { background: var(--sidebar); }
.model-option.active { background: var(--accent-soft); }
.model-option strong { font-size: 13.5px; font-weight: 500; }
.model-option span { font-size: 11.5px; color: var(--text-faint); }

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
}
.scroll::-webkit-scrollbar { width: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.thread {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 4px 20px 20px;
}
.scroll-anchor { height: 24px; }

/* ---------------------------------------------------------------- empty state */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100dvh - 260px);
  text-align: center;
  padding: 20px 0;
}
.empty-mark { color: var(--accent); margin-bottom: 14px; opacity: .95; }
.empty h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: clamp(23px, 4.4vw, 29px);
  font-weight: 500;
  letter-spacing: .005em;
}
.empty-sub { margin: 0 0 24px; color: var(--text-muted); font-size: 14px; max-width: 420px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; }
.suggestion {
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
  transition: border-color .15s, color .15s, transform .1s;
}
.suggestion:hover { border-color: var(--accent); color: var(--text); }
.suggestion:active { transform: scale(.97); }

/* ---------------------------------------------------------------- messages */

.msg { margin-bottom: 20px; animation: rise .22s ease-out; }

.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  max-width: min(80%, 560px);
  padding: 10px 15px;
  border-radius: 16px 16px 4px 16px;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant { display: flex; gap: 11px; }
.avatar {
  flex: none;
  width: 24px; height: 24px;
  margin-top: 3px;
  color: var(--accent);
  display: grid;
  place-items: center;
}
.msg.assistant .body { flex: 1; min-width: 0; }

.msg .body > *:first-child { margin-top: 0; }
.msg .body > *:last-child { margin-bottom: 0; }

.msg.error .body { color: var(--danger); font-size: 14px; }

.caret {
  display: inline-block;
  width: 8px; height: 1.05em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 1px;
  animation: blink 1s steps(2, start) infinite;
}

/* markdown */

.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.3;
  margin: 22px 0 10px;
}
.md h1 { font-size: 22px; }
.md h2 { font-size: 19px; }
.md h3 { font-size: 17px; }
.md h4 { font-size: 15.5px; }
.md ul, .md ol { margin: 0 0 12px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--text-faint); }
.md a { color: var(--accent); text-underline-offset: 2px; }
.md blockquote {
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-muted);
}
.md code {
  font-family: var(--font-mono);
  font-size: .88em;
  padding: 1.5px 5px;
  border-radius: 5px;
  background: var(--code-bg);
}
.md pre {
  margin: 0 0 14px;
  padding: 13px 15px;
  border-radius: 11px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  overflow-x: auto;
}
.md pre code { padding: 0; background: none; font-size: 12.8px; line-height: 1.6; }
.md hr { margin: 20px 0; border: none; border-top: 1px solid var(--border); }
.md table { width: 100%; border-collapse: collapse; margin: 0 0 14px; font-size: 14px; }
.md th, .md td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.md th { background: var(--code-bg); font-weight: 500; }

.code-block { position: relative; }
.code-lang {
  position: absolute;
  top: 7px; right: 9px;
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-family: var(--font-body);
}
.copy-btn {
  position: absolute;
  top: 6px; right: 8px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  opacity: 0;
  transition: opacity .15s;
}
.code-block:hover .copy-btn { opacity: 1; }

/* tool cards */

.tool {
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--bg-elevated);
  overflow: hidden;
}
.tool summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary:hover { background: var(--code-bg); }
.tool .chev { transition: transform .18s; flex: none; opacity: .6; }
.tool[open] .chev { transform: rotate(90deg); }
.tool .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: 12.3px; }
.tool .status { flex: none; font-size: 11px; color: var(--text-faint); }
.tool .status.ok { color: var(--ok); }
.tool .status.fail { color: var(--danger); }
.tool pre {
  margin: 0;
  padding: 11px 13px;
  border-top: 1px solid var(--border);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 12.2px;
  line-height: 1.55;
  max-height: 340px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.reasoning {
  margin: 0 0 12px;
  font-size: 13.5px;
  color: var(--text-muted);
}
.reasoning summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  color: var(--text-faint);
  font-size: 13px;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning[open] summary { margin-bottom: 6px; }
.reasoning .text {
  padding-left: 12px;
  border-left: 2px solid var(--border);
  white-space: pre-wrap;
}

.spinner {
  width: 13px; height: 13px;
  border: 1.6px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}

/* ---------------------------------------------------------------- composer */

.composer-wrap {
  flex: none;
  padding: 6px 20px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 68%, transparent);
}
.composer {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 10px 11px 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}
.composer textarea {
  display: block;
  width: 100%;
  max-height: 190px;
  min-height: 26px;
  padding: 3px 2px 6px;
  border: none;
  outline: none;
  background: none;
  resize: none;
  line-height: 1.55;
}
.composer textarea::placeholder { color: var(--text-faint); }

.composer-row { display: flex; align-items: center; gap: 6px; }
.composer-spacer { flex: 1; }

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  transition: border-color .15s, color .15s;
}
.pill:hover { border-color: var(--border-strong); color: var(--text); }

.send {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  transition: filter .15s, transform .08s, opacity .15s;
}
.send:hover { filter: brightness(1.07); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .4; cursor: default; }

.stop-row { width: min(720px, 100%); margin: 8px auto 0; display: flex; justify-content: center; }
.stop {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13px;
}
.stop:hover { color: var(--text); border-color: var(--text-faint); }
.stop-square { width: 8px; height: 8px; border-radius: 2px; background: currentColor; }

.disclaimer {
  width: min(720px, 100%);
  margin: 7px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ---------------------------------------------------------------- sheet */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 19, 17, .35);
  backdrop-filter: blur(2px);
}
.sheet-card {
  width: min(520px, 100%);
  max-height: min(84dvh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h3 { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 500; }
.sheet-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; }
.sheet-body h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); font-weight: 600; }
.sheet-body section { display: flex; flex-direction: column; gap: 8px; }
.hint { margin: 0; font-size: 12.5px; color: var(--text-muted); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack input {
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: var(--bg);
  outline: none;
}
.stack input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.key-list { display: flex; flex-direction: column; gap: 6px; }
.key-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  background: var(--code-bg);
  font-size: 12.5px;
}
.key-row .meta { color: var(--text-faint); }
.key-row .grace { color: var(--accent); }
.new-key {
  margin: 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
}
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.facts dt { color: var(--text-faint); }
.facts dd { margin: 0; font-family: var(--font-mono); font-size: 12px; word-break: break-all; }

.scrim { display: none; }

/* ---------------------------------------------------------------- animation */

@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; }
  .scroll { scroll-behavior: auto; }
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 50;
    width: min(84vw, 300px);
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.22, .8, .3, 1);
    box-shadow: 0 0 40px rgba(0, 0, 0, .17);
  }
  .app.drawer .sidebar { transform: none; }
  .app.drawer .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(20, 19, 17, .3);
  }
  .close-sidebar { display: grid; }
  .open-sidebar { display: grid; }

  .thread { padding: 0 15px 16px; }
  .composer-wrap { padding: 6px 12px calc(8px + var(--safe-bottom)); }
  .msg.user .bubble { max-width: 88%; }
  .topbar { height: 50px; padding: 0 8px; gap: 4px; }
  .usage-chip { display: none; }
  .empty { min-height: calc(100dvh - 300px); }
  .empty-sub { font-size: 13.5px; }
  .suggestions { gap: 7px; }
  .suggestion { font-size: 12.5px; padding: 7px 11px; }
  .md pre { font-size: 12px; }
  .sheet { place-items: end center; padding: 0; }
  .sheet-card { border-radius: 16px 16px 0 0; max-height: 88dvh; }
}

@media (max-width: 380px) {
  html, body { font-size: 15px; }
  .thread { padding: 0 12px 14px; }
}

/* Question panel (option questions)
 *
 * Mirrors the Codex apps: a bordered card inside the assistant turn, numbered rows that
 * read as one tap targets on a phone, and the escape hatch ("write your own reply") kept
 * visible because a fixed option list is often not enough.
 */

.question-card {
  margin: 12px 0 4px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: var(--bg-elevated);
  overflow: hidden;
  animation: rise .2s ease-out;
}

.qc-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 13px 4px;
  color: var(--text-muted);
  font-size: 12.5px;
}
.qc-badge {
  display: grid;
  place-items: center;
  width: 17px; height: 17px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-size: 10.5px;
  color: var(--text-faint);
  flex: none;
}
.qc-head-text { flex: 1; letter-spacing: .02em; }
.qc-close {
  padding: 2px 5px;
  border-radius: 6px;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
}
.qc-close:hover { background: var(--code-bg); color: var(--text); }

.qc-body { padding: 2px 10px 8px; }

.qc-title {
  margin: 6px 3px 10px;
  font-size: 14.5px;
  color: var(--text);
}

.qc-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 11px;
  margin-bottom: 4px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--code-bg);
  text-align: left;
  font-size: 13.5px;
  color: var(--text);
  transition: background .12s, border-color .12s;
}
.qc-option:hover { border-color: var(--border-strong); }
.qc-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.qc-num {
  display: grid;
  place-items: center;
  width: 19px; height: 19px;
  border-radius: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
  flex: none;
}
.qc-option.selected .qc-num { color: var(--accent); border-color: var(--accent); }
.qc-label { flex: 1; min-width: 0; }
.qc-arrow { color: var(--text-faint); flex: none; }
.qc-option.selected .qc-arrow { color: var(--accent); }

.qc-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.qc-hint { flex: 1; color: var(--text-faint); font-size: 12px; }
.qc-skip {
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 12.5px;
}
.qc-skip:hover { color: var(--text); }
.qc-send {
  padding: 5px 14px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 12.5px;
  font-weight: 500;
}
.qc-send:disabled { opacity: .35; cursor: default; }

.msg.blocking { margin-bottom: 20px; }

@media (max-width: 860px) {
  .qc-option { padding: 11px; font-size: 14px; }
  .qc-foot { flex-wrap: wrap; }
  .qc-hint { flex-basis: 100%; margin-bottom: 2px; }
}

/* Backwards paging and background sync
 *
 * A conversation can hold thousands of items, so only the newest page is rendered at first.
 * The button sits above the first message, where the user expects "older" to be.
 */

.load-older {
  display: block;
  margin: 4px auto 18px;
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 12.5px;
  transition: border-color .15s, color .15s, opacity .15s;
}
.load-older:hover { border-color: var(--border-strong); color: var(--text); }
.load-older:disabled { opacity: .55; cursor: default; }

.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--code-bg);
  color: var(--text-faint);
  font-size: 11.5px;
}
.sync-chip .spinner { width: 11px; height: 11px; border-width: 1.4px; }

@media (max-width: 860px) {
  .sync-chip { font-size: 11px; padding: 3px 8px; }
}

/* Settings controls */

.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: var(--code-bg);
}
.segmented button {
  flex: 1;
  padding: 7px 6px;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12.5px;
  transition: background .15s, color .15s;
}
.segmented button.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

.field {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.field > span { flex: none; width: 68px; }
.field select,
.field input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.field select:focus,
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Sidebar search */

.thread-search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-faint);
}
.thread-search-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.thread-search-wrap input {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: none;
  outline: none;
  background: none;
  font-size: 13px;
  color: var(--text);
}
.thread-search-wrap input::-webkit-search-cancel-button { display: none; }
.search-clear { display: grid; place-items: center; padding: 3px; border-radius: 5px; color: var(--text-faint); }
.search-clear:hover { background: var(--code-bg); color: var(--text); }

/* Per-conversation action menu */

.thread-menu {
  position: fixed;
  z-index: 80;
  min-width: 148px;
  padding: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: var(--shadow);
}
.thread-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  text-align: left;
}
.thread-menu button:hover { background: var(--sidebar); }
.thread-menu button.danger { color: var(--danger); }
.thread-menu button.danger.armed { background: var(--danger); color: #fff; }

.thread-item.rename { padding: 4px 6px; }
.thread-item input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--accent);
  background: var(--bg);
  font-size: 12.5px;
  outline: none;
}

.thread-empty-hint { padding: 12px 10px; color: var(--text-faint); font-size: 12.5px; line-height: 1.5; }

/* Rich content: widgets, tables, images */

.md img {
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  margin: 4px 0;
}

/* The demo is part of the answer, not a card inside it: no border, no header bar, no
 * background of its own. Only the height is managed, so there is no inner scrollbar. */
.widget { margin: 2px 0 10px; }

.widget-frame {
  display: block;
  width: 100%;
  height: 380px;
  border: 0;
  background: transparent;
  overflow: hidden;
  border-radius: 12px;
  transition: height .18s ease;
}

.widget-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding-left: 2px;
  opacity: .45;
  transition: opacity .15s;
}
.widget:hover .widget-tools { opacity: 1; }
.widget-link {
  padding: 2px 0;
  color: var(--text-faint);
  font-size: 11.5px;
  background: none;
  border: none;
}
.widget-link:hover { color: var(--text-muted); text-decoration: underline; text-underline-offset: 2px; }
.widget-dot { color: var(--text-faint); font-size: 11px; }

.widget-source {
  margin: 8px 0 0;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 11.8px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-wrap { overflow-x: auto; margin: 0 0 14px; }
.md table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.md th, .md td { padding: 9px 11px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--code-bg); font-weight: 500; color: var(--text-muted); }
.md td img { margin: 0; }
/* An uncapped image makes the table layout give it all the width and crush the text
 * column beside it, which defeats the two-column presentation. */
.md td img { max-width: 260px; }

.widget-frame {
  display: block;
  width: 100%;
  height: min(460px, 62vh);
  border: 0;
  background: #fff;
  resize: vertical;
  overflow: auto;
}
.widget-source {
  margin: 0;
  padding: 11px 13px;
  border-top: 1px solid var(--border);
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 11.8px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 860px) {
  .widget-frame { height: 420px; }
  .md table { font-size: 13px; }
  .md th, .md td { padding: 7px 8px; }
  .md td img { max-width: 132px; }
}

/* A link that has to look like a settings button */
.btn-link {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  color: var(--text);
}
