/* =========================================================================
   Конструктор ИИ-ботов — дизайн-система (SIBUR brand)
   Внешний файл под строгим CSP (style-src 'self' разрешён).
   Все классы и CSS-переменные, на которые завязаны шаблоны и JS,
   сохранены — добавлены токены, компоненты и «воздух».
   ========================================================================= */

/* ---------- Дизайн-токены ---------- */
:root {
    /* Бренд-палитра СИБУР */
    --sibur-dna: #008C95;
    --sibur-dark: #00313C;
    --sibur-mint: #77E2C3;
    --sibur-orange: #E04E39;
    --sibur-beige: #FFE6D7;
    --sibur-gray-85: #262626;
    --sibur-gray-50: #5A5A5A;
    --sibur-gray-28: #CCCCCC;
    --sibur-bg: #f4f7f8;

    /* Производные оттенки */
    --teal-700: #006D74;       /* primary-кнопка */
    --teal-800: #005a60;
    --teal-050: #e9f6f6;       /* мягкая бирюзовая заливка */
    --teal-100: #d8eef0;
    --line: #e7edee;           /* границы/разделители */
    --line-soft: #eef2f3;
    --surface: #ffffff;
    --surface-muted: #f7fafa;
    --text: #1c2b30;
    --warn-bg: #fff7e6;
    --warn-line: #f0a836;
    --warn-text: #a16700;
    --ok-bg: #e6f7f0;
    --ok-text: #006D74;
    --danger-text: #A82B1A;

    /* Скругления */
    --r-sm: 7px;
    --r: 12px;
    --r-lg: 16px;
    --r-pill: 999px;

    /* Тени — мягкие, фирменно-тёмные */
    --sh-1: 0 1px 2px rgba(0,49,60,0.05), 0 2px 8px rgba(0,49,60,0.06);
    --sh-2: 0 2px 6px rgba(0,49,60,0.08), 0 8px 24px rgba(0,49,60,0.08);
    --sh-pop: 0 12px 44px rgba(0,49,60,0.22);
    --ring: 0 0 0 3px rgba(0,140,149,0.22);

    --nav-h: 60px;
    --maxw: 1040px;
    --maxw-wide: 1180px;
}

/* ---------- Сброс / база ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 520px at 100% -10%, rgba(119,226,195,0.10), transparent 60%),
        radial-gradient(1000px 480px at -5% 0%, rgba(0,140,149,0.06), transparent 55%),
        var(--sibur-bg);
    background-attachment: fixed;
    line-height: 1.55;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
}

a { color: var(--sibur-dna); text-decoration: none; transition: color .15s; }
a:hover { color: var(--teal-800); text-decoration: underline; }

h1, h2, h3, h4 { color: var(--sibur-dark); line-height: 1.25; font-weight: 700; }
h2 { font-size: 1.55rem; margin-bottom: 0.3rem; letter-spacing: -0.01em; }
h3 { font-size: 1.15rem; }

code {
    font-family: 'SF Mono', ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.86em;
    background: var(--teal-050);
    color: var(--teal-800);
    padding: 0.08em 0.4em;
    border-radius: 5px;
}

::selection { background: rgba(0,140,149,0.18); }

/* Видимый фокус по всей системе (WCAG). */
:focus-visible {
    outline: 2px solid var(--sibur-dna);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---------- Навбар ---------- */
.navbar {
    background: linear-gradient(100deg, var(--sibur-dna) 0%, #016a72 45%, var(--sibur-dark) 100%);
    color: #fff;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--nav-h);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 12px rgba(0,49,60,0.18);
}
.navbar a { color: #fff; }
.navbar .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.12rem;
    letter-spacing: 0.01em;
}
.navbar .brand:hover { text-decoration: none; opacity: 0.95; }
.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    object-fit: cover;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,49,60,0.25), inset 0 0 0 1px rgba(255,255,255,0.3);
    flex-shrink: 0;
}
.navbar .user-info { display: flex; align-items: center; gap: 1.15rem; font-size: 0.9rem; }
.navbar .user-info > span { opacity: 0.92; }
.navbar .user-info a { opacity: 0.92; transition: opacity .15s; }
.navbar .user-info a:hover { opacity: 1; text-decoration: none; }
.navbar-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.2rem 0.5rem;
    border-radius: 8px;
}
.navbar-toggle:hover { background: rgba(255,255,255,0.12); }

/* ---------- Контейнер ---------- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 2rem 2rem 3.5rem; }
.container-wide { max-width: var(--maxw-wide); }

/* ---------- Заголовок страницы ---------- */
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.4rem;
}

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--r-sm);
    border: 1.5px solid transparent;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, box-shadow .15s, transform .05s, color .15s, border-color .15s, opacity .15s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: linear-gradient(180deg, var(--sibur-dna), var(--teal-700));
    color: #fff;
    box-shadow: 0 1px 2px rgba(0,49,60,0.18), 0 4px 12px rgba(0,140,149,0.22);
}
.btn-primary:hover { background: linear-gradient(180deg, #0298a1, var(--teal-800)); color: #fff; box-shadow: 0 2px 4px rgba(0,49,60,0.2), 0 6px 18px rgba(0,140,149,0.28); }

.btn-secondary { background: var(--sibur-dark); color: #fff; }
.btn-secondary:hover { background: #013c49; color: #fff; }

.btn-outline { background: #fff; color: var(--teal-700); border-color: var(--sibur-gray-28); }
.btn-outline:hover { background: var(--teal-050); border-color: var(--sibur-dna); color: var(--teal-800); }

.btn-ghost { background: transparent; color: var(--sibur-gray-50); border-color: transparent; }
.btn-ghost:hover { background: rgba(0,49,60,0.06); color: var(--sibur-dark); }

.btn-danger { background: #fff; color: var(--sibur-orange); border-color: rgba(224,78,57,0.5); }
.btn-danger:hover { background: rgba(224,78,57,0.08); border-color: var(--sibur-orange); color: var(--sibur-orange); }

.btn-sm { padding: 0.34rem 0.8rem; font-size: 0.8rem; border-radius: 6px; }
.btn-block { width: 100%; }

/* ---------- Карточки ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 1.5rem;
    margin-bottom: 1.1rem;
    box-shadow: var(--sh-1);
}
.card > header,
.card-header {
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--sibur-gray-50);
    margin-bottom: 0.9rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--line-soft);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Акцентная (бирюзовая) карточка — для AI-помощника, подсказок «готово?» */
.card-accent {
    background: linear-gradient(135deg, rgba(0,140,149,0.05), rgba(119,226,195,0.08));
    border: 1.5px solid rgba(0,140,149,0.18);
}
.card-accent > header { border-bottom-color: rgba(0,140,149,0.18); color: var(--teal-800); }

/* ---------- Таблицы ---------- */
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; font-weight: 700; font-size: 0.74rem; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--sibur-gray-50); padding: 0.65rem 0.85rem;
    border-bottom: 1.5px solid var(--line);
}
td { padding: 0.7rem 0.85rem; border-bottom: 1px solid var(--line-soft); font-size: 0.9rem; vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover td { background: var(--surface-muted); }
tbody tr:last-child td { border-bottom: none; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Карточка-обёртка для таблиц «в край» */
.card-table { padding: 0; overflow: hidden; }

/* ---------- Формы ---------- */
label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 0.35rem; color: var(--sibur-dark); }
.hint { font-size: 0.8rem; color: var(--sibur-gray-50); margin-bottom: 0.5rem; line-height: 1.5; }

input[type="text"], input[type="password"], input[type="number"], input[type="url"], input[type="email"],
select, textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1.5px solid var(--sibur-gray-28);
    border-radius: var(--r-sm);
    font-family: inherit;
    font-size: 0.92rem;
    color: var(--text);
    background: #fff;
    margin-bottom: 0.2rem;
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #9aa6a9; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--sibur-dna);
    box-shadow: var(--ring);
}
input:disabled, textarea:disabled, select:disabled {
    background: #f0f2f3;
    color: var(--sibur-gray-50);
    cursor: not-allowed;
}
textarea { line-height: 1.55; }
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235A5A5A' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.85rem center;
    padding-right: 2.2rem;
}
.field { margin-bottom: 1.1rem; }
.row { display: grid; gap: 1rem; }
.row-2 { grid-template-columns: 1fr 1fr; }

/* Чекбокс-строка (опции бота) */
.check-row {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--sibur-dark);
    margin-bottom: 0.3rem;
}
.check-row input[type="checkbox"] {
    width: 18px; height: 18px; margin: 0.1rem 0 0; flex-shrink: 0;
    accent-color: var(--sibur-dna); cursor: pointer;
}

/* ---------- Статус-пиллы ---------- */
.status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.2rem 0.6rem 0.2rem 0.55rem;
    border-radius: var(--r-pill);
    white-space: nowrap;
}
.status::before {
    content: "";
    width: 6px; height: 6px; border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}
.status-running { background: var(--ok-bg); color: var(--ok-text); }
.status-stopped { background: #eef1f2; color: var(--sibur-gray-50); }
.status-draft   { background: #eef1f2; color: var(--sibur-gray-50); }
.status-error   { background: var(--sibur-beige); color: var(--danger-text); }
.badge-admin    { background: var(--teal-700); color: #fff; }
.badge-admin::before { background: #fff; }

/* ---------- Прочее ---------- */
.actions { display: flex; gap: 0.55rem; align-items: center; flex-wrap: wrap; }
details > summary {
    cursor: pointer; color: var(--sibur-dna); font-weight: 600; font-size: 0.9rem;
    list-style: none; padding: 0.15rem 0; user-select: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; color: var(--sibur-dna); }
details[open] > summary::before { content: "▾ "; }

.subtext { font-size: 0.85rem; color: var(--sibur-gray-50); }

/* Sticky-панель действий (форма редактирования) */
.actions-sticky {
    position: sticky;
    bottom: 0;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(6px);
    box-shadow: 0 -2px 14px rgba(0,49,60,0.1);
    padding: 0.85rem 1.5rem;
    margin: 1rem -1.5rem -1.5rem;
    border-radius: 0 0 var(--r) var(--r);
    border-top: 1px solid var(--line);
    display: flex;
    gap: 0.55rem;
    align-items: center;
    flex-wrap: wrap;
    z-index: 5;
}

/* Выбор файла */
.file-picker { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.file-picker input[type="file"] { display: none; }
.file-picker .file-name { font-size: 0.85rem; color: var(--sibur-gray-50); word-break: break-all; }

/* Поле токена с глазом */
.token-field { position: relative; }
.token-field input { padding-right: 2.6rem; }
.token-field .token-toggle {
    position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer; padding: 0.3rem 0.4rem;
    font-size: 1.1rem; line-height: 1; color: var(--sibur-gray-50); border-radius: 6px;
}
.token-field .token-toggle:hover { color: var(--sibur-dna); background: var(--teal-050); }

/* Пустое состояние */
.empty-state {
    text-align: center;
    padding: 3.5rem 2rem;
    background:
        radial-gradient(420px 200px at 50% 0%, rgba(0,140,149,0.05), transparent 70%),
        var(--surface);
}
.empty-state .empty-emoji { font-size: 2.6rem; line-height: 1; margin-bottom: 0.8rem; }
.empty-state .empty-title { font-size: 1.2rem; font-weight: 700; color: var(--sibur-dark); margin-bottom: 0.35rem; }
.empty-state .empty-sub { color: var(--sibur-gray-50); margin-bottom: 1.3rem; }

/* Метрики (плитки) */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.75rem; }
.metric {
    padding: 0.85rem 1rem;
    background: linear-gradient(180deg, #fbfdfd, var(--surface-muted));
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
}
.metric-label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sibur-gray-50); font-weight: 600; }
.metric-value { font-size: 1.55rem; font-weight: 700; color: var(--sibur-dark); line-height: 1.1; margin-top: 0.2rem; }
.metric-sub { font-size: 0.76rem; color: var(--sibur-gray-50); }

/* Информационные баннеры */
.banner { border-radius: var(--r); padding: 1rem 1.2rem; margin-bottom: 1rem; border: 1.5px solid; }
.banner p { margin: 0; }
.banner-info { background: var(--ok-bg); border-color: var(--sibur-mint); color: var(--ok-text); }
.banner-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-text); }
.banner-danger { background: var(--sibur-beige); border-color: var(--sibur-orange); color: var(--danger-text); }

/* Модалка */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,30,36,0.45);
    backdrop-filter: blur(2px); z-index: 200;
    display: flex; align-items: flex-start; justify-content: center;
    padding: 1.5rem; overflow-y: auto;
}
.modal-box {
    width: 100%; max-width: 520px; margin: 8vh auto;
    background: #fff; border-radius: var(--r-lg); padding: 1.6rem;
    box-shadow: var(--sh-pop);
}

/* Прокручиваемая область с диалогами/логами */
.scroll-area { max-height: 400px; overflow-y: auto; }

/* ---------- Адаптив ---------- */
@media (max-width: 720px) {
    .navbar { padding: 0 1rem; }
    .navbar-toggle { display: block; }
    .navbar .user-info {
        display: none;
        position: absolute;
        top: var(--nav-h);
        right: 0; left: 0;
        background: var(--sibur-dark);
        flex-direction: column;
        align-items: flex-start;
        padding: 0.9rem 1.1rem;
        gap: 0.85rem;
        box-shadow: 0 8px 18px rgba(0,0,0,0.28);
        z-index: 100;
    }
    .navbar .user-info.open { display: flex; }
    .container { padding: 1.25rem 1rem 3rem; }
    .card { padding: 1.15rem; }
    .row-2 { grid-template-columns: 1fr; }
    h2 { font-size: 1.35rem; }
    .table-scroll::after {
        content: "↔ свайпните таблицу";
        display: block;
        font-size: 0.72rem;
        color: var(--sibur-gray-50);
        padding: 0.4rem 0 0.1rem;
        text-align: center;
    }
    .actions-sticky { padding: 0.75rem 1rem; margin: 1rem -1.15rem -1.15rem; }
}

/* =========================================================================
   Плавающий AI-ассистент
   ========================================================================= */
#ai-widget { position: fixed; right: 22px; bottom: 22px; z-index: 1000; }
#ai-widget-btn {
    width: 62px; height: 62px; border-radius: 50%; border: 2px solid #fff; padding: 0;
    cursor: pointer; background: #fff; box-shadow: 0 6px 20px rgba(0,49,60,0.28);
    transition: transform .15s, box-shadow .15s; overflow: hidden;
    position: relative;
}
#ai-widget-btn::after {
    content: ""; position: absolute; right: 3px; bottom: 3px;
    width: 13px; height: 13px; border-radius: 50%;
    background: var(--sibur-mint); border: 2px solid #fff;
}
#ai-widget-btn:hover { transform: scale(1.07) translateY(-1px); box-shadow: 0 10px 28px rgba(0,49,60,0.34); }
#ai-widget-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
#ai-widget-panel {
    position: absolute; right: 0; bottom: 78px; width: 372px; max-width: calc(100vw - 40px);
    height: 500px; max-height: calc(100vh - 130px); background: #fff; border-radius: var(--r-lg);
    box-shadow: var(--sh-pop); display: flex; flex-direction: column; overflow: hidden;
    border: 1px solid var(--line);
}
#ai-widget-header {
    display: flex; align-items: center; gap: 0.65rem; padding: 0.8rem 1rem;
    background: linear-gradient(100deg, var(--sibur-dna), var(--sibur-dark)); color: #fff;
}
#ai-widget-header img { width: 38px; height: 38px; border-radius: 50%; background: #fff; flex-shrink: 0; box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }
.ai-widget-title { font-weight: 700; font-size: 0.98rem; }
.ai-widget-sub { font-size: 0.74rem; opacity: 0.88; }
#ai-widget-close {
    margin-left: auto; background: rgba(255,255,255,0.14); border: none; color: #fff;
    font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0.1rem 0.5rem; border-radius: 8px;
}
#ai-widget-close:hover { background: rgba(255,255,255,0.26); }
#ai-widget-log { flex: 1; overflow-y: auto; padding: 0.9rem; background: var(--surface-muted); }
.ai-bubble { margin: 0.4rem 0; display: flex; }
.ai-bubble.user { justify-content: flex-end; }
.ai-bubble span {
    display: inline-block; padding: 0.5rem 0.75rem; border-radius: 14px; max-width: 86%;
    white-space: pre-wrap; font-size: 0.88rem; line-height: 1.5; word-break: break-word;
}
.ai-bubble.user span { background: linear-gradient(180deg, var(--sibur-dna), var(--teal-700)); color: #fff; border-bottom-right-radius: 5px; }
.ai-bubble.bot span { background: #fff; border: 1px solid var(--line); color: var(--sibur-dark); border-bottom-left-radius: 5px; box-shadow: var(--sh-1); }
.ai-bubble.bot ul { margin: 0 0 0.5rem 1.1rem; padding: 0; }
#ai-widget-input-row {
    display: flex; gap: 0.45rem; padding: 0.65rem; border-top: 1px solid var(--line);
    align-items: flex-end; background: #fff;
}
#ai-widget-input { resize: vertical; margin: 0; font-size: 0.88rem; min-height: 64px; max-height: 180px; line-height: 1.45; }
#ai-widget-input-row button { flex-shrink: 0; height: 40px; width: 44px; padding: 0; font-size: 1rem; }

@media (max-width: 480px) {
    #ai-widget { right: 14px; bottom: 14px; }
    #ai-widget-panel { width: calc(100vw - 28px); height: 72vh; }
}
