/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --card: #ffffff;
  --card-2: #faf9f6;
  --ink: #1b1f24;
  --ink-2: #52514e;
  --muted: #6f6e69;
  --line: #e7e4dc;
  --brand: #d9480f;
  --brand-2: #f08c00;
  --brand-ink: #b8400d;
  --brand-soft: #fff1e8;
  --agent-bubble: #f2f0ea;
  --ok: #2f855a;
  --ok-soft: #e6f6ec;
  --warn: #b7791f;
  --warn-soft: #fff8e1;
  --bad: #c53030;
  --bad-soft: #fff5f5;
  --shadow: 0 1px 2px rgba(17, 17, 17, 0.04), 0 4px 16px rgba(17, 17, 17, 0.05);
  --shadow-lg: 0 12px 40px rgba(17, 17, 17, 0.18);
  --radius: 14px;
  --topbar-h: 60px;
  --tabbar-h: 0px;

  /* chart roles (validated categorical slots 1-4, chart chrome) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Dark is its own set of steps, not an automatic inversion. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0f0f0e; --card: #1a1a19; --card-2: #212120; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a988f;
    --line: #2c2c2a; --brand: #f76707; --brand-ink: #ff8a3d; --brand-soft: #2a1b11; --agent-bubble: #262624;
    --ok: #4ade80; --ok-soft: #12261a; --warn: #f6c35b; --warn-soft: #2a2312; --bad: #f87171; --bad-soft: #2a1414;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --grid: #2c2c2a; --axis: #383835;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --card: #1a1a19; --card-2: #212120; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --brand: #f76707; --brand-ink: #ff8a3d; --brand-soft: #2a1b11; --agent-bubble: #262624;
  --ok: #4ade80; --ok-soft: #12261a; --warn: #f6c35b; --warn-soft: #2a2312; --bad: #f87171; --bad-soft: #2a1414;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --grid: #2c2c2a; --axis: #383835;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; -webkit-font-smoothing: antialiased; }
h1 { font-size: clamp(1.35rem, 2.5vw, 1.75rem); margin: 0 0 0.25rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0; }
h3 { margin: 0 0 0.75rem; font-size: 1rem; }
h4 { margin: 1.1rem 0 0.4rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--bad); }
.loading { color: var(--muted); font-style: italic; }
[hidden] { display: none !important; }
svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon { display: inline-flex; vertical-align: -0.2em; }
.icon svg { width: 1em; height: 1em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
kbd { font: 600 0.72rem/1 ui-monospace, monospace; padding: 0.15rem 0.35rem; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--card); }

/* ---------- buttons & controls ---------- */
button, .button {
  font: inherit; font-weight: 550; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
  padding: 0.6rem 1.05rem; display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  text-decoration: none; transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s; color: inherit;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; box-shadow: 0 4px 14px rgba(217, 72, 15, 0.28); }
.primary:hover:not(:disabled) { box-shadow: 0 6px 20px rgba(217, 72, 15, 0.38); }
.primary.big { padding: 0.85rem 1.6rem; font-size: 1.02rem; border-radius: 12px; }
.secondary { background: var(--card); border-color: var(--line); color: var(--ink); }
.secondary:hover:not(:disabled) { border-color: var(--brand); color: var(--brand-ink); }
.danger { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.danger:hover:not(:disabled) { border-color: var(--bad); }
.link { background: none; color: var(--ink-2); padding: 0.4rem 0.2rem; }
.link:hover { color: var(--brand-ink); }
.icon-btn { background: transparent; border: 1px solid var(--line); padding: 0.45rem; border-radius: 10px; color: var(--ink-2); }
.icon-btn:hover { color: var(--brand-ink); border-color: var(--brand); }
.row, .actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.row { margin-top: 1.25rem; }

.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 0.38rem 0.85rem;
  font-size: 0.86rem; font-weight: 500; color: var(--ink-2);
}
.chip:hover { border-color: var(--brand); color: var(--brand-ink); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--card); }
.chip-count { font-size: 0.75rem; opacity: 0.7; margin-left: 0.15rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.75rem 0 1rem; }

.search {
  font: inherit; flex: 1; min-width: 0; max-width: 420px; padding: 0.6rem 0.9rem; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
}
.toolbar { display: flex; gap: 0.6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.pill { display: inline-block; padding: 0.18rem 0.65rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; background: var(--card-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.order_enquiry { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.follow_up_required { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.not_interested { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.avatar {
  width: 42px; height: 42px; border-radius: 12px; display: inline-grid; place-items: center; flex: none;
  font-weight: 700; font-size: 0.9rem; color: #fff; background: linear-gradient(135deg, #6250d6, #2a78d6);
}
.avatar.a1 { background: linear-gradient(135deg, #1baf7a, #0f8a5f); }
.avatar.a2 { background: linear-gradient(135deg, #e87ba4, #c2477a); }
.avatar.a3 { background: linear-gradient(135deg, #eda100, #c97a00); }
.avatar.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 0.78rem; }
.agent-avatar { background: linear-gradient(135deg, var(--brand), var(--brand-2)); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card > header { margin-bottom: 0.9rem; }
.card > header h3 { margin: 0; }
.card > header .muted { font-size: 0.85rem; margin-top: 0.15rem; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1.25rem 0.9rem; background: var(--card); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.65rem; padding: 0 0.35rem; }
.logo { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 4px 12px rgba(217, 72, 15, 0.3); }
.logo svg { width: 26px; height: 26px; stroke: none; }
.logo svg path { stroke: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 1.05rem; color: var(--brand-ink); }
.brand-text small { color: var(--muted); font-size: 0.78rem; }

.nav { display: flex; flex-direction: column; gap: 0.2rem; }
.nav-item { justify-content: flex-start; gap: 0.75rem; padding: 0.65rem 0.8rem; background: none; color: var(--ink-2); font-weight: 500; }
.nav-item:hover { background: var(--card-2); color: var(--ink); }
.nav-item[aria-current] { background: var(--brand-soft); color: var(--brand-ink); font-weight: 650; }
.nav-item svg { width: 1.25rem; height: 1.25rem; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.agent-card { display: flex; gap: 0.65rem; align-items: center; padding: 0.75rem; border-radius: 12px; background: var(--card-2); border: 1px solid var(--line); }
.agent-card div { display: flex; flex-direction: column; line-height: 1.2; }
.agent-card small { color: var(--muted); font-size: 0.78rem; }
.llm-status { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.78rem; color: var(--ink-2); padding: 0.3rem 0.7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--card); white-space: nowrap; }
.llm-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-good) 25%, transparent); }
.llm-status.mock .dot { background: var(--status-warning); box-shadow: 0 0 0 3px color-mix(in srgb, var(--status-warning) 25%, transparent); }
.llm-status.offline .dot { background: var(--status-critical); }

.content { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; justify-content: flex-end; gap: 0.75rem;
  padding: 0 1.75rem; position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: blur(10px);
}
.topbar .brand, .topbar .llm-status { display: none; }
.topbar-right { display: flex; gap: 0.6rem; align-items: center; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle .moon { display: block; }
}

main { width: 100%; max-width: 1280px; margin: 0 auto; padding: 0.25rem 1.75rem 2.5rem; }
.screen { animation: enter 0.25s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head .muted { max-width: 60ch; }

/* ---------- empty state & toasts ---------- */
.empty-state { text-align: center; padding: 3.5rem 1rem; display: flex; flex-direction: column; align-items: center; gap: 0.6rem; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-state h3 { margin: 0; }
.empty-icon svg { width: 44px; height: 44px; color: var(--brand); }
.toasts { position: fixed; right: 1rem; bottom: calc(1rem + var(--tabbar-h)); display: flex; flex-direction: column; gap: 0.5rem; z-index: 60; }
.toast { display: flex; gap: 0.55rem; align-items: center; padding: 0.7rem 1rem; border-radius: 12px; background: var(--ink); color: var(--card); box-shadow: var(--shadow-lg); font-size: 0.9rem; animation: enter 0.2s ease-out; transition: opacity 0.3s, transform 0.3s; }
.toast.error { background: var(--bad); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* ---------- dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.dash-grid .span-2 { grid-column: span 2; }
.hero-card { display: flex; flex-direction: column; justify-content: center; gap: 0.35rem; position: relative; overflow: hidden; }
.hero-card::after { content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--brand) 18%, transparent), transparent 70%); }
.hero-value { font-size: clamp(2.4rem, 4.5vw, 3.2rem); font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; }
.stat-row { grid-column: span 2; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; gap: 0.2rem; box-shadow: var(--shadow); }
.stat-label { font-size: 0.8rem; color: var(--muted); font-weight: 550; }
.stat-value { font-size: 1.7rem; font-weight: 650; letter-spacing: -0.01em; }
.stat-sub { font-size: 0.8rem; color: var(--muted); }

.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 0.7rem; padding: 0.6rem 0.4rem; border-radius: 10px; cursor: pointer; }
.feed li:hover { background: var(--card-2); }
.feed li div { display: flex; flex-direction: column; text-transform: none; }
.feed li strong { font-weight: 600; font-size: 0.92rem; }
.feed li small { color: var(--muted); }
.feed-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: var(--brand-soft); color: var(--brand-ink); }

/* ---------- charts ---------- */
.viz-bars { display: flex; flex-direction: column; gap: 0.55rem; }
.viz-bar-row { display: grid; grid-template-columns: minmax(90px, 46%) 1fr; gap: 0.7rem; align-items: center; font-size: 0.86rem; }
.viz-bar-label { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viz-bar-track { display: flex; align-items: center; gap: 0.4rem; height: 26px; border-radius: 4px; cursor: default; }
.viz-bar-track:hover .viz-bar, .viz-bar-track:focus .viz-bar { filter: brightness(1.1); }
.viz-bar { height: 16px; background: var(--series-1); border-radius: 0 4px 4px 0; border-left: 1px solid var(--axis); }
.viz-bar-value { font-size: 0.8rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }

.viz-columns { display: grid; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); gap: 0.35rem; height: 190px; }
.viz-col { display: flex; flex-direction: column; min-width: 0; cursor: default; border-radius: 6px; }
.viz-col:hover, .viz-col:focus { background: var(--card-2); }
.viz-col-plot { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; border-bottom: 1px solid var(--axis); min-height: 0; }
.viz-col-bar { width: min(24px, 60%); background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 2px; }
.viz-col-value { font-size: 0.78rem; color: var(--ink-2); margin-bottom: 0.2rem; font-variant-numeric: tabular-nums; }
.viz-col-label { text-align: center; font-size: 0.75rem; color: var(--muted); padding-top: 0.35rem; }

.viz-stack { display: flex; gap: 2px; height: 22px; border-radius: 4px; overflow: hidden; margin: 0.4rem 0 1rem; }
.viz-seg { min-width: 4px; cursor: default; }
.viz-seg:hover, .viz-seg:focus { filter: brightness(1.12); }
.s1 { background: var(--series-1); } .s2 { background: var(--series-2); } .s3 { background: var(--series-3); } .s4 { background: var(--series-4); }
.viz-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.45rem; font-size: 0.88rem; }
.viz-legend li { display: grid; grid-template-columns: 12px 1fr auto 3rem; gap: 0.55rem; align-items: center; color: var(--ink-2); }
.viz-legend strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.viz-legend small { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.viz-swatch { width: 12px; height: 12px; border-radius: 3px; }

.viz-tooltip { position: absolute; z-index: 80; pointer-events: none; display: flex; flex-direction: column; gap: 0.1rem; padding: 0.5rem 0.7rem; border-radius: 8px; background: var(--ink); color: var(--card); font-size: 0.8rem; box-shadow: var(--shadow-lg); max-width: 260px; }
.viz-data { margin-top: 0.9rem; font-size: 0.82rem; }
.viz-data summary { color: var(--muted); cursor: pointer; }
.viz-data table { margin-top: 0.5rem; font-size: 0.82rem; }
.viz-data th, .viz-data td { padding: 0.35rem 0.5rem; }

/* ---------- start screen ---------- */
.retailer-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 0.9rem; }
.retailer-list .retailer {
  text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 1.05rem; display: flex; flex-direction: column; align-items: stretch; gap: 0.6rem; box-shadow: var(--shadow); font-weight: 400;
}
.retailer-list .retailer:hover { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); transform: translateY(-2px); }
.retailer-list .retailer[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent); }
.retailer-top { display: flex; gap: 0.75rem; align-items: center; }
.retailer-top > span:last-child { display: flex; flex-direction: column; }
.retailer-list .retailer small { color: var(--muted); }
.retailer-list .retailer .area { font-size: 0.85rem; }
.tags { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.cat-tag { font-size: 0.74rem; padding: 0.15rem 0.55rem; border-radius: 6px; background: var(--card-2); border: 1px solid var(--line); color: var(--ink-2); text-transform: capitalize; }
.last-call { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: var(--ink-2); border-top: 1px dashed var(--line); padding-top: 0.6rem; }
.start-bar { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; margin-top: 1.4rem; }

/* ---------- live call ---------- */
.call-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1rem; align-items: start; }
.call-main { display: flex; flex-direction: column; height: calc(100dvh - var(--topbar-h) - 2.75rem - var(--tabbar-h)); min-height: 520px; padding: 1rem 1.1rem; }
.call-header { display: flex; align-items: center; gap: 0.75rem; padding-bottom: 0.85rem; border-bottom: 1px solid var(--line); }
.call-who { flex: 1; min-width: 0; }
.call-who h2, .call-who p { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-who p { font-size: 0.86rem; }
.live { display: inline-flex; align-items: center; gap: 0.4rem; font-variant-numeric: tabular-nums; font-size: 0.85rem; font-weight: 600; padding: 0.3rem 0.65rem; border-radius: 999px; background: var(--bad-soft); color: var(--bad); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: 0.25; } }
.order-toggle { display: none; }
.order-toggle.flash, .order-panel.flash { animation: flash 0.9s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--status-good) 55%, transparent); } 100% { box-shadow: 0 0 0 14px transparent; } }

.memory { display: flex; gap: 0.7rem; align-items: flex-start; margin-top: 0.8rem; padding: 0.7rem 0.85rem; border-radius: 12px; background: color-mix(in srgb, var(--series-1) 9%, var(--card)); border: 1px solid color-mix(in srgb, var(--series-1) 25%, transparent); font-size: 0.88rem; }
.memory strong { margin-right: 0.45rem; }
.memory p { margin-top: 0.3rem; color: var(--ink-2); }
.memory-icon { color: var(--series-1); padding-top: 0.1rem; }
.banner { display: flex; gap: 0.55rem; align-items: center; background: var(--warn-soft); color: var(--warn); padding: 0.6rem 0.85rem; border-radius: 10px; margin-top: 0.75rem; font-size: 0.88rem; }

.transcript { list-style: none; margin: 0; padding: 1rem 0.25rem 0.5rem; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 0.8rem; scroll-behavior: smooth; }
.msg { display: flex; gap: 0.55rem; align-items: flex-end; max-width: 86%; animation: enter 0.2s ease-out; }
.bubble { padding: 0.65rem 0.9rem; border-radius: 16px; line-height: 1.45; display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.msg-meta { font-size: 0.7rem; color: var(--muted); }
.msg.agent { align-self: flex-start; }
.msg.agent .bubble { background: var(--agent-bubble); border-bottom-left-radius: 5px; }
.msg.retailer { align-self: flex-end; }
.msg.retailer .bubble { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border-bottom-right-radius: 5px; }
.msg.retailer .msg-meta { color: rgba(255, 255, 255, 0.8); align-self: flex-end; }
.msg.error { align-self: center; max-width: 100%; }
.msg.error .bubble { background: var(--bad-soft); color: var(--bad); text-align: center; flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: center; }
.msg.error .msg-meta { display: none; }
.msg.error button { padding: 0.25rem 0.8rem; background: var(--bad); color: #fff; }
.typing { display: inline-flex; gap: 4px; padding: 0.3rem 0.1rem; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; } .typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-4px); opacity: 1; } }

/* agent trace: the tool calls behind a reply */
.trace { font-size: 0.78rem; margin-top: 0.2rem; }
.trace summary { cursor: pointer; color: var(--ink-2); display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--card); border: 1px solid var(--line); list-style: none; }
.trace summary::-webkit-details-marker { display: none; }
.trace[open] summary { border-color: var(--series-1); color: var(--series-1); }
.trace ol { margin: 0.5rem 0 0; padding: 0 0 0 1.1rem; display: flex; flex-direction: column; gap: 0.4rem; }
.trace li { display: flex; flex-direction: column; color: var(--ink-2); }
.trace li.failed strong { color: var(--bad); }
.trace code { font-size: 0.72rem; color: var(--muted); word-break: break-all; }
.tool-chips { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.15rem; }
.tool-chip { display: inline-flex; gap: 0.25rem; align-items: center; font-size: 0.72rem; color: var(--ink-2); padding: 0.1rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); background: var(--card); }

.interim { min-height: 1.3em; color: var(--muted); font-style: italic; margin: 0.25rem 0; text-align: right; font-size: 0.9rem; }

.suggestions { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.4rem 0 0.7rem; }
.suggestions .chip { text-transform: none; font-size: 0.82rem; padding: 0.32rem 0.75rem; }
.suggestions.disabled { opacity: 0.5; pointer-events: none; }

.composer { display: flex; gap: 0.9rem; align-items: center; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.composer-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.mic-row { display: flex; align-items: center; gap: 0.9rem; flex-wrap: wrap; font-size: 0.86rem; }
.mic-label { font-weight: 650; }
.kbd-hint { margin-left: auto; color: var(--muted); font-size: 0.76rem; }
.toggle { color: var(--ink-2); display: inline-flex; gap: 0.45rem; align-items: center; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { width: 34px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s; }
.toggle input:checked + .switch { background: var(--status-good); }
.toggle input:checked + .switch::after { transform: translateX(14px); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--brand); outline-offset: 2px; }

.mic {
  width: 68px; height: 68px; border-radius: 50%; padding: 0; flex: none; color: #fff; position: relative;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 6px 18px rgba(217, 72, 15, 0.35);
}
.mic svg.mic-glyph { width: 28px; height: 28px; }
.mic .wave { display: none; gap: 3px; align-items: center; height: 26px; }
.mic .wave i { width: 4px; height: 100%; border-radius: 2px; background: #fff; animation: wave 0.9s ease-in-out infinite; }
.mic .wave i:nth-child(2) { animation-delay: -0.7s; } .mic .wave i:nth-child(3) { animation-delay: -0.45s; }
.mic .wave i:nth-child(4) { animation-delay: -0.2s; } .mic .wave i:nth-child(5) { animation-delay: -0.55s; }
@keyframes wave { 0%, 100% { transform: scaleY(0.3); } 50% { transform: scaleY(1); } }
.mic[data-state="listening"] .mic-glyph, .mic[data-state="speaking"] .mic-glyph { display: none; }
.mic[data-state="listening"] .wave, .mic[data-state="speaking"] .wave { display: inline-flex; }
.mic[data-state="listening"] { background: #d03b3b; animation: pulse 1.3s infinite; }
.mic[data-state="speaking"] { background: linear-gradient(135deg, #0f9d58, #1baf7a); box-shadow: 0 6px 18px rgba(15, 157, 88, 0.35); }
.mic[data-state="thinking"] { background: linear-gradient(135deg, #b7791f, #eda100); }
.mic[data-state="thinking"]::after { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 3px solid transparent; border-top-color: #eda100; animation: spin 0.9s linear infinite; }
.mic[data-state="unavailable"] { background: #a0a3a8; box-shadow: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(208, 59, 59, 0.5); } 70% { box-shadow: 0 0 0 16px rgba(208, 59, 59, 0); } 100% { box-shadow: 0 0 0 0 rgba(208, 59, 59, 0); } }
@keyframes spin { to { transform: rotate(360deg); } }

.text-form { display: flex; gap: 0.5rem; }
.text-form input { flex: 1; min-width: 0; font: inherit; padding: 0.65rem 0.9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2); color: var(--ink); }
.text-form input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }

/* live order panel */
.order-panel { position: sticky; top: calc(var(--topbar-h) + 0.25rem); max-height: calc(100dvh - var(--topbar-h) - 2.75rem); overflow-y: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; padding-bottom: 0.9rem; margin-bottom: 0.9rem; border-bottom: 1px solid var(--line); }
.panel-head > div { display: flex; flex-direction: column; gap: 0.1rem; }
#order-close { display: none; }
.order-net { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.order-savings { font-size: 0.85rem; color: var(--ok); font-weight: 600; }
.cap-list { list-style: none; margin: 0; padding: 0; font-size: 0.9rem; }
.cap-list li { padding: 0.45rem 0; border-bottom: 1px dashed var(--line); }
.cap-list li small { display: block; color: var(--muted); }
.cap-list li small.expired { color: var(--bad); }
.cap-list li small.active { color: var(--ok); }
.cap-list .empty, #cap-quote .empty { color: var(--muted); font-style: italic; border: none; font-size: 0.9rem; }
.nudges { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.75rem; }
.nudge { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.6rem 0.75rem; border-radius: 10px; background: var(--warn-soft); color: var(--ink); font-size: 0.85rem; line-height: 1.4; border: 1px solid color-mix(in srgb, var(--status-warning) 40%, transparent); }
.nudge .icon { color: var(--warn); padding-top: 0.1rem; }
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 40; animation: enter 0.2s; }

/* quote breakdown (panel, summary, detail) */
.quote-lines { list-style: none; margin: 0 0 0.6rem; padding: 0; font-size: 0.9rem; }
.quote-lines li { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.4rem 0; border-bottom: 1px dashed var(--line); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quote-totals { display: grid; grid-template-columns: 1fr auto; gap: 0.35rem 0.75rem; margin: 0; font-size: 0.88rem; }
.quote-totals dt { color: var(--ink-2); display: flex; gap: 0.35rem; align-items: center; }
.quote-totals dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.quote-totals .saving { color: var(--ok); font-weight: 600; }
.quote-totals .net { font-weight: 700; font-size: 1rem; color: var(--ink); padding-top: 0.4rem; border-top: 1px solid var(--line); }

/* ---------- summary & detail ---------- */
.summary-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; margin-bottom: 1rem; }
.summary-hero { grid-row: span 2; display: flex; flex-direction: column; gap: 0.9rem; }
.who { display: flex; gap: 0.75rem; align-items: center; }
.who > div { display: flex; flex-direction: column; min-width: 0; }
.hero-meta { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; font-size: 0.85rem; }
.sentiment { font-size: 0.78rem; font-weight: 600; padding: 0.18rem 0.6rem; border-radius: 999px; border: 1px solid var(--line); }
.sentiment.positive { color: var(--ok); } .sentiment.negative { color: var(--bad); }
.overview { font-size: 1.02rem; line-height: 1.55; }
.next-action { display: flex; gap: 0.65rem; padding: 0.85rem 1rem; border-radius: 12px; background: var(--brand-soft); }
.next-action .icon { color: var(--brand-ink); padding-top: 0.1rem; }
.next-action div { display: flex; flex-direction: column; gap: 0.15rem; }
.summary-hero .actions { margin-top: auto; }
.summary-hero .actions button { padding: 0.45rem 0.8rem; font-size: 0.88rem; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 0.6rem 1rem; margin: 0; font-size: 0.92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-transform: none; }
ul.plain { margin: 0; padding-left: 1.1rem; }
details { margin-top: 1rem; }
details > summary { cursor: pointer; color: var(--ink-2); font-size: 0.88rem; }
details pre { background: var(--card-2); border: 1px solid var(--line); padding: 0.75rem; border-radius: 10px; overflow-x: auto; font-size: 0.78rem; }
.transcript.full { height: auto; overflow: visible; padding: 0; }
.back { margin-bottom: 0.75rem; }

/* ---------- history ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem 0.95rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--card-2); }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr { cursor: pointer; transition: background 0.12s; }
.history-table tbody tr:hover { background: var(--brand-soft); }
.history-table td:nth-child(4) { font-size: 0.88rem; color: var(--ink-2); max-width: 320px; }

/* ---------- catalogue ---------- */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0.9rem; }
.product { display: flex; flex-direction: column; gap: 0.45rem; padding: 1.05rem; }
.product header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.2rem; }
.product h3 { margin: 0; font-size: 1rem; }
.price-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-top: 0.3rem; }
.price { font-size: 1.35rem; font-weight: 700; }
.margin { font-size: 0.78rem; font-weight: 600; color: var(--ok); background: var(--ok-soft); padding: 0.15rem 0.5rem; border-radius: 6px; white-space: nowrap; }
.stock { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.76rem; font-weight: 600; color: var(--ink-2); }
.stock .icon { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; }
.stock .icon svg { width: 12px; height: 12px; stroke-width: 3; }
.stock.in_stock .icon { background: var(--status-good); }
.stock.low_stock .icon { background: var(--status-warning); color: #0b0b0b; }
.stock.out_of_stock .icon { background: var(--status-critical); }
.scheme-tags { list-style: none; margin: 0.25rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.scheme-tags li { display: inline-flex; gap: 0.3rem; align-items: center; font-size: 0.76rem; padding: 0.2rem 0.55rem; border-radius: 6px; background: var(--brand-soft); color: var(--brand-ink); font-weight: 550; cursor: help; }

/* ---------- LLM config ---------- */
.settings-form { max-width: 620px; display: flex; flex-direction: column; gap: 1.1rem; }
.settings-form .banner { margin-top: 0; }
.form-fields { display: flex; flex-direction: column; gap: 1.1rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.field small { font-size: 0.8rem; line-height: 1.4; }
.field a { color: var(--brand-ink); }
.field input, .field select { font: inherit; width: 100%; min-width: 0; padding: 0.6rem 0.9rem; border: 1px solid var(--line); border-radius: 10px; background: var(--card-2); color: var(--ink); }
.field input:focus, .field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.input-row { display: flex; gap: 0.5rem; }
.form-status { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.6rem 0.85rem; border-radius: 10px; font-size: 0.9rem; }
.form-status .icon { padding-top: 0.15rem; }
.form-status.good { background: var(--ok-soft); color: var(--ok); }
.form-status.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .call-layout { grid-template-columns: minmax(0, 1fr); }
  .order-toggle { display: inline-flex; }
  #order-close { display: inline-flex; }
  .order-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 92vw); max-height: none; z-index: 50;
    border-radius: var(--radius) 0 0 var(--radius); transform: translateX(105%); transition: transform 0.25s ease-out; box-shadow: var(--shadow-lg);
  }
  .order-panel.open { transform: none; }
  .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dash-grid .hero-card, .stat-row { grid-column: span 2; }
  .stat-row { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  :root { --topbar-h: 56px; --tabbar-h: calc(64px + env(safe-area-inset-bottom)); }
  .app { grid-template-columns: 1fr; }
  /* the sidebar becomes a bottom tab bar */
  .sidebar {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: var(--tabbar-h); z-index: 30;
    flex-direction: row; padding: 0.35rem 0.5rem env(safe-area-inset-bottom); border-right: none; border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px);
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav-item { flex: 1; flex-direction: column; gap: 0.2rem; padding: 0.45rem 0.2rem; font-size: 0.72rem; }
  .nav-item[aria-current] { background: none; }
  .nav-item[aria-current] svg { background: var(--brand-soft); border-radius: 999px; padding: 0.2rem 0.9rem; box-sizing: content-box; }
  .topbar { justify-content: space-between; padding: 0 1rem; border-bottom: 1px solid var(--line); }
  .topbar .brand { display: flex; padding: 0; }
  .topbar .logo { width: 32px; height: 32px; }
  .topbar .llm-status { display: inline-flex; }
  main { padding: 1rem 1rem calc(var(--tabbar-h) + 1.5rem); }
  .toasts { left: 1rem; }
  .summary-grid { grid-template-columns: 1fr; }
  .summary-hero { grid-row: auto; }
  .start-bar { position: sticky; bottom: calc(var(--tabbar-h) + 0.75rem); align-items: stretch; }
  .start-bar .primary { box-shadow: var(--shadow-lg); }
  .call-main { height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 2rem); min-height: 440px; }
  /* during a live call the tab bar steps aside, so the transcript gets the room */
  body[data-screen="call"] { --tabbar-h: 0px; }
  body[data-screen="call"] .sidebar { display: none; }
}

@media (max-width: 640px) {
  .topbar .llm-status { font-size: 0.7rem; padding: 0.25rem 0.55rem; }
  .dash-grid, .stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .dash-grid > * { grid-column: span 2 !important; }
  .stat { padding: 0.85rem; }
  .stat-value { font-size: 1.4rem; }
  .card { padding: 1rem; }
  .page-head { align-items: stretch; }
  .page-head > .primary { width: 100%; }

  .call-main { padding: 0.75rem; border-radius: 12px; margin: 0 -0.25rem; }
  .call-header { flex-wrap: wrap; gap: 0.55rem; }
  .call-header .avatar { width: 36px; height: 36px; }
  .call-who { flex-basis: calc(100% - 140px); }
  .order-toggle, #end-btn { flex: 1; padding: 0.5rem 0.6rem; font-size: 0.88rem; }
  .memory { padding: 0.45rem 0.7rem; margin-top: 0.6rem; font-size: 0.8rem; align-items: center; }
  .memory p { display: none; }
  .memory .pill { font-size: 0.7rem; }
  .msg { max-width: 94%; }
  .msg.agent .avatar { display: none; }
  .suggestions { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -0.75rem; padding: 0.4rem 0.75rem 0.6rem; }
  .suggestions::-webkit-scrollbar { display: none; }
  .suggestions .chip { flex: none; }
  .composer { gap: 0.65rem; align-items: flex-end; }
  .mic { width: 56px; height: 56px; }
  .kbd-hint { display: none; }
  .mic-row { gap: 0.6rem; font-size: 0.8rem; }

  /* history rows become cards */
  .history-table thead { display: none; }
  .history-table, .history-table tbody, .history-table tr, .history-table td { display: block; width: 100%; }
  .history-table tr { padding: 0.8rem 0.9rem; border-bottom: 1px solid var(--line); }
  .history-table td { border: none; padding: 0.2rem 0; display: flex; justify-content: space-between; gap: 1rem; text-align: right; max-width: none !important; }
  .history-table td::before { content: attr(data-label); color: var(--muted); font-size: 0.78rem; text-align: left; flex: none; }
  .history-table td .who { text-align: left; }
  .kv { grid-template-columns: 1fr; gap: 0.2rem; }
  .kv dd { margin-bottom: 0.6rem; }
  .search { max-width: none; }
}

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

@media print {
  .sidebar, .topbar, .no-print, .toasts, button { display: none !important; }
  .app { display: block; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .summary-grid { grid-template-columns: 1fr; }
}
