/* ============================================================
   ultram.net — общие стили
   Главная, карточка маршрута, вход и админ-панель.
   Акцентный цвет типа маршрута задаётся классом типа
   (.tram / .marshrutka / .bus / .trolleybus) через --accent.
   ============================================================ */

:root {
    --blue: #2196F3;
    --blue-dark: #1976D2;
    --bg: #eef1f4;
    --text: #1f2430;
    --muted: #78828e;
    --line: #eceff2;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg);
    color: var(--text);
}

/* Ширина шапки совпадает с шириной блока карточек */
.container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 0 24px;
}

.wrap {
    padding-bottom: 40px;
}

/* ---------- Шапка ---------- */
header {
    background: var(--blue);
    color: white;
    padding: 14px 0;
    margin-bottom: 20px;
}
header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2px 15px;
    flex-wrap: wrap;
}
header h1 {
    font-size: 21px;
    font-weight: 600;
    white-space: nowrap;
}
/* На мобильном заголовок переносится в две строки */
.title-short, .title-br {
    display: none;
}
.header-left {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.header-left.row {
    flex-direction: row;
    align-items: center;
    gap: 12px;
}
/* Круглая иконка-кнопка в шапке (например, «назад к списку») */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    color: #fff;
    text-decoration: none;
    transition: background .15s ease;
}
.icon-btn:hover {
    background: rgba(255, 255, 255, .32);
}
.icon-btn svg {
    width: 19px;
    height: 19px;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}
.totals {
    display: flex;
    flex-direction: column;
    text-align: right;
    line-height: 1.45;
    font-size: 13px;
    opacity: .95;
}
.back-link {
    color: #fff;
    text-decoration: none;
    font-size: 13px;
    opacity: .85;
    align-self: flex-start;
}
.back-link:hover {
    opacity: 1;
    text-decoration: underline;
}
.date-picker {
    display: flex;
    align-items: center;
    gap: 10px;
}
.date-picker label {
    font-weight: 500;
}
.date-picker input[type="date"] {
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
}

/* ---------- Транспортная карта (шапка главной) ---------- */
/* Блок — отдельный flex-элемент контейнера шапки с flex-basis:100%,
   поэтому всегда занимает вторую линию целиком; содержимое прижато
   вправо и на ПК, и на мобильном. Одна компактная строка:
   «Транспортная карта [№ карты] [OK]». */
.wallet {
    flex: 0 0 100%;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}
.off {
    display: none !important;
}
.wallet-form {
    display: flex;
    align-items: center;
    gap: 8px;
}
.wallet-label {
    font-size: 12px;
    opacity: .9;
    white-space: nowrap;
}
.wallet-input {
    width: 88px;
    padding: 3px 6px;
    border: none;
    border-radius: 3px;
    font-size: 12px;
}
.wallet-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .25);
    color: #fff;
    cursor: pointer;
    transition: background .15s ease;
}
.wallet-btn svg {
    width: 14px;
    height: 14px;
}
.wallet-btn:hover {
    background: rgba(255, 255, 255, .4);
}
.wallet-result {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
}
.wallet-name {
    max-width: 320px;
    font-size: 12px;
    line-height: 1.25;
    opacity: .9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.wallet-value {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: default;
}
.wallet-x {
    border: none;
    background: none;
    color: #fff;
    opacity: .7;
    font-size: 13px;
    line-height: 1;
    padding: 1px 3px;
    cursor: pointer;
    border-radius: 50%;
    transition: opacity .15s ease, background .15s ease;
}
.wallet-x:hover {
    opacity: 1;
    background: rgba(255, 255, 255, .2);
}
/* Всплывающая подсказка (клик по балансу на мобильном) */
.wallet-pop {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 30;
    width: max-content;
    max-width: 70vw;
    padding: 8px 10px;
    background: #fff;
    color: var(--text);
    font-size: 12px;
    line-height: 1.4;
    text-align: right;
    white-space: pre-line;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
}
.wallet-pop.open {
    display: block;
}
.wallet-note {
    font-size: 11px;
    opacity: .9;
    white-space: nowrap;
}

/* ---------- Цвета типов маршрутов ---------- */
.tram       { --accent: #F57C00; }
.marshrutka { --accent: #F4C400; }
.bus        { --accent: #E03131; }
.bus-regional { --accent: #B02A37; }
.trolleybus { --accent: #1971C2; }

/* ---------- Секции и карточки главной ---------- */
section {
    margin-bottom: 34px;
}
section.collapsed {
    margin-bottom: 20px;
}
section.collapsed .cards {
    display: none;
}
.section-head {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin: 0 0 12px;
    border-left: 5px solid var(--accent);
    padding-left: 10px;
    cursor: pointer;
    user-select: none;
}
.section-head h2 {
    margin: 0;
    font-size: 20px;
}
.section-head .count {
    color: var(--muted);
    font-size: 14px;
}
/* Сводка по секции: Всего N • На линии M (не путать с .totals шапки — там колонка) */
.section-head .section-totals {
    color: var(--muted);
    font-size: 14px;
    white-space: nowrap;
}
.section-head .section-totals b {
    font-weight: 600;
    color: #3f4a58;
}
.section-head .section-totals .sep {
    font-weight: 700;
    padding: 0 5px;
}
.section-head .section-totals b.live {
    color: #2e7d32;
}
.section-head .caret {
    margin-left: auto;
    color: var(--muted);
    font-size: 14px;
    transition: transform .15s;
}
section.collapsed .caret {
    transform: rotate(-90deg);
}
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 12px;
}
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-top: 3px solid var(--accent);
    transition: box-shadow .15s, transform .15s;
    position: relative;
}
.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    transform: translateY(-2px);
}
.card-main {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    text-decoration: none;
    color: inherit;
}
.num {
    flex: 0 0 auto;
    min-width: 52px;
    text-align: center;
    padding: 6px 9px;
    border-radius: 8px;
    font-size: 21px;
    font-weight: 800;
    line-height: 1.1;
    color: #fff;
    background: var(--accent);
}
/* На жёлтом (маршрутки) белый текст нечитаем */
.num.light {
    color: #3a3000;
}
.card-main .title {
    font-size: 14px;
    font-weight: 600;
    padding-top: 4px;
}
.title .arr {
    color: #90a0b0;
    padding: 0 3px;
}
/* Индикатор свежести данных: зелёный = есть позиции за последние 30 минут */
.pulse {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.pulse.on {
    background: #43a047;
    box-shadow: 0 0 0 3px rgba(67,160,71,.18);
}
.pulse.off {
    background: #c3ccd6;
}
.stats {
    display: grid;
    grid-template-columns: auto auto;
    gap: 4px 12px;
    font-size: 13px;
    justify-content: space-between;
}
.stats .k {
    color: var(--muted);
}
.stats .v {
    font-weight: 600;
    text-align: right;
}
.live {
    color: #2e7d32;
}
.operator {
    font-size: 12px;
    color: var(--muted);
    border-top: 1px solid var(--line);
    padding-top: 8px;
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.operator .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.operator .go {
    flex: 0 0 auto;
    color: var(--blue);
    font-weight: 600;
    text-decoration: none;
}
.operator .go:hover {
    opacity: .7;
}
.operator .go.disabled {
    opacity: .3;
    cursor: not-allowed;
    pointer-events: none;
}
/* Компактные числа "онлайн (всего)" — только на мобильном */
.mini {
    display: none;
}

.no-data {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    padding: 40px;
    color: #666;
}

/* ---------- Подвал ---------- */
footer {
    position: relative;
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 12px;
}
footer a {
    color: inherit;
    text-decoration: none;
}
/* Тихая ссылка на админку в углу подвала */
.footer-pi {
    position: absolute;
    right: 24px;
    bottom: 20px;
    font-size: 10px;
    color: #fff;
    line-height: 1;
}
.footer-pi:hover {
    color: var(--blue);
}

/* ---------- Кнопки ---------- */
.btn {
    display: inline-block;
    padding: 9px 16px;
    border: none;
    border-radius: 6px;
    background: var(--blue);
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: opacity .15s, background .15s;
}
.btn:hover {
    opacity: .85;
}
.btn.green { background: #43a047; }
.btn.danger { background: #E03131; }
.btn.gray { background: #94a0ad; }
.btn.white { background: #fff; color: var(--blue-dark); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; }
.btn.disabled {
    background: #c3ccd6;
    pointer-events: none;
}

/* ---------- Панели и карточки страниц (карточка маршрута, админка) ---------- */
.panel {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    margin-bottom: 20px;
    border-top: 3px solid var(--accent, var(--blue));
}
.panel h2 {
    font-size: 17px;
    margin-bottom: 14px;
}
.panel.table-panel {
    padding: 0;
}
.panel.table-panel h2 {
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--line);
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}
.detail-item {
    background: #f4f6f8;
    padding: 10px 14px;
    border-radius: 6px;
}
.detail-item label {
    font-size: 12px;
    color: var(--muted);
    display: block;
    margin-bottom: 4px;
}
.detail-item .value {
    font-size: 15px;
    font-weight: 600;
}
.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.summary-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    border-top: 3px solid var(--accent, var(--blue));
}
.summary-card h3 {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
}
.summary-card .value {
    font-size: 30px;
    font-weight: 800;
    color: var(--accent, var(--blue));
}
/* Жёлтый акцент (маршрутки) нечитаем крупным текстом — затемняем */
.marshrutka .summary-card .value,
.marshrutka .cache-count {
    color: #a08300;
}
.summary-card .value.date {
    font-size: 20px;
}

/* ---------- Таблицы ---------- */
.table-wrapper {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    padding: 10px 15px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}
th {
    background: #f7f9fb;
    font-weight: 600;
    color: #5a6572;
    font-size: 13px;
}
tr:last-child td {
    border-bottom: none;
}
tbody tr:hover td {
    background: #f7fafd;
}
.row-num {
    color: var(--muted);
    width: 40px;
}
.vehicle-id {
    font-weight: 600;
    color: var(--blue);
}
.label-chip {
    background: #eef4fb;
    color: #1a5a9e;
    padding: 3px 8px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.num-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
td .btn {
    margin-right: 8px;
}

/* ---------- Вход и админка ---------- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.auth-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 12px rgba(0,0,0,.14);
    padding: 36px 32px;
    width: 100%;
    max-width: 360px;
    border-top: 4px solid var(--blue);
}
.auth-card h1 {
    font-size: 20px;
    text-align: center;
    margin-bottom: 22px;
}
.auth-home {
    display: block;
    text-align: center;
    margin-top: 18px;
    font-size: 13px;
    color: var(--muted);
    text-decoration: none;
}
.auth-home:hover {
    color: var(--blue);
}
.field {
    margin-bottom: 14px;
}
.field label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 5px;
}
.field input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d5dbe2;
    border-radius: 6px;
    font-size: 15px;
    background: #fff;
    color: var(--text);
}
.field input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(33,150,243,.15);
}
.error-note {
    background: #fdecea;
    color: #b3261e;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 16px;
}
.cache-count {
    font-size: 42px;
    font-weight: 800;
    color: var(--blue);
    line-height: 1;
}
.cache-caption {
    color: var(--muted);
    font-size: 14px;
    margin-top: 6px;
}
.cache-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
    align-items: center;
}
.cache-result {
    font-size: 14px;
    color: var(--muted);
}
.cache-result.ok { color: #2e7d32; }
.cache-result.err { color: #b3261e; }

/* ---------- Админка: вкладки, ключи кеша, редактор меток ---------- */
.muted { color: var(--muted); font-weight: 400; font-size: 14px; }
.admin-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 2px solid var(--line);
}
.tab-btn {
    appearance: none;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 9px 16px;
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
}
.tab-btn:hover { color: var(--blue-dark); }
.tab-btn.active {
    color: var(--blue);
    border-bottom-color: var(--blue);
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.cache-invalidate { margin-top: 14px; }
.cache-invalidate label { font-size: 14px; }
.cache-invalidate input {
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
}
.cache-invalidate input[type="number"] { width: 110px; }
.cache-invalidate-hint { font-size: 13px; margin-top: 8px; }

/* Кнопки GPX на странице маршрута — только для админа. Страница кэшируется
   одна на всех, поэтому колонка скрыта в CSS, а скрипт маршрута читает флаг
   из localStorage (его кладёт admin.html при загрузке): у анонимов флага нет.
   Граница всё равно на сервере: /export/gpx без валидной куки отдаёт 401. */
.gpx-col { display: none; }
body.is-admin .gpx-col { display: table-cell; }

.keys-table { font-size: 13px; }
.keys-table th, .keys-table td { padding: 7px 10px; }
.labels-editor {
    width: 100%;
    min-height: 420px;
    margin-top: 10px;
    padding: 12px;
    font-family: Consolas, Menlo, monospace;
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid var(--line);
    border-radius: 6px;
    resize: vertical;
    box-sizing: border-box;
}

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 700px) {
    .container {
        padding: 0 12px;
    }
    .cards {
        grid-template-columns: 1fr;
    }
    /* Компактная карточка: строки статистики свёрнуты в числа у оператора */
    .stats {
        display: none;
    }
    .mini {
        display: inline;
        flex: 0 0 auto;
        font-weight: 700;
        color: #3f4a58;
    }
    .mini.live {
        color: #2e7d32;
    }
    .card {
        padding: 10px 12px 8px;
        gap: 6px;
    }
    header {
        padding: 10px 0;
    }
    header .container {
        gap: 2px 8px;
    }
    header h1 {
        font-size: 13px;
        white-space: normal;
    }
    /* Заголовок в две строки, без эмодзи и слов "в работе"/"сегодня" */
    .title-emoji, .title-long, .word {
        display: none;
    }
    .title-short, .title-br {
        display: inline;
    }
    .header-right {
        gap: 8px;
    }
    /* На карточке маршрута: дата и «График» — столбиком */
    .header-right.header-stack {
        flex-direction: column;
        align-items: flex-end;
        gap: 6px;
    }
    .chart-btn {
        padding: 4px 9px;
        font-size: 11px;
    }
    .header-left.row {
        gap: 8px;
    }
    .icon-btn {
        width: 28px;
        height: 28px;
    }
    .icon-btn svg {
        width: 15px;
        height: 15px;
    }
    .totals {
        font-size: 10px;
        line-height: 1.35;
        white-space: nowrap;
    }
    .date-picker {
        gap: 5px;
    }
    .date-picker label {
        display: none;
    }
    .date-picker input[type="date"] {
        padding: 4px 5px;
        font-size: 11px;
    }
    /* Заголовок секции на узком экране: сводка по транспорту — в две строки */
    .section-head {
        gap: 8px;
    }
    .section-head h2 {
        font-size: 16px;
    }
    .section-head .count {
        font-size: 12px;
    }
    .section-head .section-totals {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        font-size: 12px;
        line-height: 1.15;
    }
    .section-head .section-totals .sep {
        display: none;
    }
    /* Транспортная карта: своей строкой под остальной шапкой, тоже справа */
    .wallet {
        gap: 6px;
    }
    .wallet-label {
        font-size: 10px;
    }
    .wallet-form {
        gap: 4px;
    }
    .wallet-input {
        width: 84px;
        font-size: 11px;
    }
    .wallet-btn {
        width: 20px;
        height: 20px;
    }
    .wallet-btn svg {
        width: 11px;
        height: 11px;
    }
    .wallet-name {
        max-width: 120px;
        font-size: 10px;
    }
    .wallet-value {
        font-size: 12px;
    }
    .wallet-x {
        font-size: 12px;
    }
    .wallet-note {
        font-size: 10px;
    }
    .wallet-pop {
        font-size: 11px;
    }
}
