/* Базовая тема. Вёрстка «mobile first»: основной сценарий — телефон казначея,
   поэтому одноколоночная раскладка по умолчанию, ширина ограничивается только
   на широких экранах. */

:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e2e5ea;
    --accent: #2f6feb;
    --positive: #1a7f45;
    --negative: #c0392b;
    --neutral: #6b7280;
    --radius: 10px;
}

* { box-sizing: border-box; }

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

.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    font-weight: 600;
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
}

.app-footer {
    padding: 12px 16px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

h1 { font-size: 22px; margin: 0 0 12px; }

.muted { color: var(--muted); }

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

.amount-positive { color: var(--positive); }
.amount-negative { color: var(--negative); }
.amount-zero { color: var(--neutral); }

/* --- Формы и кнопки --- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.btn {
    font: inherit;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.btn:disabled { opacity: .55; cursor: default; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}

.btn-sm { padding: 6px 12px; font-size: 14px; }

.btn-link {
    border: none;
    background: none;
    color: var(--accent);
    padding: 6px;
    text-align: center;
}

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

/* Атрибут hidden должен побеждать display у .stack и подобных — иначе форма
   второго шага видна с самого начала. */
[hidden] { display: none !important; }

label { font-size: 14px; color: var(--muted); }

input[type="tel"],
input[type="text"],
input[type="number"],
input[type="date"] {
    font: inherit;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

.page-auth { justify-content: center; }

.auth-card {
    width: 100%;
    max-width: 380px;
    margin: auto;
    padding: 24px 16px;
}

.auth-card h1 { margin-bottom: 4px; }

.form-message { min-height: 1.5em; font-size: 14px; }
.form-message.is-error { color: var(--negative); }
.form-message.is-ok { color: var(--muted); }

/* --- Вкладки, карточки, поля --- */

.app-tabs {
    display: flex;
    gap: 4px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 8px;
    overflow-x: auto;
}

.tab {
    padding: 10px 14px;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
}

.tab.is-active {
    color: var(--text);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: 4px; }

.hint { margin: 0; font-size: 13px; color: var(--muted); }

.req { color: var(--negative); }

h2 { font-size: 18px; margin: 24px 0 8px; }

.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; }

fieldset.students {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

fieldset.students legend { font-size: 14px; color: var(--muted); padding: 0 6px; }

.student-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
}

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

.card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 12px 12px 34px;
}

.card-number {
    position: absolute;
    left: 12px;
    top: 22px;
    color: var(--muted);
    font-size: 13px;
}

.btn-danger { color: var(--negative); }

/* --- Список с суммами, итог фонда, модальное окно --- */

.row-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
}

.row-card-info { display: flex; flex-direction: column; gap: 2px; }
.row-card-name { font-weight: 500; }
.row-card-total { color: var(--muted); font-size: 14px; }

.fund-total {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin: 16px 0;
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 16px;
}

.fund-total strong { font-size: 18px; }

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 30, .45);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 10;
}

.modal-body {
    background: var(--bg);
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 16px;
}

@media (min-width: 640px) {
    .modal { align-items: center; }
    .modal-body { border-radius: var(--radius); }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.modal-head h2 { margin: 0; font-size: 18px; }

h3 { font-size: 16px; margin: 20px 0 8px; }

.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.history-text { display: flex; flex-direction: column; gap: 2px; font-size: 15px; }

/* --- Таблицы, фильтры, чекбоксы --- */

.btn.block { display: block; width: 100%; margin-bottom: 12px; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 12px;
}

.filters .field { flex: 1 1 140px; }

.table-scroll {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.table { width: 100%; border-collapse: collapse; font-size: 14px; }

.table th,
.table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.table th { color: var(--muted); font-weight: 500; white-space: nowrap; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }
.table .actions { white-space: nowrap; text-align: right; }

.badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    color: var(--text);
    font-size: 15px;
}

.check-row input { width: auto; }

input[type="file"] {
    font: inherit;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    width: 100%;
}

select {
    font: inherit;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

/* --- Баланс --- */

.balance-value { font-size: 17px; font-weight: 600; white-space: nowrap; }

/* --- Пальцевые касания ---
   На сенсорных экранах мелкие кнопки промахиваются: «Изменить»/«Удалить» в
   сводной таблице были 33 px высотой. Поднимаем область нажатия до 44 px,
   не увеличивая при этом сам текст. */

@media (pointer: coarse) {
    .btn-sm,
    .btn-link {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .table .actions .btn-link { padding-left: 10px; padding-right: 10px; }

    .check-row { padding: 10px 0; }
    .check-row input { width: 22px; height: 22px; }
}

/* Узкие экраны (от 320 px): вкладки должны помещаться целиком, иначе
   «Баланс» оказывается за краем и его не видно без прокрутки. */

@media (max-width: 400px) {
    .app-tabs { padding: 0 2px; }

    .tab {
        padding: 10px 7px;
        font-size: 14px;
    }

    .app-header { padding: 10px 12px; }
    .app-content { padding: 12px; }
    .modal-body { padding: 12px; }
}

/* Переход между входом и регистрацией */
.auth-switch {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
}

.auth-switch .btn { text-decoration: none; }

/* --- Проверочная картинка --- */

.captcha-row {
    display: flex;
    align-items: center;
    gap: 10px;
    /* На узком экране кнопка переносится под картинку, а не наезжает на неё */
    flex-wrap: wrap;
}

.captcha-image {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    user-select: none;
}

.captcha-row .btn { flex: 0 0 auto; }

.captcha-answer {
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* --- Переход между входом и регистрацией --- */

.auth-switch {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
}

.auth-switch .btn { text-decoration: none; }

.steps { padding-left: 20px; color: var(--text); }
.steps li { margin-bottom: 6px; }
