:root {
  --bg: #ffffff;
  --surface: #f9fafb;
  --surface-2: #f3f4f6;
  --surface-3: #e5e7eb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-dim: #6b7280;
  --text-mute: #9ca3af;
  --accent: #ef950d;
  --accent-hover: #d17f05;
  --accent-soft: #fef3e2;
  --link: #2563eb;
  --green: #10b981;
  --orange: #f59e0b;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;

  --rail-w: 56px;
  --rail-w-expanded: 232px;
  --list-w: 320px;

  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,.07), 0 1px 2px 0 rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.hidden { display: none !important; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--link); }

/* ============ LOGIN ============ */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface);
}
.login-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 28px;
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: var(--shadow);
}
.login-card h1 {
  margin: 0; font-size: 26px; text-align: center; letter-spacing: 1px;
  color: var(--accent);
  font-weight: 700;
}
.login-card .subtitle { margin: 0 0 12px; text-align: center; color: var(--text-dim); }
.login-card input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
}
.login-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  background: var(--accent); color: #fff; border: 0;
  padding: 10px; border-radius: 8px; font-weight: 600; cursor: pointer;
  font-size: 14px;
}
.login-card button:hover { background: var(--accent-hover); }
.error {
  background: #fef2f2;
  color: var(--red);
  border: 1px solid #fecaca;
  padding: 8px 10px; border-radius: 6px;
  font-size: 13px;
}

/* ============ APP LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--list-w) 1fr;
  height: 100vh;
  background: var(--surface);
  transition: grid-template-columns .2s ease;
}
.app.rail-expanded {
  grid-template-columns: var(--rail-w-expanded) var(--list-w) 1fr;
}

/* ============ NAV RAIL (Supabase-style) ============ */
.nav-rail {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 8px;
  overflow: hidden;
}
.nav-logo {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
  letter-spacing: 0;
  margin: 0 0 8px;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}
.nav-logo:hover { background: var(--accent-hover); }

.nav-items { flex: 1; display: flex; flex-direction: column; gap: 2px; padding-top: 8px; }

.nav-item {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center;
  gap: 12px;
  height: 40px;
  width: 100%;
  text-align: left;
  transition: background .12s, color .12s;
  overflow: hidden;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}
.nav-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.nav-icon svg { width: 18px; height: 18px; }
.nav-label {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
}
.app.rail-expanded .nav-label { opacity: 1; }

.nav-item.logout { color: var(--text-mute); margin-top: auto; }
.nav-item.logout:hover { color: var(--red); }

/* ============ LIST PANE ============ */
.list-pane {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-width: 0;
}
.list-section {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
.list-header {
  padding: 16px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.list-header-counter {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
}

/* filters */
.filters {
  padding: 10px 12px;
  display: flex; gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}
.filter-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: all .12s;
}
.filter-btn:hover { color: var(--text); border-color: var(--border-strong); }
.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* dialogs list */
.dialogs-list { overflow-y: auto; flex: 1; }
.dialog-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
  transition: background .1s;
}
.dialog-item:hover { background: var(--surface); }
.dialog-item.active { background: var(--accent-soft); border-left: 3px solid var(--accent); padding-left: 13px; }
.dialog-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.dialog-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1; min-width: 0;
}
.dialog-time { color: var(--text-dim); font-size: 11px; flex-shrink: 0; }
.dialog-last {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dialog-badges { display: flex; gap: 6px; }
.badge {
  font-size: 10px;
  padding: 2px 7px; border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-channel { background: #dbeafe; color: var(--blue); }

.channel-icon {
  width: 20px; height: 20px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}
.badge-status-new { background: var(--surface-2); color: var(--text-dim); }
.badge-status-in_progress { background: #dbeafe; color: var(--blue); }
.badge-status-calculated { background: #fef3c7; color: #b45309; }
.badge-status-measurement { background: #d1fae5; color: var(--green); }
.badge-status-not_qualified { background: var(--surface-2); color: var(--text-dim); }
.badge-status-rejected { background: #fee2e2; color: var(--red); }
.badge-manual { background: #ffedd5; color: var(--orange); }

/* agent list */
.agent-list { overflow-y: auto; flex: 1; padding: 8px; }
.agent-list-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  background: transparent;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  text-align: left;
  margin-bottom: 2px;
  transition: background .12s;
}
.agent-list-item:hover { background: var(--surface); }
.agent-list-item.active { background: var(--accent-soft); color: var(--accent-hover); }
.agent-list-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.agent-list-text { min-width: 0; flex: 1; }
.agent-list-title { font-weight: 600; font-size: 13px; }
.agent-list-sub { color: var(--text-dim); font-size: 11px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-list-item.disabled .agent-list-title { color: var(--text-mute); }

.agent-list-divider {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 12px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-mute);
  font-weight: 600;
}
.ghost-btn-tiny {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 22px; height: 22px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.ghost-btn-tiny:hover { color: var(--accent); border-color: var(--accent); }

.kb-files { display: flex; flex-direction: column; gap: 0; }
.kb-empty { padding: 16px 12px; color: var(--text-mute); font-size: 12px; text-align: center; }

/* ============ CONTENT PANE ============ */
.content-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.empty-state {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim);
  gap: 12px;
}
.empty-icon { font-size: 40px; opacity: .5; }

.content-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  background: var(--bg);
  flex-wrap: wrap;
}
.content-header-info { min-width: 0; flex: 1; }
.content-header-name { font-weight: 600; font-size: 16px; color: var(--text); }
.content-header-meta { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.content-header-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.title-input {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 0;
  width: 100%;
  outline: none;
}
.title-input:focus { color: var(--accent-hover); }

.status-select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.mode-btn {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.mode-btn:hover { border-color: var(--accent); }
.mode-btn.manual {
  background: var(--orange); border-color: var(--orange); color: #fff;
}

.primary-btn {
  background: var(--accent); color: #fff; border: 0;
  padding: 8px 16px; border-radius: 6px;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: .5; cursor: not-allowed; }
.ghost-btn {
  background: var(--bg); color: var(--text-dim);
  border: 1px solid var(--border-strong);
  padding: 8px 14px; border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:hover { color: var(--text); border-color: var(--text-dim); }
.ghost-btn.danger:hover { color: var(--red); border-color: var(--red); }

.toggle-switch {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}
.toggle-switch:hover { border-color: var(--accent); }
.toggle-switch input { margin: 0; accent-color: var(--accent); }

/* ============ CHAT ============ */
.chat { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Центрирование контента чата в узкой колонке на широких экранах.
   Используем padding с max() — фон растягивается на всю ширину, контент центрируется. */
:root { --chat-pad: max(20px, calc((100% - 860px) / 2)); }

.profile-strip {
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  display: flex; gap: 6px 20px; flex-wrap: wrap;
  align-items: baseline;
}
.profile-strip:empty { display: none; }
.profile-strip .param-item {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  white-space: nowrap;
}
.profile-strip .param-label {
  color: var(--text-dim);
  font-weight: 600;
}
.profile-strip .param-known strong { color: var(--text); font-weight: 600; }
.profile-strip .param-skipped span,
.profile-strip .param-empty span { color: var(--text-mute); }
.profile-strip a { color: var(--text); text-decoration: none; }
.profile-strip a:hover { color: var(--accent); }

.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 20px var(--chat-pad);
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface);
}
.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
}
.message-user { align-self: flex-start; background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.message-bot { align-self: flex-end; background: var(--accent); color: #fff; }
.message-human { align-self: flex-end; background: var(--orange); color: #fff; }
.message-time { font-size: 10px; opacity: .7; margin-top: 4px; }
.message-bot .message-time, .message-human .message-time { color: rgba(255,255,255,.85); }
.message-user .message-time { color: var(--text-dim); }

.send-form {
  padding: 12px var(--chat-pad);
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg);
  flex-shrink: 0;
}
.send-form textarea {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  min-height: 40px; max-height: 120px;
  font-size: 14px;
}
.send-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.send-form button {
  background: var(--accent); color: #fff; border: 0;
  padding: 10px 18px; border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

/* ============ EDITORS (PROMPT / KB FILE) ============ */
.prompt-view {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
/* compact toggle (Просмотр / Редактор) inside content-header */
.view-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  gap: 0;
}
.view-tab {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.view-tab:hover { color: var(--text); }
.view-tab.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.code-textarea {
  flex: 1;
  background: var(--bg);
  border: 0;
  color: var(--text);
  padding: 20px;
  font-family: 'SF Mono', Menlo, Monaco, Consolas, 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: none;
  outline: none;
}

/* markdown preview */
.md-preview {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}
.md-preview h1, .md-preview h2, .md-preview h3, .md-preview h4 {
  font-weight: 700;
  line-height: 1.3;
  margin: 1.4em 0 .5em;
  color: var(--text);
}
.md-preview h1:first-child, .md-preview h2:first-child, .md-preview h3:first-child {
  margin-top: 0;
}
.md-preview h1 { font-size: 22px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.md-preview h2 { font-size: 18px; }
.md-preview h3 { font-size: 16px; }
.md-preview h4 { font-size: 14px; color: var(--text-dim); }
.md-preview p { margin: .6em 0; }
.md-preview ul, .md-preview ol { margin: .6em 0; padding-left: 24px; }
.md-preview li { margin: .25em 0; }
.md-preview ul li::marker { color: var(--accent); }
.md-preview strong { color: var(--text); font-weight: 700; }
.md-preview em { font-style: italic; }
.md-preview code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  color: #be185d;
}
.md-preview pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  margin: 1em 0;
}
.md-preview pre code {
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.55;
}
.md-preview blockquote {
  margin: 1em 0;
  padding: 0 16px;
  border-left: 3px solid var(--accent);
  color: var(--text-dim);
  background: var(--accent-soft);
  border-radius: 0 6px 6px 0;
}
.md-preview hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1.6em 0;
}
.md-preview table {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 13px;
  width: 100%;
}
.md-preview th, .md-preview td {
  border: 1px solid var(--border);
  padding: 6px 12px;
  text-align: left;
}
.md-preview th { background: var(--surface-2); font-weight: 600; }
.md-preview a { color: var(--link); text-decoration: underline; }
.status-bar {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--border);
  background: var(--surface);
  min-height: 32px;
}
.status-bar.success { color: var(--green); }
.status-bar.error { color: var(--red); }

/* ============ SETTINGS FORM ============ */
.settings-form {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  background: var(--bg);
}
.setting-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.setting-title {
  font-weight: 700; font-size: 14px;
  color: var(--text);
  margin-bottom: 4px;
}
.setting-title-sm {
  font-weight: 600; font-size: 12px;
  color: var(--text);
  margin: 8px 0 4px;
}
.setting-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  line-height: 1.5;
}
.setting-row {
  display: flex; align-items: flex-start; gap: 10px;
  cursor: pointer;
  padding: 4px 0;
}
.setting-row input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent);
}
.setting-row .setting-title { margin-bottom: 2px; }
.radio-row {
  display: flex; gap: 16px; flex-wrap: wrap;
}
.radio-row label {
  display: inline-flex; align-items: center; gap: 6px;
  cursor: pointer;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  transition: all .12s;
}
.radio-row label:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-hover);
  font-weight: 600;
}
.radio-row input[type="radio"] { accent-color: var(--accent); }

.setting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-top: 10px;
}
.setting-grid label {
  display: flex; flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.setting-grid input, .setting-grid select {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
}
.setting-grid input:focus, .setting-grid select:focus {
  outline: none; border-color: var(--accent);
}
.setting-block-inner { display: block; margin-top: 8px; }
.textarea-flat {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  resize: vertical;
  min-height: 60px;
}
.textarea-flat:focus { outline: none; border-color: var(--accent); }
.badge-soon {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  font-weight: 600;
}

/* ============ CALCULATOR ============ */
.calc-wrap {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.calc-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 13px;
}
.calc-table thead th {
  background: var(--surface-2);
  color: var(--text-dim);
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.calc-table tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.calc-table tbody tr:last-child td { border-bottom: none; }
.calc-table tbody tr:hover { background: var(--surface); }
.calc-unit-col  { width: 70px; }
.calc-qty-col   { width: 110px; }
.calc-price-col { width: 160px; }
.calc-sum-col   { width: 130px; text-align: right; }
.calc-table .calc-sum {
  text-align: right;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.calc-table .calc-sum.calc-sum-active { color: var(--text); font-weight: 600; }
.calc-table input[type="number"] {
  width: 100px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
  text-align: right;
}
.calc-table input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.calc-table input.calc-changed { border-color: var(--accent); background: var(--accent-soft); }
.calc-table input.calc-qty { width: 90px; }

.calc-totals {
  margin-top: 18px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.calc-totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-size: 14px;
}
.calc-totals-row + .calc-totals-row { border-top: 1px solid var(--border); }
.calc-totals-label { color: var(--text-dim); font-weight: 600; }
.calc-totals-value { font-variant-numeric: tabular-nums; }
.calc-totals-base .calc-totals-value { color: var(--text); font-weight: 600; }
.calc-totals-range {
  background: var(--accent);
  color: #fff;
}
.calc-totals-range .calc-totals-label { color: rgba(255,255,255,.85); }
.calc-totals-range .calc-totals-value { color: #fff; font-weight: 700; font-size: 16px; }
.calc-totals-range #calc-total-min,
.calc-totals-range #calc-total-max { font-weight: 800; }
.calc-unit-badge {
  display: inline-block;
  padding: 2px 8px;
  background: var(--surface-2);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
}
.calc-note {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
}

/* ============ FOLLOWUP (дожимы) ============ */
.fu-level {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fu-level-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}
.fu-del {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}
.fu-del:hover { color: var(--red); background: var(--surface-2); }
.fu-level label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
}
.fu-rel, .fu-abs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.fu-rel label, .fu-abs label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  color: var(--text);
}
.fu-level select, .fu-level input {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text);
}
.fu-level select:focus, .fu-level input:focus { outline: none; border-color: var(--accent); }
.fu-level input[type="number"] { width: 72px; }
.fu-level input[type="time"] { width: 110px; }
.marker-legend {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
}
.marker-legend code {
  background: rgba(255, 220, 100, 0.25);
  color: var(--text);
  padding: 1px 5px;
  border-radius: 3px;
}

/* ============ SANDBOX ============ */
.sandbox-view {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
.sandbox-body {
  display: grid;
  grid-template-columns: 1fr 360px;
  flex: 1;
  min-height: 0;
  background: var(--surface);
}
@media(max-width: 1000px) {
  .sandbox-body { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .sandbox-debug { max-height: 40vh; }
}
.sandbox-chat {
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0;
  overflow: hidden;
}
.sandbox-debug {
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
  font-size: 12px;
}
.sandbox-debug-section {
  margin-bottom: 16px;
}
.sandbox-debug-title {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-dim);
  padding-bottom: 4px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.sandbox-debug-content {
  color: var(--text);
  line-height: 1.5;
}
.sandbox-debug-content .row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 2px 0;
}
.sandbox-debug-content .row .key { color: var(--text-dim); }
.sandbox-debug-content .row .val { font-weight: 600; }
.sandbox-debug-content .row.skipped .val {
  color: var(--text-mute); font-style: italic; font-weight: 500;
}
.sandbox-debug-content .empty {
  color: var(--text-mute); font-style: italic;
}
.sandbox-debug-content .tool-call {
  background: var(--surface);
  border-radius: 4px;
  padding: 4px 8px;
  margin-bottom: 4px;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
}
.sandbox-debug-content .tool-call .name {
  color: var(--accent-hover); font-weight: 600;
}
.sandbox-debug-content .tool-call .ts {
  color: var(--text-mute); font-size: 10px;
}
.sandbox-snapshot {
  white-space: pre-wrap;
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
  background: var(--surface);
  border-radius: 4px;
  padding: 8px;
  margin: 0;
  max-height: 280px;
  overflow-y: auto;
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }
