:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --text: #17191c;
    --muted: #747b84;
    --border: #e4e7eb;
    --accent: #e63232;
    --accent-dark: #c52626;
    --shadow: 0 14px 42px rgba(18, 24, 32, .12);
    --sidebar: 410px;
}

* { box-sizing: border-box; }

html,
body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

body {
    color: var(--text);
    background: var(--bg);
    font-family: Arial, "Segoe UI", sans-serif;
}

button,
input { font: inherit; }

button { cursor: pointer; }

[hidden] { display: none !important; }

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    width: 100%;
    height: 100dvh;
}

.sidebar {
    position: relative;
    z-index: 20;
    min-width: 0;
    height: 100dvh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 8px 0 28px rgba(23, 25, 28, .05);
}

.sidebar-header {
    height: 70px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.brand,
.mobile-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 21px;
    font-weight: 800;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    font-weight: 900;
}

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

.sidebar-scroll {
    height: calc(100dvh - 70px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.planner {
    padding: 24px 22px 20px;
    border-bottom: 1px solid var(--border);
}

.planner h1 {
    margin: 0 0 20px;
    font-size: 27px;
    letter-spacing: -.8px;
}

.route-fields {
    position: relative;
    display: grid;
    gap: 10px;
}

.station-field {
    position: relative;
}

.station-field label {
    display: block;
    margin: 0 0 6px 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .09em;
    text-transform: uppercase;
}

.input-wrap {
    height: 58px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 12px 0 15px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 15px;
    transition: .15s ease;
}

.input-wrap:focus-within {
    background: #fff;
    border-color: #b5bbc3;
    box-shadow: 0 0 0 4px rgba(23, 25, 28, .04);
}

.field-dot {
    width: 12px;
    height: 12px;
    flex: 0 0 auto;
    border: 3px solid var(--accent);
    border-radius: 50%;
    background: #fff;
}

.field-dot.is-destination {
    background: var(--accent);
}

.input-wrap input {
    min-width: 0;
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    font-weight: 700;
}

.input-wrap input::placeholder {
    color: #a0a6ae;
    font-weight: 400;
}

.clear-field {
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    color: #9aa0a8;
    font-size: 21px;
}

.clear-field:hover {
    background: #eceef1;
    color: var(--text);
}

.swap-button {
    position: absolute;
    z-index: 4;
    top: 79px;
    right: 14px;
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    box-shadow: 0 5px 16px rgba(20, 24, 32, .08);
    font-size: 20px;
}

.station-list {
    position: absolute;
    z-index: 60;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 360px;
    overflow-y: auto;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

.station-option {
    width: 100%;
    min-height: 52px;
    padding: 8px 9px;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border: 0;
    border-radius: 11px;
    background: transparent;
    text-align: left;
}

.station-option:hover,
.station-option.is-active {
    background: var(--surface-2);
}

.line-chip {
    min-width: 34px;
    height: 34px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    color: #fff;
    font-size: 12px;
    font-weight: 900;
}

.station-option-copy {
    min-width: 0;
}

.station-option-name {
    display: block;
    overflow: hidden;
    color: var(--text);
    font-size: 14px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.station-option-line {
    display: block;
    margin-top: 3px;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.station-list-empty {
    padding: 16px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.build-button {
    width: 100%;
    min-height: 52px;
    margin-top: 14px;
    border: 0;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}

.build-button:hover { background: var(--accent-dark); }

.build-button:disabled {
    opacity: .55;
    cursor: wait;
}

.form-error {
    margin-top: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    background: #fff0f0;
    color: #a41f1f;
    font-size: 13px;
    line-height: 1.4;
}

.route-results,
.station-card {
    padding: 20px 22px 28px;
}

.section-label {
    margin-bottom: 5px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .1em;
    text-transform: uppercase;
}

.route-pair {
    font-size: 17px;
    font-weight: 800;
    line-height: 1.35;
}

.variant-list {
    display: grid;
    gap: 9px;
    margin-top: 16px;
}

.variant-card {
    width: 100%;
    padding: 13px 14px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    text-align: left;
}

.variant-card:hover {
    background: var(--surface-2);
}

.variant-card.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(230, 50, 50, .09);
}

.variant-name {
    display: block;
    font-size: 14px;
    font-weight: 900;
}

.variant-benefit {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.variant-time {
    font-size: 17px;
    font-weight: 900;
    white-space: nowrap;
}

.route-detail {
    margin-top: 18px;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

.detail-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 13px;
}

.detail-pill {
    padding: 7px 9px;
    border-radius: 999px;
    background: var(--surface-2);
    color: #555c64;
    font-size: 12px;
}

.leg {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 0;
}

.leg-badge {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: grid;
    place-items: center;
    color: #fff;
    background: #777;
    font-size: 11px;
    font-weight: 900;
}

.leg-title {
    font-size: 13px;
    font-weight: 800;
    line-height: 1.35;
}

.leg-meta {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.station-card h2 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -.5px;
}

.station-card-line {
    margin-top: 9px;
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}

.station-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px;
    margin-top: 18px;
}

.station-card-actions button {
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 800;
}

.station-card-actions button:last-child {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

.station-card-note {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.map-panel {
    position: relative;
    min-width: 0;
    height: 100dvh;
    overflow: hidden;
    background: #f1f2f4;
}

.map-stage {
    position: absolute;
    inset: 0;
    overflow: hidden;
    touch-action: none;
    cursor: grab;
    user-select: none;
}

.map-stage.is-dragging { cursor: grabbing; }

.map-stage svg {
    width: 100%;
    height: 100%;
    display: block;
}

.map-loading {
    position: absolute;
    z-index: 30;
    inset: 0;
    display: grid;
    place-content: center;
    gap: 12px;
    color: var(--muted);
    background: #f1f2f4;
    font-size: 13px;
}

.loader {
    width: 30px;
    height: 30px;
    margin: 0 auto;
    border: 3px solid #ddd;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.map-controls {
    position: absolute;
    z-index: 15;
    right: 20px;
    bottom: 20px;
    display: grid;
    gap: 8px;
}

.map-controls button,
.mobile-topbar button {
    width: 44px;
    height: 44px;
    border: 1px solid rgba(0, 0, 0, .08);
    border-radius: 13px;
    background: rgba(255,255,255,.96);
    color: var(--text);
    box-shadow: 0 5px 18px rgba(20,24,32,.12);
    font-size: 20px;
    font-weight: 800;
}

.mobile-topbar,
.mobile-sheet {
    display: none;
}

#vm-map-connections,
#vm-map-transitions,
#vm-map-stations {
    transition: opacity .18s ease;
}

.vm-map-station {
    cursor: pointer;
}

.vm-map-station-hit {
    fill: transparent;
    pointer-events: all;
}

.map-stage.has-route .vm-map-connection,
.map-stage.has-route .vm-map-transition {
    opacity: .16;
}

.map-stage.has-route .vm-map-station {
    opacity: .55;
}

.map-stage.has-route .vm-map-connection.is-route,
.map-stage.has-route .vm-map-transition.is-route,
.map-stage.has-route .vm-map-station.is-route-station {
    opacity: 1;
    filter: drop-shadow(0 0 2px rgba(0,0,0,.22));
}

.vm-map-station.is-selected .vm-map-station-marker {
    filter: drop-shadow(0 0 5px rgba(230,50,50,.8));
}

@media (max-width: 760px) {
    html,
    body {
        overscroll-behavior: none;
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        display: none;
    }

    .map-panel {
        width: 100%;
        height: 100dvh;
    }

    .mobile-topbar {
        position: absolute;
        z-index: 22;
        top: 0;
        left: 0;
        right: 0;
        padding:
            max(10px, env(safe-area-inset-top))
            12px
            8px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        pointer-events: none;
    }

    .mobile-topbar > * {
        pointer-events: auto;
    }

    .mobile-brand {
        padding: 7px 10px 7px 7px;
        border: 1px solid rgba(0,0,0,.07);
        border-radius: 14px;
        background: rgba(255,255,255,.95);
        box-shadow: 0 5px 18px rgba(20,24,32,.1);
        font-size: 17px;
    }

    .mobile-brand .brand-mark {
        width: 30px;
        height: 30px;
        border-radius: 9px;
    }

    .map-controls {
        display: none;
    }

    .mobile-sheet {
        position: absolute;
        z-index: 24;
        left: 8px;
        right: 8px;
        bottom: max(8px, env(safe-area-inset-bottom));
        max-height: 46dvh;
        display: block;
        overflow: hidden;
        background: #fff;
        border: 1px solid rgba(0,0,0,.07);
        border-radius: 22px;
        box-shadow: 0 16px 50px rgba(20,24,32,.22);
        transition: max-height .2s ease;
    }

    .mobile-sheet.is-expanded {
        max-height: 82dvh;
    }

    .sheet-handle {
        width: 100%;
        height: 28px;
        display: grid;
        place-items: center;
        border: 0;
        background: #fff;
    }

    .sheet-handle span {
        width: 42px;
        height: 4px;
        border-radius: 99px;
        background: #d7dadd;
    }

    .mobile-sheet-content {
        max-height: calc(82dvh - 28px);
        overflow-y: auto;
        padding: 0 14px 16px;
    }

    .mobile-route-fields {
        display: grid;
        gap: 8px;
    }

    .mobile-input {
        width: 100%;
        min-height: 49px;
        padding: 0 13px;
        border: 1px solid var(--border);
        border-radius: 13px;
        outline: 0;
        background: var(--surface-2);
        font-size: 15px;
        font-weight: 700;
    }

    .mobile-station-list {
        max-height: 40dvh;
        overflow-y: auto;
        margin-top: 8px;
        border-top: 1px solid var(--border);
        padding-top: 6px;
    }

    .mobile-build {
        width: 100%;
        min-height: 48px;
        margin-top: 10px;
        border: 0;
        border-radius: 13px;
        background: var(--accent);
        color: #fff;
        font-weight: 800;
    }

    .mobile-sheet .variant-list {
        margin-top: 12px;
    }

    .mobile-sheet .route-detail {
        margin-top: 14px;
    }

    .mobile-sheet .station-card-actions {
        margin-top: 14px;
    }
}

/* === VMETRO MAP VISUAL PRIORITY V1.1 START === */

.vm-map-additional {
    opacity: .48;
    transition: opacity .18s ease, filter .18s ease;
}

.map-stage.has-route .vm-map-additional {
    opacity: .24;
    filter: saturate(.72);
}

.map-stage.has-route .vm-map-connection:not(.is-route),
.map-stage.has-route .vm-map-transition:not(.is-route) {
    opacity: .10;
    filter: saturate(.38);
}

.map-stage.has-route .vm-map-station:not(.is-route-station) {
    opacity: .30;
}

.map-stage.has-route .vm-map-connection.is-route,
.map-stage.has-route .vm-map-transition.is-route {
    opacity: 1;
    filter:
        saturate(1.08)
        drop-shadow(0 0 1px rgba(255,255,255,.95))
        drop-shadow(0 0 2px rgba(20,24,32,.28));
}

.map-stage.has-route .vm-map-station.is-route-station {
    opacity: 1;
}

/* === VMETRO MAP VISUAL PRIORITY V1.1 END === */

/* === VMETRO MAP UI V1.2 START === */

.vm-map-additional {
    opacity: .28;
    filter: saturate(.42) contrast(.96);
    transition: opacity .18s ease, filter .18s ease;
}

.map-stage.has-route .vm-map-additional {
    opacity: .10;
    filter: saturate(.25) contrast(.94);
}

.map-stage.has-route .vm-map-connection:not(.is-route),
.map-stage.has-route .vm-map-transition:not(.is-route) {
    opacity: .15;
    filter: saturate(.52);
}

.map-stage.has-route .vm-map-station:not(.is-route-station) {
    opacity: .28;
}

.map-stage.has-route .vm-map-connection.is-route,
.map-stage.has-route .vm-map-transition.is-route {
    opacity: 1;
    filter:
        saturate(1.16)
        contrast(1.06)
        drop-shadow(0 0 1px rgba(255,255,255,.98))
        drop-shadow(0 0 3px rgba(20,24,32,.30));
}

.map-stage.has-route .vm-map-station.is-route-station {
    opacity: 1;
    filter:
        drop-shadow(0 0 1px rgba(255,255,255,.98))
        drop-shadow(0 0 2px rgba(20,24,32,.22));
}

/* === VMETRO MAP UI V1.2 END === */

/* === VMETRO MOBILE SHEET V1.5 START === */
@media (max-width: 760px) {
    /*
     * По умолчанию панель занимает меньше карты.
     * Высоту можно менять перетаскиванием верхней ручки.
     */
    .mobile-sheet {
        height: 30dvh;
        min-height: 150px;
        max-height: 80dvh;
        transition: height .18s ease;
    }

    .mobile-sheet.is-expanded {
        height: 78dvh;
        max-height: 80dvh;
    }

    .mobile-sheet.is-resizing {
        transition: none;
    }

    .sheet-handle {
        touch-action: none;
        cursor: ns-resize;
        user-select: none;
        -webkit-user-select: none;
    }

    .sheet-handle span {
        width: 48px;
        height: 5px;
    }

    .mobile-sheet-content {
        height: calc(100% - 28px);
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}
/* === VMETRO MOBILE SHEET V1.5 END === */

/* === VMETRO STATION CARD V1.6 START === */

.station-facts {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.station-fact {
    padding: 11px 12px;
    border-radius: 12px;
    background: var(--surface-2);
}

.station-fact-label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.station-fact-value {
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.45;
}

.station-services {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.station-service-chip {
    padding: 6px 8px;
    border-radius: 999px;
    background: #eef0f3;
    color: #4d545d;
    font-size: 11px;
    font-weight: 700;
}

.station-card-empty {
    margin-top: 14px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

@media (max-width: 760px) {
    .mobile-station-title {
        margin: 0;
        font-size: 23px;
        line-height: 1.15;
        letter-spacing: -.4px;
    }

    .mobile-sheet .station-facts {
        margin-top: 13px;
    }

    .mobile-sheet .station-card-actions {
        position: sticky;
        bottom: 0;
        padding-top: 10px;
        padding-bottom: max(2px, env(safe-area-inset-bottom));
        background: linear-gradient(
            to bottom,
            rgba(255,255,255,0),
            rgba(255,255,255,.96) 14px,
            #fff 28px
        );
    }
}

/* === VMETRO STATION CARD V1.6 END === */
