/* Единая таблица стилей UI. Токены — из макетов (светлая тема). Повторяющиеся
   куски (кнопки, карточки, чипы, переключатели) описаны один раз и переиспользуются
   обоими экранами. */

:root {
    --bg: #f7f7fa;
    --surface: #ffffff;
    --surface-2: #f3f4f6;
    --line: #e5e7eb;
    --line-2: #d1d5db;

    --text: #111827;
    --muted: #6b7280;
    --subtle: #9ca3af;

    --accent: #6366f1;
    --accent-weak: #eef2ff;
    --accent-strong: #4f46e5;
    --accent-ring: rgba(99, 102, 241, 0.18);

    --green: #22c55e;
    --danger: #dc2626;
    --amber: #d97706;

    --radius: 12px;
    --shadow-pop: 0 12px 30px rgba(17, 24, 39, 0.14);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
svg { display: block; }
h1 { font-size: 26px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }

code {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
    color: var(--muted);
}

/* ——— Каркас ——— */

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

.sidebar {
    width: 240px;
    flex: 0 0 240px;
    padding: 20px 14px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
    height: 100vh;
}

.content { flex: 1; min-width: 0; background: var(--bg); }

.page { max-width: 1060px; margin: 0 auto; padding: 28px 32px 72px; }

.page__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

/* ——— Сайдбар ——— */

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; }
.brand__mark { width: 28px; height: 28px; }
.brand__name { font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav__item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 11px;
    border: none;
    border-radius: 9px;
    background: none;
    color: var(--muted);
    font-size: 14px;
    cursor: pointer;
    text-align: left;
}

.nav__item:hover { background: var(--surface-2); color: var(--text); }
.nav__item.is-active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav__icon { display: inline-flex; }

/* ——— Кнопки ——— */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 7px 10px; }
.btn--ghost:hover { background: var(--surface-2); color: var(--text); }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--subtle);
    cursor: pointer;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn--danger:hover { background: #fef2f2; color: var(--danger); }

/* ——— Поиск ——— */

.search { position: relative; margin-bottom: 22px; }
.search__icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--subtle); display: flex; }

.search__input {
    width: 100%;
    padding: 12px 14px 12px 42px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
    font: inherit;
    font-size: 14px;
    color: var(--text);
}

.search__input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }

/* ——— Карточки и список групп ——— */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list { display: flex; flex-direction: column; gap: 12px; }

.group__head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; user-select: none; }
.group__chevron { color: var(--subtle); display: flex; transform: rotate(-90deg); transition: transform 0.15s ease; }
.group.is-open .group__chevron { transform: rotate(0); }
.group__name { font-weight: 600; font-size: 15px; }
.group__meta { color: var(--muted); font-size: 13px; }
.group__spacer { flex: 1; }
.group__body { display: none; padding: 0 16px 14px; }
.group.is-open .group__body { display: block; }

.badge { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 20px; border: 1px solid transparent; }
.badge--green { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge--gray { background: var(--surface-2); color: var(--muted); border-color: var(--line); }

.notice {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0 2px;
    padding: 9px 12px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 10px;
    color: #92400e;
    font-size: 13px;
}

.notice__icon { display: flex; color: var(--amber); }

/* ——— Таблица целей ——— */

.targets { width: 100%; border-collapse: collapse; margin-top: 6px; }

.targets th {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--subtle);
}

.targets td { padding: 11px 10px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.targets tbody tr:last-child td { border-bottom: none; }
.ta-right { text-align: right; white-space: nowrap; }
.t-name { font-weight: 500; display: flex; align-items: center; gap: 7px; }
.warn-mark { color: var(--amber); display: inline-flex; }

.method {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    padding: 3px 9px;
    border-radius: 7px;
    border: 1px solid transparent;
}

.method--get { color: #1d4ed8; background: #eff6ff; border-color: #bfdbfe; }
.method--post { color: #6d28d9; background: #f5f3ff; border-color: #ddd6fe; }
.method--head { color: #0f766e; background: #f0fdfa; border-color: #99f6e4; }
.method--put { color: #c2410c; background: #fff7ed; border-color: #fed7aa; }
.method--delete { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }

.empty { color: var(--muted); font-size: 14px; padding: 12px 2px; margin: 0; }
.empty--big { text-align: center; padding: 56px 0; color: var(--subtle); }

/* ——— Боты ——— */

.bots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.bot { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.bot.is-off { opacity: 0.6; }
.bot__head { display: flex; align-items: center; }
.bot__spacer { flex: 1; }

.type {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 4px 9px;
    border-radius: 7px;
}

.type--compass { color: #0284c7; background: #f0f9ff; }
.type--telegram { color: #2563eb; background: #eff6ff; }

.bot__title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.bot__name { font-weight: 600; font-size: 16px; }
.bot__chat { font-size: 13px; color: var(--muted); }
.bot__chat code { color: var(--text); }

.bot__token { display: flex; align-items: center; padding: 9px 11px; background: var(--surface-2); border-radius: 9px; }
.token { flex: 1; letter-spacing: 0.08em; color: var(--muted); overflow: hidden; }

/* ——— Переключатель ——— */

.toggle { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle__track {
    width: 38px;
    height: 22px;
    padding: 2px;
    border-radius: 999px;
    background: var(--line-2);
    transition: background 0.15s ease;
    display: inline-flex;
    align-items: center;
}
.toggle__thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease; }
.toggle input:checked + .toggle__track { background: var(--green); }
.toggle input:checked + .toggle__track .toggle__thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle__track { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ——— Чипы ——— */

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
}
.chips__empty { font-size: 12px; color: var(--subtle); }
.chip--add { padding: 0; width: 26px; height: 26px; justify-content: center; color: var(--muted); background: transparent; border-style: dashed; cursor: pointer; }
.chip--add:hover { color: var(--accent); border-color: var(--accent); }
.chip--removable { cursor: pointer; background: var(--accent-weak); border-color: #c7d2fe; color: var(--accent); }
.chip--removable svg { opacity: 0.7; }

/* ——— Затемнение и выезжающая панель ———
   Скрим накрывает весь вьюпорт, включая сайдбар, и затемняет мягко. Он один
   на оба экрана, поэтому затемнение всегда одинаковое. */

.scrim { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.18); opacity: 0; transition: opacity 0.2s ease; z-index: 40; }
.scrim.is-in { opacity: 1; }

.drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 420px;
    max-width: 92vw;
    background: var(--surface);
    border-left: 1px solid var(--line);
    box-shadow: -16px 0 40px rgba(17, 24, 39, 0.08);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    z-index: 50;
}

.drawer.is-in { transform: translateX(0); }
.drawer__head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.drawer__title { font-size: 17px; font-weight: 600; margin: 0; }
.drawer__body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 20px; border-top: 1px solid var(--line); }
.drawer__foot-start { margin-right: auto; }
/* Кнопка «Проверить», пока запрос идёт (до таймаута — 10 с). */
.btn:disabled, .icon-btn:disabled { opacity: .5; cursor: progress; }

/* ——— Формы ——— */

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }

.input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    font: inherit;
    font-size: 14px;
    color: var(--text);
}

.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.select-wrap, .input-affix { position: relative; }
.select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer; }
.select__chevron { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.input-affix .input { padding-right: 42px; }
.affix-btn { position: absolute; right: 7px; top: 50%; transform: translateY(-50%); display: flex; padding: 6px; border: none; border-radius: 7px; background: none; color: var(--subtle); cursor: pointer; }
.affix-btn:hover { background: var(--surface-2); color: var(--text); }

.segmented { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 11px; }
.seg {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: none;
    font: inherit;
    font-size: 14px;
    color: var(--muted);
    cursor: pointer;
}
.seg.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.segmented.is-locked .seg { cursor: default; }
.seg:disabled { opacity: 1; }

.switch-row { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 500; padding-top: 2px; }

/* ——— Мультиселект групп ——— */

.multiselect { position: relative; }
.multiselect__control {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.multiselect.is-open .multiselect__control { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.multiselect__chips { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.multiselect__placeholder { color: var(--subtle); font-size: 14px; }
.multiselect__chevron { color: var(--subtle); display: flex; transition: transform 0.15s ease; }
.multiselect.is-open .multiselect__chevron { transform: rotate(180deg); }

.multiselect__menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 5;
    max-height: 220px;
    overflow: auto;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow-pop);
}
.ms-option { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.ms-option:hover { background: var(--surface-2); }
.ms-option input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ——— Меню «…» ——— */

.menu { position: absolute; min-width: 184px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow-pop); z-index: 60; }
.menu__item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; border-radius: 8px; background: none; font: inherit; font-size: 14px; color: var(--text); text-align: left; cursor: pointer; }
.menu__item:hover { background: var(--surface-2); }
.menu__item.is-danger { color: var(--danger); }
.menu__item.is-danger:hover { background: #fef2f2; }
.menu__icon { display: flex; color: var(--subtle); }
.menu__item.is-danger .menu__icon { color: var(--danger); }

/* ——— Тосты ——— */

.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 80; }
.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 380px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
    box-shadow: 0 10px 30px rgba(17, 24, 39, 0.12);
    font-size: 14px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.is-in { opacity: 1; transform: translateY(0); }
.toast__icon { display: flex; }
.toast--error { border-color: #fecaca; }
.toast--error .toast__icon { color: var(--danger); }
.toast--warn { border-color: #fde68a; }
.toast--warn .toast__icon { color: var(--amber); }
.toast--ok { border-color: #bbf7d0; }
.toast--ok .toast__icon { color: #16a34a; }

/* ——— Узкий экран ——— */

@media (max-width: 760px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: auto;
        flex: none;
        height: auto;
        position: static;
        display: flex;
        align-items: center;
        gap: 20px;
        padding: 12px 16px;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
    .brand { padding: 0; }
    .nav { flex-direction: row; }
    .page { padding: 20px 16px 48px; }
    .drawer { width: 100%; max-width: none; }
}
