:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --text: #1f1a14;
  --muted: #6b6258;
  --line: #e2dbd1;
  --accent: #e09000;          /* orange action */
  --accent-text: #241603;     /* dark text on orange */
  --secondary: #ece7df;       /* grey cancel/secondary */
  --secondary-text: #2b251e;
  --user: #fff3dc;
  --danger: #a3271b;
  --ok: #2f6b2f;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { 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; }
.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 rgba(36, 22, 3, .18); 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 rgba(255, 255, 255, .55);
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: rgba(36, 22, 3, .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: rgba(246, 243, 238, .92);
  -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: #fff0cf; color: #6a4300; border-color: #f0d08d; }
.chip.waiting { background: #ffe1db; color: #7d1d12; border-color: #f2b5aa; }
.empty { text-align: center; padding: 2rem 1rem; }

/* Conversation */
.conv .status { padding: .45rem .9rem; font-size: .9rem; background: #fff6e4; border-bottom: 1px solid #f0dfba; color: #5c3b00; }
.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 #f1dcb4; border-radius: var(--radius) var(--radius) 4px var(--radius); padding: .55rem .8rem; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); 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: #f3efe8; padding: .5rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; }
.msg.assistant .text code { background: #f3efe8; 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 */
.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: rgba(255, 255, 255, .55);
}
.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: #fdecea; border: 1px solid #f3c2bc; 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: #f3efe8; 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; }
.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: rgba(246, 243, 238, .95);
  -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: var(--danger); color: #fff; border-color: var(--danger); 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: rgba(246, 243, 238, .74); -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: rgba(255, 255, 255, .7); 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(36, 22, 3, .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; } }
