/* BOTIX — Application Styles
 * Дизайн-система: modules/ui/css/tokens.css + components.css
 * Здесь: brand override + BOTIX-specific алиасы + компоненты приложения
 */

/* === Help button (кружочек ? рядом с заголовком) === */
.help-q {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; border-radius: 50%;
    background: none; border: 1.5px solid #c7c7cc;
    color: #aeaeb2; font-size: 12px; font-weight: 600;
    cursor: pointer; font-family: inherit;
    transition: all 0.15s; vertical-align: middle;
    margin-left: 6px; padding: 0; flex-shrink: 0;
}
.help-q:hover { border-color: var(--primary); color: var(--primary); }

/* === BOTIX BRAND + ALIASES === */
:root {
    /* Brand: синий (Apple Blue) — кнопки, ссылки, интерактив */
    --ui-primary: #007AFF;
    --ui-primary-dark: #0056CC;
    --ui-primary-light: #409CFF;

    /* Short aliases → --ui-* (используются во всех Views) */
    --primary: var(--ui-primary);
    --primary-dark: var(--ui-primary-dark);
    --primary-light: var(--ui-primary-light);
    --bg: var(--ui-bg);
    --bg-secondary: var(--ui-bg-secondary);
    --bg-card: var(--ui-bg-card);
    --bg-card-hover: var(--ui-bg-card-hover);
    --bg-input: var(--ui-bg-input);
    --text: var(--ui-text);
    --text-muted: var(--ui-text-muted);
    --text-secondary: var(--ui-text-secondary);
    --border: var(--ui-border);
    --border-focus: var(--ui-border-focus);
    --success: var(--ui-success);
    --success-bg: var(--ui-success-bg);
    --warning: var(--ui-warning);
    --warning-bg: var(--ui-warning-bg);
    --danger: var(--ui-danger);
    --danger-bg: var(--ui-danger-bg);
    --radius: var(--ui-radius-lg);
    --radius-sm: var(--ui-radius-md);
    --radius-xs: var(--ui-radius-sm);
    --shadow: var(--ui-shadow-sm);
    --shadow-md: var(--ui-shadow-md);
    --shadow-lg: var(--ui-shadow-lg);
    --bg-main: var(--ui-bg);

    /* BOTIX-specific (не в дизайн-системе) */
    --sidebar-width: 220px;
    --sidebar-collapsed-width: 60px;
    --canvas-bg: #F1F5F9;
    --canvas-dot: rgba(100, 116, 139, 0.2);
    --node-bg: #FFFFFF;
    --node-border: #E2E8F0;
    --node-shadow: 0 1px 4px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);
    --connection-color: #94A3B8;
    --toolbar-bg: #1E293B;
    --toolbar-text: #F8FAFC;
}

/* === DARK — BOTIX-specific only (common vars auto-switch via tokens.css) === */
[data-theme="dark"] {
    --canvas-bg: #0F172A;
    --canvas-dot: rgba(100, 116, 139, 0.15);
    --node-bg: #1E293B;
    --node-border: #334155;
    --node-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
    --connection-color: #64748B;
    --toolbar-bg: #334155;
    --toolbar-text: #F8FAFC;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
a.doc-btn, a.doc-btn:hover,
a.tpl-btn, a.tpl-btn:hover,
a.tpl-card, a.tpl-card:hover,
a.btn-export, a.btn-export:hover { text-decoration: none; }

[data-theme="dark"] a { color: var(--primary-light); }

/* === APPLE-STYLE COMPONENTS === */

.segmented-control {
    display: inline-flex;
    gap: 2px;
    background: var(--border);
    border-radius: 10px;
    padding: 3px;
}

.segmented-control__item {
    padding: 7px 18px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.segmented-control__item:hover {
    color: var(--text);
}

.segmented-control__item.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] .segmented-control__item.active {
    background: #334155;
    color: #F1F5F9;
}

.btn-studio {
    background: var(--text);
    color: var(--bg-card);
    border: none;
}

.btn-studio:hover {
    opacity: 0.85;
    text-decoration: none;
}

.section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* === AUTH PAGES === */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.auth-card {
    width: 100%;
    max-width: var(--w-narrow);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 40px 40px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 36px;
    text-decoration: none;
}

/* ===== BOTIX LOGO (PNG image) ===== */
.logo-img {
    display: block;
    height: auto;
    object-fit: contain;
}
.logo-img-lg { width: 160px; }  /* auth pages */
.logo-img-md { width: 90px; }  /* header, footer */
.logo-img-sm { width: 108px; }  /* sidebar */

.auth-card h2 {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
    letter-spacing: -0.02em;
}

.auth-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
    letter-spacing: -0.01em;
}

/* === FORMS === */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--text-muted);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .form-control:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
}

.form-control::placeholder {
    color: var(--text-muted);
}

/* Единая высота для select и input */
select.form-control {
    height: 44px;
    padding-top: 0;
    padding-bottom: 0;
}

/* Компактные числовые поля */
input[type="number"].form-control {
    -moz-appearance: textfield;
}
input[type="number"].form-control::-webkit-inner-spin-button,
input[type="number"].form-control::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Компактные инпуты для форм в accordion и inline */
.form-compact .form-group { margin-bottom: 12px; }
.form-compact .form-control { padding: 8px 12px; font-size: 14px; }
.form-compact select.form-control { height: 38px; }
.form-compact label { font-size: 12px; margin-bottom: 4px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.auth-card .btn-primary {
    background: var(--text);
    color: var(--bg-card);
    width: 100%;
    padding: 13px 20px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 12px;
    margin-top: 4px;
}

.auth-card .btn-primary:hover {
    opacity: 0.85;
    text-decoration: none;
}

.auth-card .btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--primary-dark);
    text-decoration: none;
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg-card-hover);
    text-decoration: none;
}

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

.auth-footer {
    text-align: center;
    margin-top: 28px;
    font-size: 14px;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 13px;
    display: none;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.alert.show { display: block; }

/* === APP LAYOUT === */

.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
}

.sidebar-header {
    padding: 20px;
}

.sidebar-header .logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-size: 18px;
    font-weight: 700;
}

.sidebar-header .logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-xs);
    font-weight: 800;
    font-size: 16px;
}

/* Bot indicator in sidebar (demo) */
.sidebar-bot-indicator {
    padding: 0 12px 0;
}
.sidebar-bot-indicator__inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--primary-bg, rgba(99,102,241,.08));
    text-decoration: none;
    color: var(--text);
    transition: background 0.15s;
}
.sidebar-bot-indicator__inner:hover {
    background: var(--primary-bg-hover, rgba(99,102,241,.14));
}
.sidebar-bot-indicator__avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: contain;
    flex-shrink: 0;
}
.sidebar-bot-indicator__avatar--placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    color: var(--text-muted);
}
.sidebar-bot-indicator__name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-section-title {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 0 12px;
    margin-bottom: 4px;
    opacity: 0.7;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 400;
    transition: all 0.15s;
}

.nav-item:hover {
    background: var(--bg-card-hover);
    color: var(--text);
    text-decoration: none;
}

.nav-item.active {
    background: var(--bg-card-hover);
    color: var(--text);
    font-weight: 600;
}

[data-theme="dark"] .nav-item.active {
    background: var(--bg-card-hover);
    color: var(--text);
    font-weight: 600;
}

.nav-item--ai { color: #E53935; }
.nav-item--ai .nav-icon { stroke: #E53935; }
.nav-item--ai:hover { color: #E53935; }
.nav-ai-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: #E53935;
    padding: 1px 6px;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

/* Контроль — красный блок в sidebar */
.nav-control-block {
    margin: 4px 0;
    border-radius: 10px;
    padding: 2px 0;
    background: rgba(229,57,53,.04);
    border: 1px solid rgba(229,57,53,.1);
}
.nav-item--control {
    color: #E53935 !important;
    font-weight: 600 !important;
}
.nav-item--control .nav-icon {
    stroke: #E53935;
}
.nav-item--control:hover {
    background: rgba(229,57,53,.08) !important;
    color: #E53935 !important;
}
.nav-item--control.active {
    background: rgba(229,57,53,.1) !important;
    color: #E53935 !important;
}
.nav-item--control-sub {
    padding-left: 20px;
    font-size: 13px;
}
.nav-item--control-sub .nav-icon {
    width: 16px;
    height: 16px;
    opacity: .6;
}

/* Context Assistant */
#ctxAssistant { position: fixed; bottom: 24px; right: 24px; z-index: 90; }
.ctx-btn { width: 48px; height: 48px; border-radius: 50%; background: #E53935; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 12px rgba(229,57,53,0.3); transition: transform 0.15s; }
.ctx-btn:hover { transform: scale(1.05); }
.ctx-bubble { position: absolute; bottom: 60px; right: 0; background: var(--bg-card, #fff); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; max-width: 260px; font-size: 14px; color: var(--text); line-height: 1.4; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
.ctx-bubble-close { position: absolute; top: 6px; right: 8px; background: none; border: none; font-size: 16px; color: var(--text-muted); cursor: pointer; line-height: 1; }
.ctx-chat { position: absolute; bottom: 60px; right: 0; width: 340px; max-height: 480px; background: var(--bg-card, #fff); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 8px 32px rgba(0,0,0,0.12); flex-direction: column; overflow: hidden; }
.ctx-chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.ctx-chat-ava { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
.ctx-chat-info { flex: 1; }
.ctx-chat-name { font-size: 14px; font-weight: 600; color: var(--text); }
.ctx-chat-status { font-size: 11px; color: var(--text-muted); }
.ctx-chat-close { background: none; border: none; font-size: 20px; color: var(--text-muted); cursor: pointer; }
.ctx-chat-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; max-height: 300px; }
.ctx-msg { max-width: 85%; padding: 10px 14px; font-size: 14px; line-height: 1.45; border-radius: 14px; }
.ctx-msg-bot { background: var(--bg-secondary, #f0f0f2); color: var(--text); border-radius: 14px 14px 14px 4px; align-self: flex-start; }
.ctx-msg-user { background: var(--primary); color: #fff; border-radius: 14px 14px 4px 14px; align-self: flex-end; }
.ctx-chat-btns { padding: 8px 12px 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.ctx-pill { padding: 6px 14px; border-radius: 16px; border: 1px solid var(--border); background: var(--bg-card, #fff); color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.ctx-pill:hover { border-color: #E53935; color: #E53935; }

.nav-badge {
    margin-left: auto;
    background: #FF3B30;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

.user-name {
    font-size: 13px;
    font-weight: 500;
}

.user-email {
    font-size: 11px;
    color: var(--text-muted);
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 32px;
    min-width: 0;
    overflow-x: hidden;
    max-width: 100vw;
}

/* === Sidebar collapse === */
.sidebar, .main-content { transition: width 0.25s ease, margin-left 0.25s ease; }

.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: -12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 51;
    padding: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    transition: transform 0.25s ease;
}
.sidebar-toggle:hover { background: var(--bg-card-hover, #e2e8f0); }
.sidebar-toggle svg { width: 14px; height: 14px; stroke: var(--text-secondary); fill: none; stroke-width: 2; }

body.sidebar-collapsed .sidebar { width: var(--sidebar-collapsed-width); }
body.sidebar-collapsed .main-content { margin-left: var(--sidebar-collapsed-width); }

/* Повернуть стрелку */
body.sidebar-collapsed .sidebar-toggle { transform: rotate(180deg); }

/* Скрыть текст (bare text nodes — через font-size:0, иконки сохраняют размер) */
body.sidebar-collapsed .sidebar .nav-item {
    font-size: 0;
    justify-content: center;
    padding: 10px;
    gap: 0;
    position: relative;
}
/* .nav-item--control-sub имеет свой font-size/padding-left — переопределяем через специфичность
   (4 класса > 1 класс), чтобы текст пропал и иконка отцентровалась */
body.sidebar-collapsed .sidebar .nav-item--control-sub {
    font-size: 0;
    padding: 10px;
}
body.sidebar-collapsed .sidebar .nav-icon { flex-shrink: 0; width: 20px; height: 20px; }
body.sidebar-collapsed .sidebar .nav-section-title { display: none; }
body.sidebar-collapsed .sidebar .sidebar-bot-indicator__name { display: none; }
body.sidebar-collapsed .sidebar .sidebar-bot-indicator__inner { justify-content: center; }
body.sidebar-collapsed .sidebar .user-name,
body.sidebar-collapsed .sidebar .user-email { display: none; }
body.sidebar-collapsed .sidebar .user-info { justify-content: center; gap: 0; }
body.sidebar-collapsed .sidebar .theme-switcher { display: none; }
body.sidebar-collapsed .sidebar .nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    font-size: 9px;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
}
/* Лого при collapsed */
body.sidebar-collapsed .sidebar-header { padding: 16px 12px; text-align: center; }
body.sidebar-collapsed .sidebar-header .logo { justify-content: center; }
body.sidebar-collapsed .sidebar-header .logo-img { max-width: 32px; }

/* Sidebar-nav padding при collapsed */
body.sidebar-collapsed .sidebar-nav { padding: 12px 8px; }
body.sidebar-collapsed .sidebar-footer { padding: 12px 8px; }

/* Tooltip при наведении на collapsed nav-item */
body.sidebar-collapsed .sidebar .nav-item[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

/* Cards grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all 0.2s;
    box-shadow: var(--shadow);
}

.card:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.card h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.card p {
    font-size: 13px;
    color: var(--text-muted);
}

/* === SCENARIO CARDS (вариант «Больше воздуха») === */

a.scenario-card {
    text-decoration: none;
    color: inherit;
}

.scenario-card {
    position: relative;
    height: 140px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: none;
    display: flex;
    gap: 6px;
    align-items: stretch;
    overflow: hidden;
}

.scenario-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
    border-color: transparent;
}

[data-theme="dark"] .scenario-card {
    box-shadow: none;
}

[data-theme="dark"] .scenario-card:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.scenario-card__left {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
}

.scenario-card__avatar {
    width: 113px;
    height: 113px;
    margin-bottom: -5px;
}

.scenario-card__avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.scenario-card__avatar svg {
    width: 34px;
    height: 34px;
    color: var(--text-muted);
}

.scenario-card__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 4px 0;
}

.scenario-card__title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.scenario-card__desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 4px 0 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.scenario-card__bottom {
    position: absolute;
    bottom: 5px;
    right: 5px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.scenario-card__channels {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
}

.scenario-card__status {
    position: absolute;
    top: 5px;
    left: 5px;
    z-index: 2;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 100px;
    white-space: nowrap;
}

.scenario-card__status--active {
    background: var(--success-bg, rgba(52,199,89,.12));
    color: var(--success, #34C759);
}

.scenario-card__status--draft {
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.scenario-card__version {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-size: 10px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 100px;
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-muted);
}

.scenario-card__settings {
    position: absolute;
    bottom: 5px;
    left: 5px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
}

.scenario-card:hover .scenario-card__settings {
    opacity: 1;
}

/* Selected bot card (demo) */
.scenario-card--selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99,102,241,.15);
}

/* Bot card action buttons (demo) */
.scenario-card__actions {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}
.scenario-card:hover .scenario-card__actions,
.scenario-card--selected .scenario-card__actions {
    opacity: 1;
}
.scenario-card__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 100px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background 0.15s, transform 0.15s;
    white-space: nowrap;
}
.scenario-card__btn:hover { transform: scale(1.04); }
.scenario-card__btn--primary {
    background: var(--primary);
    color: #fff;
}
.scenario-card--selected .scenario-card__btn--primary {
    background: var(--success, #34C759);
    pointer-events: none;
}
.scenario-card__btn--secondary {
    background: var(--bg-secondary);
    color: var(--text-muted);
    padding: 5px 8px;
}
.scenario-card__btn--secondary:hover {
    color: var(--text);
}

.scenario-card__settings:hover {
    color: var(--text-primary);
}

/* Request scenario card */
.scenario-card--request {
    border-style: dashed;
    border-color: var(--border);
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
}
.scenario-card--request:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.03);
}
[data-theme="dark"] .scenario-card--request:hover {
    background: rgba(99, 102, 241, 0.06);
}
.scenario-card__avatar--request {
    background: var(--bg-secondary);
    border: 2px dashed var(--border);
}

/* === TEMPLATES CATALOG === */

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.template-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.template-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(108, 92, 231, 0.1);
}

.template-card__header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-card__icon {
    font-size: 24px;
    line-height: 1;
}

.template-card__category {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary);
    background: rgba(108, 92, 231, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
}

.template-card__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.template-card__desc {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0;
    flex: 1;
}

.template-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
}

.template-card__channels {
    display: flex;
    gap: 4px;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 13px;
    border-radius: 6px;
}

/* === AVATAR UPLOAD === */

.avatar-upload {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.avatar-upload__preview {
    max-width: 120px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-upload__preview img {
    max-width: 100%;
    height: auto;
    display: block;
}

.avatar-upload__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.avatar-upload__actions {
    padding-top: 8px;
}

/* Модалка кадрирования аватара */
.avatar-crop-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.avatar-crop-modal {
    background: #fff;
    border-radius: 16px;
    max-width: var(--w-modal-md);
    width: 95%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.avatar-crop-modal__header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.avatar-crop-modal__header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d1d1f;
}

.avatar-crop-modal__header button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #86868b;
    padding: 0;
    line-height: 1;
}

.avatar-crop-modal__body {
    padding: 20px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

.avatar-crop-modal__container {
    max-width: 100%;
    max-height: 60vh;
}

.avatar-crop-modal__container img {
    max-width: 100%;
    max-height: 60vh;
    display: block;
}

.avatar-crop-modal__footer {
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Оверлей-образец для совмещения */
.avatar-reference-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: url('/images/avatars/avatar-booking.png') center/100% no-repeat;
    opacity: 0.3;
    pointer-events: none;
    z-index: 10;
}

.avatar-zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.avatar-zoom-controls button {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    background: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1d1d1f;
}

.avatar-zoom-controls button:hover {
    background: #f5f5f7;
}

/* === SETTINGS MODAL === */

/* Модалка настроек демо-бота — по Brand Book (Apple-стиль) */
.settings-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-modal {
    position: relative;
    background: #FFFFFF;
    border-radius: 14px;
    overflow: hidden;
    width: 460px;
    max-width: 92vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}
[data-theme="dark"] .settings-modal { background: #1E293B; }

.settings-modal__header {
    padding: 18px 20px 0;
}

.settings-modal__header h2 {
    font-size: 16px;
    font-weight: 600;
    color: #1D1D1F;
    margin: 0;
}

.settings-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    color: #8E8E93;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
    z-index: 1;
}

.settings-modal__close:hover {
    background: rgba(60, 60, 67, 0.08);
    color: #1D1D1F;
}

.settings-modal__tabs {
    padding: 8px 20px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-bottom: 1px solid rgba(60, 60, 67, 0.08);
}
.settings-modal__tabs::-webkit-scrollbar { display: none; }

.settings-modal__tabs .segmented-control {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    max-width: 100%;
    margin-bottom: 8px;
}

.settings-modal__tabs .segmented-control__item {
    flex-shrink: 0;
    white-space: nowrap;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #6E6E73;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}
.settings-modal__tabs .segmented-control__item:hover {
    color: #1D1D1F;
}
.settings-modal__tabs .segmented-control__item.active {
    background: #fff;
    color: #1D1D1F;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.settings-modal__body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

/* ---- Формы внутри модалки настроек — по Brand Book ---- */
.settings-modal .form-group {
    margin-bottom: 14px;
}
.settings-modal .form-group:last-child { margin-bottom: 0; }
.settings-modal .form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #1D1D1F;
    margin-bottom: 6px;
}
.settings-modal .form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    color: #1D1D1F;
    background: #fff;
    border: 1px solid rgba(60, 60, 67, 0.12);
    border-radius: 8px;
    transition: border-color 0.15s;
}
.settings-modal .form-control:focus {
    outline: none;
    border-color: #007AFF;
    box-shadow: none;
}
.settings-modal textarea.form-control {
    resize: vertical;
    min-height: 60px;
    line-height: 1.4;
}
.settings-modal select.form-control {
    height: auto;
    padding: 8px 30px 8px 12px;
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

/* ---- Футер модалки (Brand Book: в модалках — футер, flex end, gap 8) ---- */
.settings-modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid rgba(60, 60, 67, 0.08);
    background: #fff;
}
.settings-modal__footer .btn {
    width: auto;
    padding: 8px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
}

.settings-modal__panel {
    display: none;
}

.settings-modal__panel.active {
    display: block;
}

.channel-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
}

.channel-badge--web {
    background: var(--primary-tint);
    color: var(--primary);
}

.channel-badge--tg {
    background: rgba(0, 136, 204, 0.1);
    color: #0088CC;
}

.channel-badge--wa {
    background: rgba(37, 211, 102, 0.1);
    color: #25D366;
}

.channel-badge--ai {
    background: rgba(60, 60, 67, 0.08);
    color: var(--text);
}

[data-theme="dark"] .channel-badge--ai {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
}

[data-theme="dark"] .channel-badge--web {
    background: rgba(59, 130, 246, 0.15);
    color: #60A5FA;
}

[data-theme="dark"] .channel-badge--tg {
    background: rgba(0, 136, 204, 0.15);
    color: #38BDF8;
}

[data-theme="dark"] .channel-badge--wa {
    background: rgba(37, 211, 102, 0.15);
    color: #4ADE80;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: none;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.stat-card .stat-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.stat-card .stat-change {
    font-size: 12px;
    margin-top: 4px;
}

.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* Project selector */
.project-selector {
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 13px;
    width: 100%;
    cursor: pointer;
}

/* Add project card */
.card-add {
    border: 1.5px dashed var(--border);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    border-radius: 16px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: none;
}

.card-add:hover {
    color: var(--text);
    border-color: var(--text-muted);
    background: var(--bg-card-hover);
    transform: none;
}

/* Theme switcher (3 modes: light / dark / system) */
.theme-switcher {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: var(--border);
    border-radius: 10px;
    width: 100%;
}

.theme-switcher__btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 0;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.theme-switcher__btn svg {
    width: 16px;
    height: 16px;
}

.theme-switcher__btn:hover {
    color: var(--text);
}

.theme-switcher__btn.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

/* Auth page theme toggle */
.auth-theme-toggle {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s;
    z-index: 10;
}

.auth-theme-toggle:hover {
    background: var(--bg-card-hover);
}

/* Super Admin link */
.sa-link {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
    margin-bottom: 8px;
}

.sa-link:hover {
    background: var(--danger-bg);
    text-decoration: none;
}

.sa-link-back {
    border-color: var(--border);
    color: var(--text-muted);
    font-weight: 500;
}

.sa-link-back:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

/* ========================
   DEMO MODE
   ======================== */

/* Demo Banner — pill по центру, не закрывает логотип и боковые кнопки */
.demo-banner {
    position: fixed;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: linear-gradient(135deg, #EF4444, #DC2626);
    color: #fff;
    padding: 0 20px;
    height: 36px;
    border-radius: 100px;
    box-shadow: 0 2px 12px rgba(0,0,0,.2);
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.demo-banner-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: rgba(255,255,255,.2);
    padding: 2px 8px;
    border-radius: 100px;
}

.demo-banner-text {
    font-size: 13px;
    font-weight: 600;
}

.demo-banner-btn {
    padding: 4px 14px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all .2s;
    white-space: nowrap;
    color: #fff;
    border: 1px solid rgba(255,255,255,.4);
}

.demo-banner-btn:hover {
    background: rgba(255,255,255,.15);
    text-decoration: none;
}

.demo-banner-btn--primary {
    background: #fff;
    color: #DC2626;
    border-color: #fff;
}

.demo-banner-btn--primary:hover {
    background: #FEE2E2;
}

/* ========================
   UNIFIED TABLES — .btx-table
   ======================== */

.btx-table { width: 100%; border-collapse: collapse; }
.btx-table th {
    text-align: left;
    padding: 10px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    white-space: nowrap;
}
.btx-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}
.btx-table tbody tr { transition: background 0.1s; }
.btx-table tbody tr:hover td { background: var(--bg-card-hover); }
.btx-table .td-r { text-align: right; }
.btx-table .td-c { text-align: center; }
.btx-table .td-muted { color: var(--text-muted); font-size: 13px; }
.btx-table .td-bold { font-weight: 600; }
.btx-table .td-nowrap { white-space: nowrap; }
.btx-table .td-action {
    width: 40px;
    text-align: center;
    padding: 8px;
}
.btx-table .td-action button {
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); padding: 4px;
    transition: color 0.15s;
}
.btx-table .td-action button:hover { color: var(--danger); }

/* Responsive: таблица со скроллом на мобильных */
.btx-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
}

/* ========================
   BADGES — .badge
   ======================== */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-primary { background: rgba(99,102,241,.1); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--bg-card-hover); color: var(--text-muted); }

/* ========================
   SETTINGS CARDS — max-width
   ======================== */

.settings-card { max-width: var(--w-content); }

/* Accordion-row для inline-редактирования в таблицах */
.btx-table .accordion-row td {
    padding: 0;
    border-bottom: 2px solid var(--primary);
    background: var(--bg);
}
.accordion-form {
    padding: 16px 16px 12px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
    align-items: end;
}
.accordion-form .form-group { margin-bottom: 0; }
.accordion-form .form-group label {
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-muted);
}
.accordion-form .form-control {
    padding: 8px 12px;
    font-size: 14px;
}
.accordion-form select.form-control { height: 38px; }
.accordion-form .accordion-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* ========================
   KPI GRID — адаптивная
   ======================== */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .demo-banner { padding: 0 12px; gap: 8px; }
    .demo-banner-text { display: none; }
    .settings-card { max-width: 100%; }
    .accordion-form { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .main-content { padding: 10px; }
    .kpi-grid { grid-template-columns: 1fr; }
}

/* === Success indicator (iOS-style) === */
.success-circle {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.8);
    width: 80px; height: 80px; border-radius: 50%;
    background: rgba(255,255,255,.2); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 24px rgba(0,0,0,.08);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999; opacity: 0; pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
}
.success-circle.show {
    opacity: 1; transform: translate(-50%, -50%) scale(1);
}
.success-circle svg {
    width: 36px; height: 36px; stroke: #34C759; stroke-width: 3;
    fill: none; stroke-linecap: round; stroke-linejoin: round;
}
.success-circle svg path {
    stroke-dasharray: 40; stroke-dashoffset: 40;
    transition: stroke-dashoffset 0.35s 0.15s;
}
.success-circle.show svg path {
    stroke-dashoffset: 0;
}

/* === BOTIX SVG-icon sprite ===
 * Заменяет Bootstrap Icons font (38 КБ → 32 КБ gzip, без @font-face).
 * Использование: <svg class="bi"><use href="/icons/sprite.svg#NAME"/></svg>
 * Поведение совместимо с iconfont: 1em размер от parent font-size, цвет через currentColor.
 */
svg.bi {
    display: inline-block;
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    fill: currentColor;
    flex-shrink: 0;
}
