:root {
  --bg: #ffffff;
  --surface: #f9fafb;
  --surface-2: #f3f4f6;
  --surface-3: #e5e7eb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #1F1F1F;
  --text-dim: #6b7280;
  --text-mute: #9ca3af;
  --accent: #2196F3;
  --accent-hover: #1976D2;
  --accent-soft: #E3F0FC;
  --chat-max-w: 720px;
  --chat-bg: #b8d4e8;
  --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-logo {
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 4px;
}
.login-card .subtitle { margin: 0 0 12px; text-align: center; color: var(--text-dim); font-size: 15px; }
.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[type="submit"] {
  background: var(--accent); color: #fff; border: 0;
  padding: 10px; border-radius: 8px; font-weight: 600; cursor: pointer;
  font-size: 14px;
}
.login-card button[type="submit"]: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;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
  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 ============ */
.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;
  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; align-items: center; }
.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: 18px; height: 18px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
  object-fit: contain;
}
.badge-status-in_work { background: #dbeafe; color: var(--blue); }
.badge-status-kval { background: var(--accent-soft); color: var(--accent-hover); }
.badge-status-call { background: #d1fae5; color: var(--green); }
.badge-status-wait { background: #fef3c7; color: #b45309; }
.badge-status-buy { background: #d1fae5; color: var(--green); }
.badge-status-rejected { background: #fee2e2; color: var(--red); }
.badge-manual { background: #ffedd5; color: var(--orange); }
.unread-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 5px;
  flex-shrink: 0;
  vertical-align: middle;
}

/* 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; flex-wrap: wrap; }

.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 dropdown */
.status-dropdown-wrap, .goal-dropdown-wrap { position: relative; }
.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;
  white-space: nowrap;
}
.status-select:hover { border-color: var(--accent); }
.status-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  display: flex; flex-direction: column;
  min-width: 130px;
  overflow: hidden;
}
.status-dropdown-menu button {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 14px;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
  transition: background .1s;
}
.status-dropdown-menu button:hover { background: var(--surface-2); }

.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; }
.profile-strip {
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  display: flex; gap: 16px; flex-wrap: wrap;
}
.profile-strip .field strong { color: var(--text); margin-right: 4px; }
.profile-strip:empty { display: none; }

.messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 20px max(20px, calc((100% - var(--chat-max-w)) / 2));
  display: flex; flex-direction: column; gap: 8px;
  background: var(--chat-bg);
}
.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 14px;
  line-height: 1.45;
}
.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); }
.message-system {
  align-self: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 80%;
  text-align: center;
}
.date-separator {
  text-align: center;
  font-size: 11px;
  color: #33485a;
  font-weight: 500;
  margin: 4px 0;
}
.message img { max-width: 260px; max-height: 180px; border-radius: 8px; display: block; margin-bottom: 4px; }

.send-form {
  padding: 12px max(20px, calc((100% - var(--chat-max-w)) / 2));
  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;
}
.send-form button:hover { background: var(--accent-hover); }

/* ============ SANDBOX COMPOSER (pill, авто-рост из 1 строки) ============ */
.composer {
  flex-shrink: 0;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  background: var(--surface-2, #f3f4f6);
  border-radius: 22px;
  color: var(--text);
  padding: 10px 16px;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  max-height: 160px;
  overflow-y: hidden;
}
.composer textarea:focus {
  outline: none; border-color: var(--accent);
  background: var(--bg); box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer-send {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .12s;
}
.composer-send:hover { background: var(--accent-hover); }
.composer-send:disabled { opacity: .5; cursor: default; }
.composer-send svg { width: 20px; height: 20px; }
/* Композер в Диалогах — центрируем по ширине чата (как сообщения) */
.composer-centered { padding: 12px max(20px, calc((100% - var(--chat-max-w)) / 2)); }

/* ============ EDITORS (PROMPT / KB PAGE) ============ */
.prompt-view {
  display: flex; flex-direction: column;
  flex: 1; min-height: 0;
}
.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-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; }
.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); }

/* ============ 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-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: 500px; overflow-y: auto;
}

/* ============ FOLLOWUP ============ */
/* Промт дожима — крупное поле в стиле формы настроек */
.fu-textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 220px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border-strong, #c4d3e0);
  border-radius: 8px;
  color: var(--text);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
}
.fu-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Карточка уровня */
.fu-level {
  border: 1px solid var(--border, #d8e2ec);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--card, #fff);
  display: grid;
  gap: 12px;
}
.fu-level-head { display: flex; justify-content: space-between; align-items: center; }
.fu-level-head b { font-size: 13px; color: var(--text); }
.fu-del {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 16px; line-height: 1;
  padding: 2px 6px; border-radius: 6px; transition: background .12s, color .12s;
}
.fu-del:hover { background: #fdecea; color: #c0392b; }

/* Поля внутри уровня — как в .setting-grid */
.fu-level label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.fu-level select,
.fu-level input {
  padding: 8px 10px;
  border: 1px solid var(--border-strong, #c4d3e0);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.fu-level select:focus,
.fu-level input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Строка относительного тайминга: «через [N] [единица]» в ряд */
.fu-rel label, .fu-abs label { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; }
.fu-rel input.fu-relnum { width: 90px; }
.fu-abs input.fu-afterdays { width: 90px; }
.fu-abs input.fu-attime { width: 130px; }
.fu-abs { display: flex; flex-wrap: wrap; gap: 16px; }

#fu-add-level {
  background: var(--accent-soft, #E3F0FC);
  border: 1px dashed var(--accent, #2196F3);
  color: var(--accent, #2196F3);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
#fu-add-level:hover { background: #d6e9fb; }

/* ============ RADIO ROW ============ */
.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;
}
.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-title-sm { font-weight: 600; font-size: 12px; color: var(--text); margin: 8px 0 4px; }
.setting-block-inner { display: block; margin-top: 8px; }
.textarea-flat {
  width: 100%; box-sizing: border-box; background: var(--bg);
  border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 8px 10px; font: inherit; font-size: 13px; resize: vertical;
}
.textarea-flat:focus { outline: none; border-color: var(--accent); }

/* ============ MARKER HIGHLIGHT ============ */
.hl-wrap { position: relative; background: var(--bg); border-radius: 8px; }
.hl-backdrop {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  margin: 0; z-index: 0; color: transparent;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word;
}
.hl-backdrop mark { background: #fff2b2; color: transparent; border-radius: 3px; }
.hl-wrap > textarea { position: relative; z-index: 1; background: transparent !important; }

.marker-legend { font-size: 11px; color: var(--text-dim); margin-top: 8px; line-height: 1.5; }
.marker-legend mark { background: #fff2b2; color: var(--text); padding: 0 4px; border-radius: 3px; }
.marker-legend code { background: var(--surface-2, #f3f4f6); padding: 0 4px; border-radius: 3px; font-size: 11px; }

.marker-hl { background: #fff2b2; color: var(--text); border-radius: 3px; padding: 0 2px; }

/* 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); }
