:root {
  --bg: #ffffff;
  --bg-side: #f9f9f9;
  --bg-elevated: #ffffff;
  --bg-inset: #f4f4f4;
  --border: #e5e5e5;
  --border-strong: #d4d4d4;
  --text: #0d0d0d;
  --text-muted: #6b6b6b;
  --text-faint: #9a9a9a;
  --accent: #10a37f;
  --accent-hover: #0e8f70;
  --danger: #d93b3b;
  --user-bubble: #f4f4f4;
  --code-bg: #f6f6f6;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.05);
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #212121;
    --bg-side: #171717;
    --bg-elevated: #2a2a2a;
    --bg-inset: #2f2f2f;
    --border: #383838;
    --border-strong: #4a4a4a;
    --text: #ececec;
    --text-muted: #a8a8a8;
    --text-faint: #7a7a7a;
    --user-bubble: #2f2f2f;
    --code-bg: #1b1b1b;
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- layout ---------- */
#app { display: flex; height: 100dvh; overflow: hidden; }

#sidebar {
  width: 268px; flex: 0 0 268px;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: margin-left .18s ease;
}
#sidebar.collapsed { margin-left: -268px; }

.sidebar-top { padding: 12px; }
.new-chat {
  width: 100%; padding: 10px 12px;
  background: transparent; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 10px;
  font-size: 14px; text-align: left;
}
.new-chat:hover { background: var(--bg-inset); }

.conversation-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin-bottom: 2px;
  border-radius: 9px; cursor: pointer;
  font-size: 14px; color: var(--text);
}
.conv:hover { background: var(--bg-inset); }
.conv.active { background: var(--bg-inset); font-weight: 500; }
.conv-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); flex: 0 0 7px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.conv .del {
  opacity: 0; border: 0; background: none; color: var(--text-faint);
  padding: 2px 4px; border-radius: 5px; line-height: 1;
}
.conv:hover .del { opacity: 1; }
.conv .del:hover { color: var(--danger); background: var(--bg); }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 10px 12px; display: flex; align-items: center; gap: 8px;
}
.who { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: 0 0 26px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.who-name {
  font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.admin-card { max-height: min(85dvh, 700px); overflow: auto; }
.admin-create { display: flex; align-items: end; gap: 10px; }
.admin-create .stack { flex: 1; }
.admin-user { display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
#activation-link { width: 100%; padding: 8px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--bg-inset); }

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.title-wrap { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
#chat-title {
  font-size: 15px; font-weight: 600; margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-status { font-size: 12px; color: var(--text-faint); white-space: nowrap; }

/* model / effort pickers, sitting in the composer action row */
.field { display: flex; align-items: center; gap: 4px; min-width: 0; }
.field span { display: none; }
.field select {
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px 6px; font-size: 12px;
  color: var(--text-muted); max-width: 130px;
}
.field select:hover { color: var(--text); }

.ghost {
  background: none; border: 1px solid transparent; border-radius: 8px;
  color: var(--text-muted); padding: 5px 9px; font-size: 13px;
}
.ghost:hover { background: var(--bg-inset); color: var(--text); }
.ghost.icon { font-size: 16px; padding: 4px 8px; }

/* ---------- banner ---------- */
.banner {
  margin: 10px 16px 0; padding: 10px 14px;
  border: 1px solid var(--border-strong); border-left: 3px solid var(--danger);
  border-radius: 8px; background: var(--bg-inset);
  font-size: 13px; color: var(--text-muted);
}
.banner code { font-family: var(--mono); font-size: 12px; }

/* ---------- transcript ---------- */
.transcript {
  flex: 1; overflow-y: auto; scroll-behavior: smooth;
  padding: 24px 0 8px;
}
.inner { max-width: 760px; margin: 0 auto; padding: 0 20px; }

.empty-state { max-width: 620px; margin: 12vh auto 0; padding: 0 20px; text-align: center; }
.empty-state h2 { font-size: 24px; font-weight: 600; margin: 0 0 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; margin: 0 0 24px; }
.examples { display: flex; flex-direction: column; gap: 8px; }
.example {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 14px; text-align: left;
  font-size: 14px; color: var(--text-muted);
}
.example:hover { border-color: var(--border-strong); color: var(--text); }

.msg { margin-bottom: 26px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .body {
  background: var(--user-bubble); border-radius: 18px;
  padding: 10px 16px; max-width: 80%; white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.assistant .body { max-width: 100%; }

/* reasoning */
.reasoning {
  border: 1px solid var(--border); border-radius: 10px;
  margin-bottom: 12px; background: var(--bg-side); overflow: hidden;
}
.reasoning > summary {
  cursor: pointer; padding: 8px 12px; font-size: 13px;
  color: var(--text-muted); list-style: none; display: flex; align-items: center; gap: 7px;
}
.reasoning > summary::-webkit-details-marker { display: none; }
.reasoning > summary::before {
  content: "▸"; font-size: 10px; color: var(--text-faint); transition: transform .15s;
}
.reasoning[open] > summary::before { transform: rotate(90deg); }
.reasoning .thinking { font-size: 12px; color: var(--text-faint); font-style: italic; }
.reasoning .reasoning-text {
  padding: 8px 14px 12px; font-family: var(--serif);
  font-size: 14px; line-height: 1.75; color: var(--text-muted);
  overflow-wrap: anywhere; max-height: 340px; overflow-y: auto;
}
/* Streamed text keeps its newlines; rendered markdown does its own layout. */
.reasoning .reasoning-text.thinking { white-space: pre-wrap; }
/* Markdown inside the panel is secondary content, so it runs a step smaller
   and never wider than the panel. */
.reasoning-text.md { font-size: 13.5px; }
.reasoning-text.md h1,
.reasoning-text.md h2,
.reasoning-text.md h3 { font-size: 15px; margin: 14px 0 8px; }
.reasoning-text.md p { margin-bottom: 10px; }
.reasoning-text.md pre { font-size: 12px; }
.reasoning-text.md table { font-size: 13px; }
.reasoning-text.md ul,
.reasoning-text.md ol { margin-bottom: 10px; padding-left: 22px; }

/* markdown */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3 { margin: 22px 0 10px; line-height: 1.35; }
.md h1 { font-size: 21px; } .md h2 { font-size: 18px; } .md h3 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin-bottom: 5px; }
.md a { color: var(--accent); }
.md blockquote {
  margin: 0 0 14px; padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}
.md code {
  font-family: var(--mono); font-size: .875em;
  background: var(--bg-inset); border-radius: 5px; padding: 2px 5px;
}
.md pre {
  background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 0 0 14px;
}
.md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.md table { border-collapse: collapse; margin: 0 0 14px; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--bg-inset); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }

.cursor {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--text); vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0 } }

.error-line {
  color: var(--danger); font-size: 13px;
  border-left: 3px solid var(--danger); padding-left: 10px; margin: 12px 0;
}
.send-error {
  max-width: 760px; margin: 0 auto 10px;
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg-inset); border-radius: 8px; padding: 9px 12px;
}
.send-error span { flex: 1; }
.error-close {
  background: none; border: 0; color: var(--text-faint);
  font-size: 12px; padding: 0 2px; line-height: 1.4;
}
.error-close:hover { color: var(--danger); }
.usage {
  margin-top: 10px; font-size: 11px; color: var(--text-faint);
  font-family: var(--mono);
}

/* ---------- composer ---------- */
#composer-wrap {
  border-top: 1px solid var(--border);
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.composer {
  max-width: 760px; margin: 0 auto;
  border: 1px solid var(--border-strong); border-radius: 22px;
  background: var(--bg-elevated); box-shadow: var(--shadow);
  padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 6px;
}
.composer:focus-within { border-color: var(--accent); }
#input {
  width: 100%; border: 0; outline: 0; resize: none; background: none;
  max-height: 220px; line-height: 1.6; font-size: 15px;
  padding: 2px 4px;
}
.composer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.hint { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis; font-size: 11px; color: var(--text-faint); }
.send {
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 7px 16px; font-size: 14px; font-weight: 500;
}
.send:hover:not(:disabled) { background: var(--accent-hover); }
.send:disabled { background: var(--border-strong); cursor: not-allowed; opacity: .7; }
.stop {
  background: none; border: 1px solid var(--border-strong); border-radius: 9px;
  padding: 6px 14px; font-size: 14px; color: var(--text);
}
.stop:hover { background: var(--bg-inset); }
.footnote {
  max-width: 760px; margin: 8px auto 0; text-align: center;
  font-size: 11px; color: var(--text-faint);
}

/* ---------- attachments in the composer ---------- */
.pending {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px 6px;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px;
  background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 9px; padding: 3px 4px 3px 3px; font-size: 12px;
}
.chip img { width: 26px; height: 26px; object-fit: cover; border-radius: 6px; }
.chip-tag {
  display: inline-grid; place-items: center; min-width: 26px; height: 26px;
  padding: 0 4px; border-radius: 6px; background: var(--bg);
  font-family: var(--mono); font-size: 9px; color: var(--text-muted);
}
.chip-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 130px; color: var(--text-muted);
}
.chip-x {
  background: none; border: 0; color: var(--text-faint);
  font-size: 11px; padding: 0 3px; line-height: 1.2;
}
.chip-x:hover { color: var(--danger); }
.composer.dropping { border-color: var(--accent); border-style: dashed; }
.ghost.busy { opacity: .6; }

/* ---------- attachments shown in a message ---------- */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-image img {
  display: block; max-width: 200px; max-height: 200px; border-radius: 10px;
  border: 1px solid var(--border);
}
.msg-file {
  display: inline-block; background: var(--bg-inset); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 10px; font-size: 13px; color: var(--text);
  text-decoration: none; max-width: 240px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-file:hover { border-color: var(--accent); }
.user-text { white-space: pre-wrap; }

/* ---------- generated images ---------- */
.image-strip { display: flex; flex-wrap: wrap; gap: 12px; margin: 4px 0 10px; }
.image-card {
  margin: 0; border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; background: var(--bg-inset); max-width: 340px;
}
.image-card img { display: block; width: 100%; height: auto; }
.image-card .image-frame a { display: block; width: 100%; }
.image-card figcaption {
  padding: 7px 10px 9px; font-size: 11px; color: var(--text-faint);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.image-actions { display: flex; gap: 6px; padding: 8px 9px 9px; }
.image-action {
  flex: 1; background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 5px 8px; font-size: 12px; color: var(--text);
}
.image-action:hover { border-color: var(--accent); color: var(--accent); }
/* A card that is not finished yet: same footprint as a picture so the layout
   does not jump when the image arrives. */
.image-frame {
  display: flex; align-items: center; justify-content: center;
  min-height: 132px; background: var(--bg-inset);
}
.image-frame.working {
  flex-direction: column; gap: 10px;
  border-bottom: 1px dashed var(--border);
}
.image-frame.failed { flex-direction: column; gap: 6px; background: transparent; }
.image-icon {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
  background: var(--danger); color: #fff;
}
.image-note { font-size: 12px; color: var(--text-faint); }
.image-card.state-queued { border-style: dashed; }
.image-card.state-running { border-color: var(--accent); }
.image-why { color: var(--danger) !important; }
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- resource library panel ---------- */
/* Dim the transcript while the sidebar overlay is open on a phone. */
body.sidebar-open::after {
  content: ''; position: fixed; inset: 0; z-index: 19;
  background: rgba(0, 0, 0, .28);
}

.library {
  position: absolute; top: 57px; right: 0; bottom: 0; width: 340px; z-index: 15;
  background: var(--bg-elevated); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
#main { position: relative; }
.library-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.library-usage {
  flex: 1; font-size: 11px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.library-list { flex: 1; overflow-y: auto; padding: 8px; }
.library-empty { font-size: 13px; color: var(--text-faint); padding: 12px 6px; }
.lib-item {
  display: flex; align-items: center; gap: 9px; padding: 7px 6px;
  border-radius: 10px;
}
.lib-item:hover { background: var(--bg-inset); }
.lib-preview {
  width: 40px; height: 40px; flex: none; border-radius: 8px; overflow: hidden;
  background: var(--bg-inset); border: 1px solid var(--border);
  display: grid; place-items: center; font-family: var(--mono);
  font-size: 9px; color: var(--text-muted);
}
.lib-preview img { width: 100%; height: 100%; object-fit: cover; }
.lib-info { flex: 1; min-width: 0; }
.lib-name {
  font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.lib-meta { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }
.lib-actions { display: flex; flex-direction: column; gap: 3px; }
.lib-btn {
  background: none; border: 1px solid var(--border); border-radius: 7px;
  padding: 2px 7px; font-size: 10px; color: var(--text-muted);
}
.lib-btn:hover { border-color: var(--accent); color: var(--accent); }
.lib-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

/* ---------- login ---------- */
.login-screen {
  min-height: 100dvh; display: grid; place-items: center;
  background: var(--bg-side); padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); padding: 28px;
}
.login-card h1 { margin: 0; font-size: 22px; text-align: center; }
.login-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 4px 0 22px; }
.stack { display: block; margin-bottom: 14px; }
.stack span { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }
.stack input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--bg);
}
.stack input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.login-actions { display: flex; gap: 8px; margin-top: 20px; }
.login-actions .send { flex: 1; }
.login-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  #sidebar {
    position: fixed; z-index: 20; height: 100dvh;
    box-shadow: var(--shadow);
  }
  #sidebar.collapsed { margin-left: -268px; }
  .msg.user .body { max-width: 92%; }
  #topbar { padding: 8px 12px; }
  .transcript { padding-top: 16px; }

  /* Keep the whole action row on one line: the hint is the only part that can
     be dropped without losing a control, so it goes first. */
  .composer-actions { flex-wrap: nowrap; gap: 6px; }
  .hint { display: none; }
  .field select { max-width: 96px; padding: 4px 4px; }
  #attach { padding: 6px 8px; font-size: 15px; }
  /* Buttons must keep their label on one line; white-space alone is not
     enough without nowrap plus a no-shrink floor. */
  .send, .stop { padding: 7px 12px; white-space: nowrap; flex: none; }
  .field { flex: none; }

  /* The library covers the transcript on a phone instead of squeezing beside it. */
  .library { width: 100%; top: 53px; }
  /* Chips and cards get finger-sized hit areas. */
  .chip { max-width: 46vw; }
  .chip-x { padding: 4px 6px; font-size: 13px; }
  .image-card { max-width: 100%; }
  .image-action { padding: 9px 8px; font-size: 13px; }
  .lib-btn { padding: 6px 10px; font-size: 11px; }
  .ghost.icon { padding: 8px 10px; }
  .msg-image img { max-width: 62vw; max-height: 62vw; }
}

/* Touch devices: keep the composer above the on-screen keyboard and stop iOS
   from zooming when a control smaller than 16px takes focus. */
@media (hover: none) {
  .chip-x, .image-action, .lib-btn, .ghost, .stop { touch-action: manipulation; }
  #composer-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
@media (max-width: 760px) and (hover: none) {
  #input { font-size: 16px; }
}

/* ---------- personal library dock + upward drawer ---------- */
#sidebar { position: relative; }
.library-dock {
  width: 100%; min-height: 44px; border: 0; border-top: 1px solid var(--border);
  background: transparent; padding: 9px 12px; display: flex; align-items: center;
  gap: 8px; color: var(--text); text-align: left; font-size: 13px;
}
.library-dock:hover, .library-dock[aria-expanded="true"] { background: var(--bg-inset); }
.library-dock-icon { color: var(--text-muted); font-size: 15px; }
.library-dock .library-usage { margin-left: auto; flex: none; font-family: var(--mono); }
.library-dock-chevron { color: var(--text-faint); transition: transform .15s ease; }
.library-dock[aria-expanded="true"] .library-dock-chevron { transform: rotate(180deg); }
.library {
  position: absolute; inset: auto 0 89px 0; width: auto; height: min(50vh, 430px);
  z-index: 3; background: var(--bg-elevated); border: 1px solid var(--border);
  border-width: 1px 0 0; display: flex; flex-direction: column;
  box-shadow: 0 -10px 28px rgba(0,0,0,.12);
}
.library-head strong { flex: 1; }
.library-head .ghost { flex: none; }

/* The attachment control always keeps the paperclip footprint while its
   spinner temporarily replaces it, so upload completion cannot leave stale UI. */
.attach-button { width: 34px; height: 34px; display: grid; place-items: center; }
.paperclip { width: 19px; height: 19px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attach-spinner { display: none; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite; }
.attach-button.busy .paperclip { display: none; }
.attach-button.busy .attach-spinner { display: block; }

/* ---------- persisted turn actions ---------- */
.turn-actions {
  display: flex; align-items: center; gap: 3px; margin-top: 9px;
  color: var(--text-faint); min-height: 27px;
}
.turn-action {
  border: 0; background: transparent; border-radius: 7px; padding: 4px 7px;
  color: inherit; font-size: 12px; line-height: 1.4;
}
.turn-action:hover:not(:disabled) { color: var(--text); background: var(--bg-inset); }
.turn-action:disabled { cursor: not-allowed; opacity: .4; }
.turn-details { margin-left: auto; position: relative; }
.turn-details > summary {
  cursor: pointer; list-style: none; border-radius: 7px; padding: 4px 7px;
  font-family: var(--mono); font-size: 13px;
}
.turn-details > summary::-webkit-details-marker { display: none; }
.turn-details > summary::before { content: "›"; display: inline-block; transition: transform .15s; }
.turn-details[open] > summary::before { transform: rotate(90deg); }
.turn-details > summary:hover { color: var(--text); background: var(--bg-inset); }
.turn-metrics {
  position: absolute; right: 0; bottom: 100%; z-index: 2; min-width: 190px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-elevated); box-shadow: var(--shadow); color: var(--text-muted);
  font: 11px/1.7 var(--mono); white-space: nowrap;
}
.turn-metrics span { display: flex; justify-content: space-between; gap: 16px; }

/* ---------- prompt details + image lightbox ---------- */
.image-prompt {
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  background: color-mix(in srgb, var(--accent) 8%, var(--bg-elevated));
  color: var(--accent); font-size: 12px;
}
.image-prompt > summary { cursor: pointer; list-style: none; padding: 8px 10px; font-weight: 600; }
.image-prompt > summary::-webkit-details-marker { display: none; }
.image-prompt > summary::before { content: "›"; display: inline-block; margin-right: 6px; transition: transform .15s; }
.image-prompt[open] > summary::before { transform: rotate(90deg); }
.image-prompt p { margin: 0; padding: 0 10px 9px; color: var(--text-muted); line-height: 1.55; overflow-wrap: anywhere; }
.image-frame button, .msg-image, .lib-preview.image-preview { cursor: zoom-in; }
.image-frame .image-open { width: 100%; border: 0; padding: 0; background: transparent; }
.lightbox {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.86);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 52px 22px 24px;
}
.lightbox img { max-width: min(94vw, 1400px); max-height: calc(100vh - 110px);
  object-fit: contain; border-radius: 8px; box-shadow: 0 12px 48px rgba(0,0,0,.45); }
.lightbox-close { position: absolute; top: 14px; right: 16px; width: 38px; height: 38px;
  border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; font-size: 18px; }
.lightbox-close:hover { background: rgba(255,255,255,.25); }
.lightbox-caption { max-width: 760px; margin: 10px 0 0; color: #ddd; font-size: 13px;
  text-align: center; overflow-wrap: anywhere; }
body.lightbox-open { overflow: hidden; }

@media (max-width: 760px) {
  #attach { padding: 0; font-size: inherit; }
  .library { top: auto; width: auto; height: min(50vh, 430px); }
  .turn-actions { gap: 1px; }
  .turn-action { padding: 6px; }
}
.msg-image.image-open { border: 0; padding: 0; background: transparent; }
