/* Электрички ЦППК — основные стили */

:root {
    --brand-1: #1e3c72;
    --brand-2: #2a5298;
    --accent: #4a7dff;
    --accent-dark: #3a5ca8;
    --transfer: #ff9800;
    --text: #1c2738;
    --muted: #6b7a90;
    --surface: #ffffff;
    --surface-2: #f3f6fc;
    --border: #e1e7f2;
    --panel-text: #ffffff;
    --panel-muted: #c2d6ff;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(20, 40, 90, 0.18);
    --panel-width: 400px;
    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: #f0f5ff;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

button, input {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

a {
    color: var(--accent);
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

/* ---------- Каркас ---------- */

.app {
    display: grid;
    grid-template-columns: var(--panel-width) 1fr;
    height: 100vh;
    height: 100dvh;
}

.panel {
    position: relative;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: linear-gradient(160deg, var(--brand-1), var(--brand-2));
    color: var(--panel-text);
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.2);
}

.panel-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px 20px 28px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.sheet-handle {
    display: none;
}

.map-wrap {
    position: relative;
    min-width: 0;
}

#map {
    position: absolute;
    inset: 0;
    background: #eef1f5;
}

/* ---------- Шапка ---------- */

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.brand-logo {
    flex: none;
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #ffffff; /* логотип ЦППК зелёно-синий, на синем фоне его не видно */
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.brand-logo img {
    width: 34px;
    height: auto;
    display: block;
}

.brand-text {
    flex: 1;
    min-width: 0;
}

.brand h1 {
    font-size: 21px;
    line-height: 1.2;
    font-weight: 700;
}

.brand p {
    margin-top: 2px;
    font-size: 12.5px;
    color: var(--panel-muted);
}

.lang-switch {
    display: flex;
    flex: none;
    padding: 3px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.12);
}

.lang-switch button {
    padding: 4px 9px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    color: var(--panel-muted);
    transition: background 0.2s, color 0.2s;
}

.lang-switch button[aria-pressed="true"] {
    background: #fff;
    color: var(--brand-1);
}

/* ---------- Поиск ---------- */

.search-box {
    position: relative;
    z-index: 30; /* выпадающий список поверх кнопок и подсказки ниже */
    display: grid;
    gap: 10px;
}

/* пока открыт список, кнопка "поменять местами" не лезет поверх него */
.search-box:has(.dropdown.is-open) .swap-btn {
    opacity: 0;
    pointer-events: none;
}

.field {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 0 10px;
    height: 50px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.field:focus-within {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.18);
    box-shadow: 0 0 0 4px rgba(74, 125, 255, 0.25);
}

.field-badge {
    flex: none;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 13px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.field-badge.is-b {
    background: #e74c5b;
}

.field input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    color: #fff;
}

.field input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.icon-btn {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    color: #fff;
    transition: background 0.2s, transform 0.15s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn svg {
    width: 19px;
    height: 19px;
}

.icon-btn.is-recording {
    background: #e74c5b;
    animation: pulse-ring 1.2s infinite;
}

.swap-btn {
    position: absolute;
    right: -8px;
    top: 50%;
    z-index: 2;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--brand-1);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    transition: transform 0.35s cubic-bezier(.34, 1.56, .64, 1), opacity 0.15s;
}

.swap-btn:hover {
    transform: translateY(-50%) rotate(180deg);
}

.swap-btn svg {
    width: 16px;
    height: 16px;
}

.dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    max-height: 300px;
    overflow-y: auto;
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    box-shadow: var(--shadow);
    display: none;
}

.dropdown.is-open {
    display: block;
    animation: blur-fade-in 0.22s ease-out both;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--surface-2);
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover,
.dropdown-item.is-active {
    background: #eef3ff;
}

.dropdown-item .dot {
    flex: none;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.dropdown-item .name {
    flex: 1;
    font-size: 14.5px;
}

.dropdown-item .name small {
    display: block;
    font-size: 11.5px;
    color: var(--muted);
}

.dropdown-item .dir {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
}

.dropdown-empty {
    padding: 14px;
    font-size: 14px;
    color: var(--muted);
}

.actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    margin-top: 14px;
}

.btn {
    height: 46px;
    padding: 0 18px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    transition: transform 0.15s, background 0.2s, opacity 0.2s;
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.2);
}

.hint {
    margin-top: 12px;
    font-size: 12.5px;
    color: var(--panel-muted);
    line-height: 1.45;
}

/* ---------- Результат маршрута ---------- */

.route {
    margin-top: 22px;
}

.route-summary {
    position: relative;
    padding: 16px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow: hidden;
}

.route-title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
}

.route-stats {
    display: grid;
    grid-template-columns: 1.7fr 1fr 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

.stat {
    text-align: center;
}

.stat b {
    display: block;
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stat span {
    font-size: 11px;
    color: var(--panel-muted);
}

.route-note {
    margin-top: 12px;
    font-size: 12px;
    color: var(--panel-muted);
    line-height: 1.4;
}

.route-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.chip-btn {
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12.5px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    transition: background 0.2s;
}

.chip-btn:hover {
    background: rgba(255, 255, 255, 0.24);
}

.legs {
    list-style: none;
    margin-top: 14px;
    display: grid;
    gap: 10px;
}

.leg {
    position: relative;
    padding: 14px 14px 14px 18px;
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    box-shadow: 0 4px 14px rgba(10, 30, 80, 0.15);
}

.leg::before {
    content: "";
    position: absolute;
    left: 0;
    top: 12px;
    bottom: 12px;
    width: 5px;
    border-radius: 0 4px 4px 0;
    background: var(--leg-color, var(--accent));
}

.leg-transfer {
    background: #fff7ea;
}

.leg-transfer::before {
    background: repeating-linear-gradient(180deg, var(--transfer) 0 6px, transparent 6px 10px);
}

.leg-head {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.leg-head .dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--leg-color, var(--accent));
}

.leg-head .time {
    margin-left: auto;
    text-transform: none;
    color: var(--text);
}

.leg-stations {
    margin-top: 6px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.35;
}

.leg-meta {
    margin-top: 4px;
    font-size: 12.5px;
    color: var(--muted);
}

.leg-stops {
    margin-top: 8px;
}

.leg-stops summary {
    font-size: 12.5px;
    color: var(--accent);
    cursor: pointer;
    list-style: none;
}

.leg-stops summary::-webkit-details-marker {
    display: none;
}

.leg-stops ol {
    margin: 8px 0 0 4px;
    padding-left: 14px;
    border-left: 2px dotted var(--border);
    list-style: none;
    font-size: 13px;
    line-height: 1.7;
    color: var(--muted);
}

/* Расписание и билеты в карточке участка */

.trains {
    margin-top: 12px;
    border-top: 1px solid var(--surface-2);
    padding-top: 10px;
}

.trains-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.train {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 4px 10px;
    padding: 7px 0;
    border-bottom: 1px dashed var(--surface-2);
    font-size: 13px;
}

.train:last-child {
    border-bottom: none;
}

.train-time {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    font-size: 14px;
}

.train-time small {
    font-weight: 400;
    color: var(--muted);
}

.train-info {
    min-width: 0;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.train-price {
    font-weight: 600;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: #eef3ff;
    color: var(--accent-dark);
    margin-right: 4px;
}

.badge-express {
    background: #ffe9e9;
    color: #c0392b;
}

.trains-empty,
.trains-loading {
    font-size: 13px;
    color: var(--muted);
    padding: 4px 0;
}

.skeleton {
    height: 14px;
    margin: 8px 0;
    border-radius: 6px;
    background: linear-gradient(90deg, #eef1f6 25%, #f8f9fc 50%, #eef1f6 75%);
    background-size: 200% 100%;
    animation: skeleton 1.2s infinite linear;
}

.tickets {
    margin-top: 10px;
}

.tickets-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}

.ticket-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ticket-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 9px;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    transition: border-color 0.2s, transform 0.15s, background 0.2s;
}

.ticket-link:hover {
    border-color: var(--accent);
    background: #fff;
    transform: translateY(-1px);
}

.ticket-link i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--svc, var(--accent));
}

.ticket-link small {
    font-weight: 400;
    color: var(--muted);
}

.tickets-note {
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--muted);
    line-height: 1.4;
}

/* ---------- Карта: элементы управления ---------- */

.map-controls {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 900;
    display: grid;
    gap: 8px;
}

.map-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--brand-1);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s, background 0.2s;
}

.map-btn:hover {
    background: #f1f5ff;
}

.map-btn:active {
    transform: scale(0.93);
}

.map-btn[aria-pressed="true"] {
    background: var(--accent);
    color: #fff;
}

.map-btn svg {
    width: 20px;
    height: 20px;
}

.legend {
    position: absolute;
    top: 14px;
    right: 66px;
    z-index: 900;
    width: 230px;
    padding: 14px;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.97);
    box-shadow: var(--shadow);
    font-size: 13px;
}

.legend h4 {
    font-size: 13px;
    margin-bottom: 8px;
}

.legend ul {
    list-style: none;
    display: grid;
    gap: 5px;
}

.legend li {
    display: flex;
    align-items: center;
    gap: 9px;
}

.legend .swatch {
    flex: none;
    width: 22px;
    height: 5px;
    border-radius: 3px;
}

.legend .swatch-transfer {
    background: repeating-linear-gradient(90deg, var(--transfer) 0 5px, transparent 5px 8px);
}

/* Карточка станции */

.station-card {
    position: absolute;
    left: 14px;
    top: 14px;
    z-index: 950;
    width: 340px;
    max-height: calc(100% - 28px);
    overflow-y: auto;
    padding: 18px;
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.station-card-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.station-card h3 {
    flex: 1;
    font-size: 19px;
    line-height: 1.25;
}

.station-card .close-btn {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: var(--muted);
    background: var(--surface-2);
}

.station-card .close-btn:hover {
    color: var(--text);
}

.station-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--surface-2);
    color: var(--muted);
}

.tag i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.station-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 14px;
}

.btn-from,
.btn-to {
    height: 38px;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    color: #fff;
}

.btn-from {
    background: var(--accent);
}

.btn-to {
    background: #e74c5b;
}

.station-about {
    margin-top: 14px;
    font-size: 14px;
    line-height: 1.55;
}

.station-about p + p {
    margin-top: 8px;
}

.station-about h4 {
    margin: 14px 0 6px;
    font-size: 13px;
    color: var(--muted);
}

.station-about ul {
    padding-left: 18px;
}

.station-about li + li {
    margin-top: 4px;
}

.story {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f1f5ff, #f8f3ff);
    font-size: 14px;
    line-height: 1.55;
}

.story-btn {
    margin-top: 14px;
    width: 100%;
}

/* Метки и маркеры на карте */

.station-label {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    font-size: 11.5px;
    font-weight: 600;
    color: #24324a;
    text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
    white-space: nowrap;
    pointer-events: none;
}

.station-label::before {
    display: none;
}

.station-label.is-major {
    font-size: 12.5px;
    font-weight: 700;
}

.station-label.is-dim {
    opacity: 0.35;
}

.endpoint-pin {
    background: none;
    border: none;
}

.endpoint-pin span {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: var(--accent);
    border: 3px solid #fff;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    animation: pin-drop 0.5s cubic-bezier(.34, 1.56, .64, 1) both;
}

.endpoint-pin.is-b span {
    background: #e74c5b;
}

.endpoint-pin span::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid currentColor;
    color: inherit;
    animation: pulse-ring 1.8s 0.5s infinite;
}

.leaflet-container {
    font-family: var(--font);
}

.leaflet-tooltip.station-tip {
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    border: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.18);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    z-index: 5000;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 12px 18px;
    border-radius: 12px;
    background: #1c2738;
    color: #fff;
    font-size: 14px;
    box-shadow: var(--shadow);
    animation: blur-fade-in 0.3s ease-out both;
}

/* ---------- Телефон: панель как выдвижной лист снизу ---------- */

@media (max-width: 899px) {
    .app {
        display: block;
    }

    .map-wrap {
        position: fixed;
        inset: 0;
    }

    .panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 88dvh;
        height: var(--sheet-height, 290px);
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
        transition: height 0.35s cubic-bezier(.32, .72, 0, 1);
    }

    .panel.is-dragging {
        transition: none;
    }

    .sheet-handle {
        display: block;
        flex: none;
        height: 26px;
        cursor: grab;
        touch-action: none;
    }

    .sheet-handle::before {
        content: "";
        display: block;
        width: 42px;
        height: 5px;
        margin: 10px auto 0;
        border-radius: 3px;
        background: rgba(255, 255, 255, 0.45);
    }

    .panel-scroll {
        padding: 4px 16px 20px;
    }

    .brand {
        margin-bottom: 12px;
    }

    .brand-logo {
        width: 38px;
        height: 38px;
    }

    .brand-logo img {
        width: 28px;
    }

    .brand h1 {
        font-size: 17px;
    }

    .brand p {
        display: none;
    }

    .field {
        height: 46px;
    }

    .map-controls {
        top: 12px;
        right: 12px;
    }

    .legend {
        right: 62px;
        top: 12px;
        width: 210px;
        max-height: 60vh;
        overflow-y: auto;
    }

    .station-card {
        left: 12px;
        right: 12px;
        top: 12px;
        width: auto;
        max-height: calc(100dvh - var(--sheet-height, 290px) - 24px);
    }

    /* на телефоне масштаб меняют двумя пальцами, кнопки только мешают */
    .leaflet-control-zoom {
        display: none;
    }

    .leaflet-bottom.leaflet-right {
        bottom: var(--sheet-height, 290px);
    }
}

@media (max-width: 380px) {
    .route-stats {
        grid-template-columns: repeat(2, 1fr);
    }
}
