:root {
    /* Primary theme */
    --primary-color: #2563EB;
    --primary-dark: #1E40AF;
    /* Backgrounds */
    --page-bg: #F8FAFC;
    --card-bg: #FFFFFF;
    --header-bg: #1651b8;
    --table-header-bg: #2563EB;
    --table-header-color: #fff;
    /* Text */
    --text-primary: #111827;
    --text-muted: #6B7280;
    /* Status colors */
    --status-on: #16A34A;
    --status-off: #DC2626;
    --status-maintenance: #F59E0B;
}

body {
    background: var(--page-bg);
    margin-bottom: 60px;
}

.dashboard-navbar {
    background-color: var(--primary-color);
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
    margin-bottom: 0 !important;
}

    .dashboard-navbar .navbar-brand,
    .dashboard-navbar .nav-link {
        color: #fff !important;
    }

    .dashboard-navbar .navbar-brand {
        font-size: 1.25rem;
        pointer-events: none; /* title bar — not a clickable link */
    }

        .dashboard-navbar .nav-link:hover {
            color: #E0E7FF !important;
        }

/* Remove any gap between header and body */
header { margin-bottom: 0 !important; }

html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

.card {
    background: var(--card-bg);
    border-radius: 1rem;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* ── Dark navbar ─────────────────────────────────────────────────────── */
.dash-navbar {
    background: #0f172a;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    width: 100%;
}

/* Pad the dashboard body content away from the edges */
.container-fluid > main > .container {
    max-width: 100%;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.dash-navbar .nav-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.dash-navbar .nav-actions { display: flex; align-items: center; gap: 0.75rem; }

.dash-navbar .btn-nav {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 8px;
    padding: 0.35rem 0.85rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.dash-navbar .btn-nav:hover { background: rgba(255,255,255,0.2); }

.dash-navbar .btn-nav-primary {
    background: #2563EB;
    border-color: #2563EB;
}

.dash-navbar .btn-nav-primary:hover { background: #1d4ed8; }

/* Download button colors */
.dash-navbar .btn-nav-excel {
    background: rgba(33, 115, 70, 0.85);
    border-color: #217346;
    color: #fff;
}
.dash-navbar .btn-nav-excel:hover { background: #217346; }

.dash-navbar .btn-nav-pdf {
    background: rgba(185, 28, 28, 0.85);
    border-color: #b91c1c;
    color: #fff;
}
.dash-navbar .btn-nav-pdf:hover { background: #b91c1c; }

.dash-navbar .btn-nav-csv {
    background: rgba(14, 116, 144, 0.85);
    border-color: #0e7490;
    color: #fff;
}
.dash-navbar .btn-nav-csv:hover { background: #0e7490; }

.btn-nav-label {
    font-size: 0.78rem;
    margin-left: 2px;
}

/* KPI */
.kpi-card {
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    box-shadow: 0 1px 8px rgba(0,0,0,0.06);
    background: #fff;
    border-left: 4px solid var(--kpi-color, #2563EB);
}

.kpi-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.kpi-card.kpi-blue  { --kpi-color: #2563EB; }
.kpi-card.kpi-green { --kpi-color: #16A34A; }
.kpi-card.kpi-red   { --kpi-color: #DC2626; }
.kpi-card.kpi-yellow{ --kpi-color: #F59E0B; }

/* Table */
.table-dashboard {
    border-collapse: collapse;
    table-layout: auto;
    width: 100%;
}

.table-dashboard th {
    background-color: var(--table-header-bg) !important;
    --bs-table-bg: var(--table-header-bg);
    color: var(--table-header-color) !important;
    font-weight: 700;
    border: 1px solid #1d4ed8;
    white-space: nowrap;
    position: sticky !important;
    top: 0 !important;
    z-index: 2;
}

.table-dashboard td {
    border: 1px solid #dee2e6;
    font-size: 1.05rem;
    vertical-align: middle;
}

.table-dashboard tbody tr:hover {
    background-color: #f0f6ff;
}

/* ── Sticky Status column (always visible on the right while scrolling) ──
   Uses an explicit class rather than :last-child so sticky stacking is
   unambiguous regardless of table/overflow-container nesting.           ── */
/* Report column — rightmost frozen */
.table-dashboard th.col-sticky-report {
    position: sticky !important;
    top: 0 !important;
    right: 0;
    z-index: 4;
    background-color: var(--table-header-bg) !important;
}

.table-dashboard td.col-sticky-report {
    position: sticky !important;
    right: 0;
    z-index: 2;
    background-color: #ffffff !important;
}

.table-dashboard tbody tr:hover td.col-sticky-report {
    background-color: #f0f6ff !important;
}

/* Status column — second from right, frozen next to Report */
.table-dashboard th.col-sticky-right {
    position: sticky !important;
    top: 0 !important;
    right: 65px;                                       /* width of Report column */
    z-index: 4;
    background-color: var(--table-header-bg) !important;
    box-shadow: -3px 0 6px rgba(0,0,0,0.18);
}

.table-dashboard td.col-sticky-right {
    position: sticky !important;
    right: 65px;
    z-index: 2;
    background-color: #ffffff !important;
    box-shadow: -3px 0 6px rgba(0,0,0,0.10);
}

.table-dashboard tbody tr:hover td.col-sticky-right {
    background-color: #f0f6ff !important;
}

/* Sortable column headers */
.table-dashboard th.sortable {
    cursor: pointer;
    user-select: none;
}

.table-dashboard th.sortable:hover {
    background-color: #1d4ed8 !important;
}

.table-dashboard th.sort-asc,
.table-dashboard th.sort-desc {
    background-color: #1e40af !important;
}

.sort-icon {
    font-size: 0.75rem;
    opacity: 0.55;
    margin-left: 4px;
    pointer-events: none;
}

.table-dashboard th.sort-asc .sort-icon,
.table-dashboard th.sort-desc .sort-icon {
    opacity: 1;
}


/* Status badges */
.badge-status-on {
    background: #e6f9ed;
    color: var(--status-on);
    font-weight: 600;
    border-radius: 16px;
    padding: .25em 1.1em;
}

.badge-status-off {
    background: #f1f5f9;
    color: var(--status-off);
    font-weight: 600;
    border-radius: 16px;
    padding: .25em 1.1em;
}

.badge-status-maint {
    background: #fef3c7;
    color: var(--status-maintenance);
    font-weight: 600;
    border-radius: 16px;
    padding: .25em 1.1em;
}

/* Buttons */
.btn-primary,
.btn-outline-primary {
    border-radius: 8px;
    font-weight: 600;
}

.btn-primary {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

    .btn-primary:hover {
        background: var(--primary-dark);
        border-color: var(--primary-dark);
    }


/* =========================================================
   DASHBOARD PANEL HEIGHTS — map and table always match
   ========================================================= */

/* Row is already a Bootstrap flex container; lock it to a fixed height
   and force both child columns to stretch to the same edge. */
#dashboardRow {
    height: 420px;
    align-items: stretch;   /* both cols grow to the same height */
}

/* Columns must fill the row height */
#mapCol,
#tableCol {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* Cards inside each column fill the column exactly —
   override the global .card margin-bottom so nothing is cut short */
#mapCol .card,
#tableCol .card {
    flex: 1 1 0;
    height: 100%;
    min-height: 0;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

/* Map div fills its card */
#map {
    flex: 1 1 0;
    min-height: 0;
    height: 100%;
}

/* Table-responsive scrolls inside the card; grows to fill remaining space
   after the "Report Issue" button row.
   overflow-x + overflow-y set separately so sticky-right has a clear
   single-axis horizontal scroll container. */
#tableCol .table-responsive {
    flex: 1 1 0;
    min-height: 0;
    overflow-x: auto;
    overflow-y: auto;
}

/* Expand map mode */
#dashboardRow.expand-map #map {
    height: calc(100vh - 280px);
    min-height: 400px;
}

/* =========================================================
   EXPANDED MAP / LIST MODES
   ========================================================= */

.expand-map #mapCol {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100%;
}

.expand-map #tableCol {
    display: none;
}

.expand-list #tableCol {
    flex: 0 0 100% !important;
    width: 100% !important;
    max-width: 100%;
}

.expand-list #mapCol {
    display: none;
}

/* Expanded height uses viewport */
#dashboardRow.expand-map,
#dashboardRow.expand-list {
    height: calc(100vh - 200px);
    min-height: 500px;
}

#dashboardRow.expand-list #tableCol .table-responsive {
    max-height: none;   /* let flex handle it in expanded mode */
}

/* Active view button */
.view-btn.active {
    background-color: #0d6efd;
    color: #fff;
    border-color: #0d6efd;
}

/* Reset button — subtle pulse on hover to hint it does something */
#btnReset {
    transition: box-shadow 0.2s ease, transform 0.15s ease;
}

#btnReset:hover {
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
    transform: scale(1.06);
}

#btnReset:active {
    transform: scale(0.96);
}
.dashboard-title {
    font-size: 1.75rem;
}

@media (max-width: 768px) {
    .dashboard-title {
        font-size: 1.15rem;
    }
}

/* BDA top navbar on mobile */
@media (max-width: 576px) {
    .dashboard-navbar .navbar-brand img { height: 28px !important; }
    .dashboard-navbar .navbar-brand span { font-size: 0.85rem; }
    .dashboard-navbar { padding-top: 0.4rem; padding-bottom: 0.4rem; }
}

/* ── Row flash animation (status change) ─────────────────────────────── */
@keyframes rowFlash {
    0%   { background-color: #fef9c3; }
    50%  { background-color: #fde68a; }
    100% { background-color: transparent; }
}

.row-flash {
    animation: rowFlash 2s ease-out forwards;
}

/* ── Column resize handle ────────────────────────────────────────────── */
.col-resizer {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 5px;
    cursor: col-resize;
    user-select: none;
    z-index: 10;
}

.col-resizer:hover { background: rgba(255,255,255,0.4); }

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

/* ── Small screens (≤ 576px) ──────────────────────────────── */
@media (max-width: 576px) {

    /* Navbar: stack vertically, reduce padding */
    .dash-navbar {
        flex-wrap: wrap;
        padding: 0.5rem 0.75rem;
        gap: 0.4rem;
    }
    .dash-navbar .nav-title {
        order: -1;
        width: 100%;
        text-align: center;
        font-size: 1.1rem;
        margin-bottom: 0.25rem;
    }
    .dash-navbar .nav-actions {
        gap: 0.4rem;
    }
    .dash-navbar .btn-nav {
        padding: 0.25rem 0.55rem;
        font-size: 0.78rem;
    }
    .btn-nav-label { display: none; }   /* icons only on mobile */

    /* KPI cards: tighter on small screens */
    .kpi-card {
        padding: 0.6rem 0.75rem;
    }
    .kpi-title { font-size: 0.72rem; }
    .kpi-value { font-size: 1.4rem; }

    /* Dashboard row: auto height on mobile instead of fixed 420px */
    #dashboardRow {
        height: auto !important;
    }
    #mapCol, #tableCol {
        height: auto !important;
    }
    /* Remove h-100 constraint on cards so they grow with content */
    #mapCol .card,
    #tableCol .card {
        height: auto !important;
        min-height: auto !important;
    }
    /* Let table-responsive grow naturally in the flex card */
    #tableCol .table-responsive {
        flex: 0 0 auto;
        overflow-x: auto;
    }
    #map {
        min-height: 250px !important;
        height: 250px;
    }

    /* Expanded modes on mobile */
    #dashboardRow.expand-map,
    #dashboardRow.expand-list {
        height: auto;
        min-height: auto;
    }
    #dashboardRow.expand-map #map {
        min-height: 350px !important;
        height: 60vh;
    }

    /* Table: hide Vendor, Operator, JE columns on mobile (Dashboard only) */
    #tableCol .table-dashboard th:nth-child(2),
    #tableCol .table-dashboard td:nth-child(2),
    #tableCol .table-dashboard th:nth-child(4),
    #tableCol .table-dashboard td:nth-child(4),
    #tableCol .table-dashboard th:nth-child(5),
    #tableCol .table-dashboard td:nth-child(5) {
        display: none;
    }

    /* Running Summary: hide Vendor, Location, OFF/Maint sub-columns on mobile */
    .summary-table th.col-hide-mobile,
    .summary-table td.col-hide-mobile {
        display: none;
    }

    .table-dashboard td,
    .table-dashboard th {
        font-size: 0.85rem;
        padding: 0.35rem 0.5rem;
    }

    /* Status legend: smaller, wrap */
    .status-legend {
        gap: 0.4rem !important;
        font-size: 0.75rem;
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    /* View toggle buttons */
    .view-btn, #btnReset {
        font-size: 0.78rem;
        padding: 0.2rem 0.5rem;
    }

    /* Last updated label */
    #lastUpdatedLabel {
        font-size: 0.72rem;
    }

    /* Modals: nearly full-screen */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    .modal-dialog-scrollable .modal-body {
        max-height: 70vh;
    }

    /* Pump detail modal: horizontal scroll for log table */
    #pdLogTableWrap {
        font-size: 0.8rem;
    }

    /* Sticky columns: less offset on mobile (narrower report col) */
    .table-dashboard th.col-sticky-right,
    .table-dashboard td.col-sticky-right {
        right: 45px;
    }

    /* Complaint modal: tighter spacing */
    .modal-body .row.g-3 { --bs-gutter-y: 0.5rem; }

    /* Container padding */
    .container-fluid.px-4 {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* ── Medium screens (≤ 768px) ─────────────────────────────── */
@media (max-width: 768px) {
    /* Dashboard row: auto height so map and table stack */
    #dashboardRow {
        height: auto;
    }
    #mapCol, #tableCol {
        height: auto;
    }
    #map {
        min-height: 300px;
    }
    #mapCol .card, #tableCol .card {
        height: auto !important;
        min-height: auto !important;
    }
    #tableCol .table-responsive {
        flex: 0 0 auto;
    }

    /* Reduce KPI spacing */
    .kpi-card {
        padding: 0.75rem 1rem;
        margin-bottom: 0.5rem;
    }
    .kpi-value { font-size: 1.6rem; }
}
