/* =========================================================
   Nour Public Site — Map
   ---------------------------------------------------------
   خريطةٌ بملء المساحة تحت الشريط، وفوقها ألواحٌ بيضاءُ عائمة:
   لوحةُ التصفية أعلى اليمين، وقائمةُ الوحدات يساراً، وشريطُ
   الأرقام أسفل الوسط. الحالات (active / visible) يبدّلها map.js.
   ========================================================= */

.map-page {
    position: relative;
    height: calc(100vh - var(--nav-h));
    min-height: 520px;
    overflow: hidden;
    background: #E8ECF4;
}

#map { position: absolute; inset: 0; z-index: 1; }

/* Shared floating panel surface */
.map-filter-card,
.map-type-card,
.map-sidebar,
.map-stats-bar,
.map-empty {
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border: 1px solid rgba(228, 231, 236, 0.9);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 18px 40px -18px rgba(16, 24, 40, 0.35);
}

/* ---- Toolbar (top start) ---- */
.map-toolbar {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.6rem;
}

.map-filter-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem;
    border-radius: var(--radius-lg);
}

.map-filter-card select {
    height: 44px;
    min-width: 210px;
    padding: 0 0.85rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.map-filter-card select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(36, 48, 143, 0.12);
}

.map-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    height: 44px;
    padding: 0 1.15rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 700;
    color: #fff;
    background: var(--primary);
    border: 0;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.map-filter-btn:hover {
    background: var(--primary-hover);
    box-shadow: 0 10px 20px -10px rgba(36, 48, 143, 0.6);
}

/* Territories toggle drawn as a switch */
.map-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    height: 44px;
    padding: 0 0.9rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    user-select: none;
}

.map-toggle-label input {
    appearance: none;
    -webkit-appearance: none;
    position: relative;
    width: 34px;
    height: 20px;
    margin: 0;
    border-radius: 999px;
    background: var(--border-strong);
    cursor: pointer;
    transition: background-color 0.2s var(--ease);
}

.map-toggle-label input::after {
    content: "";
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.25);
    transition: transform 0.2s var(--ease);
}

.map-toggle-label input:checked { background: var(--primary); }
.map-toggle-label input:checked::after { transform: translateX(-14px); }
.map-toggle-label input:focus-visible { outline: 3px solid rgba(36, 48, 143, 0.35); outline-offset: 2px; }

/* Map style segmented control */
.map-type-card {
    display: inline-flex;
    gap: 2px;
    padding: 4px;
    border-radius: var(--radius);
}

.map-type-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.2s var(--ease), background-color 0.2s var(--ease);
}

.map-type-btn:hover { color: var(--ink); background: var(--bg-subtle); }
.map-type-btn.active { color: #fff; background: var(--primary); box-shadow: var(--shadow-sm); }

/* ---- Sidebar (units list) ---- */
.map-sidebar {
    position: absolute;
    top: 1rem;
    left: 1rem;
    bottom: 1rem;
    z-index: 1000;
    width: 360px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--radius-xl);
}

.map-sidebar.visible { display: flex; }

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #fff;
}

.sidebar-head h3 {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ink);
}

.sidebar-head h3 .bi {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.95rem;
}

.sidebar-badge {
    padding: 0.3rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 999px;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.units-list { list-style: none; margin: 0; padding: 0; }

.governorate-section { margin-bottom: 1rem; }

.governorate-header {
    position: sticky;
    top: -0.75rem;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 -0.75rem 0.5rem;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-label);
    background: rgba(248, 249, 252, 0.96);
    border-top: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft);
}

.governorate-header span:first-child { color: var(--text-secondary); }

.governorate-badge {
    min-width: 26px;
    padding: 0.1rem 0.5rem;
    font-size: 0.78rem;
    text-align: center;
    color: #fff;
    background: var(--primary);
    border-radius: 999px;
}

.governorate-operators { list-style: none; margin: 0; padding: 0; }

.unit-item {
    position: relative;
    margin-bottom: 0.45rem;
    padding: 0.85rem 1rem 0.85rem 0.9rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background-color 0.2s var(--ease);
}

.unit-item:hover { border-color: var(--primary-100); box-shadow: var(--shadow-sm); }

.unit-item.active {
    background: var(--primary-soft);
    border-color: var(--primary-200);
    box-shadow: inset -3px 0 0 var(--primary);
}

.unit-name {
    margin-bottom: 0.35rem;
    font-size: 0.97rem;
    font-weight: 800;
    color: var(--ink);
}

.unit-details {
    font-size: 0.84rem;
    line-height: 1.85;
    color: var(--text-muted);
}

.unit-details i { margin-inline-end: 0.3rem; color: var(--text-label); }

/* ---- Stats bar (bottom centre) ---- */
.map-stats-bar {
    position: absolute;
    bottom: 1.25rem;
    left: 50%;
    z-index: 1000;
    transform: translateX(-50%);
    display: none;
    align-items: stretch;
    max-width: calc(100% - 2rem);
    padding: 0.4rem;
    overflow-x: auto;
    border-radius: var(--radius-lg);
}

.map-stats-bar.visible { display: flex; }

.map-stat {
    flex-shrink: 0;
    padding: 0.5rem 1.1rem;
    text-align: center;
    border-inline-start: 1px solid var(--border-soft);
}

.map-stat:first-child {
    border-inline-start: 0;
    background: var(--primary);
    border-radius: var(--radius);
}

.map-stat:first-child .map-stat-val,
.map-stat:first-child .map-stat-label { color: #fff; }

.map-stat-val {
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.2;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.map-stat-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-label);
    white-space: nowrap;
}

/* ---- Loading / empty ---- */
.map-loading {
    position: absolute;
    inset: 0;
    z-index: 1100;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    background: rgba(248, 249, 252, 0.72);
    backdrop-filter: blur(3px);
}

.map-loading.active { display: flex; }

.map-spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--primary-100);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: mapSpin 0.8s linear infinite;
}

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

.map-loading-text { font-size: 0.95rem; font-weight: 700; color: var(--text-secondary); }

.map-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    z-index: 1050;
    transform: translate(-50%, -50%);
    display: none;
    min-width: 260px;
    padding: 1.75rem 2rem;
    text-align: center;
    border-radius: var(--radius-xl);
}

.map-empty.active { display: block; }

.map-empty i {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    margin: 0 auto 0.85rem;
    font-size: 1.4rem;
    color: var(--text-label);
    background: var(--bg-subtle);
    border-radius: 50%;
}

.map-empty h3 { font-size: 1.05rem; font-weight: 800; color: var(--ink); margin-bottom: 0.3rem; }
.map-empty p { font-size: 0.9rem; color: var(--text-label); margin: 0; }

/* ---- Leaflet popups ---- */
.leaflet-container { font-family: 'Tajawal', sans-serif; }

.leaflet-popup-content-wrapper {
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 48px -16px rgba(16, 24, 40, 0.35);
}

.leaflet-popup-content { margin: 0; width: 290px !important; }
.leaflet-popup-tip { box-shadow: none; }

.leaflet-container a.leaflet-popup-close-button {
    top: 10px;
    left: 10px;
    right: auto;
    width: 26px;
    height: 26px;
    font-size: 18px;
    line-height: 24px;
    color: var(--text-label);
    background: #fff;
    border-radius: 50%;
}

.nour-popup { direction: rtl; text-align: right; }

.nour-popup-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.1rem;
    background: linear-gradient(180deg, var(--primary-soft), #fff);
    border-bottom: 1px solid var(--border-soft);
}

.nour-popup-icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    border-radius: 11px;
    background: var(--primary);
}

.nour-popup-icon i { color: #fff; font-size: 1.1rem; }
.nour-popup-icon-territory { background: var(--accent-soft); }
.nour-popup-icon-territory i { color: var(--accent-strong); }

.nour-popup-title { font-size: 1rem; font-weight: 800; line-height: 1.4; color: var(--ink); }
.nour-popup-code { margin-top: 0.1rem; font-size: 0.78rem; font-weight: 600; color: var(--text-label); direction: ltr; text-align: right; }

.nour-popup-body { padding: 0.35rem 1.1rem 0.6rem; }

.nour-popup-row {
    display: grid;
    grid-template-columns: 18px 72px 1fr;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0;
    font-size: 0.86rem;
    border-bottom: 1px solid var(--border-soft);
}

.nour-popup-row:last-child { border-bottom: 0; }
.nour-popup-row > i { color: var(--text-label); text-align: center; }
.nour-popup-label { color: var(--text-label); font-weight: 600; }
.nour-popup-val { color: var(--ink); font-weight: 700; word-break: break-word; }

.nour-popup-phone a { color: var(--primary); text-decoration: none; direction: ltr; text-align: right; }
.nour-popup-phone a:hover { text-decoration: underline; }

.leaflet-control-zoom { border: 0 !important; box-shadow: var(--shadow-md) !important; border-radius: var(--radius) !important; overflow: hidden; }
.leaflet-control-zoom a { width: 36px !important; height: 36px !important; line-height: 36px !important; color: var(--text-secondary) !important; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .map-page { min-height: 480px; }
    .map-toolbar { top: 0.6rem; right: 0.6rem; left: 0.6rem; align-items: stretch; }
    .map-filter-card { padding: 0.55rem; }
    .map-filter-card select { flex: 1; min-width: 0; }
    .map-toggle-label { flex: 1; justify-content: center; }
    .map-type-card { align-self: flex-end; }
    .map-sidebar { top: auto; left: 0.6rem; right: 0.6rem; bottom: 0.6rem; width: auto; max-height: 42vh; border-radius: var(--radius-lg); }
    .map-stats-bar { bottom: auto; top: 9.5rem; }
}
