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

:root {
  --bg: #ffffff;
  --bg-side: #fafafa;
  --bg-2: #ffffff;
  --bg-3: #ececee;
  --bg-code: #f6f6f7;
  --border: #e3e3e7;
  --border-soft: #ededf0;
  --text: #17171c;
  --text-dim: #55555e;
  --text-faint: #8e8e98;
  --accent: #3478f6;
  --accent-soft: #e8f0fe;
  --accent-2: #2563eb;
  --danger: #e5484d;
  --ok: #1f9d63;
  /* Delta text colours: darker steps of the same green/red ramps. The --ok and
     --danger steps above measure 3.5:1 / 3.9:1 on white — large-text only.
     These clear 6.5:1, which small delta labels need. */
  --delta-good: #0b6b40;
  --delta-bad: #b3261e;
  --radius: 10px;
  --content-w: 820px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", "Noto Sans Arabic", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}

.hidden { display: none !important; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* custom scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: #d4d4d9; background-clip: content-box; }

/* ============================= login ============================= */

#login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 500px at 70% -10%, rgba(59, 111, 246, 0.07), transparent 60%),
    var(--bg);
}

.login-card {
  width: min(400px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px 28px;
  box-shadow: 0 20px 50px rgba(20, 30, 50, 0.14);
}

.login-logo {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  text-align: center;
}

.login-sub {
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  margin: 4px 0 26px;
}

.login-card form { display: flex; flex-direction: column; gap: 12px; }

.login-card input {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 11px 14px;
  transition: border-color 0.15s;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card input::placeholder { color: var(--text-faint); }

#login-btn {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 11px 14px;
  margin-top: 4px;
  transition: background 0.15s;
}
#login-btn:hover { background: var(--accent-2); }
#login-btn:disabled { opacity: 0.6; cursor: default; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 1.3em;
  text-align: center;
}

/* ============================= app layout ============================= */

#app { display: flex; height: 100dvh; overflow: hidden; }

#sidebar {
  width: 268px;
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  background: var(--bg-side);
  border-right: 1px solid var(--border-soft);
  min-height: 0;
}

.sidebar-head { padding: 14px 12px 8px; }

#new-chat,
#process-open {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  transition: background 0.15s, border-color 0.15s;
}
#new-chat:hover, #process-open:hover { background: var(--bg-3); border-color: #d4d4d9; }
#new-chat .plus, #process-open .plus { color: var(--accent-2); font-size: 16px; font-weight: 700; }

/* --- sidebar sections: briefings sit above chats and never mix with them --- */

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.side-head-chats { border-top: 1px solid var(--border-soft); margin-top: 6px; }
/* Second section inside the reports pane: the weekly retail report under the
   daily briefing, separated by a rule rather than by a fourth tab. */
.side-head-sub { border-top: 1px solid var(--border-soft); margin-top: 6px; }

#briefing-run,
#retail-run {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent-2);
  padding: 2px 6px;
  border-radius: 6px;
}
#briefing-run:hover,
#retail-run:hover { background: var(--accent-soft); }
#briefing-run:disabled,
#retail-run:disabled { color: var(--text-faint); cursor: default; background: none; }

#briefing-section { flex: 0 0 auto; }

/* flex:1 each: the two report lists split the pane and scroll independently. */
#briefing-list,
#retail-list,
#process-list {
  flex: 1;
  padding: 0 8px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.side-empty {
  padding: 6px 10px 10px;
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.4;
}

.brief-item {
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.brief-item:hover { background: var(--bg-3); }
.brief-item.active { background: var(--bg-3); }

.brief-day {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.brief-bad {
  font-size: 10px;
  font-weight: 600;
  color: var(--delta-bad);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.brief-headline {
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.35;
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.chat-item:hover { background: var(--bg-3); }
.chat-item.active { background: var(--bg-3); }

.chat-item-main { flex: 1; min-width: 0; }

.chat-item-title {
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-time { font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.chat-del {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 16px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--danger); background: rgba(255, 93, 93, 0.1); }

.sidebar-foot {
  border-top: 1px solid var(--border-soft);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#user-email {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#signout {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  transition: color 0.12s, border-color 0.12s;
}
#signout:hover { color: var(--text); border-color: #d4d4d9; }

#sidebar-overlay { display: none; }

/* ============================= main column ============================= */

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

#topbar {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}

#hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-dim);
}
#hamburger:hover { background: var(--bg-3); color: var(--text); }

#chat-title {
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#chat-meta {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 11.5px;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ============================= thread ============================= */

#thread {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 16px 12px;
}

.thread-inner {
  max-width: var(--content-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.thread-loading {
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  padding-top: 40px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 0 24px;
}
.empty-title {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-dim);
}
.empty-sub { max-width: 440px; font-size: 14px; color: var(--text-faint); }

/* messages */

.msg { display: flex; }

.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%;
  background: var(--accent-soft);
  border: 1px solid rgba(79, 124, 255, 0.25);
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.msg.assistant .bubble { width: 100%; min-width: 0; }

.msg.error-msg .bubble {
  width: 100%;
  background: rgba(229, 72, 77, 0.08);
  border: 1px solid rgba(255, 93, 93, 0.35);
  color: #b4262b;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
}

.sys-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 2px 0;
}

.usage { font-size: 11px; color: var(--text-faint); margin-top: 10px; }
.stopped-note { font-size: 12px; font-style: italic; color: var(--text-faint); margin-top: 8px; }

/* thinking block */

.thinking {
  margin: 0 0 10px;
  border-left: 3px solid var(--border);
  border-radius: 2px;
}
.thinking summary {
  cursor: pointer;
  list-style: none;
  font-size: 13px;
  color: var(--text-dim);
  padding: 4px 12px;
  user-select: none;
}
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary::before { content: "▸ "; color: var(--text-faint); }
.thinking[open] summary::before { content: "▾ "; }
.thinking-body {
  font-size: 13px;
  color: var(--text-faint);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  padding: 2px 12px 8px;
  max-height: 240px;
  overflow-y: auto;
}

/* ============================= chips ============================= */

.chips-wrap { margin-bottom: 10px; }

.chips-summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 11px 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-2);
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
.chips-summary::-webkit-details-marker { display: none; }
.chips-summary::before {
  content: '▸';
  font-size: 10px;
  color: var(--text-faint);
  transition: transform 0.15s;
}
.chips-wrap[open] > .chips-summary::before { transform: rotate(90deg); }
.chips-summary:hover { border-color: var(--accent); color: var(--text); background: var(--bg-3); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.6;
  white-space: nowrap;
}

.chip .chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}

.chip .chip-ms { color: var(--text-faint); font-size: 11px; }
.chip .chip-icon { font-size: 11px; }
.chip.ok .chip-icon { color: var(--ok); }
.chip.fail { border-color: rgba(255, 93, 93, 0.4); }
.chip.fail .chip-icon { color: var(--danger); }
.chip.running { border-color: rgba(79, 124, 255, 0.4); }
.chip.effort-chip { color: var(--accent-2); border-color: rgba(79, 124, 255, 0.35); }
.chip.agent-chip .chip-icon { color: #b8860b; }

/* Persona chip: which lens answered. Colour-coded so the two are tellable at a
   glance without reading — analyst teal, strategist amber. */
.chip.persona-chip { font-weight: 600; letter-spacing: 0.01em; }
.chip.persona-chip.analyst {
  color: #0f766e;
  border-color: rgba(15, 118, 110, 0.35);
  background: rgba(15, 118, 110, 0.07);
}
.chip.persona-chip.strategist {
  color: #a35a00;
  border-color: rgba(163, 90, 0, 0.35);
  background: rgba(163, 90, 0, 0.07);
}

/* spinner */

.spinner {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid rgba(0, 0, 0, 0.10);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================= status strip ============================= */

#status-strip {
  flex: 0 0 auto;
  max-width: var(--content-w);
  width: 100%;
  margin: 0 auto;
  padding: 4px 16px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.tool-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.tool-status #tool-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}

.agent-badge-wrap { position: relative; }

#agent-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid rgba(79, 124, 255, 0.4);
  color: var(--text);
  font-size: 12px;
}
#agent-badge:hover { background: var(--bg-3); }
#agent-badge.pulse { animation: pulse 1.6s ease-out infinite; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(79, 124, 255, 0.45); }
  70% { box-shadow: 0 0 0 9px rgba(79, 124, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(79, 124, 255, 0); }
}

.agent-list {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 260px;
  max-width: 380px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(20, 30, 50, 0.16);
  padding: 6px;
  z-index: 20;
}

.agent-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12.5px;
}
.agent-row:hover { background: var(--bg-3); }

.agent-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-ms { color: var(--text-faint); font-size: 11px; }

.agent-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
}
.agent-dot.running { background: var(--accent-2); animation: dotblink 1.1s ease-in-out infinite; }
.agent-dot.done { background: var(--ok); }
.agent-dot.error { background: var(--danger); }

@keyframes dotblink { 50% { opacity: 0.35; } }

/* ============================= composer ============================= */

#composer {
  flex: 0 0 auto;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom));
}

.composer-box {
  max-width: var(--content-w);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 10px 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.07);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within {
  border-color: #d4d4d9;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05), 0 12px 34px rgba(0, 0, 0, 0.09);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.attach-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
.attach-btn:hover { background: var(--bg-3); color: var(--accent-2); }

.composer-hint {
  max-width: var(--content-w);
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

/* attachment previews in the composer */
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 2px;
}
.att-item { position: relative; }
.att-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}
.att-file {
  max-width: 200px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-3);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.att-remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  line-height: 18px;
  text-align: center;
  border: 2px solid var(--bg-2);
}
.composer-err {
  max-width: var(--content-w);
  margin: 0 auto;
  color: var(--danger);
  font-size: 12px;
  display: none;
}
.composer-err.show { display: block; }

/* attachments shown inside a sent user message */
.msg-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.msg-att-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 10px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  display: block;
}
.msg-att-file {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg-2);
  font-size: 13px;
}
.msg-text { white-space: pre-wrap; overflow-wrap: break-word; }

/* drag-and-drop overlay */
#drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  backdrop-filter: blur(1px);
  pointer-events: none;
}
.drop-inner {
  padding: 20px 32px;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  background: var(--bg-2);
  color: var(--accent-2);
  font-size: 15px;
  font-weight: 600;
}

#input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  max-height: 200px;
  padding: 4px 2px;
}
#input::placeholder { color: var(--text-faint); }

.composer-controls { display: flex; align-items: center; gap: 8px; }

/* --- custom dropdowns (persona / effort) --- */

.dd { position: relative; }

.dd-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 9px 0 10px;
  background: var(--bg-3);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.dd-btn:hover { background: #e2e2e5; color: var(--text); }
/* An explicit non-Auto pick is a deliberate act — make it read as one. */
.dd-btn.picked { color: var(--text); font-weight: 600; }

.dd-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}
.dd-icon svg { width: 100%; height: 100%; }

.dd-caret {
  display: inline-flex;
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  color: var(--text-faint);
}
.dd-caret svg { width: 100%; height: 100%; }

.dd-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  min-width: 172px;
  padding: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06), 0 16px 40px rgba(0, 0, 0, 0.14);
  z-index: 30;
}

.dd-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--text);
  text-align: start;
  transition: background 0.1s;
}
.dd-item:hover { background: var(--bg-3); }
.dd-item.selected { background: var(--accent-soft); }
.dd-item .dd-icon { width: 15px; height: 15px; color: var(--text-dim); }
.dd-item.selected .dd-icon { color: var(--accent-2); }

.dd-item-label { flex: 1; }

/* effort signal bars */
.dd-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  flex: 0 0 auto;
}
.dd-bars i {
  width: 3px;
  border-radius: 2px;
  background: var(--border);
}
.dd-bars i:nth-child(1) { height: 5px; }
.dd-bars i:nth-child(2) { height: 8px; }
.dd-bars i:nth-child(3) { height: 11px; }
.dd-bars i.on { background: var(--text-dim); }
.dd-bars i.hot.on { background: var(--accent); }
.dd-item.selected .dd-bars i.on { background: var(--accent-2); }

#send {
  background: var(--accent);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 999px;
  height: 32px;
  padding: 0 18px;
  transition: background 0.15s;
}
#send:hover { background: var(--accent-2); }
#send.stop { background: var(--danger); }
#send.stop:hover { background: #ff7676; }

/* ============================= markdown content ============================= */

.md { min-width: 0; overflow-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }

.md p { margin: 0 0 0.85em; }
.md h1, .md h2, .md h3, .md h4 {
  margin: 1.3em 0 0.55em;
  line-height: 1.3;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.md h1 { font-size: 1.45em; }
.md h2 { font-size: 1.25em; }
.md h3 { font-size: 1.1em; }
.md h4 { font-size: 1em; }

.md ul, .md ol { margin: 0 0 0.85em; padding-inline-start: 1.5em; }
.md li { margin: 0.25em 0; }
.md li > ul, .md li > ol { margin-bottom: 0; }

.md blockquote {
  border-inline-start: 3px solid var(--border);
  color: var(--text-dim);
  padding: 2px 14px;
  margin: 0 0 0.85em;
}

.md hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }

.md a { color: var(--accent-2); text-decoration: none; }
.md a:hover { text-decoration: underline; }

.md strong { font-weight: 650; }

.md code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--bg-3);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.md pre {
  position: relative;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin: 0 0 0.95em;
  overflow-x: auto;
  direction: ltr;
}
.md pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
}

.code-copy {
  position: absolute;
  top: 7px;
  right: 7px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  opacity: 0;
  transition: opacity 0.15s;
}
.md pre:hover .code-copy { opacity: 1; }
.code-copy:hover { color: var(--text); }

/* tables */

.table-box {
  position: relative;
  margin: 0 0 0.95em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; max-width: 100%; }

.table-tools {
  position: absolute;
  top: 6px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 3;
}
.table-box:hover .table-tools, .table-tools:focus-within { opacity: 1; }

.tbl-btn {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  box-shadow: 0 2px 8px rgba(20, 30, 50, 0.10);
}
.tbl-btn:hover { color: var(--text); background: var(--bg-3); }

.md table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13.5px;
}

.md th, .md td {
  padding: 8px 13px;
  border-bottom: 1px solid var(--border-soft);
  text-align: start;
  vertical-align: top;
}

.md thead th {
  position: sticky;
  top: 0;
  background: var(--bg-3);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  z-index: 2;
}

.md tbody tr:nth-child(even) { background: rgba(52, 120, 246, 0.05); }
.md tbody tr:hover { background: rgba(79, 124, 255, 0.06); }
.md tbody tr:last-child td { border-bottom: none; }

/* mermaid */

.mermaid-out {
  margin: 0 0 0.95em;
  padding: 14px;
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow-x: auto;
  text-align: center;
}
.mermaid-out svg { max-width: 100%; height: auto; }

.mermaid-error {
  font-size: 12px;
  color: var(--danger);
  margin: -0.5em 0 0.95em;
}

/* ============================= responsive ============================= */

@media (max-width: 899px) {
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(300px, 84vw);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(20, 30, 50, 0.18);
  }
  body.sidebar-open #sidebar { transform: none; }

  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(0, 0, 0, 0.5);
  }
  body.sidebar-open #sidebar-overlay { display: block; }

  .msg.user .bubble { max-width: 90%; }
  .chip .chip-label { max-width: 200px; }
  .tool-status #tool-label { max-width: 180px; }
  #thread { padding: 18px 12px 8px; }
  #composer { padding-left: 12px; padding-right: 12px; }
}

/* ============================= daily briefing ============================= */
/* A distinct reading surface. Paper-white panel, generous measure, no bubbles —
   it must not read as a chat message even at a glance. */

#briefing-view,
#process-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 28px 16px 40px;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(59, 111, 246, 0.05), transparent 70%),
    var(--bg);
}

.briefing-inner {
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px 22px;
  box-shadow: 0 1px 2px rgba(20, 30, 50, 0.04), 0 8px 24px rgba(20, 30, 50, 0.05);
}

.briefing-head { border-bottom: 1px solid var(--border-soft); padding-bottom: 14px; margin-bottom: 18px; }

.briefing-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.briefing-date { font-size: 22px; font-weight: 680; line-height: 1.25; margin-top: 3px; }

.briefing-meta { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.briefing-meta.is-error { color: var(--delta-bad); }

.briefing-body > :first-child { margin-top: 0; }
.briefing-body h2 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 26px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border-soft);
}
.briefing-body ul { margin: 6px 0; padding-left: 20px; }
.briefing-body li { margin: 4px 0; }
.briefing-body p { margin: 8px 0; }
/* The headline sentence under the KPI row — the one line he must not miss. */
.briefing-body > p:first-of-type strong { font-size: 16.5px; line-height: 1.45; }

.brief-error {
  background: #fdf1f0;
  border: 1px solid #f3c9c6;
  color: var(--delta-bad);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.briefing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  border-radius: 9px;
  padding: 8px 16px;
}
.btn-primary:hover { background: var(--accent-2); }

.btn-ghost {
  background: var(--bg-3);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 8px 14px;
}
.btn-ghost:hover { color: var(--text); border-color: #d4d4d9; }
.btn-ghost:disabled { opacity: 0.5; cursor: default; }

/* ----------------------------- KPI stat tiles -----------------------------
   A row of headline numbers, not a chart. Value dominates; the delta is a
   supporting cue carrying an arrow glyph AND a named comparison, so colour is
   never the only channel. Proportional figures on the value (tabular-nums makes
   large numbers look loose); tabular only where digits must align in columns. */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 10px;
  margin: 4px 0 22px;
}

.kpi-tile {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 13px 11px;
  min-width: 0;
}

.kpi-label {
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.kpi-value {
  font-size: 25px;
  font-weight: 650;
  line-height: 1.15;
  margin-top: 5px;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  font-size: 12.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.kpi-delta.good { color: var(--delta-good); }
.kpi-delta.bad { color: var(--delta-bad); }
.kpi-delta.flat { color: var(--text-faint); }
.kpi-arrow { font-size: 9px; line-height: 1; }

.kpi-note { font-size: 11px; color: var(--text-faint); margin-top: 3px; line-height: 1.3; }

/* Unparseable ```kpi block: keep it visible as code rather than hide the numbers. */
pre.kpi-raw { border-left: 3px solid var(--danger); }

/* ----------------------------- line diffs -----------------------------
   Used in two places: ```diff fences in chat (the push flow) and the Process
   page's "Show changes" view. Color never carries the meaning alone — the
   +/− prefix characters stay in the text. */

.diff-pre {
  direction: ltr; /* diff markers lead each line even when the content is Arabic */
}
.canvas-diff .diff-pre {
  background: var(--bg-code);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 13px 15px;
  margin: 0 0 0.95em;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
}
.diff-line {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  /* Lines stay LTR so the +/− gutter is always on the left; Arabic renders as
     RTL runs inside the line, GitHub-style. */
  padding: 0 6px;
  border-radius: 3px;
}
.diff-line.diff-add { background: rgba(31, 157, 99, 0.13); color: #14532d; }
.diff-line.diff-del { background: rgba(229, 72, 77, 0.11); color: #991b1b; text-decoration: line-through; text-decoration-color: rgba(153, 27, 27, 0.35); }
.diff-line.diff-hunk { color: var(--accent-2); margin-top: 8px; }
.diff-line.diff-hunk:first-child { margin-top: 0; }

@media (max-width: 760px) {
  #briefing-view, #process-view { padding: 14px 10px 32px; }
  .briefing-inner { padding: 18px 16px 16px; border-radius: 12px; }
  .briefing-date { font-size: 19px; }
  .kpi-row { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 8px; }
  .kpi-value { font-size: 22px; }
}

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

#side-tabs {
  display: flex;
  gap: 2px;
  background: var(--bg-3);
  border-radius: 10px;
  padding: 3px;
}
#side-tabs button {
  flex: 1;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  transition: background 0.12s, color 0.12s;
}
#side-tabs button:hover { color: var(--text); }
#side-tabs button.active {
  background: var(--bg-2);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.side-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane-action { padding: 2px 12px 8px; }

.proc-unsaved {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #a35a00;
  background: rgba(163, 90, 0, 0.1);
  border-radius: 999px;
  padding: 1px 7px;
}

/* ============================= process canvas ============================= */
/* Sits between the topbar and the thread: the chart stays visible while the
   chat below edits it. */

#canvas {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  max-height: 52vh;
  min-height: 120px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-2);
}

.canvas-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12.5px;
}
#canvas-title { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.canvas-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #a35a00;
  background: rgba(163, 90, 0, 0.1);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.canvas-spacer { flex: 1; }

#canvas-compare {
  background: var(--bg-3);
  border: none;
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  padding: 5px 9px;
  cursor: pointer;
}
#canvas-compare:hover { color: var(--text); }

.btn-sm { padding: 5px 12px !important; font-size: 12px !important; border-radius: 999px !important; }

.canvas-x {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 16px;
  line-height: 1;
  color: var(--text-faint);
}
.canvas-x:hover { background: var(--bg-3); color: var(--text); }

.canvas-zoom {
  display: flex;
  align-items: center;
  gap: 1px;
  background: var(--bg-3);
  border-radius: 999px;
  padding: 2px;
}
.canvas-zoom button {
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  padding: 3px 8px;
  line-height: 1.4;
  min-width: 26px;
}
.canvas-zoom button:hover { background: var(--bg-2); color: var(--text); }
#canvas-zoom-pct { font-variant-numeric: tabular-nums; min-width: 46px; }

.canvas-chart {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 16px 14px;
  text-align: center;
}
/* `zoom` scales layout size too, so the scroll area follows the zoom level. */
.canvas-chart > * { zoom: var(--cz, 1); }
.canvas-chart .mermaid-out {
  margin: 0;
  border: none;
  background: none;
  padding: 0;
}
.canvas-chart svg { display: block; margin: 0 auto; }
.canvas-chart pre { text-align: left; font-size: 12px; color: var(--text-faint); }

.canvas-diff {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 10px 16px 14px;
}

@media (max-width: 899px) {
  #canvas { max-height: 44vh; }
}

/* ============================= print (briefing PDF) ============================= */
/* "Download PDF" = window.print(): only the open briefing is printed, via the
   browser's save-as-PDF (correct Arabic shaping, tables, KPI tiles). */

@media print {
  #sidebar, #sidebar-overlay, #topbar, #composer, #status-strip, #canvas,
  #thread, .briefing-actions, #drop-overlay { display: none !important; }
  #app, #main { display: block; height: auto; overflow: visible; }
  #briefing-view {
    position: static;
    overflow: visible;
    padding: 0;
    background: none;
  }
  .briefing-inner {
    border: none;
    box-shadow: none;
    max-width: 100%;
    padding: 0;
  }
}

/* ============================= canvas mode (Stitch layout) ============================= */
/* Canvas open on desktop: big chart on the left, the chat docked as a right
   panel. The chart is the primary surface; the chat is the tool that edits it. */

@media (min-width: 900px) {
  #main.canvas-mode {
    display: grid;
    grid-template-columns: minmax(0, 1fr) clamp(340px, 32vw, 440px);
    grid-template-rows: auto minmax(0, 1fr) auto auto;
  }
  #main.canvas-mode > #topbar { grid-column: 1 / -1; }
  #main.canvas-mode > #canvas {
    grid-column: 1;
    grid-row: 2 / 5;
    max-height: none;
    border-bottom: none;
    border-right: 1px solid var(--border-soft);
    min-height: 0;
  }
  #main.canvas-mode > #thread { grid-column: 2; grid-row: 2; }
  #main.canvas-mode > #status-strip { grid-column: 2; grid-row: 3; }
  #main.canvas-mode > #composer { grid-column: 2; grid-row: 4; }
  #main.canvas-mode .composer-hint { display: none; }
  #main.canvas-mode .canvas-bar { flex-wrap: wrap; }
  /* Narrow chat column: input gets its own full row, controls tuck below it. */
  #main.canvas-mode .composer-row { flex-wrap: wrap; }
  #main.canvas-mode #input { flex: 1 1 100%; order: -1; }
  #main.canvas-mode .composer-controls { margin-left: auto; }

  /* Collapsible sidebar: the hamburger toggles it; canvas mode starts collapsed. */
  #sidebar { transition: flex-basis 0.2s ease, width 0.2s ease; }
  body.side-collapsed #sidebar {
    width: 0;
    flex-basis: 0;
    min-width: 0;
    overflow: hidden;
    border-right: none;
  }
}

/* compare legend */
.canvas-legend {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 7px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 12px;
}
.leg-title { font-weight: 650; color: var(--text-dim); }
.leg { border-radius: 999px; padding: 2px 10px; font-weight: 600; }
.leg-add { color: #166534; background: #dcfce7; }
.leg-chg { color: #92400e; background: #fef3c7; }
.leg-del { color: #991b1b; background: #fee2e2; text-decoration: line-through; }
.leg-none { color: var(--text-faint); }
.leg-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 11px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.leg-btn:hover { color: var(--text); background: var(--bg-3); }


/* ---- policy deploy card (admin only) ---- */
#policy-card { margin: 8px 10px 4px; padding: 10px 12px; border: 1px solid var(--border, #2a2a2e); border-radius: 10px; font-size: 12.5px; line-height: 1.55; }
#policy-card .pol-row, #policy-panel .pol-row { margin: 4px 0; }
#policy-card .pol-muted, #policy-panel .pol-muted { opacity: .65; }
#policy-card .pol-flag, #policy-panel .pol-flag { color: #e6a23c; }
#policy-card .pol-err, #policy-panel .pol-err { color: #e05b5b; }
#policy-card .pol-actions, #policy-panel .pol-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
#policy-card button, #policy-panel .pol-actions button { font: inherit; padding: 7px 14px; border-radius: 9px; border: 1px solid var(--border, #2a2a2e); background: transparent; color: inherit; cursor: pointer; white-space: nowrap; }
#policy-card button:disabled, #policy-panel .pol-actions button:disabled { opacity: .4; cursor: not-allowed; }
#policy-card .pol-deploy, #policy-panel .pol-deploy { background: #1e9e50 !important; border-color: #1e9e50 !important; color: #fff !important; font-weight: 700; padding: 7px 18px; }
#policy-card .pol-deploy:not(:disabled):hover, #policy-panel .pol-deploy:not(:disabled):hover { background: #23b95e !important; }
#policy-card .pol-deploy .pwr, #policy-panel .pol-deploy .pwr { font-size: 14px; margin-inline-end: 6px; }


/* ---- policy visual diff ---- */
#pdiff-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; display: flex; align-items: center; justify-content: center; }
.pdiff-box { background: var(--bg, #17171a); border: 1px solid var(--border, #2a2a2e); border-radius: 14px; width: min(720px, 94vw); max-height: 86vh; display: flex; flex-direction: column; }
.pdiff-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border, #2a2a2e); }
.pdiff-chips { display: inline-flex; gap: 6px; }
.pdiff-head .chip { padding: 1px 8px; border-radius: 20px; font-size: 12px; }
.chip-add { background: rgba(30,158,80,.18); color: #4cd07d; }
.chip-del { background: rgba(224,91,91,.15); color: #e05b5b; }
.chip-mod { background: rgba(230,162,60,.15); color: #e6a23c; }
.pdiff-close { margin-inline-start: auto; background: none; border: none; color: inherit; font-size: 16px; cursor: pointer; }
.pdiff-body { overflow-y: auto; padding: 12px 16px; }
.pdiff-rule { border: 1px solid var(--border, #2a2a2e); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 12.5px; line-height: 1.6; }
.pdiff-add { border-inline-start: 4px solid #1e9e50; }
.pdiff-del { border-inline-start: 4px solid #e05b5b; opacity: .8; }
.pdiff-mod { border-inline-start: 4px solid #e6a23c; }
.pdiff-title { font-weight: 700; margin: 4px 0 6px; }
.pdiff-k { opacity: .6; }
.pdiff-old { color: #e05b5b; text-decoration: line-through; }
.pdiff-new { color: #4cd07d; }

#policy-panel { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 55; display: flex; align-items: center; justify-content: center; }
#policy-card .pol-open { width: 100%; font-weight: 600; }
.pol-new { color: #4cd07d; }
