/* =========================================================================
   dmitrov.org — Транспорт: A→B карта ниток + мобильный + a11y (Фаза 6, 07.10.2026)
   ========================================================================= */

/* --- Контейнер карты на /transport (под A→B блоком) --- */
#ab-map-wrap {
    position: relative;
    background: var(--card, #fff);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-top: 12px;
}
.dark #ab-map-wrap {
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}
#ab-map {
    height: 360px;
    width: 100%;
    background: #e5e7eb;
    z-index: 1;
}
.dark #ab-map { background: #1f2937; }
#ab-map-wrap .leaflet-container {
    background: transparent;
    font-family: inherit;
    /* Атрибуция полностью скрыта (юзер 07.10.2026) */
}
#ab-map-wrap .leaflet-control-attribution,
#stop-map .leaflet-control-attribution {
    display: none !important;
}
#ab-map-msg {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-size: 14px;
    text-align: center;
    padding: 20px;
    pointer-events: none;
    z-index: 500;
    background: rgba(255, 255, 255, 0.85);
}
.dark #ab-map-msg {
    color: #9ca3af;
    background: rgba(22, 27, 34, 0.85);
}
#ab-map-msg.hidden { display: none; }

/* --- Контейнер карты на /transport/stop/{code} --- */
#stop-map {
    height: 240px;
    width: 100%;
    border-radius: 16px;
    overflow: hidden;
    background: #e5e7eb;
    margin-top: 12px;
    z-index: 1;
}
.dark #stop-map { background: #1f2937; }
#stop-map .leaflet-container {
    background: transparent;
    font-family: inherit;
}
#stop-map-msg {
    text-align: center;
    color: #6b7280;
    font-size: 13px;
    padding: 8px;
    margin-top: 4px;
}
.dark #stop-map-msg { color: #9ca3af; }

/* --- Leaflet popup стили (светлая/тёмная темы) --- */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.leaflet-popup-content {
    margin: 10px 14px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
}
.ab-popup-title {
    font-weight: 700;
    font-size: 14px;
    color: #111;
    margin-bottom: 4px;
}
.dark .ab-popup-title { color: #e6edf3; }
.ab-popup-sub {
    font-size: 11px;
    color: #6b7280;
}
.dark .ab-popup-sub { color: #9ca3af; }
.ab-popup-route-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 10px;
    color: #fff;
    margin-right: 4px;
}
.ab-popup-time {
    font-size: 12px;
    color: #007aff;
    font-weight: 600;
}

/* --- Легенда маршрутов на A→B карте --- */
#ab-map-legend {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 10px;
    padding: 8px 10px;
    font-size: 11px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 500;
    max-width: 220px;
    max-height: 180px;
    overflow-y: auto;
}
.dark #ab-map-legend {
    background: rgba(22, 27, 34, 0.95);
    color: #e6edf3;
}
.ab-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
    line-height: 1.2;
}
.ab-legend-color {
    width: 14px;
    height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* --- A→B: маркеры A/B/via --- */
.ab-marker {
    background: transparent;
    border: none;
}
.ab-marker-pin {
    width: 28px;
    height: 28px;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    border: 3px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
}
.dark .ab-marker-pin { border-color: #161b22; }
.ab-marker-pin > span { transform: rotate(45deg); }
.ab-marker-a .ab-marker-pin { background: #10b981; }
.ab-marker-b .ab-marker-pin { background: #ef4444; }
.ab-marker-via .ab-marker-pin {
    background: #f59e0b;
    width: 18px;
    height: 18px;
    font-size: 9px;
}
.ab-marker-via .ab-marker-pin > span { display: none; }

/* --- A→B: переключатель маршрутов (если несколько) --- */
#ab-map-routes {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
.dark #ab-map-routes {
    background: rgba(255, 255, 255, 0.03);
    border-bottom-color: rgba(255, 255, 255, 0.06);
}
.ab-route-toggle {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: rgba(0, 0, 0, 0.05);
    color: #374151;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
}
.dark .ab-route-toggle {
    background: rgba(255, 255, 255, 0.08);
    color: #d1d5db;
}
.ab-route-toggle:hover {
    background: rgba(0, 0, 0, 0.1);
}
.dark .ab-route-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
}
.ab-route-toggle.active {
    background: #007aff;
    color: #fff;
}
.ab-route-toggle:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
}

/* --- A11y: focus rings --- */
#ab-from:focus-visible,
#ab-to:focus-visible,
#ab-time:focus-visible,
#ab-search:focus-visible,
input:focus-visible,
button:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid #007aff;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.2);
}

/* --- A11y: skip link --- */
.skip-link {
    position: absolute;
    top: -40px;
    left: 8px;
    background: #007aff;
    color: #fff;
    padding: 8px 12px;
    border-radius: 6px;
    text-decoration: none;
    z-index: 9999;
    font-size: 13px;
    font-weight: 600;
    transition: top 0.2s;
}
.skip-link:focus {
    top: 8px;
}

/* --- Mobile: 320-640px (iPhone SE — 320, iPhone 12 — 390) --- */
@media (max-width: 640px) {
    #ab-map { height: 280px; }
    #stop-map { height: 200px; }

    /* A→B блок: компактнее */
    #ab-from, #ab-to, #ab-time {
        font-size: 16px;  /* предотвращает iOS zoom-on-focus */
        padding: 12px 14px;
    }
    #ab-search {
        min-height: 44px;  /* touch-target минимум */
        font-size: 15px;
    }

    /* Карточки маршрутов плотнее */
    .route-card {
        padding: 12px;
    }
    .route-card .text-sm {
        font-size: 13px;
    }

    /* Type chips — больше touch area */
    .type-chip {
        padding: 6px 10px !important;
        min-height: 32px;
    }

    /* Маркеры на карте — больше на мобиле */
    .ab-marker-pin {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    .ab-marker-via .ab-marker-pin {
        width: 20px;
        height: 20px;
    }

    /* Legend — компактнее */
    #ab-map-legend {
        font-size: 10px;
        max-width: 160px;
        padding: 6px 8px;
    }

    /* A→B results — touch-friendly */
    #ab-results a {
        padding: 12px;
        min-height: 56px;
        display: flex;
        flex-direction: column;
    }

    /* Стат-бар: nowrap */
    #stats-bar {
        flex-wrap: wrap;
        gap: 6px;
        font-size: 11px;
    }

    /* Кнопка «Показать на карте» — больше */
    #route-modal button[onclick*="showRouteOnMap"] {
        min-height: 48px;
    }
}

/* --- Tablet: 641-1023px --- */
@media (min-width: 641px) and (max-width: 1023px) {
    #ab-map { height: 320px; }
    #stop-map { height: 220px; }
}

/* --- Dark theme overrides для Leaflet --- */
.dark .leaflet-popup-content-wrapper,
.dark .leaflet-popup-tip {
    background: #1f2937;
    color: #e6edf3;
}
.dark .leaflet-bar a {
    background: #374151;
    color: #e6edf3;
    border-color: #4b5563;
}
.dark .leaflet-bar a:hover {
    background: #4b5563;
}

/* --- A11y: prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
    .ab-route-toggle,
    #ab-from, #ab-to, #ab-time,
    .ab-marker-pin {
        transition: none;
    }
    .leaflet-fade-anim .leaflet-tile,
    .leaflet-zoom-anim .leaflet-zoom-animated {
        transition: none !important;
    }
}

/* --- Print: скрыть карту, оставить текст --- */
@media print {
    #ab-map-wrap, #stop-map { display: none; }
    .route-card { break-inside: avoid; }
}

/* --- High contrast: a11y --- */
@media (prefers-contrast: high) {
    .route-card { border-width: 2px; }
    .ab-marker-pin { border-width: 4px; }
    .ab-route-toggle.active { outline: 2px solid #000; }
}

/* --- Loading skeleton for map --- */
.map-skeleton {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%);
    background-size: 200% 100%;
    animation: map-skeleton 1.5s infinite;
    z-index: 400;
    pointer-events: none;
}
.dark .map-skeleton {
    background: linear-gradient(90deg, #1f2937 25%, #374151 50%, #1f2937 75%);
    background-size: 200% 100%;
}
@keyframes map-skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
