:root {
  --paper: #f5f6f4;
  --panel: #eceeeb;
  --panel-strong: #e2e5e1;
  --ink: #17201f;
  --ink-soft: #5b6663;
  --ink-faint: #8f9995;
  --rule: #d9ddd9;
  --signal: #0e5f6b;
  --signal-ink: #ffffff;
  --signal-wash: rgba(14, 95, 107, 0.11);
  --danger: #a3372d;
  --edit: #9a6414;
  --edit-wash: rgba(154, 100, 20, 0.14);
  --hit: #f3d86b;
  --speaker-0: #8a3b5c;
  --speaker-1: #0e5f6b;
  --speaker-2: #9a6414;
  --speaker-3: #3c5a9a;
  --speaker-4: #4f7a3a;
  --speaker-5: #7a4f9a;
  --ui: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --lib-w: 272px;
  --chat-w: 400px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141817;
    --panel: #1b2120;
    --panel-strong: #232b29;
    --ink: #e8ecea;
    --ink-soft: #a3adaa;
    --ink-faint: #717b78;
    --rule: #2c3433;
    --signal: #5fc1cf;
    --signal-ink: #0f1f22;
    --signal-wash: rgba(95, 193, 207, 0.16);
    --danger: #e3857a;
    --edit: #e0b25c;
    --edit-wash: rgba(224, 178, 92, 0.18);
    --hit: #d8bd4a;
    --speaker-0: #e08fb3;
    --speaker-1: #6fc7d3;
    --speaker-2: #e0b25c;
    --speaker-3: #93aee6;
    --speaker-4: #9ccb84;
    --speaker-5: #c3a1e8;
  }
}
:root[data-theme="dark"] {
  --paper: #141817;
  --panel: #1b2120;
  --panel-strong: #232b29;
  --ink: #e8ecea;
  --ink-soft: #a3adaa;
  --ink-faint: #717b78;
  --rule: #2c3433;
  --signal: #5fc1cf;
  --signal-ink: #0f1f22;
  --signal-wash: rgba(95, 193, 207, 0.16);
  --danger: #e3857a;
  --edit: #e0b25c;
  --edit-wash: rgba(224, 178, 92, 0.18);
  --hit: #d8bd4a;
  --speaker-0: #e08fb3;
  --speaker-1: #6fc7d3;
  --speaker-2: #e0b25c;
  --speaker-3: #93aee6;
  --speaker-4: #9ccb84;
  --speaker-5: #c3a1e8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: var(--signal); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

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

.app {
  display: grid;
  grid-template-columns: var(--lib-w) minmax(0, 1fr) var(--chat-w);
  height: 100dvh;
}

.btn {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--ink);
}
.btn:hover { background: var(--panel); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-quiet { border-color: transparent; color: var(--ink-soft); }
.btn-quiet:hover { color: var(--danger); background: transparent; }
.btn-primary { background: var(--signal); color: var(--signal-ink); border-color: var(--signal); }
.btn-primary:hover { filter: brightness(1.08); background: var(--signal); }
.link { border: 0; background: none; color: var(--ink-soft); padding: 0; text-decoration: underline; text-underline-offset: 3px; }
.link:hover { color: var(--ink); }

/* ---- library -------------------------------------------------------------------------------- */

.library {
  border-right: 1px solid var(--rule);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand { padding: 20px 20px 12px; }
.brand-name { display: block; font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: -0.01em; }
.brand-sub { display: block; color: var(--ink-soft); font-size: 12.5px; margin-top: 2px; }

.upload {
  display: block;
  margin: 4px 14px 10px;
  padding: 12px 14px;
  border: 1px dashed var(--ink-faint);
  border-radius: 8px;
  cursor: pointer;
}
.upload:hover, .upload:focus-within { border-color: var(--signal); background: var(--signal-wash); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-main { display: block; font-weight: 500; }
.upload-sub { display: block; color: var(--ink-soft); font-size: 12px; margin-top: 2px; }

.list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.list-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--ink);
}
.list-item:hover { background: var(--panel-strong); }
.list-item.is-active { background: var(--paper); box-shadow: inset 3px 0 0 var(--signal); }
.list-title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { display: block; color: var(--ink-soft); font-size: 12px; margin-top: 1px; }
.list-sub.is-working { color: var(--signal); }
.list-sub.is-failed { color: var(--danger); }
.list-progress { display: block; height: 3px; background: var(--rule); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.list-progress i { display: block; height: 100%; background: var(--signal); transition: width 0.2s; }
.list-empty { padding: 12px; color: var(--ink-faint); font-size: 13px; }

.library-foot {
  padding: 12px 20px;
  border-top: 1px solid var(--rule);
  color: var(--ink-faint);
  font-size: 12px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 8px;
  align-items: baseline;
}
.library-foot .warn { color: var(--danger); }
/* With Settings, Issues and Sign out the links need the full width, so they wrap below the note. */
.library-foot-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; min-width: 0; }
#signout { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- reader --------------------------------------------------------------------------------- */

.reader { overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { .reader { scroll-behavior: auto; } }

.empty { max-width: 46ch; margin: 18vh auto 0; padding: 0 24px; color: var(--ink-soft); font-size: 15px; }
.empty-lead { font-family: var(--serif); font-size: 26px; color: var(--ink); margin: 0 0 8px; }

.doc { max-width: 860px; margin: 0 auto; padding: 28px 40px 80px; }

.doc-title {
  font-family: var(--serif);
  font-weight: 500;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0;
  padding: 2px 0;
  border-bottom: 1px solid transparent;
  outline: none;
}
.doc-title:hover, .doc-title:focus { border-bottom-color: var(--rule); }
.doc-meta { margin: 8px 0 0; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 4px 18px; }
.doc-actions { display: flex; gap: 8px; margin-top: 14px; align-items: center; }

.menu { position: relative; }
.menu-list {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 5;
  background: var(--paper); border: 1px solid var(--rule); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); padding: 6px; min-width: 230px;
}
.menu-list a { display: block; padding: 7px 10px; border-radius: 5px; color: var(--ink); text-decoration: none; cursor: pointer; }
.menu-list a:hover { background: var(--panel); }
.menu-list a.is-disabled { opacity: 0.45; pointer-events: none; }

.panel {
  margin-top: 18px; padding: 14px 16px; border-radius: 8px; border: 1px solid var(--rule);
  display: flex; flex-direction: column; gap: 10px;
}
.panel label { color: var(--ink-soft); }
.panel textarea, .dialog textarea, .prompt-row input, .prompt-row textarea {
  width: 100%; border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; padding: 8px 10px; resize: vertical; outline: none;
}
.panel textarea:focus, .dialog textarea:focus, .prompt-row input:focus, .prompt-row textarea:focus { border-color: var(--signal); }
.panel-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.panel-note { color: var(--ink-faint); font-size: 12.5px; }

.status {
  margin-top: 22px;
  padding: 14px 16px;
  border-radius: 8px;
  background: var(--panel);
  display: flex;
  gap: 12px;
  align-items: center;
}
.status.is-failed { background: transparent; border: 1px solid var(--danger); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--signal); flex: none; animation: pulse 1.4s ease-in-out infinite; }
.status.is-failed .status-dot { background: var(--danger); animation: none; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) { .status-dot { animation: none; } }
.status-text { flex: 1; }
.status-text small { display: block; color: var(--ink-soft); margin-top: 2px; }

.player { position: sticky; top: 0; z-index: 3; background: var(--paper); padding: 18px 0 10px; }
.player audio { width: 100%; display: block; }
.player video { width: 100%; max-height: 300px; background: #000; border-radius: 8px; display: block; }

.summary { font-family: var(--serif); font-size: 18px; line-height: 1.5; margin-top: 18px; }
.summary p { margin: 0 0 12px; }
.summary h2 { font-size: 15px; font-family: var(--ui); font-weight: 600; color: var(--ink-soft); margin: 20px 0 6px; }
.summary ul { margin: 0; padding-left: 20px; }
.summary li { margin-bottom: 6px; }
.summary h3 { font-size: 16px; font-family: var(--ui); font-weight: 600; margin: 14px 0 6px; }
.summary-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 8px; font-size: 16px; }
.summary-facts dt { font-family: var(--ui); font-weight: 600; font-size: 14px; color: var(--ink-soft); padding-top: 2px; }
.summary-facts dd { margin: 0; }
.summary-timeline { border-collapse: collapse; font-family: var(--ui); font-size: 14px; width: 100%; }
.summary-timeline th, .summary-timeline td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--rule); }
.summary-timeline th { color: var(--ink-soft); font-weight: 600; }
.summary-placeholder { color: var(--ink-faint); font-style: italic; }

.ts {
  font-family: var(--ui);
  font-size: 0.78em;
  font-variant-numeric: tabular-nums;
  color: var(--signal);
  text-decoration: none;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
}
.ts:hover { background: var(--signal-wash); }

.transcript-tools {
  display: flex; gap: 16px; align-items: center;
  margin-top: 30px; padding: 10px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
.transcript-tools input[type="search"] {
  flex: 1; min-width: 0; border: 0; background: transparent; padding: 4px 0; outline: none;
}
.toggle { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.toggle button { border: 0; background: transparent; padding: 4px 10px; color: var(--ink-soft); font-size: 12.5px; }
.toggle button.is-active { background: var(--signal); color: var(--signal-ink); }
.follow { color: var(--ink-soft); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.turn-count { color: var(--ink-faint); white-space: nowrap; }
.view-note { color: var(--ink-faint); font-size: 12.5px; margin: 8px 0 0; }
.view-note .swatch { display: inline-block; padding: 0 4px; border-radius: 3px; }
.view-note .swatch-edit { background: var(--edit-wash); color: var(--edit); }
.view-note .swatch-unsure { text-decoration: underline dotted var(--ink-faint); text-underline-offset: 3px; }

/* The transcript reads as a script: the speaker hangs in the margin, the words run beside. */
.turns { padding-top: 10px; }
.turn {
  display: grid;
  grid-template-columns: 148px minmax(0, 1fr);
  gap: 0 20px;
  padding: 12px 10px;
  border-radius: 6px;
  margin: 0 -10px;
}
.turn.is-current { background: var(--panel); }
.turn.is-hidden { display: none; }
.turn-who { padding-top: 5px; min-width: 0; }
.turn-speaker {
  border: 0; background: none; padding: 0; text-align: left;
  font-weight: 600; font-size: 13px; color: var(--speaker, var(--ink));
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
}
.turn-speaker:hover { text-decoration: underline; text-underline-offset: 3px; }
.turn-speaker-input { width: 100%; border: 0; border-bottom: 1px solid var(--signal); background: transparent; padding: 0; font-weight: 600; font-size: 13px; outline: none; }
.turn-time { display: block; margin-top: 2px; }
.turn-text { font-family: var(--serif); font-size: 18.5px; line-height: 1.5; margin: 0; }
.w { border-radius: 3px; cursor: pointer; }
.w:hover { background: var(--signal-wash); }
.w.is-edited { background: var(--edit-wash); color: var(--edit); }
.w.is-unsure { text-decoration: underline dotted var(--ink-faint); text-underline-offset: 3px; }
.w.is-active { background: var(--signal); color: var(--signal-ink); }
.w.is-hit { background: var(--hit); color: #1b1b1b; }

/* ---- chat ----------------------------------------------------------------------------------- */

.chat {
  border-left: 1px solid var(--rule);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--paper);
}
.chat-head { padding: 20px 20px 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 12px; }
.chip {
  border: 1px solid var(--rule); background: transparent; border-radius: 999px;
  padding: 4px 11px; font-size: 12.5px; color: var(--ink-soft);
}
.chip:hover:not(:disabled) { border-color: var(--signal); color: var(--signal); }
.chip:disabled { opacity: 0.5; cursor: default; }
.chip-add { border-style: dashed; }

.messages { flex: 1; overflow-y: auto; padding: 4px 20px 12px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 100%; }
.msg-user { align-self: flex-end; background: var(--panel-strong); border-radius: 12px 12px 3px 12px; padding: 8px 12px; max-width: 88%; white-space: pre-wrap; }
.msg-assistant { line-height: 1.5; }
.msg-body > :first-child { margin-top: 0; }
.msg-body > :last-child { margin-bottom: 0; }
.msg-body p { margin: 0 0 8px; }
.msg-body ul, .msg-body ol { margin: 0 0 8px; padding-left: 20px; }
.msg-body li { margin-bottom: 3px; }
.msg-body li > ul, .msg-body li > ol { margin: 3px 0 0; }
.msg-body h1, .msg-body h2, .msg-body h3, .msg-body h4 { font-size: 14px; margin: 12px 0 4px; }
.msg-body h2 { font-size: 15px; }
.msg-body code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--panel); padding: 1px 4px; border-radius: 3px; }
.msg-body pre { background: var(--panel); padding: 10px; border-radius: 6px; overflow-x: auto; }
.msg-body pre code { background: none; padding: 0; }
.msg-body blockquote { margin: 0 0 8px; padding: 2px 0 2px 12px; border-left: 3px solid var(--rule); color: var(--ink-soft); }
.msg-body hr { border: 0; border-top: 1px solid var(--rule); margin: 10px 0; }
.msg-body table { border-collapse: collapse; margin: 4px 0 10px; font-size: 13px; width: 100%; }
.msg-body th, .msg-body td { border: 1px solid var(--rule); padding: 5px 8px; text-align: left; vertical-align: top; }
.msg-body th { background: var(--panel); font-weight: 600; }
.msg-body .cursor { display: inline-block; width: 7px; height: 14px; background: var(--signal); vertical-align: -2px; margin-left: 2px; animation: pulse 0.9s infinite; }
.msg-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.msg-tools { display: flex; gap: 12px; margin-top: 6px; opacity: 0; transition: opacity 0.15s; }
.msg-assistant:hover .msg-tools, .msg-assistant:focus-within .msg-tools { opacity: 1; }
.msg-tools button { border: 0; background: none; padding: 0; color: var(--ink-faint); font-size: 12px; }
.msg-tools button:hover { color: var(--signal); }
.messages-empty { color: var(--ink-faint); font-size: 13px; }
.msg-divider { display: flex; align-items: center; gap: 10px; color: var(--ink-faint); font-size: 12px; text-align: center; }
.msg-divider::before, .msg-divider::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
.msg-divider span { max-width: 70%; }

.composer { display: flex; gap: 8px; padding: 12px 20px 18px; border-top: 1px solid var(--rule); align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--rule); background: var(--panel); border-radius: 8px;
  padding: 9px 12px; max-height: 160px; outline: none; line-height: 1.4;
}
.composer textarea:focus { border-color: var(--signal); }
.composer button {
  border: 0; background: var(--signal); color: var(--signal-ink); border-radius: 8px; padding: 9px 14px; font-weight: 500;
}
.composer button:disabled { opacity: 0.45; cursor: default; }

/* ---- settings dialog ------------------------------------------------------------------------ */

.dialog {
  border: 1px solid var(--rule); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--paper); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.dialog form { padding: 24px 28px 20px; display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 80px); overflow-y: auto; }
/* The form scrolls when it is taller than the window; without this its boxes shrink to fit instead. */
.dialog form > * { flex-shrink: 0; }
.dialog h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 0 0 6px; }
.dialog h3 { font-size: 14px; margin: 14px 0 0; }
.dialog-help { margin: 0; color: var(--ink-soft); font-size: 13px; }
.prompt-rows { display: flex; flex-direction: column; gap: 10px; }
.prompt-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 8px; align-items: start; }
.prompt-row textarea { resize: vertical; min-height: 38px; }
.prompt-row .link { padding-top: 10px; }
.dialog-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ---- overlays ------------------------------------------------------------------------------- */

.tabs { display: none; }

.dropzone {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(14, 95, 107, 0.14);
  border: 3px dashed var(--signal);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 32px; color: var(--signal);
  pointer-events: none;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; max-width: 90vw;
}

.login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login-card h1 { font-family: var(--serif); font-weight: 500; font-size: 30px; margin: 0; }
.login-card p { margin: 0; color: var(--ink-soft); }
.login-card input { border: 1px solid var(--rule); background: var(--panel); border-radius: 8px; padding: 10px 12px; }
.login-card button { border: 0; background: var(--signal); color: var(--signal-ink); border-radius: 8px; padding: 10px; font-weight: 500; }
.login-error { color: var(--danger); min-height: 1.2em; }

/* ---- narrow screens ------------------------------------------------------------------------- */

@media (max-width: 1100px) {
  :root { --chat-w: 340px; --lib-w: 240px; }
  .doc { padding: 24px 28px 80px; }
  .turn { grid-template-columns: 120px minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .library, .reader, .chat { display: none; border: 0; }
  .app[data-view="library"] .library { display: flex; }
  .app[data-view="reader"] .reader { display: block; }
  .app[data-view="chat"] .chat { display: flex; }
  .tabs {
    display: grid; grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--rule); background: var(--panel);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabs button { border: 0; background: none; padding: 12px 0; color: var(--ink-soft); }
  .tabs button.is-active { color: var(--signal); font-weight: 600; box-shadow: inset 0 2px 0 var(--signal); }
  .doc { padding: 20px 16px 60px; }
  .doc-title { font-size: 27px; }
  .doc-actions { flex-wrap: wrap; }
  .turn { grid-template-columns: 1fr; gap: 2px; }
  .turn-who { display: flex; gap: 10px; align-items: baseline; padding-top: 0; }
  .turn-time { margin: 0; }
  .turn-text { font-size: 17.5px; }
  .transcript-tools { flex-wrap: wrap; }
  .prompt-row { grid-template-columns: 1fr; }
  .msg-tools { opacity: 1; }
}

/* ---- additions: model picker, documents, export rows ----------------------------------------- */

.chat-head-right { display: flex; gap: 12px; align-items: center; }
#model-select {
  border: 1px solid var(--rule); background: var(--panel); color: var(--ink-soft); border-radius: 6px;
  padding: 3px 6px; font-size: 12.5px; max-width: 170px;
}
#model-select:focus { border-color: var(--signal); outline: none; }

.chip-doc { border-color: var(--signal); color: var(--signal); }
.docpanel { margin: 0 20px 12px; }
.docpanel select { border: 1px solid var(--rule); background: var(--panel); border-radius: 6px; padding: 7px 10px; }

.menu-wide { min-width: 330px; }
.menu-row { display: flex; align-items: center; gap: 4px; padding: 4px 10px; }
.menu-row span { flex: 1; color: var(--ink-soft); }
.menu-row a { display: inline-block; padding: 3px 8px; font-size: 12.5px; color: var(--signal); }
.menu-sep { border-top: 1px solid var(--rule); margin: 6px 4px; }

.msg-doc { border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; }
.msg-doc-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 8px; }
.msg-doc-head b { color: var(--ink); font-weight: 600; }
.msg-doc .msg-body { font-family: var(--serif); font-size: 15.5px; max-height: 360px; overflow-y: auto; padding-right: 4px; }
.msg-doc .msg-body h2 { font-family: var(--ui); font-size: 13px; color: var(--ink-soft); margin: 14px 0 4px; }
.msg-doc .msg-body h3 { font-family: var(--ui); font-size: 13px; margin: 10px 0 2px; }
.msg-doc .msg-tools, .msg-doc:hover .msg-tools { opacity: 1; }
.msg-tools .btn-file { color: var(--signal); }
.msg-doc .msg-body > h1:first-child { display: none; }

/* ---- saved documents ------------------------------------------------------------------------- */

.docpanel-row { display: flex; gap: 8px; }
.docpanel-row select:first-child { flex: 1; min-width: 0; }

.doc-card {
  border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; margin-top: 8px;
  display: grid; grid-template-columns: 34px 1fr auto; gap: 4px 10px; align-items: center;
}
.doc-card-icon {
  width: 34px; height: 40px; border-radius: 5px; background: var(--signal); color: var(--signal-ink);
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 11px; grid-row: span 2;
}
.doc-card-icon.is-pdf { background: #b23a2a; color: #fff; }
.doc-card-icon.is-md { background: var(--ink-soft); color: var(--paper); }
.doc-card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card-sub { color: var(--ink-soft); font-size: 12px; grid-column: 2; }
.doc-card-sub a, .doc-card-sub button { color: var(--signal); background: none; border: 0; padding: 0; font-size: 12px; text-decoration: none; cursor: pointer; }
.doc-card-sub a:hover, .doc-card-sub button:hover { text-decoration: underline; }
.doc-card > .btn { grid-column: 3; grid-row: span 2; }
.doc-preview {
  margin-top: 6px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px;
  font-family: var(--serif); font-size: 15px; max-height: 320px; overflow-y: auto;
}
.doc-preview h1 { font-size: 18px; margin: 0 0 8px; }
.doc-preview h2 { font-family: var(--ui); font-size: 12.5px; color: var(--ink-soft); margin: 12px 0 4px; }
.doc-preview p { margin: 0 0 8px; }
.doc-preview table { border-collapse: collapse; font-family: var(--ui); font-size: 12.5px; width: 100%; }
.doc-preview th, .doc-preview td { border: 1px solid var(--rule); padding: 4px 6px; text-align: left; }
.writing { color: var(--ink-soft); font-size: 13px; display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.writing i { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--signal); animation: pulse 1.2s infinite; }
.writing span { flex: 1; min-width: 0; }
.writing.is-quiet { color: var(--ink-faint); font-size: 12px; }
.writing.is-quiet i { width: 6px; height: 6px; opacity: 0.6; }

.docs-drawer { margin: 0 20px 12px; border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; }
.docs-drawer h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--ink-soft); font-weight: 600; }
.docs-line { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 4px 0; border-top: 1px solid var(--rule); }
.docs-line:first-of-type { border-top: 0; }
.docs-line b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docs-line .versions { display: flex; gap: 6px; }
.docs-line .versions a { font-size: 12px; color: var(--signal); text-decoration: none; padding: 1px 6px; border: 1px solid var(--rule); border-radius: 999px; }
.docs-line .versions a.is-latest { border-color: var(--signal); }
.docs-empty { color: var(--ink-faint); font-size: 12.5px; }
.chat-head { flex-wrap: wrap; gap: 6px 12px; }
.chat-head > span:first-child { white-space: nowrap; }
#model-select { max-width: 150px; }

/* The Issues link in the library footer turns red while the last 24 hours hold an error. */
#open-issues.has-errors { color: var(--danger); font-weight: 500; }

/* Speaker name suggestions from the summary pass, confirmed one by one or all at once. */
.speaker-suggest { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: 0 0 16px; padding: 10px 14px; background: var(--signal-wash); border-radius: 10px; font-size: 14px; }
.speaker-suggest-lead { color: var(--ink-soft); }
.suggest-item b { color: var(--speaker); }
.suggest-item .link { margin-left: 2px; }
.turn-speaker.is-suggested small { font-weight: 400; color: var(--ink-faint); }

/* Editing a turn in place. */
.turn-edit { font-size: 12px; color: var(--ink-faint); opacity: 0; margin-top: 6px; }
.turn:hover .turn-edit, .turn-edit:focus { opacity: 1; }
.turn-editor { width: 100%; font: inherit; line-height: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--signal); border-radius: 8px; padding: 8px 10px; resize: vertical; outline: none; }

/* Native file cards (Excel, PowerPoint). */
.doc-card-icon.is-xlsx { background: #1d6f42; color: #fff; }
.doc-card-icon.is-pptx { background: #c43e1c; color: #fff; }

/* Settings: password fields and the accounts list. */
.field-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field-row input, .field-row select { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); color: var(--ink); min-width: 0; flex: 1 1 160px; }
.field-row select { flex: 0 1 auto; }
.user-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.user-row { display: grid; grid-template-columns: minmax(0, 1fr) 110px minmax(0, 1fr) 36px 64px; gap: 8px; align-items: center; font-size: 14px; }
.user-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row select, .user-row input { font: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--rule); border-radius: 6px; background: var(--panel); color: var(--ink); min-width: 0; }
@media (max-width: 640px) { .user-row { grid-template-columns: 1fr 1fr; } }
.backup-status { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.backup-line { margin: 0; font-size: 13px; color: var(--ink); overflow-wrap: anywhere; }
.backup-line.is-failed { color: var(--danger); }

/* ---- skills ------------------------------------------------------------------------------------ */

.dialog-wide { width: min(860px, calc(100vw - 32px)); }
#skills { max-height: calc(100vh - 48px); }
#skills[open] { display: flex; flex-direction: column; }
.skills-head { padding: 24px 28px 8px; }
.skills-head h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 0 0 6px; }
.skills-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.skills-list { overflow-y: auto; padding: 0 28px; flex: 1; min-height: 0; }
#skills .dialog-actions { padding: 0 28px 20px; }
.skill-group { margin-top: 18px; }
.skill-group h3 { font-size: 14px; margin: 0; }
.skill-group > .dialog-help { margin-bottom: 6px; }
.skill-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--rule); }
.skill-main { min-width: 0; flex: 1; }
.skill-name { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 14px; }
.skill-desc { color: var(--ink-soft); font-size: 13px; margin-top: 2px; overflow-wrap: anywhere; }
.skill-badge { font-size: 11px; color: var(--ink-soft); border: 1px solid var(--rule); border-radius: 999px; padding: 1px 7px; }
.skill-badge.is-default { color: var(--signal); border-color: var(--signal); }
.skill-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.skill-tools { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: flex-end; flex: none; max-width: 45%; font-size: 13px; }
.skill-empty { color: var(--ink-faint); font-size: 13px; margin: 6px 0; }
@media (max-width: 640px) {
  .skill-row { flex-direction: column; }
  .skill-tools { max-width: none; justify-content: flex-start; }
}

#skill-edit label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
#skill-edit .check-row label { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
#skill-edit input[type="text"], #skill-edit select { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); color: var(--ink); min-width: 0; }
#skill-edit textarea { font-family: inherit; font-size: 14px; }
#skill-body { font-family: ui-monospace, Consolas, monospace; font-size: 13px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .field-grid { grid-template-columns: 1fr; } }
.check-row { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 4px; }
.look-fields { border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; margin: 4px 0; }
.look-fields legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.color-pair { display: flex; gap: 6px; align-items: center; }
.color-pair input[type="color"] { width: 40px; height: 36px; padding: 2px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); }
.color-pair input[type="text"] { flex: 1; }
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.logo-row img { max-height: 44px; max-width: 160px; border: 1px solid var(--rule); border-radius: 6px; padding: 4px; background: #fff; }
.banner-box { display: flex; flex-direction: column; gap: 8px; }
.banner-box img { width: 100%; aspect-ratio: 3 / 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--rule); }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.banner-actions input[type="text"] { flex: 1 1 240px; }
.btn.is-busy { opacity: 0.6; pointer-events: none; }

/* ---- skill builder ------------------------------------------------------------------------------- */

#builder { width: min(1100px, calc(100vw - 32px)); height: min(860px, calc(100vh - 48px)); }
#builder[open] { display: flex; flex-direction: column; }
.builder-head { padding: 22px 28px 6px; }
.builder-head h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 0 0 6px; }
.builder-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; padding: 8px 28px 0; }
.builder-chat { display: flex; flex-direction: column; min-height: 0; border: 1px solid var(--rule); border-radius: 10px; background: var(--panel); }
.builder-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }
.builder-options { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.builder-composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--rule); align-items: flex-end; }
.builder-composer textarea { flex: 1; resize: none; font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper); color: var(--ink); }
.builder-draft { min-height: 0; overflow-y: auto; border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; }
.builder-draft-head { display: flex; align-items: center; gap: 8px; }
.builder-draft-head h3 { margin: 0; font-size: 14px; }
.builder-fields { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.builder-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.builder-fields input, .builder-fields textarea, .builder-try select { font: inherit; font-size: 14px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); color: var(--ink); min-width: 0; }
#builder-body { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; resize: vertical; }
.builder-look { display: flex; gap: 10px; align-items: center; font-size: 13px; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; }
.skill-swatch.big { width: 32px; height: 32px; border-radius: 6px; flex: none; }
.builder-try { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.builder-try select { flex: 1 1 200px; }
.builder-preview { width: 100%; height: 520px; border: 1px solid var(--rule); border-radius: 8px; background: #fff; }
.builder-actions { padding: 12px 28px 18px; margin-top: 0; }
@media (max-width: 860px) {
  #builder { height: calc(100vh - 24px); }
  .builder-body { grid-template-columns: 1fr; overflow-y: auto; }
  .builder-chat { min-height: 360px; }
  .builder-draft { overflow: visible; }
}
