/* =====================================================================
   GeoPORTAL BPTD Jabar — Modul OD Intelligence (od.css)
   Peta Flow / Desire Lines, Matriks Asal-Tujuan, & Analitik Regional
   ===================================================================== */

/* =====================================================================
   1. MAP SECTION & LEGEND
   ===================================================================== */
.od-map-card {
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.od-map-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.od-map-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.btn-map-control {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.3rem 0.65rem;
    border-radius: 0.375rem;
    background: #ffffff;
    color: #334155;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-map-control:hover {
    background: #f1f5f9;
    color: var(--primary);
    border-color: #cbd5e1;
}

.od-legend-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.legend-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.65rem;
    border-radius: 9999px;
    background: #f1f5f9;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.legend-peak {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.legend-high {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.legend-mid {
    background: #eff6ff;
    color: #1e40af;
    border-color: #bfdbfe;
}

.legend-node {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}

.legend-dot-solid {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex: none;
}

.od-map-container {
    width: 100%;
    height: 440px;
    min-height: 420px;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid var(--border);
    position: relative;
    background: #0f172a;
}

.map-status-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.88);
    color: #f8fafc;
    padding: 0.875rem 1.5rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.map-status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #38bdf8;
    border-radius: 50%;
    animation: mapSpin 0.8s linear infinite;
}

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

/* Custom Marker Leaflet */
.od-node-marker {
    background: #10b981;
    border: 2px solid #ffffff;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.9), 0 2px 5px rgba(0, 0, 0, 0.35);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s ease, background 0.15s ease;
}

.od-node-marker:hover {
    transform: scale(1.35);
    background: #059669;
}

/* Popup Styling Overrides */
.leaflet-popup-content-wrapper {
    background: #ffffff !important;
    color: #0f172a !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25) !important;
    border: 1px solid #cbd5e1 !important;
}

.leaflet-popup-tip {
    background: #ffffff !important;
}

.leaflet-popup-content {
    margin: 0.75rem 0.85rem !important;
    color: #0f172a !important;
}

/* =====================================================================
   2. ANALYTICS CARD & TAB SWITCHER
   ===================================================================== */
.od-analytics-card {
    padding: 1.25rem;
    margin-bottom: 2rem;
}

.analytics-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.od-tablist {
    display: inline-flex;
    background: #f1f5f9;
    border-radius: 0.5rem;
    padding: 0.25rem;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.od-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border: none;
    border-radius: 0.375rem;
    background: transparent;
    color: #64748b;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.od-tab-btn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.6);
}

.od-tab-btn.is-active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}

.od-tabpanel {
    display: block;
}

.od-tabpanel[hidden] {
    display: none !important;
}

.panel-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 240px;
    max-width: 440px;
}

.search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    max-width: 16px;
    max-height: 16px;
    color: #94a3b8;
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 38px;
    padding: 0.5rem 0.85rem 0.5rem 2.35rem;
    font-size: 0.8125rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: #ffffff;
    color: var(--text-primary);
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

/* =====================================================================
   3. MATRIX TABLE WITH STICKY HEADERS & HEATMAP CELLS
   ===================================================================== */
.matrix-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 560px;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    position: relative;
    background: #ffffff;
}

.matrix-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8125rem;
}

.matrix-table thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: #f8fafc;
    color: #334155;
    font-weight: 700;
    text-align: right;
    padding: 0.625rem 0.75rem;
    border-bottom: 2px solid #cbd5e1;
    border-right: 1px solid #e2e8f0;
    white-space: nowrap;
    min-width: 96px;
}

.matrix-table thead th.th-origin-sticky {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 10;
    background: #f1f5f9;
    text-align: left;
    min-width: 180px;
    width: 180px;
    box-shadow: 2px 0 4px rgba(0,0,0,0.05);
}

.matrix-table thead th.th-total {
    background: #f1f5f9;
    color: #1e293b;
    border-left: 2px solid #cbd5e1;
}

.matrix-table tbody td {
    padding: 0.5rem 0.65rem;
    border-bottom: 1px solid #f1f5f9;
    border-right: 1px solid #f1f5f9;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    transition: background 0.1s ease;
}

.matrix-table tbody td.td-origin-sticky {
    position: sticky;
    left: 0;
    z-index: 3;
    background: #ffffff;
    font-weight: 600;
    color: #0f172a;
    text-align: left;
    box-shadow: 2px 0 4px rgba(0,0,0,0.04);
}

.matrix-table tbody tr:hover td.td-origin-sticky {
    background: #f8fafc;
}

.matrix-table tbody tr:hover td {
    filter: brightness(0.96);
}

.matrix-table tbody td.td-total {
    font-weight: 700;
    background: #f8fafc;
    color: #0f172a;
    border-left: 2px solid #e2e8f0;
}

/* Heatmap Shading Classes */
.heat-none {
    color: #cbd5e1;
    background: transparent;
}

.heat-low {
    background: #f0fdf4;
    color: #166534;
}

.heat-mid {
    background: #eff6ff;
    color: #1e40af;
    font-weight: 500;
}

.heat-high {
    background: #fef3c7;
    color: #92400e;
    font-weight: 600;
}

.heat-peak {
    background: #fee2e2;
    color: #991b1b;
    font-weight: 700;
}

/* Clickable cell */
.clickable-cell {
    cursor: pointer;
}
.clickable-cell:hover {
    outline: 2px solid #3b82f6;
    outline-offset: -2px;
}

/* =====================================================================
   4. DATA TABLES (REGIONAL & CORRIDORS)
   ===================================================================== */
.regional-table-wrap,
.corridors-table-wrap {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 520px;
    border: 1px solid var(--border);
    border-radius: 0.625rem;
    background: #ffffff;
}

.od-data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.od-data-table thead th {
    position: sticky;
    top: 0;
    z-index: 4;
    background: #f8fafc;
    color: #334155;
    font-weight: 700;
    padding: 0.65rem 0.875rem;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    text-align: left;
}

.od-data-table thead th.th-right,
.od-data-table tbody td.th-right {
    text-align: right;
}

.od-data-table thead th.th-center,
.od-data-table tbody td.th-center {
    text-align: center;
}

.od-data-table tbody td {
    padding: 0.625rem 0.875rem;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.od-data-table tbody tr:hover td {
    background: #f8fafc;
}

/* Regional Visual Ratio Bar */
.ratio-bar-wrap {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
}

.ratio-bar-track {
    flex: 1;
    height: 12px;
    background: #e2e8f0;
    border-radius: 9999px;
    overflow: hidden;
    display: flex;
}

.ratio-bar-outflow {
    background: #f59e0b;
    height: 100%;
    transition: width 0.3s ease;
}

.ratio-bar-inflow {
    background: #3b82f6;
    height: 100%;
    transition: width 0.3s ease;
}

.ratio-bar-label {
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    color: #64748b;
    min-width: 90px;
}

/* Rank Badge */
.rank-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    background: #f1f5f9;
    color: #475569;
}

.rank-badge-1 {
    background: #fef3c7;
    color: #b45309;
}

.rank-badge-2 {
    background: #f1f5f9;
    color: #475569;
}

.rank-badge-3 {
    background: #ffedd5;
    color: #c2410c;
}

/* Action button in table */
.btn-table-action {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 0.25rem;
    border: 1px solid var(--border);
    background: #ffffff;
    color: #3b82f6;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-table-action:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
}

/* =====================================================================
   5. MODAL DIALOG & CONNECTIONS LIST
   ===================================================================== */
.modal-top-connections {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.connection-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    border-radius: 0.375rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.connection-route {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #0f172a;
}

.connection-vol {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    font-weight: 700;
    color: #1e40af;
}

/* Responsive Overrides */
@media (max-width: 768px) {
    .od-map-container {
        height: 340px;
        min-height: 340px;
    }

    .analytics-header-row {
        flex-direction: column;
        align-items: stretch;
    }

    .od-tablist {
        width: 100%;
    }

    .od-tab-btn {
        flex: 1;
        justify-content: center;
    }
}
