/* AIBitrix — единый дизайн-токен-сет в iOS-стиле.
 *
 * Все шаблоны (Jinja) подгружают только этот файл через <link> в base.html.
 * Локальные <style> в шаблонах быть НЕ должно — если чего-то не хватает,
 * сюда же и добавляем. Inline-стили допустимы только для одноразовых правок
 * (например, height у конкретного блока), но не для повторяющихся паттернов.
 */

/* =========================================================================
 * Tokens
 * ========================================================================= */
:root {
    /* Палитра iOS */
    --c-bg: #f2f2f7;
    --c-card: #ffffff;
    --c-text: #1c1c1e;
    --c-text-soft: #3a3a3c;
    --c-muted: #8e8e93;
    --c-line: rgba(60, 60, 67, 0.18);
    --c-line-soft: rgba(60, 60, 67, 0.08);
    --c-accent: #007aff;
    --c-accent-hover: #006fe6;
    --c-accent-soft: rgba(0, 122, 255, 0.08);
    --c-accent-soft-hover: rgba(0, 122, 255, 0.16);
    --c-accent-glow: rgba(0, 122, 255, 0.18);

    --c-purple: #5856d6;
    --c-purple-soft: rgba(88, 86, 214, 0.08);
    --c-purple-soft-hover: rgba(88, 86, 214, 0.16);

    --c-green: #34c759;
    --c-green-dark: #1e8a47;
    --c-yellow: #ff9500;
    --c-yellow-dark: #b8860b;
    --c-red: #ff3b30;
    --c-red-dark: #aa2e2e;

    /* Радиусы */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 12px;
    --r-xl: 14px;
    --r-pill: 999px;

    /* Тени */
    --shadow-card: 0 1px 0 rgba(60, 60, 67, 0.1);
    --shadow-elevated: 0 4px 12px rgba(0, 0, 0, 0.06);

    /* Типографика */
    --f-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
                "Helvetica Neue", Roboto, sans-serif;
    --f-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

    /* Размеры */
    --container-max: 1100px;
    --header-h: 56px;
}

/* =========================================================================
 * Reset
 * ========================================================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--c-bg);
    color: var(--c-text);
    font-family: var(--f-system);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a { color: var(--c-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

h1, h2, h3, h4 { color: var(--c-text); margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 20px; margin-top: 28px; }
h3 { font-size: 16px; margin-top: 20px; }
h4 { font-size: 14px; margin-top: 16px; }

p { margin: 0 0 12px; }

small { font-size: 12px; }
code, .text-mono { font-family: var(--f-mono); font-size: 0.92em; }

/* =========================================================================
 * Layout
 * ========================================================================= */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 24px;
}

/* =========================================================================
 * App header (top nav)
 * ========================================================================= */
.app-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--c-line);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
}
.app-header__inner {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 24px;
}
.app-header__brand {
    font-size: 16px;
    font-weight: 700;
    color: var(--c-text);
    text-decoration: none;
    letter-spacing: -0.01em;
}
.app-header__brand:hover { text-decoration: none; }
.app-header__nav {
    display: flex;
    gap: 4px;
    flex: 1;
}
.app-header__nav a {
    color: var(--c-text-soft);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: var(--r-md);
    transition: background 0.12s ease, color 0.12s ease;
}
.app-header__nav a:hover { background: var(--c-accent-soft); color: var(--c-accent); text-decoration: none; }
.app-header__nav a.is-active { background: var(--c-accent-soft); color: var(--c-accent); }
.app-header__user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--c-muted);
}
.app-header__user form { margin: 0; }
.app-header__user button {
    background: none;
    border: none;
    color: var(--c-accent);
    cursor: pointer;
    font-size: 13px;
    padding: 4px 8px;
    border-radius: var(--r-sm);
}
.app-header__user button:hover { background: var(--c-accent-soft); }

/* =========================================================================
 * Card
 * ========================================================================= */
.card {
    background: var(--c-card);
    border-radius: var(--r-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--c-line-soft);
}
.card--flat { box-shadow: none; }
.card + .card { margin-top: 14px; }

/* =========================================================================
 * Form (общая форма-карточка)
 * ========================================================================= */
.form {
    background: var(--c-card);
    border-radius: var(--r-xl);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    border: 1px solid var(--c-line-soft);
    box-shadow: var(--shadow-card);
}
.form--inset { background: var(--c-bg); box-shadow: none; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}

.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.form-field { flex: 1; min-width: 180px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: 6px;
}
.form-hint {
    margin: 0;
    color: var(--c-muted);
    font-size: 12px;
    line-height: 1.3;
}

.form-input,
.form-select {
    width: 100%;
    border: 1px solid var(--c-line);
    border-radius: var(--r-md);
    padding: 10px 12px;
    font-size: 15px;
    background: var(--c-card);
    color: var(--c-text);
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px var(--c-accent-glow);
}
.form-search { background: var(--c-bg); }
.form-search:focus { background: var(--c-card); }

.form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* =========================================================================
 * Section (под-блок формы с заголовком и действиями)
 * ========================================================================= */
.section {
    background: var(--c-card);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 1px solid var(--c-line-soft);
}
.section--inset { background: var(--c-bg); }
.section__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.section__title { font-size: 13px; font-weight: 600; color: var(--c-text); }
.section__actions { display: flex; gap: 4px; }

/* =========================================================================
 * Buttons
 * ========================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--r-md);
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    transition: background 0.12s ease, transform 0.08s ease, color 0.12s ease;
    white-space: nowrap;
    line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn--primary {
    background: var(--c-accent);
    color: #fff;
}
.btn--primary:hover { background: var(--c-accent-hover); color: #fff; }

.btn--submit {
    background: var(--c-accent);
    color: #fff;
    padding: 12px 18px;
    font-size: 15px;
    border-radius: var(--r-lg);
}
.btn--submit:hover { background: var(--c-accent-hover); color: #fff; }
.btn--submit.is-block { width: 100%; }

.btn--secondary {
    background: var(--c-accent-soft);
    color: var(--c-accent);
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--r-md);
}
.btn--secondary:hover { background: var(--c-accent-soft-hover); color: var(--c-accent); }

.btn--purple {
    background: var(--c-purple-soft);
    color: var(--c-purple);
    padding: 6px 12px;
    font-size: 13px;
    border-radius: var(--r-md);
}
.btn--purple:hover { background: var(--c-purple-soft-hover); color: var(--c-purple); }

.btn--ghost {
    background: transparent;
    color: var(--c-accent);
    padding: 4px 8px;
    font-size: 14px;
    border-radius: var(--r-sm);
}
.btn--ghost:hover { background: var(--c-accent-soft); color: var(--c-accent); }

.btn--danger {
    background: transparent;
    color: var(--c-red-dark);
    padding: 4px 8px;
    font-size: 14px;
    border-radius: var(--r-sm);
}
.btn--danger:hover { background: rgba(255, 59, 48, 0.08); color: var(--c-red-dark); }

.btn--icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--r-md);
}

/* Текстовая ссылка-кнопка (для inline-навигации) */
.link {
    color: var(--c-accent);
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
}
.link:hover { text-decoration: underline; }

/* =========================================================================
 * Counter chip (рядом с заголовком: "Сотрудники [N]")
 * ========================================================================= */
.counter {
    display: inline-block;
    background: var(--c-accent);
    color: #fff;
    font-size: 11px;
    border-radius: var(--r-pill);
    padding: 1px 8px;
    margin-left: 4px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}
.counter.is-empty { background: #c7c7cc; }

/* =========================================================================
 * Checklist (список с чекбоксами — сотрудники, статусы)
 * ========================================================================= */
.checklist {
    max-height: 220px;
    overflow-y: auto;
    background: var(--c-bg);
    border-radius: var(--r-md);
    padding: 4px;
    border: 1px solid var(--c-line-soft);
}
.checklist--short { max-height: 160px; }
.checklist__empty {
    padding: 20px 16px;
    text-align: center;
    color: var(--c-muted);
    font-size: 13px;
}
.checklist__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background 0.12s ease;
}
.checklist__item:hover { background: var(--c-accent-soft); }
.checklist__item.is-selected { background: var(--c-accent-soft-hover); }
.checklist__item input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #c7c7cc;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    margin: 0;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.checklist__item input[type="checkbox"]:checked {
    background: var(--c-accent);
    border-color: var(--c-accent);
}
.checklist__item input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checklist__name { flex: 1; font-size: 13px; color: var(--c-text); }
.checklist__id { color: var(--c-muted); font-size: 11px; font-family: var(--f-mono); }

/* =========================================================================
 * Radio row (большой выбор из карточек)
 * ========================================================================= */
.radio-row, .toggle-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: var(--c-card);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background 0.12s ease;
    border: 1px solid var(--c-line-soft);
}
.radio-row:hover, .toggle-row:hover { background: #fafafa; }
.radio-row input[type="radio"] {
    appearance: none;
    -webkit-appearance: none;
    display: none;
}
.radio-row__dot {
    width: 22px;
    height: 22px;
    border: 2px solid #c7c7cc;
    border-radius: 50%;
    background: #fff;
    flex-shrink: 0;
    transition: all 0.15s ease;
    position: relative;
}
.radio-row input[type="radio"]:checked + .radio-row__dot {
    border-color: var(--c-accent);
    border-width: 6px;
}
.radio-row__title { font-size: 14px; color: var(--c-text); font-weight: 500; }
.radio-row__sub { font-size: 12px; color: var(--c-muted); margin-top: 2px; }

.tag-info {
    background: var(--c-yellow);
    color: #fff;
    padding: 1px 7px;
    border-radius: var(--r-sm);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    margin-left: 6px;
    letter-spacing: 0.3px;
    vertical-align: middle;
}

/* =========================================================================
 * Toggle switch
 * ========================================================================= */
.toggle-row { justify-content: space-between; }
.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #c7c7cc;
    border-radius: 31px;
    transition: background 0.2s ease;
}
.switch__slider::before {
    position: absolute;
    content: "";
    height: 27px;
    width: 27px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
.switch input:checked + .switch__slider { background: var(--c-green); }
.switch input:checked + .switch__slider::before { transform: translateX(20px); }

/* =========================================================================
 * Table
 * ========================================================================= */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--c-card);
    border-radius: var(--r-lg);
    overflow: hidden;
    border: 1px solid var(--c-line-soft);
    font-size: 14px;
}
.table th, .table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--c-line-soft);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table th {
    background: var(--c-bg);
    font-weight: 600;
    font-size: 12px;
    color: var(--c-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.table tr:hover td { background: rgba(0, 122, 255, 0.03); }
.table td.is-muted { color: var(--c-muted); }
.table td .cell-sub {
    display: block;
    color: var(--c-muted);
    font-size: 12px;
    margin-top: 2px;
}

/* =========================================================================
 * Badges (score + status)
 * ========================================================================= */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
    color: #fff;
}
.badge--neutral { background: #c7c7cc; color: var(--c-text); }
.badge--high    { background: var(--c-green-dark); }
.badge--mid     { background: var(--c-yellow-dark); }
.badge--low     { background: var(--c-red-dark); }
.badge--na      { background: #999; }
.badge--danger  { background: var(--c-red-dark); }
.badge--warn    { background: #d39e2c; }
.badge--info    { background: var(--c-accent); }

/* Статусы джобы — нейтральная подложка, без агрессивного цвета. */
.status {
    display: inline-block;
    padding: 3px 9px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
}
.status--pending  { background: #f0f0f0; color: var(--c-muted); }
.status--running  { background: #fff4d6; color: var(--c-yellow-dark); }
.status--done     { background: #d4f0dd; color: var(--c-green-dark); }
.status--failed   { background: #f8d7d7; color: var(--c-red-dark); }
.status--canceled { background: #f0f0f0; color: var(--c-muted); }

/* Bitrix status pill для статуса лида */
.lead-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--r-sm);
    background: var(--c-bg);
    color: var(--c-text);
    font-size: 12px;
    font-weight: 500;
}

/* =========================================================================
 * Alerts (баннеры сверху страниц)
 * ========================================================================= */
.alert {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 14px 18px;
    border-radius: var(--r-lg);
    margin-bottom: 18px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert__icon { flex-shrink: 0; }
.alert__body { flex: 1; }
.alert__title {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 12px;
    margin-bottom: 2px;
}
.alert__action { margin-left: auto; }

.alert--danger {
    background: #fff5f5;
    color: var(--c-red-dark);
    border-color: #f5c7c7;
}
.alert--danger .alert__title { color: var(--c-red-dark); }

.alert--warn {
    background: #fff4d6;
    color: #7a5700;
    border-color: #e0b300;
}
.alert--warn .alert__title { color: #7a5700; }

.alert--info {
    background: #eef3fb;
    color: var(--c-accent);
    border-color: rgba(0, 122, 255, 0.2);
}

.error-box {
    background: #fff5f5;
    color: var(--c-red-dark);
    padding: 12px 16px;
    border: 1px solid #f5c7c7;
    border-radius: var(--r-md);
    margin: 12px 0;
    font-size: 14px;
}

/* =========================================================================
 * Pager
 * ========================================================================= */
.pager {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
    margin: 18px 0;
}
.pager__info {
    padding: 6px 10px;
    color: var(--c-muted);
    font-size: 13px;
}

/* =========================================================================
 * Markdown view (для result-страниц)
 * ========================================================================= */
.markdown-body {
    background: var(--c-card);
    border: 1px solid var(--c-line-soft);
    border-radius: var(--r-lg);
    padding: 22px;
    white-space: pre-wrap;
    font-family: var(--f-mono);
    font-size: 13px;
    line-height: 1.65;
    max-height: 70vh;
    overflow: auto;
    color: var(--c-text-soft);
}

/* =========================================================================
 * Icons (SF Symbols-вдохновлённые SVG, подключены через спрайт)
 * ========================================================================= */
.icon {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: -3px;
    fill: currentColor;
    flex-shrink: 0;
}
.icon--lg { width: 22px; height: 22px; vertical-align: -5px; }
.icon--xl { width: 32px; height: 32px; }
.icon--muted { color: var(--c-muted); }

/* =========================================================================
 * Login page
 * ========================================================================= */
.login-page {
    max-width: 360px;
    margin: 80px auto 0;
}
.login-page h1 { font-size: 22px; margin-bottom: 6px; }
.login-page .lead { color: var(--c-muted); font-size: 14px; margin-bottom: 20px; }

/* =========================================================================
 * Utilities
 * ========================================================================= */
.muted { color: var(--c-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-mono { font-family: var(--f-mono); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }
.mt-0 { margin-top: 0 !important; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 18px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 18px; }
.hidden { display: none !important; }
