/**
 * MoversBoard — Map View
 *
 * Split layout: left sidebar (job list) + right Leaflet map canvas.
 * All classes use the .mv- prefix to avoid collisions with Leaflet defaults.
 */

/* ── Outer container (jobsContainer gets class="mv-root") ────────────────── */
.mv-root {
    width: 100%;
    /* JS (applyMapHeight) measures the real offset and sets style.height precisely.
       This calc is a first-paint fallback only. */
    height: calc(100dvh - var(--header-h) - 230px);
    min-height: 520px;
}

/* ── Grid wrapper built inside mv-root ───────────────────────────────────── */
.mv-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 12px;
    height: 100%;
    align-items: stretch;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.mv-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
    transition: max-height .22s ease;
}

.mv-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}

.mv-sidebar-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.mv-count {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.mv-jobs {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px;
    min-height: 0;
}

.mv-jobs::-webkit-scrollbar { width: 5px; }
.mv-jobs::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Sidebar job card ────────────────────────────────────────────────────── */
.mv-job-item {
    padding: 10px 11px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 3px;
    transition: background var(--transition), border-color var(--transition);
}

.mv-job-item:hover,
.mv-job-item.active,
.mv-job-item.mv-job-selected { background: var(--accent-light); border-color: var(--accent); }

.mv-job-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 5px;
    gap: 6px;
}

.mv-job-badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* Reuse existing badge palette */
.mv-job-badge.badge-load     { background: var(--blue-light);   color: var(--blue);   }
.mv-job-badge.badge-pickup   { background: var(--orange-light); color: var(--orange); }
.mv-job-badge.badge-delivery { background: var(--green-light);  color: var(--green);  }

.mv-job-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

.mv-job-route {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    flex-wrap: nowrap;
    overflow: hidden;
}

.mv-city {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mv-state {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
}

.mv-arrow {
    color: var(--text-muted);
    flex-shrink: 0;
}

.mv-job-meta {
    display: flex;
    gap: 10px;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 5px;
}

/* ── Sidebar pager ───────────────────────────────────────────────────────── */
.mv-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 8px 10px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--white);
}

.mv-pager-pages {
    display: flex;
    align-items: center;
    gap: 4px;
}

.mv-pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.mv-pager-btn:hover:not(:disabled) { background: var(--accent-light); border-color: var(--accent); }
.mv-pager-btn:disabled { opacity: .4; cursor: not-allowed; }
.mv-pager-btn.active   { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

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

/* ── Map canvas ──────────────────────────────────────────────────────────── */
.mv-canvas {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
}

.mv-map-el {
    width: 100%;
    height: 100%;
    min-height: 400px;
    background: #e8eaed;
}

/* ── No-Leaflet fallback ─────────────────────────────────────────────────── */
.mv-no-map {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 400px;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    padding: 24px;
}

.mv-no-map svg { opacity: .35; }

/* ── Route detail card (overlay) ─────────────────────────────────────────── */
.mv-route-card {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    max-width: 380px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 14px 16px;
    z-index: 450; /* above Leaflet controls */
    transition: opacity var(--transition);
}

.mv-route-card.hidden { display: none; }

.mv-rc-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.mv-rc-id {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}

.mv-rc-close {
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mv-rc-close:hover { background: var(--bg); color: var(--text-primary); }

.mv-rc-route {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 10px;
}

.mv-rc-pt { flex: 1; min-width: 0; }

.mv-rc-city {
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mv-rc-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.mv-rc-arrow { color: var(--accent-text); flex-shrink: 0; }

.mv-rc-stats {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}

.mv-stat {
    padding: 7px 9px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.mv-stat-label {
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.mv-stat-val {
    font-size: 12px;
    font-weight: 700;
    margin-top: 2px;
    color: var(--text-primary);
}

.mv-rc-actions { display: flex; gap: 6px; }
.mv-rc-actions .btn { flex: 1; }

/* ── Legend ──────────────────────────────────────────────────────────────── */
.mv-legend {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 11px;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    z-index: 450;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.mv-leg {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.mv-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    font-style: normal; /* <i> tag used as a dot */
}

/* ── Leaflet overrides (keep inside map canvas) ───────────────────────────── */
.mv-canvas .leaflet-control-attribution {
    font-size: 10px;
    background: rgba(255,255,255,.75);
}

.mv-canvas .leaflet-bottom.leaflet-right .leaflet-control-zoom {
    margin: 0 12px 12px 0;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .mv-layout {
        grid-template-columns: 260px 1fr;
    }

    /* Tablet: give the map canvas at least 40 % of the viewport height */
    .mv-canvas {
        min-height: 40vh;
    }
}

@media (max-width: 700px) {
    /* JS (applyMapHeight) sets the exact height — let layout fill it */
    .mv-root {
        min-height: 400px;
    }

    .mv-layout {
        grid-template-columns: 1fr;
        /* sidebar takes its natural height; map canvas fills the rest */
        grid-template-rows: auto 1fr;
        height: 100%;   /* fill the JS-set parent height */
        min-height: 0;
    }

    /* Sidebar kept compact so the map canvas gets the bulk of the height */
    .mv-sidebar {
        max-height: 160px;
    }

    /* Horizontal scroll on mobile */
    .mv-jobs {
        display: flex;
        flex-direction: row;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px;
        gap: 8px;
    }

    .mv-job-item {
        min-width: 220px;
        flex-shrink: 0;
        margin-bottom: 0;
    }

    /* Map canvas: at least 40 % of the viewport height on mobile */
    .mv-canvas {
        min-height: 40vh;
        height: 100%;
    }

    /* Route card: same top-left position as desktop — no mobile override */
}

/* ── Pager moved into sidebar-head on mobile/tablet (≤768 px) ─────────────── */
@media (max-width: 768px) {
    /* Keep everything on a single line — no wrapping */
    .mv-sidebar-head {
        flex-wrap: nowrap;
        padding: 8px 12px;
        gap: 4px;
    }

    /* Auto-margin pushes count + pager to the right edge */
    .mv-sidebar-head .mv-count {
        margin-left: auto;
        flex-shrink: 0;
    }

    /* Pager (appended inside .mv-sidebar-head by JS) — strip decoration */
    .mv-sidebar-head .mv-pager {
        border-top: none;
        padding: 0;
        background: transparent;
        gap: 2px;
        flex-shrink: 0;
    }

    .mv-sidebar-head .mv-pager-pages { gap: 2px; }

    .mv-sidebar-head .mv-pager-btn {
        min-width: 22px;
        height: 22px;
        padding: 0 4px;
        font-size: 11px;
    }

    .mv-sidebar-head .mv-pager-btn svg {
        width: 10px;
        height: 10px;
    }
}

@media (max-width: 480px) {
    .mv-rc-stats { grid-template-columns: 1fr 1fr; }
    .mv-legend { gap: 8px; font-size: 10px; }
}
