/* =========================================================
   MATRIX TRACKER
   LIVE TRACKING — UNIFIED OPERATIONS UI
   Phase 7.5U
   Uses the global design tokens from app.css
   ========================================================= */

.live-tracking-content[hidden],
#liveTrackingPage[hidden] {
    display: none !important;
}

#liveTrackingPage,
#liveTrackingPage * {
    box-sizing: border-box;
}

#liveTrackingPage {
    direction: rtl;
    width: 100%;
    min-width: 0;
    margin: 0;
    padding: clamp(1rem, 2vw, 1.6rem);
    color: var(--text);
}

/* =========================================================
   PAGE INTRODUCTION
   ========================================================= */

.live-tracking-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
    margin-bottom: 1rem;
}

.live-tracking-hero > div {
    min-width: 0;
}

.live-tracking-hero h2 {
    margin: 0 0 .35rem;
    color: var(--text);
    font-size: clamp(1.35rem, 2vw, 1.75rem);
    line-height: 1.25;
    font-weight: 800;
}

.live-tracking-hero p {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
    font-size: .82rem;
    line-height: 1.8;
}

.live-refresh-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 42px;
    padding: 0 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--primary);
    font: inherit;
    font-size: .76rem;
    font-weight: 800;
    cursor: pointer;
    transition:
        background var(--transition),
        border-color var(--transition),
        color var(--transition),
        transform var(--transition),
        box-shadow var(--transition);
}

.live-refresh-button:hover {
    border-color: rgba(23, 107, 135, .22);
    background: var(--primary-soft);
    color: var(--primary-strong);
    transform: translateY(-1px);
}

.live-refresh-button:disabled {
    cursor: wait;
    opacity: .6;
    transform: none;
}

/* =========================================================
   KPI CARDS
   ========================================================= */

.live-kpis {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: .85rem;
    margin-bottom: 1rem;
}

.live-kpi {
    position: relative;
    min-width: 0;
    min-height: 104px;
    padding: 1rem 1.05rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    transition:
        transform var(--transition),
        border-color var(--transition),
        box-shadow var(--transition);
}

.live-kpi::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 3px;
    height: 100%;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    background: var(--primary);
    opacity: .7;
}

.live-kpi:hover {
    border-color: rgba(23, 107, 135, .16);
    box-shadow: 0 12px 34px rgba(15, 23, 42, .08);
    transform: translateY(-1px);
}

.live-kpi span {
    display: block;
    overflow: hidden;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 700;
    line-height: 1.45;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-kpi strong {
    display: block;
    margin-top: .7rem;
    color: var(--text);
    font-size: 1.65rem;
    line-height: 1;
    font-weight: 800;
}

/* =========================================================
   OPERATIONS WORKSPACE
   ========================================================= */

.live-map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(270px, 320px);
    grid-template-areas: "map workforce";
    align-items: stretch;
    gap: 1rem;
    min-width: 0;
}

/* =========================================================
   SHARED OPERATIONAL PANELS
   ========================================================= */

.live-map-card,
.live-workforce-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.live-map-card {
    grid-area: map;
    display: flex;
    flex-direction: column;
}

.live-workforce-card {
    grid-area: workforce;
    display: flex;
    flex-direction: column;
}

/* =========================================================
   MAP HEADER
   ========================================================= */

.live-map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    min-height: 68px;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 1rem;
}

.live-map-toolbar > strong {
    color: var(--text);
    font-size: .9rem;
    font-weight: 800;
    white-space: nowrap;
}

.live-map-toolbar > div {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    min-width: 0;
    gap: .45rem;
}

.live-map-meta {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: .3rem .55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--muted);
    font-size: .65rem;
    font-weight: 700;
    line-height: 1.3;
    white-space: nowrap;
}

/* =========================================================
   LEAFLET MAP
   ========================================================= */

#liveTrackingMap {
    position: relative;
    flex: 1 1 auto;
    width: 100%;
    height: clamp(480px, calc(100vh - 360px), 650px);
    min-height: 480px;
    overflow: hidden;
    background: #edf2f7;
}

#liveTrackingMap.leaflet-container {
    width: 100%;
    font-family: inherit;
}

/* =========================================================
   WORKFORCE PANEL
   ========================================================= */

.live-workforce-head {
    flex: 0 0 auto;
    min-height: 68px;
    padding: .85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.live-workforce-head h3 {
    margin: 0 0 .25rem;
    color: var(--text);
    font-size: .9rem;
    font-weight: 800;
}

.live-workforce-head p {
    margin: 0;
    color: var(--muted);
    font-size: .67rem;
    line-height: 1.55;
}

.live-workforce-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: clamp(480px, calc(100vh - 360px), 650px);
    padding: .75rem;
    overflow-x: hidden;
    overflow-y: auto;
    background: var(--surface-soft);
}

.live-workforce-list::-webkit-scrollbar {
    width: 6px;
}

.live-workforce-list::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: #cbd5e1;
}

.live-worker {
    width: 100%;
    min-width: 0;
    margin-bottom: .65rem;
    padding: .85rem;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    box-shadow: 0 4px 14px rgba(15, 23, 42, .035);
    cursor: pointer;
    transition:
        transform var(--transition),
        border-color var(--transition),
        box-shadow var(--transition);
}

.live-worker:last-child {
    margin-bottom: 0;
}

.live-worker:hover {
    border-color: rgba(23, 107, 135, .25);
    box-shadow: 0 8px 22px rgba(15, 23, 42, .07);
    transform: translateY(-1px);
}

.live-worker-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    min-width: 0;
    gap: .65rem;
}

.live-worker-name {
    min-width: 0;
    overflow: hidden;
    color: var(--text);
    font-size: .82rem;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.live-worker-meta {
    min-width: 0;
    margin-top: .55rem;
    color: var(--muted);
    font-size: .68rem;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.live-status {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 25px;
    padding: .25rem .5rem;
    border-radius: 999px;
    background: #f4faf8;
    color: #51816f;
    font-size: .61rem;
    font-weight: 800;
    white-space: nowrap;
}

.live-empty {
    padding: 2rem 1rem;
    color: var(--muted);
    font-size: .75rem;
    line-height: 1.8;
    text-align: center;
}

/* =========================================================
   EMPLOYEE MAP MARKER
   ========================================================= */

.live-employee-marker {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 3px solid white;
    border-radius: 50%;
    background: var(--primary);
    box-shadow:
        0 6px 18px rgba(15, 23, 42, .22),
        0 0 0 5px rgba(23, 107, 135, .12);
    color: white;
}

.live-popup {
    min-width: 205px;
    direction: rtl;
    color: var(--text);
    text-align: right;
}

.live-popup h4 {
    margin: 0 0 .45rem;
    color: var(--text);
    font-size: .88rem;
}

.live-popup p {
    margin: .2rem 0;
    color: var(--muted);
    font-size: .72rem;
    line-height: 1.55;
}

/* =========================================================
   TABLET
   ========================================================= */

@media (max-width: 1180px) {

    .live-kpis {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .live-map-layout {
        grid-template-columns: minmax(0, 1fr) minmax(245px, 285px);
    }
}

/* =========================================================
   SMALL TABLET
   ========================================================= */

@media (max-width: 900px) {

    #liveTrackingPage {
        padding: 1rem;
    }

    .live-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .live-map-layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "map"
            "workforce";
    }

    #liveTrackingMap {
        height: 520px;
        min-height: 460px;
    }

    .live-workforce-list {
        max-height: 360px;
    }
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 620px) {

    #liveTrackingPage {
        padding: .8rem;
    }

    .live-tracking-hero {
        flex-direction: column;
        align-items: stretch;
        gap: .75rem;
    }

    .live-refresh-button {
        width: 100%;
    }

    .live-kpis {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .65rem;
    }

    .live-kpi {
        min-height: 90px;
        padding: .85rem;
    }

    .live-map-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    #liveTrackingMap {
        height: 58vh;
        min-height: 400px;
    }
}

@media (max-width: 420px) {

    .live-kpis {
        grid-template-columns: 1fr;
    }
}