/* Colours follow the Octoserv colour roles (developer docs, design-system-dev.html): white and logo blue in light mode,
   a dark blue-grey derived from the brand blue in dark mode (no pure black). Orange stays the action colour in both. */
:root {
  color-scheme: light dark;
  --bg: #ffffff;              /* page */
  --surface: #ffffff;         /* cards, list rows, inputs */
  --bubble: #f3f4f6;          /* Octobot's answers */
  --code: #e5e7eb;            /* code inside an answer */
  --text: #111827;
  --muted: #5f6673;          /* Octoserv muted, one step darker: 4.5:1 also on the answer and own bubbles */
  --line: #e5e7eb;
  --brand: #00689b;           /* logo blue */
  --accent: #e09000;          /* orange action */
  --accent-text: #1a1200;     /* dark text on orange, in both schemes */
  --secondary: #eef1f4;       /* grey cancel/secondary */
  --secondary-text: #1f2937;
  --btn-border: rgba(17, 24, 39, .14);
  --btn-shine: rgba(255, 255, 255, .6);
  --user: #e8f1f6;            /* own messages: light grey-blue of the logo */
  --user-line: #c6dbe8;
  --tint: #eff6ff;            /* "Octobot works" bar */
  --tint-text: #00689b;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --danger-line: #f3c2bc;
  --ok: #2f6b2f;
  --bar: rgba(255, 255, 255, .92);
  --overlay: rgba(255, 255, 255, .78);
  --overlay-card: rgba(255, 255, 255, .8);
  --soft: #f7f9fb;            /* closed work steps */
  /* Thread colours; no red (errors) and no orange (actions). Distinct with red-green weakness. */
  --thread-0: #2f6fb3;        /* blue */
  --thread-1: #237058;        /* green */
  --thread-2: #7a4fb0;        /* violet */
  --thread-3: #8a6239;        /* brown */
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1821;
    --surface: #18232f;
    --bubble: #18232f;
    --code: #0f1821;
    --text: #e6edf3;
    --muted: #9aa7b4;
    --line: #2a3a4a;
    --brand: #7cc4e2;
    --accent: #e6a01f;
    --secondary: #223140;
    --secondary-text: #e6edf3;
    --btn-border: rgba(230, 237, 243, .14);
    --btn-shine: rgba(255, 255, 255, .06);
    --user: #123247;
    --user-line: #1f4a66;
    --tint: #142b3d;
    --tint-text: #9fd3ea;
    --danger: #f2998e;
    --danger-bg: #2e1a1a;
    --danger-line: #5c2b26;
    --ok: #8fd18f;
    --bar: rgba(15, 24, 33, .92);
    --overlay: rgba(15, 24, 33, .8);
    --overlay-card: rgba(24, 35, 47, .85);
    --soft: #18232f;
    --thread-0: #7fb2ec;
    --thread-1: #5fc7a2;
    --thread-2: #bb9be8;
    --thread-3: #cfa77c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1 { font-size: 1.15rem; margin: 0; font-weight: 650; }
a { color: var(--brand); }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; }

.view { min-height: 100dvh; display: flex; flex-direction: column; }

/* Buttons: glass style with border; orange = action, grey = secondary */
.btn {
  appearance: none; border: 1px solid var(--btn-border); border-radius: 12px;
  padding: .55rem .95rem; font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
  background: var(--secondary); color: var(--secondary-text);
  box-shadow: inset 0 1px 0 var(--btn-shine);
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: rgba(26, 18, 0, .25); }
.btn.secondary { background: var(--secondary); color: var(--secondary-text); }
.btn.icon { width: 42px; height: 42px; padding: 0; background: var(--surface); color: var(--text); }
.btn.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.wide { width: 100%; padding: .8rem; font-size: 1.05rem; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(224, 144, 0, .45); outline-offset: 2px; }

/* Top bar */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .6rem;
  padding: calc(.6rem + var(--safe-top)) .9rem .6rem; background: var(--bar);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.bar h1 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-actions { display: flex; align-items: center; gap: .5rem; }

/* Sign-in */
.auth { align-items: center; justify-content: center; padding: 2rem 1.2rem; }
.auth-box { width: 100%; max-width: 360px; text-align: center; }
.auth-box h1 { font-size: 1.6rem; margin: .6rem 0 .4rem; }
.auth-logo { display: block; margin: 0 auto 4px; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand img { flex: none; }
.token-form { display: flex; flex-direction: column; gap: 10px; }

/* List */
.conv-list { list-style: none; margin: 0; padding: .4rem .7rem calc(1rem + var(--safe-bottom)); }
.conv-list li { margin: .45rem 0; }
.conv-list button {
  display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: .75rem .9rem; font: inherit; cursor: pointer;
}
.conv-list li.swipe { position: relative; }
.conv-list li.swipe > .conv-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 76px; display: flex; align-items: center; justify-content: center;
  background: #c8321f; border: 0; border-radius: var(--radius); cursor: pointer; padding: 0;
  visibility: hidden;   /* only while the row is pushed aside, so no red edge shows behind a closed row */
}
.conv-list li.swipe.reveal > .conv-del { visibility: visible; }
.conv-del svg { width: 26px; height: 26px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.conv-list li.swipe > button:not(.conv-del) { position: relative; touch-action: pan-y; }
.conv-head { display: flex; align-items: center; gap: .5rem; }
.conv-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-last { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: .15rem; }
.chip { font-size: .75rem; font-weight: 650; border-radius: 999px; padding: .1rem .55rem; border: 1px solid transparent; white-space: nowrap; }
.chip.running { background: color-mix(in srgb, #e09000 25%, #ffffff); color: #1a1200; border-color: color-mix(in srgb, #e09000 45%, #ffffff); }
.chip.waiting { background: color-mix(in srgb, #c8321f 25%, #ffffff); color: #5a140b; border-color: color-mix(in srgb, #c8321f 45%, #ffffff); }
.empty { text-align: center; padding: 2rem 1rem; }

/* Conversation */
.conv .status { padding: .45rem .9rem; font-size: .9rem; background: var(--tint); border-bottom: 1px solid var(--line); color: var(--tint-text); }
.messages { list-style: none; margin: 0; padding: .8rem .8rem 1rem; flex: 1; display: flex; flex-direction: column; gap: .55rem; }
.msg { max-width: 92%; }
.msg.user { align-self: flex-end; background: var(--user); border: 1px solid var(--user-line); border-radius: var(--radius) var(--radius) 4px var(--radius); padding: .55rem .8rem; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--bubble); border: 1px solid var(--line); border-radius: var(--radius) var(--radius) var(--radius) 4px; padding: .6rem .85rem; }
.msg.assistant .text p { margin: .35rem 0; }
.msg.assistant .text p:first-child { margin-top: 0; }
.msg.assistant .text pre { background: var(--code); padding: .5rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }
.msg.assistant .text code { background: var(--code); padding: 0 .25rem; border-radius: 4px; font-size: .9em; }
.msg.assistant .text ul, .msg.assistant .text ol { padding-left: 1.2rem; margin: .35rem 0; }
.msg .tools { display: flex; justify-content: flex-end; margin-top: .3rem; }
.msg .tools .btn { padding: .3rem .6rem; font-size: .85rem; }
.msg.activity, .msg.info { align-self: stretch; max-width: 100%; font-size: .85rem; color: var(--muted); padding: 0 .3rem; }
.msg.activity::before { content: "• "; }
/* Collected work steps: closed by default, open with a tap */
.run-ref { font-size: .78rem; color: var(--muted); margin-bottom: .3rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.user .run-stop { display: block; margin-top: .45rem; font-size: .78rem; padding: .25rem .6rem; min-height: 0; white-space: nowrap; }
.msg.steps { align-self: stretch; max-width: 100%; font-size: .85rem; color: var(--muted); }
.msg.steps summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .45rem; min-height: 32px;
  padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--soft);
}
.msg.steps summary::-webkit-details-marker { display: none; }
.msg.steps summary::before {
  content: ""; flex: none; width: 7px; height: 7px; border: solid var(--muted); border-width: 0 1.6px 1.6px 0;
  transform: rotate(-45deg); transition: transform .15s ease; margin-right: .1rem;
}
.msg.steps details[open] summary::before { transform: rotate(45deg); }
.steps-count { flex: none; font-weight: 600; color: var(--secondary-text); }
.steps-last { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.steps details[open] .steps-last { display: none; }
.msg.steps ol { margin: .35rem 0 .1rem; padding: 0 .6rem 0 1.9rem; display: flex; flex-direction: column; gap: .2rem; word-break: break-word; }
.msg.error { align-self: stretch; max-width: 100%; color: var(--danger); background: var(--danger-bg); border: 1px solid var(--danger-line); border-radius: 10px; padding: .5rem .7rem; font-size: .92rem; }
.msg.approval { align-self: stretch; max-width: 100%; background: var(--surface); border: 2px solid var(--accent); border-radius: var(--radius); padding: .7rem .8rem; }
.msg.approval h2 { font-size: .95rem; margin: 0 0 .35rem; }
.msg.approval pre { white-space: pre-wrap; word-break: break-word; background: var(--bubble); padding: .5rem; border-radius: 8px; font-size: .82rem; max-height: 14rem; overflow: auto; margin: .3rem 0 .6rem; }
.msg.approval .row { display: flex; gap: .5rem; }
.msg.approval .row .btn { flex: 1; }
.brand { color: var(--brand); }
.msg.approval .result { font-weight: 600; }
.msg.approval.done { border-color: var(--line); }
.result.allowed { color: var(--ok); }
.result.denied, .result.expired { color: var(--danger); }

.composer {
  position: sticky; bottom: 0; display: flex; align-items: flex-end; gap: .5rem;
  padding: .55rem .7rem calc(.55rem + var(--safe-bottom)); background: var(--bar);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.composer textarea {
  flex: 1; resize: none; font: inherit; border: 1px solid var(--line); border-radius: 12px; padding: .55rem .7rem;
  background: var(--surface); color: var(--text); max-height: 40vh; min-height: 42px;
}
.btn.mic.recording { background: #c8321f; color: #ffffff; border-color: #c8321f;   /* fixed red surface: white text in both schemes */ animation: pulse 1.2s infinite; }
.btn.mic.busy { opacity: .6; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(163, 39, 27, .18); } }

.toggle { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Settings */
.settings { padding: 1rem; display: flex; flex-direction: column; gap: 1rem; max-width: 520px; }
.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .95rem; }
.field input, .field select { font: inherit; font-weight: 400; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.field p { margin: 0; font-weight: 400; }
.check { display: flex; gap: .55rem; align-items: center; font-size: .95rem; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

/* Dictation overlay: see-through, pulsing microphone, live text */
.dictation {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 1rem;
  padding: calc(1.2rem + var(--safe-top)) 1.1rem calc(1.1rem + var(--safe-bottom));
  background: var(--overlay); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}
.dict-text {
  width: 100%; max-width: 560px; flex: 1; min-height: 6rem; overflow-y: auto; font-size: 1.2rem; line-height: 1.5;
  background: var(--overlay-card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem;
}
.dict-text .interim { color: var(--muted); }
.dict-text .placeholder { display: none; color: var(--muted); }
.dict-text.empty .placeholder { display: inline; }
.dict-mic {
  --level: 0; position: relative; flex: none; width: 112px; height: 112px; border-radius: 50%; cursor: pointer;
  border: 1px solid rgba(26, 18, 0, .2); background: rgba(224, 144, 0, .78); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  transform: scale(calc(1 + var(--level) * .12)); transition: transform .12s ease-out;
  box-shadow: 0 0 0 calc(var(--level) * 18px) rgba(224, 144, 0, .22);
}
.dict-mic svg { width: 48px; height: 48px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dict-mic::before, .dict-mic::after {
  content: ""; position: absolute; inset: -1px; border-radius: 50%; border: 2px solid rgba(224, 144, 0, .55);
  animation: dict-ring 1.8s ease-out infinite; pointer-events: none;
}
.dict-mic::after { animation-delay: .9s; }
@keyframes dict-ring { from { transform: scale(1); opacity: .9; } to { transform: scale(1.75); opacity: 0; } }
.dictation.busy .dict-mic { opacity: .55; }
.dictation.busy .dict-mic::before, .dictation.busy .dict-mic::after { animation: none; opacity: 0; }
.dict-state { margin: 0; color: var(--muted); font-size: .95rem; text-align: center; min-height: 1.4em; }
.dict-actions { display: flex; gap: .6rem; width: 100%; max-width: 560px; }
.dict-actions .btn { flex: 1; padding: .8rem; font-size: 1.05rem; }
@media (prefers-reduced-motion: reduce) { .dict-mic::before, .dict-mic::after { animation: none; } }

/* Parallel runs: fine frame plus a stronger stripe on the left in the run's colour (question, answers, steps). */
.msg.thread-0 { --thread: var(--thread-0); }
.msg.thread-1 { --thread: var(--thread-1); }
.msg.thread-2 { --thread: var(--thread-2); }
.msg.thread-3 { --thread: var(--thread-3); }
.msg.user.thread, .msg.assistant.thread { border: 1px solid var(--thread); border-left-width: 4px; }
.msg.approval.thread, .msg.error.thread { border-left: 4px solid var(--thread); }
.msg.steps.thread, .msg.info.thread { border-left: 3px solid var(--thread); padding-left: .55rem; }
.msg.thread .run-ref { color: var(--thread); font-weight: 600; }
.brand picture { display: flex; flex: none; }
.brand-bot { color: #e09000; }   /* word mark like the logo: "Octo" blue, "bot" in the logo orange #e09000 in both schemes */
.auth-box h1 { color: var(--brand); }

/* Administration: staff list and invitation link */
.team-list { list-style: none; margin: .3rem 0 .6rem; padding: 0; display: flex; flex-direction: column; gap: .5rem; font-weight: 400; }
.team-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.team-list li > div { flex: 1 1 100%; display: flex; flex-direction: column; gap: .15rem; }
.team-list li small { color: var(--muted); font-size: .85rem; }
.team-list li.locked { opacity: .6; }
.invite-link { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; font-weight: 400; }
.invite-link input { font: inherit; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--text); }
.approval-detail summary { cursor: pointer; color: var(--muted); font-size: .9rem; margin: .2rem 0 .4rem; }
