<style>
:root {
  --bg: #F0F2F6;
  --surface: #fff;
  --ink: #13161C;
  --ink-2: #3B4250;
  --muted: #6A7280;
  --line: #E2E5EB;
  --line-2: #EEF0F4;
  --sidebar: #111318;
  --sidebar-hover: #1B1E26;
  --sidebar-active: #262A34;
  --accent: #2157F5;
  --accent-2: #1A46CC;
  --accent-soft: #E7EDFF;
  --good: #0B8F5B;
  --good-bg: #E5F6EE;
  --bad: #D92D20;
  --bad-bg: #FDECEC;
  --warn: #B54708;
  --warn-bg: #FEF4E6;
  --info: #175CD3;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow-lg: 0 10px 28px rgba(16,24,40,.12);
  --r: 10px;
  --rtk: #E85D04;
  --mts: #E30611;
  --domru: #2B5DE0;
  --beeline: #E6B800;
  --megafon: #00A83E;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Inter, "Noto Sans", "Segoe UI", "PT Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.app { display: flex; height: 100%; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--sidebar); color: #E8EAEF;
  display: flex; flex-direction: column; padding: 16px 12px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; }
.logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #2E6BFF, #0EA5A0);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; letter-spacing: .02em;
  color: #fff; flex-shrink: 0;
}
.brand-name { font-weight: 650; font-size: 13.5px; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: #8B909C; margin-top: 1px; }
.side-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #8B909C; padding: 4px 10px 8px; font-weight: 600;
}
.bot-list { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
.bot-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  background: transparent; border: 0; color: #C9CDD6;
  padding: 8px 10px; border-radius: 9px; text-align: left;
}
.bot-item:hover { background: var(--sidebar-hover); color: #fff; }
.bot-item.active { background: var(--sidebar-active); color: #fff; }
.bot-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.bot-item .bot-meta { flex: 1; min-width: 0; }
.bot-item .bot-title { font-weight: 600; font-size: 13px; }
.bot-item .bot-off { font-size: 11px; color: #8B909C; }
.side-actions { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; }
.side-btn {
  width: 100%; border: 1px dashed #3A3F4B; background: transparent; color: #C9CDD6;
  border-radius: 9px; padding: 8px 10px; text-align: left; font-weight: 550;
}
.side-btn:hover { border-color: #5B6270; color: #fff; background: var(--sidebar-hover); }
.side-btn.primary-ghost { border-style: solid; border-color: #2A3A6A; background: #1A2240; color: #D6E0FF; }
.side-foot { padding: 14px 10px 4px; border-top: 1px solid #262A34; margin-top: 12px; }
.side-foot .who { font-weight: 600; font-size: 12.5px; }
.side-foot .where { font-size: 11px; color: #8B909C; margin-top: 1px; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); flex-shrink: 0; }
.topbar-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; min-height: 52px;
}
.topbar-row.sub { padding: 8px 18px 10px; gap: 14px; background: #FAFBFC; border-top: 1px solid var(--line-2); }
.bot-heading { display: flex; align-items: center; gap: 10px; min-width: 0; }
.bot-heading h1 { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.badge-ex {
  font-size: 10.5px; font-weight: 650; color: var(--warn); background: var(--warn-bg);
  border-radius: 999px; padding: 2px 7px; letter-spacing: .01em;
}
.toggle { display: flex; align-items: center; gap: 8px; user-select: none; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  width: 36px; height: 20px; background: #D0D5DD; border-radius: 999px; position: relative;
  transition: .15s background;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0,0,0,.15); transition: .15s left;
}
.toggle input:checked + .switch { background: var(--good); }
.toggle input:checked + .switch::after { left: 18px; }
.toggle-label { font-weight: 600; font-size: 13px; }
.toggle-label.off { color: var(--muted); }
.stats { display: flex; gap: 8px; margin-left: auto; }
.stat {
  background: var(--bg); border: 1px solid var(--line); border-radius: 9px;
  padding: 6px 11px; min-width: 92px;
}
.stat b { display: block; font-size: 15px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--muted); }
.btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 7px 12px; font-weight: 600; font-size: 13px; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: #F7F8FA; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); border-color: #F5C2BE; background: #fff; }
.btn-danger:hover { background: var(--bad-bg); }
.btn-sm { padding: 4px 8px; font-size: 12px; border-radius: 7px; }
.field { display: flex; align-items: center; gap: 7px; }
.field label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.field input[type="text"], .field input[type="tel"], .field input[type="time"], .inp, select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 9px;
  outline: none; min-width: 0;
}
.field input[type="text"], .field input[type="tel"] { width: 148px; }
.field input[type="time"] { width: 92px; padding: 5px 7px; }
.inp:focus, select:focus, textarea:focus, .field input:focus {
  border-color: #8AA4F8; box-shadow: 0 0 0 3px rgba(33,87,245,.15);
}
.linkish { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; }
.linkish:hover { text-decoration: underline; }

/* Tabs */
.tabs {
  display: flex; gap: 2px; padding: 0 14px;
  background: var(--surface); border-bottom: 1px solid var(--line);
  overflow-x: auto; flex-shrink: 0; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 9px 9px 8px; font-weight: 600; font-size: 12.5px;
  white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.content { flex: 1; overflow: auto; padding: 16px 18px 24px; position: relative; }
.panel { display: none; }
.panel.active { display: block; }
.hint {
  background: #F7F8FB; border: 1px solid var(--line); color: var(--ink-2);
  border-radius: var(--r); padding: 8px 12px; font-size: 12.5px; margin-bottom: 10px;
}
.hint strong { font-weight: 650; }
.sec-title { font-size: 14px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

/* Speak grid */
.stage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stage-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 10px 12px 12px; box-shadow: var(--shadow);
}
.stage-card label { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 12.5px; margin-bottom: 6px; }
.num {
  width: 20px; height: 20px; border-radius: 6px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
textarea {
  width: 100%; resize: vertical; min-height: 92px; line-height: 1.45;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 9px; background: #FCFCFD;
}
.stage-card textarea { min-height: 108px; }

/* Tables / lists */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { font-size: 11.5px; color: var(--muted); font-weight: 650; background: #FAFBFC; }
tr:last-child td { border-bottom: 0; }
.mono { font-variant-numeric: tabular-nums; }
.pill {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 8px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
}
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-info { background: #E8F0FE; color: var(--info); }
.pill-mute { background: #EEF0F4; color: var(--ink-2); }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.icon-btn:hover { background: #F2F4F7; color: var(--bad); }

/* Character */
.char-grid { display: grid; grid-template-columns: 1.3fr .7fr; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px; box-shadow: var(--shadow);
}
.card h3 { font-size: 13.5px; margin-bottom: 8px; }
.slider-row { margin: 0 0 14px; }
.slider-row header { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.slider-row header span { color: var(--muted); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Voices */
.voice-toolbar {
  display: flex; align-items: end; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.voice-toolbar .grow { flex: 1; min-width: 180px; }
.voice-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.voice-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; text-align: left; box-shadow: var(--shadow); min-height: 70px;
}
.voice-card:hover { border-color: #C5D0F5; }
.voice-card.selected { border-color: var(--accent); background: #F5F7FF; box-shadow: 0 0 0 3px rgba(33,87,245,.12); }
.voice-card .vn { font-weight: 700; font-size: 13px; }
.voice-card .vk { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.voice-card .vr { font-size: 11px; color: var(--ink-2); margin-top: 3px; }
.gender { font-size: 10.5px; font-weight: 700; border-radius: 999px; padding: 1px 6px; margin-left: 6px; vertical-align: middle; }
.g-f { background: #FCE7F3; color: #9D174D; }
.g-m { background: #E0EAFF; color: #1E40AF; }
.group-label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 8px; }

/* Bases */
.bases-layout { display: flex; gap: 14px; align-items: flex-start; }
.bases-main { flex: 1; min-width: 0; }
.file-group { margin-bottom: 12px; }
.file-group h4 {
  display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 0 0 6px;
}
.file-row {
  display: grid; grid-template-columns: minmax(108px, 1.2fr) auto auto auto auto;
  gap: 8px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 10px; margin-bottom: 4px; font-size: 12.5px;
}
.file-row .fn { font-weight: 600; }
.file-row .muted { color: var(--muted); font-size: 12px; }
.file-actions { display: flex; gap: 6px; justify-content: flex-end; }
.drawer {
  width: 400px; flex-shrink: 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
  display: none; max-height: calc(100vh - 172px); overflow: hidden;
  flex-direction: column;
}
.drawer.open { display: flex; }
.drawer-body { padding: 12px 14px 8px; overflow: auto; flex: 1; min-height: 0; }
.drawer-foot {
  padding: 10px 14px 12px; border-top: 1px solid var(--line);
  display: flex; gap: 8px; justify-content: flex-end; background: #fff; flex-shrink: 0;
}
.drawer h3 { font-size: 14.5px; margin-bottom: 4px; }
.drawer .sub { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.map-row {
  display: grid; grid-template-columns: 16px 1fr 1fr; gap: 8px; align-items: center;
  padding: 5px 0; border-bottom: 1px solid var(--line-2); font-size: 12.5px;
}
.map-ok { color: var(--good); font-weight: 800; }
.map-bad { color: var(--bad); font-weight: 800; }
.counts { display: flex; gap: 8px; margin: 8px 0; }
.preview { width: 100%; font-size: 11.5px; margin-top: 8px; }
.preview th, .preview td { padding: 4px 6px; }
.preview-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }

/* Script */
.script-grid { display: grid; grid-template-columns: 1fr 260px; gap: 12px; margin-bottom: 12px; }
.script-grid textarea { min-height: 250px; font-size: 13px; }
.versions { display: flex; flex-direction: column; gap: 6px; }
.ver {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff;
}
.ver.current { border-color: #B9C9FF; background: #F5F7FF; }
.ver b { font-size: 12.5px; display: block; }
.ver .when { font-size: 11.5px; color: var(--muted); margin: 2px 0 6px; }

/* Test chat */
.test-wrap { display: grid; grid-template-columns: 1fr 260px; gap: 12px; }
.chat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; min-height: 480px; box-shadow: var(--shadow); overflow: hidden;
}
.chat-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #F7F8FB; }
.bubble { max-width: 80%; padding: 8px 11px; border-radius: 12px; font-size: 13px; }
.bubble.bot { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-top-left-radius: 4px; }
.bubble.user { background: var(--accent); color: #fff; align-self: flex-end; border-top-right-radius: 4px; }
.bubble .who { font-size: 10.5px; font-weight: 700; margin-bottom: 2px; opacity: .7; }
.chat-in { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.chat-in input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }

/* Rules */
.status-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; }
.rules-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  grid-template-areas:
    "repeats support support"
    "repeats negative negative"
    "duration outbound privacy";
  gap: 10px;
}
.rule-repeats { grid-area: repeats; }
.rule-support { grid-area: support; }
.rule-negative { grid-area: negative; }
.rule-duration { grid-area: duration; }
.rule-outbound { grid-area: outbound; }
.rule-privacy { grid-area: privacy; }
.rule {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; box-shadow: var(--shadow);
}
.rule header { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.rule h3 { font-size: 13.5px; font-weight: 700; }
.rule p.desc { font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 3px 9px; font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.chip input { margin-right: 5px; accent-color: var(--accent); }
.chip.on { background: var(--accent-soft); border-color: #C5D0F5; color: var(--accent-2); }
.block-list { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.block-list li {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px;
  border-bottom: 1px solid var(--line-2); font-size: 12.5px; list-style: none;
  flex-wrap: nowrap;
}
.block-list .mono { white-space: nowrap; flex: 0 0 auto; }
.block-list li:last-child { border-bottom: 0; }
.radios { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12.5px; }
.radios label { display: flex; align-items: center; gap: 5px; }
.rule textarea { min-height: 44px; }
.rule .field { margin: 6px 0; }

/* Calls */
.transcript { font-size: 12px; color: var(--ink-2); max-width: 320px; }
.hidden-row { display: none; }
.hidden-row td { background: #F7F8FB; font-size: 12.5px; }
.call-tr { cursor: pointer; }
.call-tr:hover td { background: #F7F8FB; }

/* Popover / toast / modal */
.popover-wrap { position: relative; }
.popover {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  width: 340px; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-lg); padding: 12px;
}
.popover.open { display: block; }
.popover h4 { font-size: 13px; margin-bottom: 8px; }
.check { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; margin: 6px 0; }
.toast {
  position: fixed; right: 18px; bottom: 18px; background: var(--ink); color: #fff;
  padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: .2s ease; z-index: 50; max-width: 360px; font-size: 13px;
}
.toast.show { opacity: 1; transform: none; }
.modal-back {
  display: none; position: fixed; inset: 0; background: rgba(16,24,40,.4);
  z-index: 40; place-items: center;
}
.modal-back.open { display: grid; }
.modal {
  background: #fff; border-radius: 14px; padding: 18px; width: min(420px, calc(100% - 32px));
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 8px; }
.modal p { color: var(--ink-2); margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.source { font-size: 11.5px; color: var(--muted); margin-top: 10px; }
.disabled-note { opacity: .55; }

@media (max-width: 1180px) {
  .voice-grid { grid-template-columns: repeat(3, 1fr); }
  .stage-grid, .rules-grid, .char-grid, .script-grid, .test-wrap { grid-template-columns: 1fr; grid-template-areas: none; }
  .rule-repeats, .rule-support, .rule-negative, .rule-duration, .rule-outbound, .rule-privacy { grid-area: auto; }
  .drawer { width: 360px; }
}
