/* ── Reset & tokens ──────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --surface:     #1a1d27;
  --surface2:    #22263a;
  --border:      #2e3347;
  --ink:         #e4e8f0;
  --muted:       #6b7280;
  --prod:        #10b981;   /* emerald — Production agent */
  --prod-dim:    #064e3b;
  --log:         #6366f1;   /* indigo — Logistics agent */
  --log-dim:     #1e1b4b;
  --accent:      #f59e0b;   /* amber — system / highlight */
  --good:        #22c55e;
  --bad:         #ef4444;
  --tool:        #38bdf8;   /* sky — tool calls */
  --tool-result: #a78bfa;  /* violet — tool results */
  --system-msg:  #374151;
  --radius:      6px;
  --mono:        "JetBrains Mono", "Fira Code", Consolas, monospace;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.topbar {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-row1 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  min-height: 44px;
}

.topbar-row2 {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px 7px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.topbar h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.topbar-sep { flex: 0 1 12px; }
.topbar-row1 .topbar-sep { flex: 1 1 auto; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

/* ── Demo cases panel ────────────────────────────────────────── */
.demo-cases-wrap {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.demo-cases-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.demo-cases-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.demo-case-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  min-width: 110px;
  max-width: 180px;
  flex: 0 0 auto;
}

.demo-case-btn:hover {
  border-color: var(--accent);
  background: #2a2408;
}

.demo-case-btn.active {
  border-color: var(--accent);
  background: #2a2408;
}

.demo-case-num {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
}

.demo-case-title {
  font-size: 11px;
  color: var(--ink);
  white-space: normal;
  word-break: break-word;
  width: 100%;
}

/* Tooltip со story при ховере */
.demo-case-btn[title] {
  position: relative;
}

.config-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.config-row label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  flex: 0 0 auto;
}

.config-row select,
.config-row input[type="number"] {
  height: 28px;
  padding: 0 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  border-radius: var(--radius);
  width: 80px;
}

.config-row select { width: 96px; }
.config-row #model { width: 142px; }
.config-row #decisionMode { width: 132px; }

.btn {
  height: 32px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover { background: #fbbf24; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--ink); border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 1200px) {
  .demo-cases-wrap { display: none; }
}

@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    overflow: visible;
  }

  .topbar-sep { display: none; }

  .topbar-actions {
    margin-left: auto;
  }

  .config-row {
    order: 2;
    flex-basis: 100%;
    overflow-x: auto;
  }
}

/* ── Main layout ─────────────────────────────────────────────── */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  grid-template-rows: 1fr;
}

/* ── Left: orders sidebar ────────────────────────────────────── */
.sidebar {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  padding: 0 4px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.order-card {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: default;
  transition: border-color .15s;
}

.order-card.active {
  border-color: var(--accent);
  background: #1f1a0e;
}

.order-card.accepted { border-color: var(--good); }
.order-card.rejected { border-color: var(--bad); opacity: .6; }
.order-card.evicted  { border-color: #ff8c00; opacity: .55; }
.order-badge.evicted { background: #ff8c00; color: #000; }

.order-card-head {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 4px;
}

.order-card-id { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.order-card-profit { color: var(--accent); font-size: 12px; }
.order-card-meta { font-size: 11px; color: var(--muted); }

.order-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 700;
}

.order-badge.ok { background: var(--good); color: #000; }
.order-badge.fail { background: var(--bad); color: #fff; }
.order-badge.pending { background: var(--surface2); color: var(--muted); }
.order-badge.active { background: var(--accent); color: #000; }

/* ── Center: negotiation room ────────────────────────────────── */
.center {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* Order header bar */
.order-header {
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 44px;
}

.order-header-id {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 15px;
}

.order-header-info { font-size: 12px; color: var(--muted); flex: 1; }
.order-header-profit { font-size: 13px; font-weight: 600; color: var(--accent); }

/* Chat stream */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

/* Message bubbles */
.msg {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  max-width: 100%;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 1px;
}

.msg.production .msg-avatar { background: var(--prod-dim); color: var(--prod); }
.msg.logistics  .msg-avatar { background: var(--log-dim);  color: var(--log); }
.msg.system     .msg-avatar { background: var(--surface2); color: var(--muted); }

.msg-body { flex: 1; min-width: 0; }

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
}

.msg-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.msg.production .msg-name { color: var(--prod); }
.msg.logistics  .msg-name { color: var(--log); }
.msg.system     .msg-name { color: var(--muted); }

.msg-role {
  font-size: 10px;
  color: var(--muted);
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
}

/* Text bubbles */
.bubble {
  display: inline-block;
  padding: 7px 11px;
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  font-size: 13px;
  line-height: 1.45;
  max-width: 100%;
  word-break: break-word;
}

.msg.production .bubble.user      { background: var(--surface2); }
.msg.logistics  .bubble.user      { background: var(--surface2); }
.msg.production .bubble.system    { background: var(--system-msg); color: var(--muted); font-size: 11px; font-style: italic; }
.msg.logistics  .bubble.system    { background: var(--system-msg); color: var(--muted); font-size: 11px; font-style: italic; }
.msg.system     .bubble           { background: transparent; color: var(--muted); font-size: 12px; padding: 3px 0; }
.msg.production .bubble.assistant { background: #0d1f18; border-left: 3px solid var(--prod); }
.msg.logistics  .bubble.assistant { background: #13122a; border-left: 3px solid var(--log); }

/* Tool call block */
.tool-call {
  background: #0c1a24;
  border: 1px solid var(--tool);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--tool);
  font-weight: 600;
  margin-bottom: 3px;
}

.tool-call-args { color: var(--muted); }

/* Tool result block */
.tool-result {
  background: #120c24;
  border: 1px solid var(--tool-result);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
}

.tool-result-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}

.tool-result.success .tool-result-header { color: var(--good); }
.tool-result.failure .tool-result-header { color: var(--bad); }

.tool-result-body { color: var(--muted); }

/* Order decision banner */
.decision-banner {
  margin: 4px 0;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.decision-banner.accepted {
  background: #052e16;
  border: 1px solid var(--good);
  color: var(--good);
}

.decision-banner.rejected {
  background: #2d0a0a;
  border: 1px solid var(--bad);
  color: var(--bad);
}

.decision-banner .profit { color: var(--accent); font-weight: 600; }

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}

.status-dot.running { background: var(--accent); animation: pulse 1.2s infinite; }
.status-dot.done    { background: var(--good); }
.status-dot.error   { background: var(--bad); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

.stat { color: var(--ink); font-weight: 600; }

/* ── Right: Gantt + comparison ───────────────────────────────── */
.rightpanel {
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  text-align: center;
  padding: 9px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { flex: 1; overflow: hidden; display: none; flex-direction: column; }
.tab-content.active { display: flex; }

/* Gantt */
.gantt-wrap {
  flex: 1;
  overflow: auto;
  padding: 10px;
}

.gantt-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
  min-height: 22px;
}

.gantt-label {
  width: 70px;
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
  font-family: var(--mono);
  padding-top: 3px;
}

.gantt-track {
  flex: 1;
  min-height: 22px;
  background: var(--surface2);
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}

.gantt-block {
  position: absolute;
  border-radius: 3px;
  display: flex;
  align-items: center;
  padding: 0 4px;
  font-size: 10px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  cursor: default;
}

.gantt-block.prod { background: var(--prod); color: #000; }
.gantt-block.log  { background: var(--log);  color: #fff; }

.gantt-axis {
  display: flex;
  margin-left: 78px;
  margin-bottom: 4px;
}

.gantt-axis-tick {
  flex: 1;
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
}

/* Comparison table */
.compare-wrap { flex: 1; overflow-y: auto; padding: 8px; }

.compare-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius);
  margin-bottom: 4px;
}

.compare-row.header {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
}

.compare-row:not(.header):hover { background: var(--surface2); }
.compare-row.winner { background: #1a1400; }
.compare-row.invalid {
  outline: 1px solid rgba(239, 68, 68, .55);
}
.compare-row.invalid .compare-name {
  color: #fca5a5;
}

.compare-name { flex: 1; font-size: 12px; font-weight: 600; min-width: 0; word-break: break-word; }
.compare-profit { font-family: var(--mono); font-size: 12px; width: 72px; text-align: right; }
.compare-pct    { font-family: var(--mono); font-size: 12px; width: 44px; text-align: right; color: var(--muted); }

.bar-wrap { width: 60px; }

.bar-track {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--muted);
  transition: width .4s ease;
}

.compare-row.winner .bar-fill { background: var(--accent); }
.compare-row.llm    .bar-fill { background: var(--prod); }

/* scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Thinking spinner */
.thinking {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  padding: 4px 0;
}

.dot-pulse {
  display: flex;
  gap: 3px;
}

.dot-pulse span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: dotpulse 1.2s infinite;
}

.dot-pulse span:nth-child(2) { animation-delay: .2s; }
.dot-pulse span:nth-child(3) { animation-delay: .4s; }

@keyframes dotpulse {
  0%, 80%, 100% { opacity: .2; transform: scale(.8); }
  40%           { opacity: 1;  transform: scale(1);   }
}

/* ── Dynamic event input ──────────────────────────────────────── */
.event-input-wrap {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.event-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 12px;
  padding: 6px 10px;
  outline: none;
  font-family: inherit;
}

.event-input::placeholder { color: var(--muted); }
.event-input:focus { border-color: var(--accent); }

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

/* Chat bubbles for injected events */
.chat-event-bubble {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: #2d2408;
  border: 1px solid #78350f;
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  color: #fde68a;
  margin: 4px 0;
}

.chat-event-label {
  font-weight: 600;
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
}

.chat-event-error {
  background: #2d0808;
  border-color: #7f1d1d;
  color: #fca5a5;
}

/* Chat bubbles for IntentRouter status */
.chat-intent-status {
  font-size: 11px;
  color: var(--ink-muted, #6b7280);
  padding: 2px 6px;
  margin: 2px 0;
  font-style: italic;
  opacity: 0.75;
}

.chat-intent-dispatch {
  color: #60a5fa;
  opacity: 1;
  font-style: normal;
  font-weight: 500;
}

.chat-intent-action {
  background: #0d2418;
  border-color: #14532d;
  color: #86efac;
}

/* ── Order summary bubble ─────────────────────────────────────── */
.chat-order-summary {
  margin: 8px 0 4px;
  padding: 10px 14px;
  background: #0c1a2e;
  border: 1px solid #1e3a5f;
  border-radius: var(--radius);
  font-size: 12px;
  color: #93c5fd;
  line-height: 1.6;
}
.chat-order-summary div + div { margin-top: 4px; }
.chat-order-summary strong { color: #bfdbfe; }
.chat-order-summary code {
  background: #1e3a5f;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11px;
  color: #7dd3fc;
}

/* ── @-mention autocomplete dropdown ─────────────────────────── */
.event-input-wrap {
  position: relative;
}

.mention-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  z-index: 100;
  overflow: hidden;
  max-height: 220px;
  overflow-y: auto;
}

.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

.mention-item:hover,
.mention-item.selected {
  background: var(--surface2);
}

.mention-kind {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

.mention-kind.agent   { background: var(--accent); color: #000; }
.mention-kind.line    { background: var(--prod-dim); color: var(--prod); }
.mention-kind.truck   { background: var(--log-dim); color: var(--log); }
.mention-kind.order   { background: var(--surface2); color: var(--muted); }

/* ── Human-in-the-loop confirmation card ─────────────────────── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.confirm-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 20px 24px;
  width: min(540px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}

.confirm-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 8px;
}

.confirm-event-text {
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--ink);
  border-left: 3px solid var(--accent);
}

.confirm-agents {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.confirm-agent-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface2);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.confirm-agent-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}

.confirm-agent-name.production { color: var(--prod); }
.confirm-agent-name.logistics  { color: var(--log); }

.confirm-agent-plan {
  font-size: 12px;
  color: var(--ink);
  line-height: 1.5;
}

.confirm-agent-reason {
  font-size: 11px;
  color: var(--muted);
}

.confirm-no-mandate {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.confirm-edit-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.confirm-edit-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  resize: vertical;
  min-height: 40px;
}

.confirm-edit-input:focus { border-color: var(--accent); }

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-confirm {
  background: var(--good);
  color: #000;
  height: 34px;
  padding: 0 20px;
  border: none;
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-confirm:hover { background: #4ade80; }

.btn-cancel-confirm {
  background: transparent;
  color: var(--bad);
  height: 34px;
  padding: 0 16px;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-cancel-confirm:hover { background: #2d0a0a; }
