/* ============================================================================
   intellemma · Config Tuning — дизайн-система (та же, что у fin-recom и BI-GPT)
   Три цвета: белый, синий #0099FA, оранжевый #FF8300. Нейтрали выведены из синего.
   Роли: синий — данные и норма, оранжевый — агент действует и внимание.
   Плоско: без градиентов и теней. Шрифты: Unbounded, Golos Text, JetBrains Mono.
   ========================================================================== */

:root {
  --white: #FFFFFF;
  --blue-050: #F5F9FE;
  --blue-100: #E3F0FB;
  --blue-200: #C6E0F7;
  --blue-300: #93C7F2;
  --blue-500: #0099FA;
  --blue-700: #0072C6;
  --blue-900: #0A2A47;
  --slate-500: #5B7893;
  --slate-600: #4A6683;
  --orange-050: #FFF4E8;
  --orange-200: #FFD9B3;
  --orange-500: #FF8300;
  --orange-700: #B85400;

  --bg: var(--white);
  --panel: var(--white);
  --panel-2: var(--blue-050);
  --border: var(--blue-200);
  --border-soft: var(--blue-100);
  --text: var(--blue-900);
  --muted: var(--slate-600);
  --muted-2: var(--slate-500);
  --accent: var(--orange-500);
  --accent-text: var(--orange-700);
  --data: var(--blue-500);
  --data-text: var(--blue-700);
  --ok: var(--blue-700);
  --err: var(--orange-700);
  --radius: 12px;

  --font-display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --font-body: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
  display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;          /* inner panes scroll, not the page */
}
::selection { background: rgba(0, 153, 250, .24); }
:focus-visible { outline: 2px solid var(--blue-500); outline-offset: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--blue-200); border-radius: 10px; border: 3px solid var(--white); }
::-webkit-scrollbar-track { background: transparent; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums lining-nums; font-variant-ligatures: none; }
.ico { width: 20px; height: 20px; display: inline-block; flex: none; }
.ico-xs { width: 14px; height: 14px; }
code { font-family: var(--font-mono); font-size: .9em; background: var(--blue-050); padding: 1px 5px; border-radius: 4px; }
h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: -.015em; line-height: 1.25; margin: 0; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-shrink: 0;
  height: 56px; padding: 0 24px;
  background: var(--white); border-bottom: 1px solid var(--border-soft);
}
.brand { display: inline-flex; align-items: center; }
.brand-logo { display: block; height: 34px; width: auto; }
.topbar-sep { width: 1px; height: 20px; background: var(--border); }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar-h { font-weight: 600; font-size: 14.5px; white-space: nowrap; }
.topbar-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.badges { display: flex; gap: 6px; }
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border-radius: 999px; background: var(--blue-050); font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--slate-500); }
.badge.on { color: var(--text); }
.badge.on::before { background: var(--blue-500); }
.badge.off { color: var(--muted-2); }
.badge.off::before { background: var(--blue-200); }
.badge.mcp-off { color: var(--orange-700); background: var(--orange-050); }
.badge.mcp-off::before { background: var(--orange-500); }

/* ---------- buttons ---------- */
button { cursor: pointer; font: inherit; color: inherit; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 40px; padding: 0 16px; border-radius: 8px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.btn-cta { background: var(--orange-500); color: var(--blue-900); }
.btn-cta:hover:not(:disabled) { background: color-mix(in srgb, var(--orange-500) 86%, var(--blue-900)); }
.btn-ghost { background: var(--white); border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { border-color: var(--blue-500); background: var(--blue-050); color: var(--blue-700); }
.btn.wide { width: 100%; margin-top: 16px; height: 44px; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center;
  background: var(--white); border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  transition: border-color 120ms, color 120ms;
}
.icon-btn:hover { border-color: var(--blue-500); color: var(--blue-700); }

/* ---------- layout ---------- */
.layout {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 400px; grid-template-rows: minmax(0, 1fr);
  gap: 24px; padding: 24px 24px 24px 32px; min-height: 0; overflow: hidden;
}
.optimize-pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; gap: 16px; }

.goal-row { display: flex; gap: 8px; margin: 0; }
.goal-row input {
  flex: 1; min-width: 0; height: 44px; padding: 0 16px; background: var(--white);
  border: 1.5px solid var(--border); border-radius: 10px; color: var(--text); font: inherit; font-size: 15px;
  transition: border-color 120ms;
}
.goal-row input::placeholder { color: var(--muted-2); }
.goal-row input:hover { border-color: var(--blue-300); }
.goal-row input:focus { border-color: var(--blue-500); outline: none; }
.goal-row .btn { height: 44px; }

/* progress */
.progress-wrap { display: flex; flex-direction: column; gap: 8px; }
.progress-meta { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); }
.progress-bar { height: 4px; background: var(--blue-100); border-radius: 2px; overflow: hidden; }
#progressFill { height: 100%; width: 0; background: var(--orange-500); transition: width .4s ease; }

/* timeline */
.scroll-area { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-right: 4px; }
.empty { padding: 40px 0 24px; max-width: 60ch; }
.empty-title { font-family: var(--font-display); font-weight: 700; font-size: clamp(20px, 2vw, 26px); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 12px; }
.empty-title::before { content: ""; display: block; width: 40px; height: 4px; background: var(--orange-500); margin-bottom: 20px; }
.empty-text { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.55; }
.timeline { display: flex; flex-direction: column; gap: 12px; }
.step { background: var(--white); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.step-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; cursor: pointer; background: var(--white); user-select: none;
}
.step-head:hover { background: var(--blue-050); }
.step.open .step-head { border-bottom: 1px solid var(--border-soft); }
.step-head .left { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; }
.step-head .right { display: flex; align-items: center; gap: 8px; }
.caret { display: inline-block; color: var(--muted-2); transition: transform .15s; font-size: 12px; }
.step.open .caret { transform: rotate(90deg); }
.chip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 4px;
  font-size: 12px; font-weight: 600; color: var(--muted); border: 1px solid var(--border);
}
.chip.score { color: var(--blue-700); border-color: var(--blue-200); background: var(--blue-050); font-family: var(--font-mono); font-weight: 600; }
.chip.done { color: var(--blue-900); background: var(--blue-500); border-color: var(--blue-500); }
.chip.continue { color: var(--orange-700); border-color: var(--orange-500); background: var(--white); }
.step-body { padding: 16px; display: none; flex-direction: column; gap: 18px; }
.step.open .step-body { display: flex; }

.block-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.thoughts {
  white-space: pre-wrap; background: var(--blue-050); border-radius: 8px; padding: 12px 14px;
  font-size: 14px; line-height: 1.55; max-height: 280px; overflow-y: auto;
}
.thoughts.streaming::after, .probe .a.streaming::after, .bubble.assistant.streaming::after {
  content: ""; display: inline-block; width: .5em; height: 1.05em; vertical-align: -.15em; margin-left: 2px;
  background: var(--orange-500); animation: blink .9s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* config change */
.cfg-change { display: flex; flex-direction: column; gap: 10px; }
.kv { font-size: 14px; }
.kv .muted, .kv[data-muted] { color: var(--muted); }
.temp-pill { display: inline-flex; gap: 8px; align-items: center; font-family: var(--font-mono); }
.temp-old { color: var(--orange-700); text-decoration: line-through; }
.temp-new { color: var(--blue-700); font-weight: 600; }
.diff {
  white-space: pre-wrap; background: var(--white); border: 1px solid var(--border-soft); border-radius: 8px; padding: 12px 14px;
  font-family: var(--font-body); font-size: 14px; line-height: 1.6;
}
.diff ins { background: var(--blue-100); color: var(--blue-900); text-decoration: none; border-bottom: 2px solid var(--blue-500); }
.diff del { background: var(--orange-050); color: var(--orange-700); text-decoration: line-through; }
.fewshot-item { border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px 12px; margin-top: 8px; font-size: 13.5px; line-height: 1.5; }
.fewshot-item.added { border-color: var(--blue-500); background: var(--blue-050); }
.fewshot-item .role { color: var(--muted-2); font-size: 11.5px; font-family: var(--font-mono); margin-bottom: 2px; }
.fewshot-item .role + .role, .fewshot-item .role:not(:first-child) { margin-top: 8px; }

/* probes */
.probe { border: 1px solid var(--border-soft); border-radius: 8px; overflow: hidden; }
.probe .q { padding: 10px 12px; background: var(--blue-050); font-weight: 600; font-size: 14px; }
.probe .q::before { content: "?"; display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 8px; border-radius: 4px; background: var(--blue-500); color: var(--blue-900); font-family: var(--font-mono); font-size: 12px; vertical-align: -3px; }
.probe .a { padding: 10px 12px; white-space: pre-wrap; font-size: 14px; line-height: 1.55; }

/* final */
.final-card { background: var(--white); border: 1px solid var(--blue-500); border-radius: var(--radius); padding: 16px; }
.final-card h3 { font-size: 16px; margin: 0 0 12px; }

/* ---------- chat with Agent A ---------- */
.chat-pane { display: flex; flex-direction: column; background: var(--blue-050); border: 1px solid var(--border-soft); border-radius: 16px; min-height: 0; }
.chat-head { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
.chat-title { font-weight: 600; font-size: 14.5px; }
.chat-cfg { font-size: 11.5px; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.bubble { padding: 10px 14px; border-radius: 12px; max-width: 92%; white-space: pre-wrap; font-size: 14px; line-height: 1.5; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--blue-500); color: var(--blue-900); font-weight: 500; border-radius: 12px 12px 2px 12px; }
.bubble.assistant { align-self: flex-start; background: var(--white); border: 1px solid var(--border-soft); border-radius: 2px 12px 12px 12px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border-soft); align-items: flex-end; }
.chat-input textarea {
  flex: 1; min-width: 0; resize: none; background: var(--white); border: 1.5px solid var(--border); border-radius: 10px;
  color: var(--text); padding: 10px 14px; font: inherit; font-size: 14.5px; line-height: 1.4; transition: border-color 120ms;
}
.chat-input textarea::placeholder { color: var(--muted-2); }
.chat-input textarea:focus { border-color: var(--blue-500); outline: none; }
.composer-send {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  background: var(--orange-500); color: var(--blue-900); border: 0; border-radius: 10px;
  transition: transform 120ms, background 120ms;
}
.composer-send:hover:not(:disabled) { background: color-mix(in srgb, var(--orange-500) 86%, var(--blue-900)); }
.composer-send:active:not(:disabled) { transform: scale(.94); }

/* ---------- overlay / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 42, 71, .4); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: 440px; max-width: 92vw; height: 100%; background: var(--white); border-left: 1px solid var(--border); display: flex; flex-direction: column; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--border-soft); }
.drawer-head h3 { font-size: 17px; }
.drawer-body { padding: 20px; overflow-y: auto; }
.drawer-body h4 { font-size: 14px; margin: 24px 0 10px; display: flex; align-items: baseline; gap: 8px; }
.drawer-body h4:first-of-type { margin-top: 20px; }
.h4-sub { font-family: var(--font-body); font-weight: 500; font-size: 12.5px; color: var(--muted-2); letter-spacing: 0; }
.drawer-body label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.drawer-body .kv { margin-top: 6px; font-weight: 500; color: var(--text); font-size: 13.5px; }
.drawer-body select, .drawer-body input[type=number], .drawer-body textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; background: var(--white); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font: inherit; font-size: 14px; font-weight: 400;
}
.drawer-body select:focus, .drawer-body input:focus, .drawer-body textarea:focus { border-color: var(--blue-500); outline: none; box-shadow: 0 0 0 3px rgba(0, 153, 250, .15); }
.drawer-body input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--orange-500); }
.note { display: block; font-size: 13px; color: var(--muted); background: var(--blue-050); padding: 10px 12px; border-radius: 8px; margin: 0 0 8px; line-height: 1.5; }
.note .ico { vertical-align: -2px; margin-right: 6px; color: var(--blue-700); }
.usage-body { white-space: pre-wrap; font-family: var(--font-mono); font-size: 12px; background: var(--blue-050); border-radius: 8px; padding: 12px; margin: 0; }
details summary { cursor: pointer; color: var(--blue-700); font-weight: 600; font-size: 13px; }

.hidden { display: none !important; }
.error-banner { background: var(--orange-050); border-left: 3px solid var(--orange-500); color: var(--orange-700); padding: 10px 14px; border-radius: 0 8px 8px 0; font-size: 14px; }

/* ---------- MCP tool calls (Agent A), interleaved with streamed text ---------- */
.text-run { white-space: pre-wrap; }
.tool-group { border: 1px solid var(--border-soft); border-radius: 10px; background: var(--blue-050); margin: 8px 0; font-size: 13px; }
.tool-group-summary { cursor: pointer; list-style: none; padding: 7px 12px; color: var(--muted); font-size: 12.5px; font-weight: 500; user-select: none; }
.tool-group-summary::-webkit-details-marker { display: none; }
.tool-group-summary::after { content: "▸"; float: right; color: var(--muted-2); transition: transform .15s; }
.tool-group[open] > .tool-group-summary::after { transform: rotate(90deg); }
.tool-group.running > .tool-group-summary { color: var(--blue-700); }
.tool-group-body { padding: 0 10px 4px; }
.tool-block { border: 1px solid var(--border-soft); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 13px; background: var(--white); }
.tool-call { color: var(--blue-700); font-family: var(--font-mono); font-size: 12.5px; word-break: break-word; }
.tool-result { margin-top: 4px; color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.tool-result.ok { color: var(--ok); }
.tool-result.err { color: var(--err); }
.tool-detail { margin-top: 4px; }
.tool-detail summary { color: var(--muted-2); font-size: 12px; font-weight: 500; }
.tool-detail pre { white-space: pre-wrap; word-break: break-word; background: var(--blue-050); border-radius: 6px; padding: 8px 10px; margin-top: 4px; font-family: var(--font-mono); font-size: 12px; max-height: 200px; overflow-y: auto; }
.probe-error { color: var(--orange-700); background: var(--orange-050); border-radius: 6px; padding: 8px 10px; margin: 6px 12px 10px; font-size: 13px; }

/* MCP servers + tool list (settings) */
.mcp-server-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.mcp-server-err { color: var(--orange-700); font-size: 12px; }
.mcp-tools-list { max-height: 220px; overflow-y: auto; margin-top: 8px; }
.mcp-tool-item { font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border-soft); color: var(--muted); }
.mcp-tool-item .name { color: var(--blue-700); font-family: var(--font-mono); font-size: 12.5px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 320px; padding: 16px; gap: 16px; }
  .topbar-sub { display: none; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .topbar-sep, .topbar-title, #provBadges { display: none; }
  .brand-logo { height: 30px; }
  .goal-row { flex-wrap: wrap; }
  #settingsBtn span { display: none; }
  #settingsBtn { width: 40px; padding: 0; }
  .goal-row input { flex-basis: 100%; }
  .layout { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
