/* © Mahdi Amouzegar — All rights reserved | مهدی آموزگار — همه حقوق محفوظ است */
/* map.css — Map Panel, Markers, Popups, Route, Saved Locations */

@layer components, overrides;

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: components
   ═══════════════════════════════════════════════════════════════════════════ */
@layer components {
    /* ═══ Map Head ═══ */
    .map-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        margin-bottom: 12px;
        flex-wrap: wrap;
    }

    .map-head-actions {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }

    #liveTrackBtn.active {
        border-color: var(--accent-cyan);
        background: var(--accent-cyan-soft);
        color: var(--accent-cyan);
        box-shadow: 0 0 12px var(--accent-cyan-soft);
    }

    .map-title {
        font-weight: 800;
        font-size: 1rem;
        color: var(--text-secondary);
    }

    /* ═══ Map Search ═══ */
    .map-search {
        position: relative;
        margin-bottom: 12px;
        z-index: 1;
    }

    .map-search-row {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 0 12px;
        border: 1.5px solid var(--border-medium);
        border-radius: var(--radius-md);
        background: var(--bg-2);
        transition: border-color .18s ease, box-shadow .18s ease;
    }

    .map-search-row:focus-within {
        border-color: var(--accent-cyan);
        box-shadow: 0 0 0 3px var(--accent-cyan-soft);
    }

    .map-search-icon {
        font-size: .9rem;
        opacity: .6;
        flex-shrink: 0;
    }

    #mapSearchInput {
        flex: 1;
        min-width: 0;
        padding: 11px 0;
        border: 0;
        background: transparent;
        color: var(--text-primary);
        font-family: inherit;
        font-size: .88rem;
        outline: none;
    }

    #mapSearchInput::placeholder {
        color: var(--text-faintest);
    }

    .map-search-mic {
        flex-shrink: 0;
        width: 32px;
        height: 32px;
        font-size: .9rem;
        border-color: var(--border-medium);
        background: var(--bg-2);
    }

    .map-search-mic:hover {
        border-color: var(--accent-cyan-border);
        color: var(--accent-cyan);
    }

    .map-search-mic.listening {
        border-color: var(--accent-pink);
        color: var(--accent-pink);
        box-shadow: 0 0 15px var(--accent-pink-soft);
        animation: pulse 1.2s ease-in-out infinite;
    }

    .map-search-clear {
        appearance: none;
        flex-shrink: 0;
        width: 26px;
        height: 26px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 50%;
        background: var(--bg-4);
        color: var(--text-muted);
        font: inherit;
        font-size: .85rem;
        cursor: pointer;
        transition: background .16s ease, color .16s ease;
    }

    .map-search-clear:hover {
        background: var(--accent-pink-soft);
        color: var(--accent-pink);
    }

    .map-search-results {
        position: absolute;
        top: calc(100% + 6px);
        left: 0;
        right: 0;
        z-index: 600;
        max-height: 280px;
        overflow-y: auto;
        border: 1px solid var(--border-medium);
        border-radius: var(--radius-md);
        background: var(--surface-raised);
        box-shadow: var(--shadow-lg);
        padding: 4px;
        scrollbar-width: thin;
        scrollbar-color: rgba(165, 165, 208, .34) transparent;
    }

    .map-search-results::-webkit-scrollbar {
        width: 7px;
    }

    .map-search-results::-webkit-scrollbar-track {
        background: transparent;
    }

    .map-search-results::-webkit-scrollbar-thumb {
        background: rgba(165, 165, 208, .30);
        border-radius: var(--radius-pill);
    }

    .map-search-item {
        display: flex;
        flex-direction: column;
        gap: 2px;
        width: 100%;
        padding: 9px 12px;
        border: 0;
        border-radius: 8px;
        background: transparent;
        color: var(--text-primary);
        font: inherit;
        font-size: .84rem;
        text-align: start;
        cursor: pointer;
        transition: background .15s ease;
    }

    .map-search-item:hover,
    .map-search-item:focus-visible {
        background: var(--surface-soft);
        outline: none;
    }

    .map-search-item-title {
        font-weight: 700;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .map-search-item-sub {
        font-size: .72rem;
        color: var(--text-muted);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .map-search-empty,
    .map-search-loading {
        padding: 12px;
        text-align: center;
        font-size: .8rem;
        color: var(--text-faint);
    }

    /* ═══ Map Wrap ═══ */
    .map-wrap {
        position: relative;
        border-radius: var(--radius-lg);
        overflow: hidden;
        border: 1px solid var(--border-medium);
        box-shadow: var(--shadow-sm);
    }

    #map {
        height: 520px;
        background: var(--bg-2);
        z-index: 0;
    }

    .map-fallback {
        height: 100%;
        min-height: 200px;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        padding: 30px;
        color: var(--text-muted);
        font-size: 0.9rem;
        line-height: 2;
    }

    .map-hint {
        position: absolute;
        top: 12px;
        inset-inline-end: 12px;
        inset-inline-start: 12px;
        z-index: 500;
        text-align: center;
        font-size: 0.8rem;
        font-weight: 700;
        color: var(--text-primary);
        background: var(--bg-3);
        border: 1px solid var(--accent-cyan-border);
        border-radius: var(--radius-md);
        padding: 10px 14px;
        opacity: 0;
        transition: opacity var(--transition-base);
        pointer-events: none;
    }

    .map-hint.show {
        opacity: 1;
    }

    .map-note {
        font-size: 0.75rem;
        color: var(--text-faint);
        margin-top: 10px;
        line-height: 1.9;
        text-align: start;
    }

    /* ═══ Markers ═══ */
    .mk {
        width: 18px;
        height: 18px;
        border-radius: 50%;
        background: radial-gradient(circle at 30% 30%, var(--accent-cyan), var(--accent-purple));
        border: 2px solid var(--text-white);
        box-shadow: 0 0 12px var(--accent-cyan-glow);
        display: block;
    }

    .mk.done {
        background: radial-gradient(circle at 30% 30%, var(--accent-green), #007744);
        box-shadow: 0 0 10px var(--accent-green-soft);
    }

    .mk-pick {
        width: 20px;
        height: 20px;
        border-radius: 50%;
        background: radial-gradient(circle at 30% 30%, var(--accent-yellow), var(--accent-pink));
        border: 2px solid var(--text-white);
        box-shadow: 0 0 16px var(--accent-pink-soft);
        display: block;
        animation: pulse 1.5s ease-in-out infinite;
    }

    @keyframes pulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.25); }
    }

    .mk-cluster {
        min-width: 30px;
        height: 30px;
        padding: 0 6px;
        border-radius: var(--radius-pill);
        background: linear-gradient(145deg, var(--accent-purple), var(--accent-cyan));
        border: 2px solid var(--text-white);
        color: var(--text-white);
        font-weight: 800;
        font-size: 0.8rem;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 0 14px var(--accent-purple-soft);
    }

    /* ═══ Leaflet Overrides ═══ */
    .leaflet-container {
        font-family: 'Vazirmatn', Tahoma, sans-serif;
        background: var(--bg-2);
    }

    .leaflet-popup-content-wrapper {
        background: var(--bg-3);
        color: var(--text-primary);
        border: 1.5px solid var(--border-medium);
        border-radius: var(--radius-md);
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    }

    .leaflet-popup-content {
        direction: rtl;
        text-align: start;
        font-family: 'Vazirmatn', Tahoma, sans-serif;
        margin: 14px 18px;
        line-height: 1.9;
    }

    .leaflet-popup-tip {
        background: var(--bg-3);
        border: 1.5px solid var(--border-medium);
    }

    .leaflet-popup-close-button {
        color: var(--text-muted) !important;
        inset-inline-start: 8px !important;
        inset-inline-end: auto !important;
    }

    .tiles-dark {
        filter: brightness(0.55) invert(1) contrast(2.6) hue-rotate(190deg) saturate(0.35);
    }

    /* ═══ Popup (pp) ═══ */
    .pp {
        border-inline-end: 5px solid var(--accent-cyan);
        border-radius: 4px;
        padding-inline-end: 10px;
    }

    .pp.pp-high { border-inline-end-color: var(--accent-pink); }
    .pp.pp-medium { border-inline-end-color: var(--accent-yellow); }
    .pp.pp-low { border-inline-end-color: var(--accent-cyan); }

    .pp-title {
        font-weight: 800;
        font-size: 0.95rem;
        margin-bottom: 4px;
        overflow-wrap: anywhere;
    }

    .pp-date {
        font-size: 0.78rem;
        color: var(--accent-cyan);
        margin-bottom: 10px;
    }

    /* ═══ Popup City ═══ */
    .pp-city {
        font-size: 0.75rem;
        color: var(--text-muted);
        margin: 4px 0 6px;
    }

    .pp-btn {
        padding: 6px 16px;
        border: none;
        border-radius: var(--radius-sm);
        background: linear-gradient(145deg, var(--accent-purple), #5a1fbd);
        color: var(--text-white);
        font-family: inherit;
        font-size: 0.78rem;
        font-weight: 700;
        cursor: pointer;
    }

    .pp-row {
        display: flex;
        gap: 8px;
        margin-top: 4px;
    }

    .pp-loc {
        display: flex;
        align-items: center;
        gap: 6px;
        margin: 6px 0 8px;
        font-size: 0.8rem;
        color: var(--text-primary);
        flex-wrap: wrap;
    }

    .pp-loc-unsaved .pp-coords {
        direction: ltr;
        unicode-bidi: plaintext;
        color: var(--text-muted);
    }

    .pp-save-btn {
        appearance: none;
        display: inline-flex;
        align-items: center;
        gap: 4px;
        padding: 4px 10px;
        border: 1px solid var(--accent-cyan-border);
        border-radius: var(--radius-pill);
        background: var(--accent-cyan-soft);
        color: var(--accent-cyan);
        font: inherit;
        font-size: 0.72rem;
        font-weight: 700;
        cursor: pointer;
        transition: background 0.16s ease, border-color 0.16s ease;
    }

    .pp-save-btn:hover {
        background: var(--accent-cyan-soft);
        border-color: var(--accent-cyan);
    }

    /* ═══ Fullscreen ═══ */
    .map-wrap.fullscreen {
        position: fixed;
        inset: 10px;
        z-index: 300;
    }

    .fs-exit {
        position: absolute;
        bottom: 14px;
        inset-inline-start: 50%;
        transform: translateX(-50%);
        z-index: 600;
        padding: 8px 20px;
        border-radius: var(--radius-pill);
        border: 1.5px solid var(--border-medium);
        background: var(--bg-3);
        color: var(--text-primary);
        font-family: inherit;
        font-size: 0.8rem;
        font-weight: 700;
        cursor: pointer;
        white-space: nowrap;
    }

    /* ═══ Route Summary ═══ */
    .route-summary {
        position: absolute;
        top: 12px;
        right: 12px;
        left: auto;
        width: min(420px, calc(100% - 24px));
        z-index: 1000;
        direction: rtl;
        font-family: 'Vazirmatn', sans-serif;
        pointer-events: auto;
    }

    .route-summary-title {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 9px 10px;
        margin-bottom: 6px;
        border: 1px solid var(--border-medium);
        border-radius: 12px 12px 8px 8px;
        background: var(--bg-3);
        color: var(--text-primary);
        font-size: 12px;
        font-weight: 700;
        backdrop-filter: blur(10px);
        box-shadow: var(--shadow-md);
    }

    .route-summary-title-text {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .route-summary-close {
        appearance: none;
        flex: 0 0 auto;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: var(--radius-xs);
        background: transparent;
        color: var(--text-muted);
        cursor: pointer;
        font: inherit;
        font-size: 20px;
        line-height: 1;
        padding: 0;
        transition: background .16s ease, color .16s ease;
    }

    .route-summary-close:hover {
        background: var(--bg-2);
        color: var(--text-primary);
    }

    .route-options {
        display: grid;
        gap: 5px;
    }

    .route-option {
        appearance: none;
        width: 100%;
        min-height: 45px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        padding: 7px 10px;
        border: 1px solid var(--border-medium);
        border-inline-end: 3px solid transparent;
        border-radius: var(--radius-sm);
        background: var(--bg-2);
        color: var(--text-primary);
        cursor: pointer;
        text-align: end;
        font: inherit;
        transition: background .16s ease, border-color .16s ease, transform .16s ease, box-shadow .16s ease;
        backdrop-filter: blur(9px);
    }

    .route-option:hover:not(:disabled) {
        transform: translateY(-1px);
        background: var(--bg-4);
    }

    .route-option.is-active {
        border-color: var(--route-color);
        border-inline-end-width: 4px;
        background: var(--bg-3);
        box-shadow: 0 0 0 1px var(--route-color), var(--shadow-md);
    }

    .route-option.is-active .route-option-name {
        color: var(--route-color);
        font-weight: 800;
    }

    .route-option.is-disabled {
        opacity: .48;
        cursor: not-allowed;
    }

    .route-option-main,
    .route-option-info {
        display: flex;
        align-items: center;
        gap: 7px;
        min-width: 0;
    }

    .route-option-icon {
        width: 22px;
        text-align: center;
        font-size: 17px;
    }

    .route-option-name {
        white-space: nowrap;
    }

    .route-option-info {
        font-size: 11px;
        color: var(--text-muted);
        white-space: nowrap;
    }

    .route-option.is-active .route-option-info {
        color: var(--text-primary);
        font-weight: 700;
    }

    /* ═══ B7: مخفی کردن route-summary وقتی نقشه مخفی است ═══ */
    body.map-hidden .route-summary {
        display: none !important;
    }

    /* ═══ Saved Locations ═══ */
    .loc-chip-actions {
        display: flex;
        align-items: center;
        gap: 4px;
        flex: 0 0 auto;
    }

    .loc-chip-save,
    .location-save-btn {
        border: 1px solid var(--accent-cyan-border);
        background: var(--accent-cyan-soft);
        color: var(--accent-cyan);
        border-radius: 7px;
        padding: 4px 8px;
        cursor: pointer;
        font: inherit;
        font-size: 11px;
        white-space: nowrap;
    }

    .loc-chip-save:hover,
    .location-save-btn:hover {
        background: var(--accent-cyan-soft);
        border-color: var(--accent-cyan);
    }

    .location-display {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
    }

    .location-display-name {
        font-weight: 700;
    }

    .location-display-coords {
        direction: ltr;
        unicode-bidi: plaintext;
    }

    .loc-line {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 8px;
        min-width: 0;
    }

    .loc-line .location-save-btn {
        flex: 0 0 auto;
    }

    .loc-btns {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px;
        min-width: 0;
    }

    .loc-btns .due-btn {
        flex: 1 1 auto;
        min-width: min(150px, 100%);
    }

    .loc-line .location-display {
        overflow: hidden;
    }

    .saved-locations {
        margin: 10px 0 0;
        direction: rtl;
    }

    .saved-locations-list {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 2px 1px 7px;
        scrollbar-width: thin;
        white-space: nowrap;
    }

    .saved-location-chip {
        appearance: none;
        border: 1px solid var(--border-subtle);
        background: var(--bg-2);
        color: var(--text-primary);
        border-radius: var(--radius-pill);
        padding: 7px 11px;
        cursor: pointer;
        font: inherit;
        font-size: 11px;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .saved-location-chip:hover {
        background: var(--bg-4);
        border-color: var(--accent-cyan-border);
    }

    .saved-locations-empty {
        font-size: 11px;
        color: var(--text-faint);
    }

    .saved-locations-manage {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        padding: 8px 12px;
        margin: 0 0 8px;
        border: 1px solid var(--accent-cyan-border);
        border-radius: var(--radius-md);
        background: var(--accent-cyan-soft);
        color: var(--accent-cyan);
        font-family: inherit;
        font-size: 0.82rem;
        font-weight: 700;
        text-align: start;
        cursor: pointer;
        transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
    }

    .saved-locations-manage:hover {
        background: var(--accent-cyan-soft);
        border-color: var(--accent-cyan);
        box-shadow: 0 0 14px var(--accent-cyan-soft);
    }

    .saved-locations-manage:focus-visible {
        outline: 2px solid var(--accent-cyan);
        outline-offset: 2px;
    }

    .saved-locations-count {
        color: var(--text-muted);
        font-weight: 400;
        font-size: 0.78rem;
    }

    .saved-locations-chevron {
        margin-inline-start: auto;
        color: var(--text-muted);
        font-size: 1.1rem;
        line-height: 1;
    }

    .saved-locations-body {
        display: flex;
        flex-direction: column;
        gap: 8px;
        max-height: min(60vh, 480px);
        overflow-y: auto;
        padding: 4px 2px;
    }

    .saved-locations-row {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 10px 14px;
        border-radius: var(--radius-md);
        border: 1.5px solid var(--border-medium);
        background: var(--bg-2);
        color: var(--text-primary);
        font-size: 0.85rem;
    }

    .saved-locations-row .slr-info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .saved-locations-row .slr-name {
        font-weight: 700;
        overflow-wrap: anywhere;
    }

    .saved-locations-row .slr-coords {
        font-size: 0.72rem;
        color: var(--text-muted);
        direction: ltr;
        unicode-bidi: plaintext;
        text-align: end;
    }

    .saved-locations-row .slr-actions {
        display: flex;
        gap: 6px;
        flex-shrink: 0;
    }

    .saved-locations-row .slr-actions button {
        width: 34px;
        height: 34px;
        border-radius: var(--radius-sm);
        border: 1.5px solid var(--border-medium);
        background: var(--bg-2);
        color: var(--accent-cyan);
        font-family: inherit;
        font-size: 0.95rem;
        cursor: pointer;
        transition: border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
    }

    .saved-locations-row .slr-actions button:hover {
        border-color: var(--accent-cyan);
        box-shadow: 0 0 12px var(--accent-cyan-soft);
    }

    .saved-locations-row .slr-actions button:active {
        transform: translateY(1px);
    }

    .saved-locations-row .slr-actions button.danger {
        color: var(--accent-pink);
    }

    .saved-locations-row .slr-actions button.danger:hover {
        border-color: var(--accent-pink);
        box-shadow: 0 0 12px var(--accent-pink-soft);
    }

    /* ═══ Mobile Pick Banner ═══ */
    .mobile-pick-banner {
        display: none;
        align-items: center;
        gap: 10px;
        margin-top: 10px;
        padding: 10px 14px;
        border: 1px solid var(--accent-cyan-border);
        border-radius: var(--radius-md);
        background: linear-gradient(145deg, var(--accent-cyan-soft), var(--accent-purple-soft));
        color: var(--accent-cyan);
        font-size: 0.82rem;
        font-weight: 600;
        line-height: 1.6;
        animation: fadeIn 0.25s ease;
    }

    .mobile-pick-banner-text {
        flex: 1;
        min-width: 0;
    }

    .mobile-pick-banner-cancel {
        appearance: none;
        flex: 0 0 auto;
        padding: 6px 12px;
        border: 1px solid var(--accent-pink-border);
        border-radius: var(--radius-sm);
        background: var(--accent-pink-soft);
        color: var(--accent-pink);
        font-family: inherit;
        font-size: 0.78rem;
        font-weight: 700;
        cursor: pointer;
        transition: background 0.16s ease, border-color 0.16s ease;
    }

    .mobile-pick-banner-cancel:hover {
        background: var(--accent-pink-soft);
        border-color: var(--accent-pink);
    }

    @media (max-width: 900px) {
        body.detail-picking-location .mobile-pick-banner {
            display: flex;
        }
    }

    /* ═══ B3: Map Divider Toggle — با text-indent برای دسترس‌پذیری ═══ */
    .map-divider-toggle {
        /* B3: به جای color: transparent + font-size: 0، از text-indent استفاده می‌کنیم
           تا متن اصلی (اگر وجود داشته باشد) برای screen reader باقی بماند */
        text-indent: -9999px;
        overflow: hidden;
        background: linear-gradient(145deg, #6b55df 0%, #5138c9 48%, #35248d 100%);
        border: 1px solid rgba(255, 255, 255, .34);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, .42),
            inset 0 -3px 0 rgba(19, 12, 63, .42),
            0 4px 0 rgba(23, 15, 70, .72),
            0 7px 16px rgba(0, 0, 0, .38),
            0 0 12px rgba(81, 56, 201, .22);
        transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
    }

    .map-divider-toggle::before {
        content: '📍';
        display: block;
        text-indent: 0;
        color: var(--text-white);
        font-size: 18px;
        font-family: "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
        line-height: 30px;
        transform: none;
        filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .45));
    }

    body.map-hidden .map-divider-toggle::before {
        content: '📍';
    }

    .map-divider-toggle:hover {
        border-color: rgba(255, 255, 255, .58);
        filter: brightness(1.08);
        box-shadow:
            inset 0 1px 0 rgba(255, 255, 255, .5),
            inset 0 -3px 0 rgba(19, 12, 63, .42),
            0 4px 0 rgba(23, 15, 70, .72),
            0 8px 20px rgba(0, 0, 0, .42),
            0 0 18px var(--accent-cyan-soft);
    }

    .map-divider-toggle:active {
        transform: translate(-50%, -50%) translateY(3px);
        box-shadow:
            inset 0 2px 3px rgba(18, 10, 55, .45),
            0 1px 0 rgba(23, 15, 70, .72),
            0 3px 9px rgba(0, 0, 0, .32);
    }

    .map-divider-toggle:focus-visible {
        outline: 2px solid var(--accent-cyan);
        outline-offset: 3px;
    }

    /* ═══ Map Hidden State ═══ */
    body.map-hidden .panel-map {
        pointer-events: none;
    }

    body.map-hidden .layout {
        display: block;
    }

    body.map-hidden .container {
        max-width: 640px;
        grid-template-columns: minmax(0, 1fr);
    }

    body.map-hidden .mobile-tabs {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   LAYER: overrides
   ═══════════════════════════════════════════════════════════════════════════ */
@layer overrides {
    /* ═══ Scrollbar — Map Panel ═══ */
    .panel-map {
        scrollbar-width: thin;
        scrollbar-color: rgba(165, 165, 208, .34) transparent;
    }

    .panel-map::-webkit-scrollbar {
        width: 7px;
    }

    .panel-map::-webkit-scrollbar-track {
        background: transparent;
    }

    .panel-map::-webkit-scrollbar-thumb {
        background: rgba(165, 165, 208, .30);
        border: 1px solid rgba(255, 255, 255, .05);
        border-radius: var(--radius-pill);
    }

    .panel-map::-webkit-scrollbar-thumb:hover {
        background: var(--accent-cyan-border);
    }

    /* ═══ Map App Shell — Desktop ═══ */
    @media (min-width: 901px) {
        .app-shell {
            max-width: 1100px;
            margin: 0 auto;
        }

        .right-flow-container {
            position: relative;
            min-width: 0;
            height: 100vh;
            min-height: 100vh;
            max-height: 100vh;
            overflow: visible;
        }

        .right-flow-container::before {
            content: '';
            position: absolute;
            top: 0;
            bottom: 0;
            inset-inline-end: 0;
            width: 1px;
            background: var(--border-subtle);
            pointer-events: none;
            z-index: 5;
        }

        .right-flow-container > .right-flow {
            position: relative;
            width: 100%;
            height: 100%;
            min-height: 0;
            max-height: 100%;
            overflow-y: auto;
            overflow-x: hidden;
            max-width: none;
            scrollbar-width: thin;
            scrollbar-color: rgba(165, 165, 208, .34) transparent;
        }

        .right-flow-container > .map-divider-toggle {
            position: absolute;
            top: 50%;
            bottom: auto;
            inset-inline-end: 0;
            transform: translate(50%, -50%);
            z-index: 30;
            width: 34px;
            height: 34px;
            min-width: 34px;
            border-radius: 50%;
            display: grid;
            place-items: center;
            padding: 0;
            margin: 0;
        }

        .app-shell[dir="rtl"] > .right-flow-container > .map-divider-toggle {
            transform: translate(-50%, -50%);
        }

        .app-shell[dir="ltr"] > .right-flow-container > .map-divider-toggle {
            transform: translate(50%, -50%);
        }

        body.map-hidden .right-flow-container > .map-divider-toggle {
            transform: translate(0%, -50%);
        }

        .right-flow-container > .map-divider-toggle::before {
            content: '📍';
        }

        .app-shell > .panel-map,
        .app-shell > .right-flow-container {
            direction: inherit;
        }

        .app-shell > .panel-map {
            position: relative;
            top: auto;
            inset-inline-start: auto;
            bottom: auto;
            width: auto;
            height: 100%;
            min-width: 0;
        }
    }

    /* ═══ Responsive — Small Screens ═══ */
    @media (max-width: 900px) {
        .detail-page .detail-accordion > summary {
            min-height: 44px;
            padding-inline-end: 38px;
        }
        .map-divider-toggle {
            display: none;
        }
    }

    @media (max-width: 600px) {
        .map-head-actions {
            width: 100%;
        }

        .map-head-actions .btn-small {
            flex: 1 1 auto;
            min-height: 42px;
        }

        #map {
            height: min(62vh, 420px);
            min-height: 300px;
        }

        /* B7: route-summary در موبایل کوچک — پایین، پرعرض، اسکرول‌پذیر */
        .route-summary {
            top: auto;
            bottom: 8px;
            right: 8px;
            left: auto;
            width: calc(100% - 16px);
            max-height: calc(100% - 16px);
            overflow-y: auto;
        }

        .route-summary-title {
            font-size: 11px;
            padding: 8px 10px;
        }

        .route-option {
            min-height: 42px;
            padding: 6px 9px;
        }
    }

    @media (max-width: 520px) {
        .list-zone .search-row input {
            font-size: .84rem;
            padding-inline-start: 36px;
        }

        .task-item .mini-link {
            min-height: 27px;
            padding-inline: 8px;
            font-size: .76rem;
        }

        .detail-page .detail-accordion-body {
            padding-inline: 10px;
        }
    }

    /* ═══ Light theme overrides ═══ */
    html.theme-light .map-wrap {
        box-shadow:
            0 4px 6px -1px rgba(15, 23, 42, 0.1),
            0 2px 4px -1px rgba(15, 23, 42, 0.04);
    }

    html.theme-light .map-hint {
        background: rgba(255, 255, 255, 0.95);
        color: var(--text-primary);
        border-color: var(--accent-cyan-border);
    }

    html.theme-light .fs-exit {
        background: rgba(255, 255, 255, 0.95);
        color: var(--text-primary);
    }

    html.theme-light .leaflet-popup-content-wrapper {
        background: #ffffff;
        box-shadow:
            0 10px 15px -3px rgba(15, 23, 42, 0.1),
            0 4px 6px -2px rgba(15, 23, 42, 0.05);
    }

    html.theme-light .leaflet-popup-tip {
        background: #ffffff;
    }

    html.theme-light .route-summary-title {
        background: #ffffff;
    }

    html.theme-light .route-option {
        background: #ffffff;
    }

    html.theme-light .route-option:hover:not(:disabled) {
        background: #f8fafc;
    }

    html.theme-light .route-option.is-active {
        background: #f8fafc;
    }

    html.theme-light .pp-loc {
        color: var(--text-primary);
    }

    html.theme-light .pp-save-btn {
        color: var(--accent-cyan);
        background: var(--accent-cyan-soft);
    }

    /* ═══ Map Search — Light theme ═══ */
    html.theme-light .map-search-row {
        background: #ffffff;
        border-color: #d8dde5;
    }

    html.theme-light .map-search-results {
        background: #ffffff;
        border-color: #e2e8f0;
        box-shadow:
            0 10px 15px -3px rgba(15, 23, 42, 0.1),
            0 4px 6px -2px rgba(15, 23, 42, 0.05);
    }

    html.theme-light .map-search-item:hover,
    html.theme-light .map-search-item:focus-visible {
        background: #f8fafc;
    }
}