/* ============================================
   ASDP - Network View (Hub-and-Spoke)
   KSA distribution network visualization
   ============================================ */

/* ---- Layout ---- */
.network-page {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--bg-light, #f0f2f5);
}

.network-header {
    background: linear-gradient(135deg, #1a5276 0%, #0e6655 100%);
    color: #fff;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.network-header h1 {
    font-size: 1.3rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.network-header .back-link {
    color: rgba(255,255,255,0.8);
    text-decoration: none;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 4px;
}

.network-header .back-link:hover {
    color: #fff;
}

/* ---- KPI Strip ---- */
.network-kpi-strip {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    overflow-x: auto;
    flex-shrink: 0;
}

.network-kpi-card {
    flex: 1;
    min-width: 140px;
    background: #f8f9fa;
    border-radius: 10px;
    padding: 0.75rem 1rem;
    text-align: center;
    border: 1px solid #e9ecef;
}

.network-kpi-card .kpi-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: #1a5276;
}

.network-kpi-card .kpi-label {
    font-size: 0.75rem;
    color: #6c757d;
    margin-top: 2px;
}

.network-kpi-card.hub-card .kpi-value { color: #0e6655; }
.network-kpi-card.depot-card .kpi-value { color: #b7950b; }
.network-kpi-card.fleet-card .kpi-value { color: #1a5276; }
.network-kpi-card.crane-card .kpi-value { color: #c0392b; }

/* ---- Main Content ---- */
.network-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ---- Map ---- */
.network-map-container {
    flex: 1;
    position: relative;
}

#networkMap {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ---- Side Panel ---- */
.network-side-panel {
    width: 380px;
    background: #fff;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
    flex-shrink: 0;
    padding: 0;
    direction: rtl;
}

.panel-section {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #f0f0f0;
}

.panel-section-title {
    font-size: 0.85rem;
    font-weight: 700;
    color: #1a5276;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ---- Hub/Depot Detail Card ---- */
.location-detail {
    display: none;
}

.location-detail.active {
    display: block;
}

.location-detail-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.25rem;
    background: linear-gradient(135deg, #1a5276 0%, #0e6655 100%);
    color: #fff;
}

.location-detail-header .location-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.location-detail-header .location-info h3 {
    margin: 0;
    font-size: 1.1rem;
}

.location-detail-header .location-info .location-type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-top: 4px;
}

.type-hub { background: rgba(46, 204, 113, 0.3); color: #d5f5e3; }
.type-depot { background: rgba(243, 156, 18, 0.3); color: #fdebd0; }

/* ---- Stat Grid ---- */
.stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.stat-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    text-align: center;
}

.stat-item .stat-number {
    font-size: 1.2rem;
    font-weight: 800;
    color: #1a5276;
}

.stat-item .stat-label {
    font-size: 0.7rem;
    color: #6c757d;
}

.stat-item.highlight {
    background: #d5f5e3;
}

.stat-item.highlight .stat-number {
    color: #0e6655;
}

.stat-item.warning {
    background: #fef9e7;
}

.stat-item.warning .stat-number {
    color: #b7950b;
}

/* ---- Fleet List ---- */
.fleet-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.8rem;
}

.fleet-row:last-child {
    border-bottom: none;
}

.fleet-row .fleet-type {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
}

.fleet-row .fleet-count {
    background: #e8f4fd;
    color: #1a5276;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.75rem;
}

/* ---- Cross-Dock Schedule ---- */
.crossdock-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.8rem;
}

.crossdock-item:last-child {
    border-bottom: none;
}

.crossdock-time {
    background: #1a5276;
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

.crossdock-route {
    flex: 1;
}

.crossdock-route .route-from-to {
    font-weight: 600;
    color: #2c3e50;
}

.crossdock-route .route-items {
    font-size: 0.7rem;
    color: #6c757d;
}

.crossdock-status {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.crossdock-status.scheduled { background: #e8f4fd; color: #1a5276; }
.crossdock-status.loading { background: #fef9e7; color: #b7950b; }
.crossdock-status.enroute { background: #d5f5e3; color: #0e6655; }
.crossdock-status.delivered { background: #d4efdf; color: #1e8449; }

/* ---- Hub List (default panel) ---- */
.hub-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 0.5rem;
}

.hub-list-item:hover {
    background: #f0f2f5;
}

.hub-list-item .hub-marker {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    color: #fff;
    flex-shrink: 0;
}

.hub-list-item .hub-marker.tier-hub { background: #0e6655; }
.hub-list-item .hub-marker.tier-depot { background: #f39c12; }

.hub-list-item .hub-info {
    flex: 1;
}

.hub-list-item .hub-info h4 {
    margin: 0;
    font-size: 0.9rem;
    color: #2c3e50;
}

.hub-list-item .hub-info .hub-meta {
    font-size: 0.7rem;
    color: #6c757d;
}

.hub-list-item .hub-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2ecc71;
    flex-shrink: 0;
}

/* ---- Legend ---- */
.map-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    background: rgba(255,255,255,0.95);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    font-size: 0.75rem;
    direction: rtl;
}

.legend-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.legend-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-dot.hub { background: #0e6655; border: 3px solid #d5f5e3; }
.legend-dot.depot { background: #f39c12; border: 3px solid #fef9e7; }
.legend-line {
    width: 20px;
    height: 3px;
    flex-shrink: 0;
    border-radius: 2px;
}
.legend-line.spoke { background: #3498db; }
.legend-line.crossdock { background: #e74c3c; border-style: dashed; }

/* ---- Utilization Bars ---- */
.util-bar-container {
    margin-bottom: 0.5rem;
}

.util-bar-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 3px;
}

.util-bar-label .label-name { color: #2c3e50; font-weight: 600; }
.util-bar-label .label-pct { color: #6c757d; }

.util-bar {
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.util-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.util-bar-fill.high { background: #2ecc71; }
.util-bar-fill.medium { background: #f39c12; }
.util-bar-fill.low { background: #e74c3c; }

/* ---- Pulse Animation for Hub Markers ---- */
@keyframes hubPulse {
    0% { box-shadow: 0 0 0 0 rgba(14, 102, 85, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(14, 102, 85, 0); }
    100% { box-shadow: 0 0 0 0 rgba(14, 102, 85, 0); }
}

.leaflet-hub-marker {
    background: #0e6655;
    border: 3px solid #d5f5e3;
    border-radius: 50%;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: hubPulse 2s infinite;
    cursor: pointer;
}

.leaflet-depot-marker {
    background: #f39c12;
    border: 3px solid #fef9e7;
    border-radius: 50%;
    color: #fff;
    font-weight: 800;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .network-content {
        flex-direction: column-reverse;
    }
    .network-side-panel {
        width: 100%;
        height: 45%;
        border-right: none;
        border-top: 1px solid #e0e0e0;
    }
    .network-map-container {
        height: 55%;
    }
    .network-kpi-strip {
        padding: 0.75rem;
        gap: 0.5rem;
    }
    .network-kpi-card {
        min-width: 100px;
        padding: 0.5rem;
    }
    .network-kpi-card .kpi-value {
        font-size: 1.2rem;
    }
}
