/* ==========================================================================
   Директ Бюджет — панель управления
   ========================================================================== */

:root {
    --primary: #2b5cd9;
    --primary-dark: #1f45ad;
    --primary-soft: #eef3ff;
    --accent: #ffb020;
    --danger: #d92d20;
    --danger-soft: #fef3f2;
    --success: #12a150;
    --success-soft: #ecfdf3;
    --warning-soft: #fffaeb;

    --bg: #f5f7fc;
    --card-bg: #ffffff;
    --border: #e4e8f0;
    --border-strong: #d3d9e5;
    --text: #1b2333;
    --muted: #6a7387;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(21, 33, 63, .05);
    --shadow-md: 0 4px 16px rgba(21, 33, 63, .07);
    --container: 1140px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

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

h1 { font-size: 24px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; letter-spacing: -.01em; }
h3 { font-size: 15px; margin: 20px 0 8px; }
p  { margin: 0 0 12px; }
ol, ul { margin: 0 0 12px; padding-left: 20px; }
ol li, ul li { margin-bottom: 6px; }
code {
    background: #eff2f7;
    padding: 1px 6px;
    border-radius: 5px;
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: .88em;
}
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

.container {
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 0 22px;
}

/* --------------------------------------------------------- Логотип ------ */

.logo { display: inline-flex; align-items: center; gap: 11px; }
.logo-mark { display: block; flex: none; border-radius: 11px; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.logo-name {
    font-weight: 700;
    font-size: 16.5px;
    color: var(--text);
    letter-spacing: -.015em;
    white-space: nowrap;
}
.logo-site {
    font-size: 11.5px;
    color: var(--muted);
    letter-spacing: .02em;
}

/* ---------------------------------------------------------- Шапка ------- */

.app-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
}
.header-inner {
    display: flex;
    align-items: center;
    gap: 26px;
    min-height: 64px;
    flex-wrap: wrap;
    padding-top: 8px;
    padding-bottom: 8px;
}
.header-inner .brand:hover { text-decoration: none; }

.main-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-right: auto;
    flex-wrap: wrap;
}
.main-nav a {
    display: block;
    padding: 7px 13px;
    border-radius: 8px;
    color: #4c566e;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}
.main-nav a:hover { background: #f2f5fa; color: var(--text); text-decoration: none; }
.main-nav a.is-active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

.user-box { display: flex; align-items: center; gap: 12px; }
.user-chip {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 5px 12px 5px 5px;
    border: 1px solid var(--border);
    border-radius: 30px;
    background: #fff;
    color: var(--text);
    font-size: 13.5px;
    font-weight: 500;
    max-width: 220px;
}
.user-chip:hover { border-color: var(--border-strong); text-decoration: none; background: #fafbfe; }
.avatar {
    width: 28px; height: 28px;
    flex: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #5b8cff, #2a44c4);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    text-transform: uppercase;
}
.user-chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-link { color: var(--muted); font-size: 13.5px; white-space: nowrap; }
.logout-link:hover { color: var(--danger); text-decoration: none; }

/* ---------------------------------------------------------- Контент ----- */

.page {
    flex: 1 0 auto;
    width: 100%;
    max-width: var(--container);
    margin: 0 auto;
    padding: 28px 22px 56px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.page-header .subtitle { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    margin-bottom: 20px;
}
.card > :last-child { margin-bottom: 0; }
.form-card { max-width: 580px; }

/* ---------------------------------------------------------- Формы ------- */

label {
    display: block;
    margin-bottom: 16px;
    font-size: 13.5px;
    font-weight: 600;
    color: #384156;
}
label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-weight: 500;
    font-size: 14px;
}
label.checkbox-label input { width: auto; margin: 0; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
select,
textarea {
    display: block;
    width: 100%;
    margin-top: 7px;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14.5px;
    font-family: inherit;
    font-weight: 400;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #a6adbd; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(43, 92, 217, .13);
}

.hint {
    display: block;
    font-weight: 400;
    color: var(--muted);
    font-size: 12.5px;
    margin-top: 6px;
    line-height: 1.45;
}

.form-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 17px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: #f5f7fb; border-color: #c3cbdb; text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 1px 2px rgba(43, 92, 217, .25);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-danger { color: var(--danger); border-color: #f3c4c0; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); border-color: #eda9a3; }

.btn-small { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }

.btn-link { background: none; border-color: transparent; color: var(--muted); }
.btn-link:hover { background: transparent; color: var(--text); border-color: transparent; text-decoration: underline; }

.btn-yandex { background: #fc3f1d; border-color: #fc3f1d; color: #fff; }
.btn-yandex:hover { background: #e13114; border-color: #e13114; }

.btn-block { width: 100%; }

/* ---------------------------------------------------------- Таблицы ----- */

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.table th, .table td {
    padding: 13px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    vertical-align: middle;
}
.table th {
    background: #fafbfe;
    font-weight: 600;
    color: #5b6478;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fbfcfe; }
.actions { white-space: nowrap; text-align: right; }
.actions .btn + form { margin-left: 4px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }

/* ---------------------------------------------------------- Бейджи ------ */

.badge {
    display: inline-block;
    padding: 3.5px 11px;
    border-radius: 30px;
    font-size: 11.5px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.5;
}
.badge-active   { background: var(--success-soft); color: #09794c; }
.badge-inactive { background: #f0f2f6; color: var(--muted); }
.badge-admin    { background: #eef1ff; color: #3f43c8; }
.badge-user     { background: #f0f2f6; color: var(--muted); }

.text-danger  { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------- Алерты ------ */

.alert {
    padding: 13px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
    line-height: 1.5;
}
.alert-success { background: var(--success-soft); color: #09794c; border-color: #b8ecd0; }
.alert-error   { background: var(--danger-soft);  color: #a52a1f; border-color: #f5c9c4; }
.alert-info    { background: var(--primary-soft); color: #294a9e; border-color: #ccdaff; }

/* ---------------------------------------------------------- Прочее ------ */

.empty-state {
    background: var(--card-bg);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 52px 30px;
    text-align: center;
    color: var(--muted);
}
.empty-state p { margin-bottom: 18px; }

.info-box {
    margin-top: 24px;
    background: var(--primary-soft);
    border: 1px solid #d5e0fb;
    border-radius: var(--radius);
    padding: 16px 20px;
    font-size: 13.5px;
    color: #2f4788;
}
.info-box p:last-child { margin-bottom: 0; }
.info-box code { background: rgba(43, 92, 217, .1); }

.code-box {
    background: #1c2438;
    color: #dbe3f4;
    padding: 13px 15px;
    border-radius: var(--radius-sm);
    font-family: "SFMono-Regular", Consolas, Menlo, monospace;
    font-size: 12.5px;
    word-break: break-all;
    margin-bottom: 14px;
    line-height: 1.5;
}

/* ------------------------------------------------------ Вход/регистр. --- */

.auth-wrap {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 44px 20px;
    gap: 22px;
}
.auth-logo { display: block; }
.auth-logo:hover { text-decoration: none; }
.auth-wrap .card {
    width: 100%;
    max-width: 410px;
    box-shadow: var(--shadow-md);
    padding: 28px;
    margin-bottom: 0;
}
.auth-wrap h1 { font-size: 20px; margin-bottom: 4px; }
.auth-wrap .card > p.muted { font-size: 13.5px; margin-bottom: 20px; }
.auth-wrap .btn-primary { width: 100%; margin-top: 4px; }
.auth-alt {
    text-align: center;
    font-size: 13.5px;
    color: var(--muted);
}

/* ---------------------------------------------------------- Подвал ------ */

.app-footer {
    flex: none;
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 22px 0;
    margin-top: auto;
}
.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px 26px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
}
.footer-links { display: flex; gap: 18px; flex-wrap: wrap; }
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--primary); }
.footer-brand { display: flex; align-items: center; gap: 9px; }

/* ---------------------------------------------------------- Адаптив ----- */

@media (max-width: 760px) {
    body { font-size: 14.5px; }
    h1 { font-size: 20px; }
    .header-inner { gap: 14px; min-height: 0; }
    .main-nav { order: 3; width: 100%; margin-right: 0; gap: 2px; }
    .main-nav a { padding: 7px 10px; font-size: 13.5px; }
    .user-box { margin-left: auto; }
    .user-chip .name { display: none; }
    .user-chip { padding: 4px; }
    .page { padding: 20px 16px 44px; }
    .container { padding: 0 16px; }
    .card { padding: 18px; }
    .table th, .table td { padding: 11px 12px; }
    .actions { text-align: left; }
    .footer-inner { flex-direction: column; align-items: flex-start; }

    /* Шапка страницы: заголовок и кнопка действия в столбик */
    .page-header { gap: 10px; }
    .page-header > .btn { width: 100%; }
    .page-header .subtitle { font-size: 13px; }

    /* Полоса тарифа: кнопка уходит на свою строку */
    .plan-strip { gap: 8px 10px; padding: 12px 14px; font-size: 13.5px; }
    .plan-strip-text { flex: 1 1 100%; order: 3; }
    .plan-strip .btn { order: 2; margin-left: auto; }
}

/* ==========================================================================
   Тарифы и оплата
   ========================================================================== */

/* Бейдж роли/тарифа */
.plan-role {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 30px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
    white-space: nowrap;
}
.plan-role-sm { padding: 2px 8px; font-size: 10.5px; }
.plan-role-free     { background: #f0f2f6; color: #5b6478; }
.plan-role-pro      { background: var(--primary-soft); color: var(--primary-dark); }
.plan-role-business { background: #fff2d9; color: #8a5a00; }

/* Полоса с тарифом на странице аккаунтов */
.plan-strip {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 13px 18px;
    margin-bottom: 20px;
    font-size: 14px;
}
.plan-strip-text { color: #45506a; margin-right: auto; }

/* Карточка текущего тарифа */
.current-plan {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    flex-wrap: wrap;
}
.current-plan-main { display: flex; align-items: center; gap: 16px; }
.current-plan-side { text-align: right; }

/* Переключатель периода */
.period-switch {
    display: inline-flex;
    background: #eef1f6;
    border-radius: 30px;
    padding: 4px;
    margin-bottom: 20px;
    gap: 2px;
}
.period-switch a {
    padding: 7px 18px;
    border-radius: 30px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
}
.period-switch a:hover { color: var(--text); text-decoration: none; }
.period-switch a.is-active {
    background: #fff;
    color: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

/* Сетка тарифов */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    align-items: stretch;
    margin-bottom: 8px;
}
.plan-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px 22px;
}
.plan-card.is-featured { border-color: var(--primary); box-shadow: var(--shadow-md); }
.plan-card.is-current  { border-color: var(--success); background: #fcfffd; }
.plan-card h3 { margin-bottom: 4px; }

.plan-badge {
    position: absolute;
    top: -11px; left: 22px;
    background: var(--success);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 4px 11px;
    border-radius: 20px;
}
.plan-badge-accent { background: var(--primary); }

.plan-tagline { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; min-height: 38px; }

.plan-price { display: flex; align-items: baseline; gap: 6px; margin-bottom: 4px; }
.plan-price .amount { font-size: 30px; font-weight: 800; letter-spacing: -.03em; }
.plan-price .period { color: var(--muted); font-size: 14px; }

.plan-saving { color: #0b7a41; font-size: 13px; font-weight: 600; margin-bottom: 14px; min-height: 20px; }

.plan-limit {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: 13.5px;
    font-weight: 600;
    color: #3d475e;
    text-align: center;
    margin-bottom: 18px;
}
.plan-card form { margin-top: auto; }
.plan-card .btn[disabled] { opacity: .55; cursor: default; }

/* Форма смены тарифа в таблице пользователей */
.plan-set-form {
    display: flex;
    gap: 4px;
    margin-top: 7px;
    align-items: center;
}
.plan-set-form select {
    margin-top: 0;
    padding: 4px 6px;
    font-size: 12px;
    width: auto;
    min-width: 0;
}
.plan-set-form .btn { padding: 4px 9px; font-size: 12px; }

/* Статусы платежей и лимитов */
.badge-pending { background: var(--warning-soft); color: #8a5a00; }
.badge-locked  { background: #f0f2f6; color: #9aa2b3; cursor: not-allowed; }

/* Сводка платежа */
.pay-summary {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
}
.pay-summary .row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 6px 0;
    font-size: 14.5px;
}

/* Иконка результата оплаты */
.result-icon {
    width: 56px; height: 56px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 700;
    margin: 0 auto 16px;
}
.result-icon-ok   { background: var(--success-soft); color: var(--success); }
.result-icon-fail { background: var(--danger-soft);  color: var(--danger); }

@media (max-width: 860px) {
    .plans-grid { grid-template-columns: 1fr; }
    .plan-tagline { min-height: 0; }
    .plan-saving { min-height: 0; }
    .current-plan { flex-direction: column; align-items: flex-start; }
    .current-plan-side { text-align: left; }
}

/* ==========================================================================
   Список аккаунтов (карточки вместо таблицы — без горизонтальной прокрутки)
   ========================================================================== */

.list-hint {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 12px;
}
.drag-dots { letter-spacing: -1px; }

.acc-list { display: flex; flex-direction: column; gap: 10px; }

.acc-row {
    display: grid;
    grid-template-columns: 40px minmax(0, 1.5fr) minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 18px;
    transition: box-shadow .15s, border-color .15s, opacity .15s;
}
.acc-row:hover { border-color: var(--border-strong); }
.acc-row.is-off { background: #fcfcfd; }
.acc-row.is-off .acc-name { color: var(--muted); }
.acc-row.is-dragging { opacity: .45; }
.acc-row.drop-before { box-shadow: 0 -3px 0 -1px var(--primary), var(--shadow-sm); }
.acc-row.drop-after  { box-shadow: 0 3px 0 -1px var(--primary), var(--shadow-sm); }

.acc-order {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #b6bdcb;
}
.drag-handle {
    cursor: grab;
    font-size: 17px;
    line-height: 1;
    user-select: none;
}
.drag-handle:active { cursor: grabbing; }

.acc-arrows { display: flex; flex-direction: column; gap: 1px; }
.acc-arrows form { display: block; line-height: 0; }
.arrow-btn {
    border: none;
    background: none;
    color: #aeb6c5;
    font-size: 9px;
    line-height: 1;
    padding: 2px 3px;
    cursor: pointer;
    border-radius: 3px;
}
.arrow-btn:hover:not(:disabled) { color: var(--primary); background: var(--primary-soft); }
.arrow-btn:disabled { opacity: .3; cursor: default; }

.acc-main { min-width: 0; }
.acc-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 3px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.acc-meta {
    display: flex;
    gap: 10px;
    font-size: 12.5px;
    color: var(--muted);
    min-width: 0;
}
.acc-meta span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.acc-meta span + span::before { content: "· "; }

.acc-figures { min-width: 0; }
.acc-balance { font-size: 15px; font-weight: 600; }
.acc-sub { font-size: 12.5px; color: var(--muted); }
.acc-error { margin-top: 2px; cursor: help; }

.acc-status form { margin: 0; }
.acc-actions { display: flex; gap: 6px; align-items: center; }
.acc-actions form { margin: 0; }

/* Кнопки-иконки: на широких экранах с подписью, на узких — только значок */
.btn-icon { gap: 6px; }
.btn-icon svg { flex: none; }

/* Подсказка о сортировке: разные тексты для мыши и тача */
.hint-mobile { display: none; }

@media (max-width: 1000px) {
    .btn-icon .btn-icon-text { display: none; }
    .btn-icon {
        width: 32px;
        height: 32px;
        padding: 0;
        justify-content: center;
    }
}

@media (max-width: 900px) {
    .acc-row {
        grid-template-columns: 32px minmax(0, 1fr) auto;
        grid-template-areas:
            "order main    status"
            "order figures actions";
        gap: 10px 12px;
        padding: 13px 14px;
    }
    .acc-order   { grid-area: order; align-self: start; padding-top: 2px; }
    .acc-main    { grid-area: main; }
    .acc-figures { grid-area: figures; }
    .acc-status  { grid-area: status; justify-self: end; align-self: start; }
    .acc-actions { grid-area: actions; justify-self: end; align-self: end; }
}

@media (max-width: 600px) {
    /* Перетаскивание мышью на тач-устройствах не работает — оставляем только стрелки */
    .drag-handle { display: none; }
    .hint-desktop { display: none; }
    .hint-mobile { display: inline; }

    .acc-row {
        grid-template-columns: 26px minmax(0, 1fr) auto;
        grid-template-areas:
            "order main     status"
            "order figures  figures"
            "order actions  actions";
        gap: 8px 10px;
        padding: 12px 12px;
    }
    .acc-actions {
        justify-self: stretch;
        justify-content: flex-end;
        border-top: 1px solid var(--border);
        padding-top: 9px;
        margin-top: 1px;
    }
    .acc-meta { flex-direction: column; gap: 1px; }
    .acc-meta span + span::before { content: ""; }
    .acc-name { font-size: 14.5px; white-space: normal; }
    .acc-balance { font-size: 16px; }
    .arrow-btn { font-size: 11px; padding: 4px 3px; }
}

/* ==========================================================================
   Иконка сообщений в шапке (только для администратора)
   ========================================================================== */

.msg-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    color: #6a7387;
    flex: none;
}
.msg-icon:hover { background: #f2f5fa; color: var(--text); text-decoration: none; }
.msg-icon.has-unread { color: var(--primary); }

.msg-count {
    position: absolute;
    top: 1px;
    right: 0;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    background: var(--danger);
    color: #fff;
    border: 2px solid #fff;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
}

/* ==========================================================================
   Плавающий чат поддержки
   ========================================================================== */

.chat-widget {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 80;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

/* --- Круглая кнопка-лаунчер --- */
.chat-launcher {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(43, 92, 217, .38);
    transition: background .16s, transform .12s, box-shadow .16s;
    flex: none;
}
.chat-launcher:hover { background: var(--primary-dark); transform: translateY(-1px); }
.chat-launcher:active { transform: translateY(0); }

.chat-launcher-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .16s, transform .16s;
}
.chat-icon-close { opacity: 0; transform: rotate(-45deg) scale(.7); }
.chat-widget.is-open .chat-icon-open  { opacity: 0; transform: rotate(45deg) scale(.7); }
.chat-widget.is-open .chat-icon-close { opacity: 1; transform: rotate(0) scale(1); }

/* --- Окно чата --- */
/* Атрибут hidden должен побеждать display:flex ниже,
   иначе окно всегда видно и кнопка закрытия «не работает» */
.chat-window[hidden] { display: none; }

.chat-window {
    width: 348px;
    max-width: calc(100vw - 32px);
    max-height: min(560px, calc(100vh - 130px));
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 56px rgba(21, 33, 63, .22);
    overflow: hidden;
    animation: chat-in .18s ease-out;
}

@keyframes chat-in {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 15px 16px;
    background: linear-gradient(135deg, #2b5cd9 0%, #1e3fae 100%);
    color: #fff;
    flex: none;
}
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
}
.chat-header-text { flex: 1; min-width: 0; }
.chat-title { font-size: 14.5px; font-weight: 600; line-height: 1.3; }
.chat-subtitle { font-size: 11.5px; color: rgba(255, 255, 255, .78); }
.chat-close {
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, .8);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    flex: none;
}
.chat-close:hover { background: rgba(255, 255, 255, .16); color: #fff; }

/* --- Лента сообщений --- */
.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 150px;
}

.chat-bubble {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    animation: bubble-in .16s ease-out;
}
.chat-bubble p { margin: 0; }
.chat-bubble p + p { margin-top: 6px; }

@keyframes bubble-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.chat-bubble-in {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--border);
    border-bottom-left-radius: 5px;
    color: var(--text);
}
.chat-bubble-out {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.chat-bubble-out a { color: #fff; text-decoration: underline; }
.chat-bubble-out.is-failed { background: var(--danger); }

.chat-bubble-warn {
    background: var(--warning-soft);
    border-color: #ffdda6;
    color: #8a5a00;
}
.chat-bubble-warn a { color: #8a5a00; }

.chat-time {
    display: block;
    margin-top: 4px;
    font-size: 10.5px;
    opacity: .75;
}

/* --- Поле ввода --- */
.chat-footer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 11px 12px;
    background: #fff;
    border-top: 1px solid var(--border);
    flex: none;
}
.chat-footer textarea {
    flex: 1;
    margin: 0;
    padding: 9px 13px;
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
}
.chat-footer textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(43, 92, 217, .13);
}

.chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    transition: background .15s;
}
.chat-send:hover:not(:disabled) { background: var(--primary-dark); }
.chat-send:disabled { opacity: .5; cursor: default; }

@media (max-width: 560px) {
    .chat-widget { right: 14px; bottom: 14px; gap: 10px; }
    .chat-launcher { width: 52px; height: 52px; }
    .chat-window {
        width: calc(100vw - 28px);
        max-height: calc(100vh - 120px);
    }
}

/* Группа однотипных полей (например, несколько email) */
.field-group { margin-bottom: 16px; }
.field-group-label {
    display: block;
    font-size: 13.5px;
    font-weight: 600;
    color: #384156;
    margin-bottom: 7px;
}
.field-group input + input { margin-top: 7px; }
.field-group .hint { margin-top: 7px; }

/* ==========================================================================
   Страница статистики аккаунта
   ========================================================================== */

.header-btns { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.section-title { font-size: 18px; margin: 30px 0 4px; }
.section-sub { font-size: 13.5px; margin-bottom: 16px; }

/* --- Выбор периода --- */
.period-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    padding: 14px 18px;
}
.period-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.period-presets a {
    padding: 6px 13px;
    border-radius: 20px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--muted);
    background: #f2f5fa;
}
.period-presets a:hover { color: var(--text); text-decoration: none; }
.period-presets a.is-active { background: var(--primary); color: #fff; font-weight: 600; }

.period-dates { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.period-dates label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 500;
    color: var(--muted);
}
.period-dates input[type="date"] {
    margin: 0;
    width: auto;
    padding: 7px 10px;
    font-size: 13.5px;
}

/* --- График --- */
.chart-card { padding: 20px; }
.chart-scroll { overflow-x: auto; }
.chart-svg { display: block; width: 100%; min-width: 620px; height: auto; }
.chart-svg .axis-text { font-size: 11px; fill: #8b93a5; font-family: inherit; }
.chart-svg .event-text { font-size: 10.5px; font-weight: 700; font-family: inherit; }
.chart-svg circle { cursor: help; }

.chart-legend {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 14px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot-line  { background: #2b5cd9; }
.dot-thr   { background: transparent; border: 2px dashed #d92d20; border-radius: 2px; height: 0; width: 14px; }
.dot-alert { background: #d92d20; }
.dot-topup { background: #12a150; }

/* --- Карточки статистики --- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
.stat-card {
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
}
.stat-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}
.stat-value { font-size: 23px; font-weight: 700; letter-spacing: -.02em; }
.stat-note { font-size: 12.5px; color: var(--muted); }

.badge-alert { background: var(--danger-soft); color: #a52a1f; }

@media (max-width: 860px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .period-form { flex-direction: column; align-items: stretch; }
}
@media (max-width: 520px) {
    .stat-grid { grid-template-columns: 1fr; }
    .stat-value { font-size: 20px; }
}

/* ==========================================================================
   Сводка и вкладки на странице настроек
   ========================================================================== */

.summary-grid {
    display: grid;
    /* Карточки подстраиваются под ширину — их число может меняться */
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.summary-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
}
.summary-value { font-size: 27px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.summary-label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    font-weight: 600;
}
.summary-note {
    font-size: 12.5px;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin-top: 2px;
}

/* --- Вкладки --- */
.tab-nav {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    margin-bottom: 22px;
}
.tab-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 500;
    color: var(--muted);
    padding: 11px 15px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    border-radius: 8px 8px 0 0;
}
.tab-btn:hover { color: var(--text); background: #f5f7fb; }
.tab-btn.is-active {
    color: var(--primary-dark);
    font-weight: 600;
    border-bottom-color: var(--primary);
    background: none;
}

.tab-badge {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    background: var(--danger);
    color: #fff;
    border-radius: 20px;
    font-size: 10.5px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.tab-panel.is-hidden { display: none; }

@media (max-width: 900px) {
    .summary-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .tab-nav {
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
    }
    .tab-nav::-webkit-scrollbar { display: none; }
    .tab-btn { padding: 10px 12px; font-size: 13.5px; }
}
@media (max-width: 520px) {
    .summary-grid { grid-template-columns: 1fr; gap: 10px; }
    .summary-value { font-size: 23px; }
}

/* ==========================================================================
   Оплата по счёту: реквизиты плательщиков и документы
   ========================================================================== */

.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row > label { flex: 1 1 200px; }

.subscribe-form { margin-top: auto; }
.pay-method, .payer-select { margin-bottom: 12px; text-align: left; }
.pay-method-label {
    display: block;
    font-size: 11.5px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
    margin-bottom: 5px;
}
.pay-method select, .payer-select select { margin-top: 0; font-size: 13.5px; padding: 8px 10px; }
.payer-select.is-hidden { display: none; }

/* --- Список реквизитов --- */
.payer-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.payer-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 14px 18px;
    flex-wrap: wrap;
}
.payer-main { min-width: 0; flex: 1 1 320px; }
.payer-name { font-weight: 600; font-size: 15px; margin-bottom: 3px; }
.payer-meta { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.payer-actions { display: flex; gap: 6px; align-items: center; }
.payer-actions form { margin: 0; }

/* --- Форма реквизитов --- */
.payer-form summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    list-style: none;
    position: relative;
    padding-right: 24px;
}
.payer-form summary::-webkit-details-marker { display: none; }
.payer-form summary::after {
    content: "";
    position: absolute;
    right: 4px; top: 6px;
    width: 8px; height: 8px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
}
.payer-form[open] summary::after { transform: rotate(-135deg); top: 9px; }

/* --- Ссылки на документы в таблицах --- */
.doc-links { white-space: nowrap; }
.doc-links a { margin-right: 10px; font-size: 13px; }
.doc-links a:last-child { margin-right: 0; }

@media (max-width: 600px) {
    .field-row { gap: 0; }
    .field-row > label { flex: 1 1 100%; }
    .payer-card { flex-direction: column; }
    .payer-actions { width: 100%; justify-content: flex-end; }
}

/* --- Автозаполнение реквизитов по ИНН --- */
.inn-lookup {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-top: 7px;
}
.inn-lookup input { margin-top: 0; }
.inn-lookup .btn { flex: none; white-space: nowrap; }

.lookup-status {
    display: block;
    margin-top: 7px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.45;
    padding: 8px 11px;
    border-radius: var(--radius-sm);
}
.lookup-status.is-ok    { background: var(--success-soft); color: #09794c; }
.lookup-status.is-error { background: var(--danger-soft);  color: #a52a1f; }
.lookup-status.is-warn  { background: var(--warning-soft); color: #8a5a00; }
.lookup-status.is-wait  { background: var(--bg); color: var(--muted); }

/* Выбор рекламного аккаунта, найденного по токену */
.acc-choice { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.acc-choice .btn { background: #fff; }
.acc-choice .btn.is-picked {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

/* Управление правами администратора и список пользователей */
.admin-grant {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.admin-grant select { margin-top: 5px; min-width: 160px; }
.admin-grant .btn { flex: none; }

.user-cell {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-bottom: 2px;
}
.user-cell b { font-size: 14.5px; }

/* Плашка статуса — кнопка, поэтому сбрасываем отступы формы */
.table form { margin: 0; }

@media (max-width: 600px) {
    .admin-grant { width: 100%; }
    .admin-grant label { flex: 1 1 100%; }
    .admin-grant select { width: 100%; }
}

/* Список пользователей: на узких экранах строки становятся карточками */
@media (max-width: 820px) {
    .table-users thead { display: none; }

    .table-users,
    .table-users tbody,
    .table-users tr,
    .table-users td {
        display: block;
        width: 100%;
    }

    .table-users tr {
        border-bottom: 1px solid var(--border);
        padding: 14px 16px;
    }
    .table-users tr:last-child { border-bottom: none; }
    .table-users tbody tr:hover td { background: none; }

    .table-users td {
        border: none;
        padding: 5px 0;
    }

    /* Подпись колонки слева от значения */
    .table-users td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        font-weight: 600;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: .05em;
        margin-bottom: 4px;
    }

    .table-users .actions { text-align: left; padding-top: 10px; }
    .table-users .plan-set-form { margin-top: 8px; }
}

/* Кнопка установки приложения (показывается, только если браузер это предлагает) */
.install-btn {
    gap: 6px;
    border-color: var(--primary);
    color: var(--primary-dark);
    background: var(--primary-soft);
}
.install-btn:hover { background: #e2ebff; border-color: var(--primary); }
.install-btn[hidden] { display: none; }

@media (max-width: 760px) {
    .install-btn .install-btn-text { display: none; }
    .install-btn { width: 32px; height: 32px; padding: 0; justify-content: center; }
}
