:root {
    --purple: #521A6A;
    --purple-dark: #381953;
    --purple-alt: #601780;
    --blue: #5FAAE2;
    --navy: #2C437C;

    --bg: #F7F5FA;
    --surface: #FFFFFF;
    --text: #231A2B;
    --muted: #6B6172;
    --border: #E7E0EC;
    --tint: #F1EAF5;

    --success: #2F8F6B;
    --warning: #B86E16;
    --danger: #B83E59;

    --accent: var(--purple);
    --accent-contrast: #ffffff;
    --badge-bg: var(--tint);

    --radius-field: 10px;
    --radius-button: 16px;
    --radius-card: 20px;
    --control-height: 48px;
    --shadow-card: 0 8px 30px rgba(56, 25, 83, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Manrope", "Inter", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* 70% ширины экрана, отступы по 15% слева/справа - вместо фиксированного max-width, чтобы
   таблицы использовали всю ширину на больших мониторах. На мобильных экранах 15%/15% съели бы
   слишком много места, поэтому на узких экранах контейнер становится полноширинным
   (см. медиа-запрос в конце файла). */
.container { width: 70%; margin: 0 auto; padding: 24px 0; }

.navbar {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.navbar-brand { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.brand-mark {
    width: 26px; height: 26px; border-radius: 7px;
    background: var(--purple); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.7em; font-weight: 800;
}
.navbar-links { display: flex; gap: 16px; flex: 1; flex-wrap: wrap; }
.navbar-links a { color: var(--muted); text-decoration: none; padding: 4px 0; font-weight: 500; border-bottom: 2px solid transparent; }
.navbar-links a.active, .navbar-links a:hover { color: var(--purple); border-bottom-color: var(--purple); }
.navbar-user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9em; }

h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.01em; margin-bottom: 16px; }
h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 8px; }

a { color: var(--purple); }

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

.card {
    background: var(--surface);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 20px 24px;
    margin-bottom: 16px;
}

.button, button, input[type="submit"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--purple);
    color: #fff;
    border: none;
    border-radius: var(--radius-button);
    padding: 0 18px;
    min-height: var(--control-height);
    font-size: 0.95em;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s ease;
}
button:active, .button:active { opacity: 0.85; }
.button.secondary { background: var(--tint); color: var(--purple); }
button.danger, .button.danger { background: var(--danger); }

.link-button {
    background: none;
    border: none;
    color: var(--purple);
    padding: 0;
    min-height: auto;
    cursor: pointer;
    font-size: inherit;
    font-weight: 500;
    text-decoration: underline;
}
/* button.danger (элемент+класс, специфичность 0,1,1) перебивает .link-button (0,1,0) для
   background - без явного background:none здесь .link-button.danger рендерился бы сплошным
   красным овалом (текст того же цвета, что и фон, поэтому невидим). */
.link-button.danger { background: none; color: var(--danger); }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: 0.92em; }
.table th { color: var(--muted); font-weight: 600; background: var(--tint); }
.table tr:last-child td { border-bottom: none; }

/* Широкие таблицы (много колонок, например «Предзапись») - горизонтальная прокрутка внутри
   своего контейнера вместо сжатия колонок; ячейки не переносятся построчно, ширина колонки
   подстраивается под содержимое. На мобильном порядок правил (media max-width:720px ниже)
   всё равно переключает .table на блочную раскладку - прокрутка там не нужна и не мешает. */
.table-scroll { overflow-x: auto; border-radius: var(--radius-card); }
.table-scroll .table { border-radius: 0; }
.table-wide th, .table-wide td { white-space: nowrap; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.badge { display: inline-block; background: var(--badge-bg); color: var(--purple); border-radius: 999px; padding: 3px 12px; font-size: 0.8em; font-weight: 600; }

dialog.modal { border: none; border-radius: var(--radius-card); box-shadow: var(--shadow-card); padding: 32px 36px; max-width: 560px; width: 90%; max-height: 85vh; overflow-y: auto; color: var(--text); background: var(--surface); box-sizing: border-box; }
dialog.modal::backdrop { background: rgba(35, 26, 43, 0.5); }
dialog.modal h3 { margin-top: 0; }
dialog.modal hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
/* Штрафы: таблица с колонкой действий нуждается в модалке пошире, чем стандартный dialog.modal. */
dialog.penalty-modal { max-width: 760px; }

/* Штрафы */
.penalty-link-button { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-button); background: var(--tint); color: var(--purple); text-decoration: none; font-weight: 700; font-size: 0.85em; }
.penalty-link-button:hover { opacity: 0.85; }
.badge-count { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.72em; font-weight: 700; }

.penalty-modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.penalty-modal-header h3 { margin: 0; }
.icon-button { display: inline-grid; place-items: center; flex: none; width: 40px; height: 40px; color: var(--muted); background: none; border: none; border-radius: 12px; cursor: pointer; font-size: 1.2rem; line-height: 1; }
.icon-button:hover { background: var(--tint); color: var(--text); }

.penalty-summary { margin: 12px 0 0; color: var(--muted); }
.penalty-summary strong { color: var(--text); }
.penalty-summary .dot { color: var(--purple); padding: 0 7px; }

.penalty-lesson-group + .penalty-lesson-group { margin-top: 28px; }
.penalty-lesson-group h4 { margin: 0 0 8px; font-size: 1em; }

.penalty-table-wrap { margin-top: 16px; border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
/* Крайняя правая колонка (действия) намеренно ограничена сверху (minmax(...,220px)), а не
   auto - у auto ширина по содержимому без верхней границы, из-за чего три экшна в строке
   (оплачен/изменить/удалить) распирали грид шире модалки и вылезали за её края. При нехватке
   места кнопки переносятся внутри .penalty-row-actions (flex-wrap), а не расширяют колонку. */
.penalty-row-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 0.5fr) minmax(0, 0.65fr) minmax(150px, 220px); gap: 12px; align-items: center; padding: 14px 18px; }
.penalty-row-grid.head { background: var(--tint); color: var(--muted); font-size: 0.82em; font-weight: 700; padding: 10px 18px; }
.penalty-row-grid:not(.head) + .penalty-row-grid { border-top: 1px solid var(--border); }
.penalty-reason { display: flex; align-items: center; gap: 12px; font-weight: 600; min-width: 0; }
.penalty-reason-icon { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%; background: var(--tint); font-size: 1.05em; }
.penalty-amount { font-weight: 750; }
.penalty-status { display: inline-flex; width: max-content; padding: 5px 11px; border-radius: 999px; font-size: 0.85em; font-weight: 700; white-space: nowrap; }
.penalty-status.unpaid { color: var(--warning); background: #FBE8CF; }
.penalty-status.paid { color: var(--success); background: #DDF2E7; }
.penalty-row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }

.button-sm { min-height: 36px; padding: 0 12px; font-size: 0.85em; white-space: nowrap; }
.button-paid { color: var(--success); background: #DDF2E7; }
.button-paid:hover { background: #cdecdd; }
.button-paid.disabled { opacity: 0.75; cursor: default; }
.button-paid.disabled:active { opacity: 0.75; }
.icon-trash { display: inline-grid; place-items: center; flex: none; width: 36px; min-height: 36px; padding: 0; color: var(--danger); background: #fff; border: 1px solid #EDBECA; border-radius: var(--radius-button); }
.icon-trash:hover { background: #FBE3E7; }

.section-title { font-size: 1.05em; font-weight: 700; margin: 24px 0 0; }
.penalty-add-card.form { max-width: none; margin-top: 12px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--bg); gap: 16px; box-sizing: border-box; }
.penalty-add-actions { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

dialog.penalty-confirm { max-width: 440px; padding: 26px; }
dialog.penalty-confirm h3 { margin: 0 0 8px; }
dialog.penalty-confirm p { margin: 0; color: var(--muted); }
.penalty-confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

@media (max-width: 640px) {
    .penalty-row-grid { grid-template-columns: 1fr; gap: 8px; }
    .penalty-row-grid.head { display: none; }
    .penalty-row-actions { justify-content: flex-start; }
}

.filters, .tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters a, .tabs a { padding: 8px 14px; border-radius: var(--radius-button); text-decoration: none; color: var(--muted); background: var(--surface); border: 1px solid var(--border); font-weight: 500; font-size: 0.92em; }
.filters a.active, .tabs a.active { color: #fff; background: var(--purple); border-color: var(--purple); }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0; }
.stat-tile { background: var(--tint); border-radius: var(--radius-field); padding: 14px 20px; min-width: 130px; }
.stat-value { display: block; font-size: 1.7rem; font-weight: 800; color: var(--purple-dark); }
.stat-label { color: var(--muted); font-size: 0.85em; font-weight: 500; }

/* Дашборд: воронка предзаписи */
.periods { display: inline-flex; gap: 6px; background: var(--bg); padding: 5px; border-radius: 14px; flex-wrap: wrap; }
.periods a { border: 0; background: transparent; color: var(--muted); padding: 9px 16px; border-radius: 10px; font-weight: 650; text-decoration: none; font-size: 0.9em; }
.periods a.active { background: var(--surface); color: var(--purple); box-shadow: 0 2px 9px rgba(60, 25, 69, .09); }

.filters-panel { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 18px; margin: 16px 0; }
.field-label { display: block; font-size: 0.78em; font-weight: 700; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.03em; }
.date-range-row { display: flex; align-items: center; gap: 8px; }
.date-range-row input { flex: 1; }
.date-separator { color: var(--muted); }
.utm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
/* Без этого правила <select> внутри .filters-panel наследуют только браузерные стили - не
   .form select (форма здесь не .form, а .filters-panel) - и выглядят гораздо мельче
   остальных полей на странице. */
.filters-panel select {
    min-height: var(--control-height);
    padding: 0 12px;
    border-radius: var(--radius-field);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95em;
    font-family: inherit;
    width: 100%;
}
.filters-panel select:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(82, 26, 106, 0.12);
}
.filters-panel .filter-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { border: 1px solid var(--border); border-radius: var(--radius-field); padding: 16px 18px; background: var(--surface); }
.kpi strong { display: block; font-size: 1.7rem; line-height: 1; color: var(--purple-dark); margin-bottom: 8px; }
.kpi span { color: var(--muted); font-size: 0.85em; }

.source-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--purple-alt); margin-right: 8px; vertical-align: middle; }

@media (max-width: 720px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .utm-grid { grid-template-columns: 1fr; }
}

/* Дашборд: верхняя (занятие + пользователи) и нижняя (рассылка + оценка) сетки из макета.
   margin-bottom на самой сетке обязателен - у вложенных .card он обнулён (gap сетки уже даёт
   отступ между ними), поэтому без него сетка вплотную касалась бы следующего блока и их тени
   визуально сливались (виден шов/наезд по скруглённым углам). */
.overview { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: stretch; margin-bottom: 16px; }
.overview .card, .bottom-grid .card { margin-bottom: 0; }
.bottom-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

.users-number { font-size: 38px; font-weight: 800; color: var(--purple-dark); line-height: 1.1; margin-top: 8px; }
.users-number span { display: block; font-size: 0.85rem; font-weight: 500; color: var(--muted); margin-top: 6px; }

@media (max-width: 900px) {
    .overview, .bottom-grid { grid-template-columns: 1fr; }
}

/* Общий полупрозрачный фон для выдвижных панелей (мобильное меню, календарь на мобиле) */
.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(35, 26, 43, 0.5);
    z-index: 40;
}
.backdrop.open { display: block; }

/* Дашборд: выбор периода - кликабельный бокс + выпадающий календарь */
.date-range {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-height: var(--control-height);
    padding: 0 14px;
    border-radius: var(--radius-field);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-weight: 600;
    color: var(--text);
}
.date-range:focus { outline: none; border-color: var(--purple); box-shadow: 0 0 0 3px rgba(82, 26, 106, 0.12); }

.calendar {
    display: none;
    position: absolute;
    top: 58px;
    left: 0;
    width: 328px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    padding: 16px;
    z-index: 50;
}
.calendar.open { display: block; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; font-weight: 700; }
.cal-nav { min-height: 32px; width: 32px; padding: 0; border-radius: 10px; background: var(--tint); color: var(--purple); font-size: 1.1em; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; color: var(--muted); font-size: 0.78em; font-weight: 700; text-align: center; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.day {
    min-height: 34px;
    border: none;
    background: none;
    border-radius: 8px;
    color: var(--text);
    font-size: 0.88em;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
}
.day:hover { background: var(--tint); }
.day.in-range { background: var(--tint); border-radius: 0; }
.day.selected, .day.start, .day.end { background: var(--purple); color: #fff; font-weight: 700; }
.day.start { border-radius: 8px 0 0 8px; }
.day.end { border-radius: 0 8px 8px 0; }
.day.start.end { border-radius: 8px; }

@media (max-width: 720px) {
    /* На мобиле календарь - центрированная модалка со своим фоном, а не выпадающий блок под полем */
    .calendar {
        position: fixed;
        top: 50%;
        left: 50%;
        width: min(328px, calc(100vw - 32px));
        transform: translate(-50%, -50%);
        z-index: 51;
    }
}

/* Мобильная навигация: бургер-меню + выдвижная панель вместо горизонтального списка ссылок */
.menu-btn {
    display: none;
    min-height: 40px;
    width: 40px;
    padding: 0;
    background: none;
    color: var(--purple);
    font-size: 1.3em;
    order: -1;
}
.mobile-only { display: none; }

@media (max-width: 900px) {
    .menu-btn { display: inline-flex; }
    .desktop-only { display: none; }

    .navbar-links {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 80vw;
        background: var(--surface);
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        padding: 72px 20px 20px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 41;
        overflow-y: auto;
    }
    .navbar-links.open { transform: translateX(0); }
    .navbar-links a { padding: 10px 4px; border-bottom: 1px solid var(--border); }
    .navbar-links a.active, .navbar-links a:hover { border-bottom-color: var(--border); background: var(--tint); border-radius: var(--radius-field); }

    .navbar-links .mobile-only {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--border);
    }
}

.form, .search-form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > label { flex: 1; min-width: 180px; }
/* .form-row задаёт display:flex с той же специфичностью, что и браузерный [hidden] -
   без этого правила скрытые через JS строки (например, в конструкторе рассылки) были бы
   видны всегда. */
.form-row[hidden] { display: none; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 0.9em; font-weight: 500; color: var(--muted); }
.form input, .form select, .form textarea, .search-form input {
    min-height: var(--control-height);
    padding: 0 12px;
    border-radius: var(--radius-field);
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95em;
    font-family: inherit;
}
.form input:focus, .form select:focus, .form textarea:focus, .search-form input:focus {
    outline: none;
    border-color: var(--purple);
    box-shadow: 0 0 0 3px rgba(82, 26, 106, 0.12);
}
.form textarea { min-height: 90px; padding: 12px; resize: vertical; }
.form .checkbox { flex-direction: row; align-items: center; }
.search-form { flex-direction: row; max-width: 480px; margin-bottom: 16px; }
.search-form input { flex: 1; }

fieldset { border: 1px solid var(--border); border-radius: var(--radius-field); padding: 12px; }
legend { color: var(--muted); font-size: 0.9em; padding: 0 6px; font-weight: 500; }

.login-box { max-width: 380px; margin: 60px auto; background: var(--surface); padding: 32px; border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.login-box h1 { margin-bottom: 20px; }
.error { color: var(--danger); }
.muted { color: var(--muted); font-size: 0.9em; }

.kv-table { border-collapse: collapse; }
.kv-table th { text-align: left; color: var(--muted); padding: 8px 16px 8px 0; font-weight: 600; vertical-align: top; }
.kv-table td { padding: 8px 0; }

.timeline { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-field); padding: 12px 16px; }
.timeline-time { color: var(--muted); font-size: 0.85em; margin-right: 8px; }

.scan-box { max-width: 480px; }
#scan-video { width: 100%; border-radius: var(--radius-card); background: #000; }
#scan-status { margin-top: 10px; font-weight: 600; }
#scan-status.ok { color: var(--success); }
#scan-status.error { color: var(--danger); }

.privacy-page { max-width: 720px; line-height: 1.6; }
.privacy-page .notice { background: #FBE8CF; color: var(--warning); padding: 10px 14px; border-radius: var(--radius-field); font-weight: 500; }

@media (max-width: 720px) {
    /* На узких экранах 15%/15% отступов почти не оставляют места контенту - контейнер
       становится полноширинным с обычным фиксированным паддингом. */
    .container { width: 100%; padding: 16px; }

    /* Таблицы: вместо горизонтальной прокрутки/сжатия колонок - каждая строка становится
       отдельной карточкой, ячейки идут одна под другой. Подпись перед значением берём из
       data-label на <td> (проставляется в шаблонах, см. HTML) - без него ячейка просто без
       подписи, но не ломается. */
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tr { border: 1px solid var(--border); border-radius: var(--radius-field); margin-bottom: 12px; overflow: hidden; }
    .table tr:last-child { margin-bottom: 0; }
    .table td { border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
    .table td:last-child { border-bottom: none; }
    .table td[data-label]::before { content: attr(data-label); color: var(--muted); font-weight: 600; font-size: 0.85em; text-align: left; }
    .table td.actions, .table td[colspan] { justify-content: flex-start; }
}
