/* Građevinko test UI — one calm stylesheet, no framework (docs/ARCHITECTURE.md, §E).
 * Colours are tokens on :root; dark mode redefines them. Layout: top bar, tabs, then a sidebar
 * (projects, conversations) next to the content. Below 800 px the sidebar becomes a drawer.
 */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde2e9;
  --border-strong: #c3cad5;
  --text: #1b2230;
  --text-2: #586273;
  --accent: #2456b5;
  --accent-hover: #1c4693;
  --accent-soft: #e7eefb;
  --on-accent: #ffffff;
  --user-bubble: #e7eefb;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --warn: #8a5300;
  --warn-soft: #fff3d9;
  --ok: #1d7340;
  --ok-soft: #e6f4ec;
  --focus: #2456b5;
  --backdrop: rgba(15, 20, 30, 0.45);
  --shadow: 0 8px 28px rgba(16, 24, 40, 0.14);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111419;
    --surface: #191d24;
    --surface-2: #222833;
    --border: #2c333f;
    --border-strong: #3c4553;
    --text: #e5e8ed;
    --text-2: #a2abb9;
    --accent: #8ab0ff;
    --accent-hover: #a5c2ff;
    --accent-soft: #1d2840;
    --on-accent: #0b1222;
    --user-bubble: #222f4a;
    --danger: #f4958c;
    --danger-soft: #3a1e1c;
    --warn: #efc06a;
    --warn-soft: #352a14;
    --ok: #7fd29d;
    --ok-soft: #163020;
    --focus: #8ab0ff;
    --backdrop: rgba(0, 0, 0, 0.6);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

/* ============================================================== base */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { line-height: 1.25; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, pre, .mono { font-family: var(--mono); }
.mono { font-size: 12.5px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.hint { margin: 0; font-size: 12.5px; color: var(--text-2); }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ============================================================== controls */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  padding: 7px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
button:hover, .btn:hover { background: var(--surface-2); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.small, .btn.small { padding: 4px 10px; font-size: 13px; }

.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.ghost { background: transparent; border-color: transparent; }
.ghost:hover { background: var(--surface-2); }
.danger { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.danger:hover { background: var(--danger); filter: brightness(0.92); }
.danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.danger-ghost:hover { background: var(--danger-soft); }
.icon-btn { padding: 6px 10px; font-size: 18px; line-height: 1; }

input, select, textarea {
  font: inherit;
  font-size: 14.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 0;
}
textarea { line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-2); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--accent); }
::placeholder { color: var(--text-2); opacity: 0.8; }

/* Labels wrap their field: caption above, field below. */
.stack label, .grid-form label, .inline-form label, .toolbar label.grow, .form-row label.grow {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
label.check {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}

/* The file input sits invisibly inside its label, so the label looks like a button and stays keyboard-reachable. */
.attach { position: relative; overflow: hidden; }
.attach input[type="file"] { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.attach:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
/* while a message is sent or a run is active nothing can be sent (app.js updateComposer) */
.composer.locked .attach { opacity: 0.55; pointer-events: none; }
.attach input[type="file"]:disabled { cursor: not-allowed; }

p.msg { margin: 12px 0 0; font-size: 14px; }
p.msg:empty { display: none; }
p.msg.error { color: var(--danger); }
p.msg.ok { color: var(--ok); }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* ============================================================== boot and sign-in */

.boot { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; color: var(--text-2); }
.boot.error { color: var(--danger); text-align: center; }

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 2px; font-size: 22px; }
.login-card > p { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.divider { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-2); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

/* ============================================================== app frame */

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);    /* no row may widen the page past the viewport */
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar > * { flex: none; }
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.org-picker { flex: 0 1 auto; min-width: 0; }
.org-picker select { width: 100%; }
#sign-out { white-space: nowrap; }
.env {
  padding: 1px 7px;
  border-radius: 4px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.env:empty { display: none; }
.org-picker select { max-width: 300px; }
.user-email { font-size: 13px; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 12px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;                    /* still scrolls sideways on narrow screens */
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  padding: 10px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-2);
  white-space: nowrap;
}
.tabs button:hover { background: transparent; color: var(--text); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:focus-visible { outline-offset: -2px; }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 0; }
.only-narrow, .sidebar-backdrop { display: none; }

/* ============================================================== sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.side-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.side-section.grow { flex: 1; min-height: 0; overflow-y: auto; border-bottom: 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.section-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-2);
}
#project-select { width: 100%; }

.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 10px; margin: 10px 0 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.conv-list { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.conv-list li.empty { padding: 6px 2px; font-size: 13px; color: var(--text-2); }
.conv {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  width: 100%;
  padding: 8px 10px;
  border-color: transparent;
  background: transparent;
  text-align: left;
  font-weight: 400;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.conv-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }

/* ============================================================== content panels */

.content { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px 32px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { margin: 0; font-size: 20px; }
.panel-head h2 .muted { font-weight: 400; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.panel > h3, .two-col h3 { margin-top: 24px; }

.card {
  margin: 0 0 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
details.card > summary { cursor: pointer; font-weight: 600; }
details.card[open] > summary { margin-bottom: 14px; }
details.card > summary:focus-visible { border-radius: 4px; }

.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.grid-form .wide { grid-column: 1 / -1; }
/* a caption that wraps to two lines must not push its field below the neighbours' */
.grid-form label > input, .grid-form label > select { margin-top: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 12px; }
.inline-form .grow { flex: 1 1 220px; }
.toolbar, .form-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.toolbar { margin-bottom: 12px; }
.toolbar .grow, .form-row .grow { flex: 1 1 240px; }

/* ============================================================== tables */

.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.card .table-wrap { margin: 0; border: 0; border-radius: 0; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.check-col { width: 36px; }
td.note { max-width: 24em; }
td.desc { min-width: 16em; max-width: 40em; }
tr.empty td { padding: 20px; text-align: center; color: var(--text-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable:focus-visible { outline-offset: -2px; }
tr.selected td { background: var(--accent-soft); }
table.rows { font-size: 13px; }

td input:not([type="checkbox"]), td select { padding: 4px 8px; }
#kn-theme-table td, #kn-proposal-items td, .add-row { vertical-align: middle; }
.num-input { width: 7.5em; text-align: right; font-variant-numeric: tabular-nums; }
.name-input { flex: 1; min-width: 12em; }
.text-input { width: 100%; min-width: 10em; }
.add-row { display: flex; align-items: center; gap: 6px; }

/* a row edited in the form, not saved yet */
tr.changed td { background: var(--warn-soft); }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 12px;
  white-space: nowrap;
}
.badge.warn, .badge.status-cancelled { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.badge.unverified { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); font-weight: 600; }
tr.unverified td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.unverified-hint {
  margin: 0 0 10px;
  padding: 8px 12px;
  border-left: 3px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--text);
}
.badge.status-completed { border-color: transparent; background: var(--ok-soft); color: var(--ok); }
.badge.status-failed { border-color: transparent; background: var(--danger-soft); color: var(--danger); }
.badge.status-running { border-color: transparent; background: var(--accent-soft); color: var(--accent); }

#bulletin-meta { margin: 10px 0; }
.bulletin-note { margin-top: 4px; }
.bulletin-more { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; }

/* ============================================================== company knowledge */

.badge.confirmed { border-color: transparent; background: var(--ok-soft); color: var(--ok); }
.badge.suggested { border-color: transparent; background: var(--warn-soft); color: var(--warn); }
.badge + .badge { margin-left: 4px; }
.kn-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 24px 0 10px; }
.kn-head h3 { margin: 0; }
#kn-theme, #kn-proposal { margin-top: 4px; }
.kn-meta { margin: 8px 0 12px; }
#kn-theme h4 { margin: 18px 0 8px; }
#kn-theme .form-row { margin-top: 12px; }
#kn-proposal .form-actions { margin-top: 12px; }
tr.current td { background: var(--accent-soft); }
.structure { color: var(--text-2); font-size: 12.5px; }
.structure div + div::before { content: "ili "; font-style: italic; }

/* a proposal's items, by what they would change against the current data */
tr.st-changed td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
tr.st-new td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
tr.st-removed td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
tr.st-unchanged td, tr.st-missing td { color: var(--text-2); }

.kn-note-text { white-space: pre-wrap; }
.kn-note-text.undone { color: var(--text-2); text-decoration: line-through; }
.note-edit textarea { width: 100%; min-height: 4.5em; resize: vertical; }

/* ============================================================== stats and details */

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 0 0 20px; }
.stat { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.stat dt { font-size: 12px; color: var(--text-2); }
.stat dd { margin: 2px 0 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stats.compact { margin: 12px 0 16px; }
.stats.compact .stat dd { font-size: 15px; }
.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }

.detail { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.detail:empty { display: none; }
.detail-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-head h3 { margin: 0; font-size: 17px; }
.detail-list { margin: 16px 0; }
.detail-list h4 { margin: 0 0 6px; font-size: 14px; }
.detail-list ul { margin: 0; padding-left: 20px; }
.detail-list li { margin: 3px 0; }
.detail-list.warn { padding: 10px 14px; background: var(--warn-soft); border-radius: var(--radius); }
.detail-list.warn h4 { color: var(--warn); }

/* ============================================================== chat */

.panel.chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.chat-title-box { min-width: 0; }
.chat-head h2 { margin: 0; overflow: hidden; font-size: 17px; text-overflow: ellipsis; white-space: nowrap; }

/* One readable column, centred on wide screens. */
.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px max(24px, calc((100% - 860px) / 2));
}
.empty-chat { margin: auto; max-width: 540px; padding: 32px 0; text-align: center; color: var(--text-2); }
.empty-chat h3 { margin: 0 0 8px; color: var(--text); font-size: 17px; }
.empty-chat p { margin: 6px 0; }

.messages > .msg { min-width: 0; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end;
  max-width: min(680px, 88%);
  padding: 10px 14px;
  background: var(--user-bubble);
  border-radius: 14px 14px 4px 14px;
}
.msg-text { white-space: pre-wrap; }
.msg-time { margin-top: 4px; font-size: 11px; color: var(--text-2); text-align: right; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg.file { align-self: flex-start; }

.file-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 2px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  overflow-wrap: anywhere;
}
.attachments .file-tag { padding-right: 3px; }
.tag-remove { padding: 0 6px; border: 0; border-radius: 999px; background: transparent; font-size: 15px; line-height: 1.3; }
.tag-remove:hover { background: var(--border); }

.file-btn { padding: 8px 14px; border-radius: var(--radius); }
.file-icon { color: var(--accent); font-weight: 700; }

.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 2px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 12.5px;
}
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--text-2); }
.chip.ok .chip-dot { background: var(--ok); }
.chip.pending { color: var(--text); border-color: var(--accent); }
.chip.pending .chip-dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
.chip.error { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.chip.error .chip-dot { background: var(--danger); }
.chip.stopped .chip-dot { background: var(--warn); }

.msg.questions {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
}
.q-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 6px; }
.question { padding: 10px 0 2px; border-top: 1px solid var(--border); }
.q-head + .question { border-top: 0; padding-top: 2px; }
.q-name { font-weight: 600; }
.q-text { margin-top: 2px; }
.q-detail { margin-top: 4px; }
.q-answers { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.answer.chosen { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.q-send { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 12px; padding-top: 10px;
          border-top: 1px solid var(--border); }

/* a proposed change of key data and a remembered note: their state comes from /v1/knowledge */
.msg.kn-card {
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}
.msg.note-card { border-left-color: var(--ok); }
.kn-card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.kn-card-head button { margin-left: auto; }
.kn-preview { margin: 6px 0 0; padding-left: 20px; }
.kn-preview:empty { display: none; }
.kn-card .kn-note-text { margin-top: 4px; }
.card-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 10px; }
.card-error { flex-basis: 100%; margin-top: 4px; color: var(--danger); font-size: 13px; }

.notice { align-self: center; max-width: 100%; font-size: 13px; color: var(--text-2); text-align: center; }
.notice.warn { color: var(--warn); }
.notice.error {
  padding: 6px 12px;
  background: var(--danger-soft);
  border-radius: 8px;
  color: var(--danger);
}

/* Model output (sanitized Markdown) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .md-table { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 18px 0 8px; }
.md h1 { font-size: 20px; }
.md h2 { font-size: 18px; }
.md h3 { font-size: 16px; }
.md h4 { font-size: 15px; }
.md ul, .md ol { padding-left: 22px; }
.md li { margin: 2px 0; }
.md code { padding: 1px 5px; background: var(--surface-2); border-radius: 4px; font-size: 0.9em; }
.md pre { padding: 10px 12px; overflow-x: auto; background: var(--surface-2); border-radius: 8px; }
.md pre code { padding: 0; background: none; }
.md blockquote { padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.md img { max-width: 100%; }
.md .md-table { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.md table { font-size: 13.5px; }
.md th { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); background: var(--surface-2); }
.md.plain { white-space: pre-wrap; }

.run-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 24px;
  background: var(--accent-soft);
  border-top: 1px solid var(--border);
  font-size: 14px;
}
#run-status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-bar #stop { margin-left: auto; }
.spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.composer { padding: 12px 24px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer.drop { outline: 2px dashed var(--accent); outline-offset: -6px; }
.composer textarea { display: block; width: 100%; min-height: 64px; max-height: 40vh; resize: vertical; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.attachments:empty { display: none; }
.composer-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.composer-actions #send { margin-left: auto; }

/* ============================================================== dialogs and toasts */

dialog {
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: var(--backdrop); }
dialog h2 { margin: 0; font-size: 17px; }
dialog .stack { margin-top: 0; }
dialog .section-head h2 { font-size: 17px; letter-spacing: 0; text-transform: none; color: var(--text); }
.wide-dialog { width: min(920px, calc(100vw - 32px)); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.json {
  max-height: 70vh;
  margin: 0;
  padding: 12px;
  overflow: auto;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 12.5px;
  white-space: pre;
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--accent); }
.toast-text { flex: 1; overflow-wrap: anywhere; }
.toast-close { padding: 0 6px; border: 0; background: transparent; font-size: 18px; line-height: 1.2; }

/* ============================================================== motion */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.35; } }

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

/* ============================================================== narrow screens */

@media (max-width: 800px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  #menu.only-narrow { display: inline-flex; }
  .user-email { display: none; }
  .brand { font-size: 15px; }
  .tabs { padding: 0 4px; }
  .tabs button { padding: 10px 10px; }

  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(320px, 86vw);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    visibility: hidden;                     /* closed: out of the tab order too */
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  body.sidebar-open .sidebar { transform: none; visibility: visible; transition: transform 0.2s ease; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: var(--backdrop); }

  .panel { padding: 16px 16px 28px; }
  .chat-head, .run-bar { padding-left: 16px; padding-right: 16px; }
  .messages { padding: 16px; }
  .composer { padding: 10px 12px 12px; }
  .composer-actions .hint { display: none; }
  .msg.user { max-width: 92%; }
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .panel-head h2 { font-size: 18px; }
  .stat dd { font-size: 16px; }
}

@media (max-width: 520px) {
  .env { display: none; }                     /* room for the company picker */
  #sign-out { padding-left: 8px; padding-right: 8px; }
}
