/* Autobahn Alliance Theme - Dark Blue & Yellow */

:root {
    /* Core Colors (Dark Mode Default) */
    --autobahn-blue-dark: #050a1e;
    --autobahn-blue-mid: #0d1b3e;
    --autobahn-blue-light: #1a2b5e;
    --autobahn-yellow: #ffcc00;
    --autobahn-yellow-hover: #ffdb4d;

    /* Bootstrap Overrides / System Colors */
    --bs-primary: var(--autobahn-yellow);
    --bs-secondary: #64748b;
    --bs-success: #22c55e;
    --bs-warning: #eab308;
    --bs-danger: #ef4444;
    --bs-light: #f8fafc;
    --bs-dark: #0f172a;

    /* Theme Semantics */
    --color-bg-body: var(--autobahn-blue-mid);
    --color-card-bg: rgba(20, 35, 75, 0.6);
    --color-card-border: rgba(255, 204, 0, 0.1);
    --color-text-main: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-text-inverse: #0d1b3e;

    /* Component Specifics */
    --navbar-bg: rgba(5, 10, 30, 0.85);
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-text: #ffffff;
    --input-focus-bg: rgba(255, 255, 255, 0.1);
    --table-border-color: rgba(255, 255, 255, 0.1);
    --table-hover-bg: rgba(255, 204, 0, 0.1);
    --table-hover-text: #ffffff;
    --badge-bg-light: rgba(255, 255, 255, 0.1);

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Components */
    --card-radius: 16px;
    --btn-radius: 10px;
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --glass-blur: blur(12px);

    /* Utility Logic */
    --invert-icon: invert(1);
}

/* Light Mode Overrides */
[data-theme="light"] {
    /* Core Colors Re-mapped */
    --autobahn-blue-dark: #f1f5f9;
    /* Slate 100 */
    --autobahn-blue-mid: #ffffff;
    /* White */
    --autobahn-blue-light: #e2e8f0;
    /* Slate 200 */
    --autobahn-yellow: #ffcc00;
    /* Keep yellow, maybe darken slightly for contrast if needed */

    /* Semantics */
    --color-bg-body: #f8fafc;
    --color-card-bg: rgba(255, 255, 255, 0.75);
    --color-card-border: rgba(0, 0, 0, 0.05);
    --color-text-main: #0f172a;
    /* Slate 900 */
    --color-text-muted: #64748b;
    /* Slate 500 */
    --color-text-inverse: #0d1b3e;

    /* Components */
    --navbar-bg: rgba(255, 255, 255, 0.85);
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
    --input-text: #0f172a;
    --input-focus-bg: #ffffff;
    --table-border-color: #e2e8f0;
    --table-hover-bg: rgba(255, 204, 0, 0.1);
    --table-hover-text: #0f172a;
    --badge-bg-light: #e2e8f0;

    --card-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.1);
    /* Slightly stronger shadow */
    --invert-icon: none;
}

/* Global Reset & Body */
body {
    background-color: var(--color-bg-body);
    background-image:
        linear-gradient(135deg, var(--autobahn-blue-dark) 0%, var(--autobahn-blue-mid) 50%, var(--autobahn-blue-light) 100%);
    background-attachment: fixed;
    color: var(--color-text-main);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
    /* Prevent horizontal scroll globally */
    max-width: 100vw;
}

html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Headings */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--color-text-main);
    font-weight: 700;
    letter-spacing: 0.5px;
}

h1 {
    text-transform: uppercase;
    color: var(--autobahn-yellow);
}

/* In Light mode, yellow on white might be hard to read for text. 
   Changes H1 to dark blue in light mode for better contrast? 
   Or keep yellow but add text-shadow. */
[data-theme="light"] h1 {
    color: #eab308;
    /* Darker yellow/gold for readability */
}

/* Links */
a {
    color: var(--autobahn-yellow);
    text-decoration: none;
    transition: color 0.2s;
}

[data-theme="light"] a {
    color: #ca8a04;
    /* Darker yellow */
}

a:hover {
    color: var(--autobahn-yellow-hover);
}

/* Navbar Overrides */
.navbar {
    background: var(--navbar-bg) !important;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid rgba(255, 204, 0, 0.25);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: background-color 0.3s ease;
}

[data-theme="light"] .navbar {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.navbar-brand {
    color: var(--autobahn-yellow) !important;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

[data-theme="light"] .navbar-brand {
    color: #eab308 !important;
}

.nav-link {
    color: rgba(255, 255, 255, 0.8) !important;
}

[data-theme="light"] .nav-link {
    color: rgba(0, 0, 0, 0.7) !important;
}

/* Navbar Toggler – white icon + label, clearly visible */
.navbar-toggler {
    border-color: rgba(255, 255, 255, 0.5) !important;
    color: #ffffff !important;
    padding: 0.4rem 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}

.navbar-toggler .bi-list {
    font-size: 1.5rem;
    line-height: 1;
}

.navbar-toggler-label {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

[data-theme="light"] .navbar-toggler {
    border-color: rgba(0, 0, 0, 0.3) !important;
    color: #1e293b !important;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 204, 0, 0.35);
}

/* Hide the old Bootstrap toggler-icon (replaced by bi-list) */
.navbar-toggler-icon {
    display: none;
}

/* Collapsed navbar dropdown background on mobile */
@media (max-width: 991.98px) {
    .navbar .navbar-collapse {
        background: rgba(5, 10, 30, 0.97);
        border-radius: 0 0 12px 12px;
        padding: 0.75rem 1rem;
        margin: 0 -0.75rem;
        border-top: 1px solid rgba(255, 204, 0, 0.15);
    }

    [data-theme="light"] .navbar .navbar-collapse {
        background: rgba(255, 255, 255, 0.97);
        border-top: 1px solid rgba(0, 0, 0, 0.08);
    }
}

.nav-link:hover,
.nav-link.active {
    color: var(--autobahn-yellow) !important;
}

[data-theme="light"] .nav-link:hover,
[data-theme="light"] .nav-link.active {
    color: #b45309 !important;
    /* Darker orange/gold for active state on light bg (was #eab308) */
}

.dropdown-menu {
    background-color: var(--autobahn-blue-mid);
    border: 1px solid var(--color-card-border);
    box-shadow: var(--card-shadow);
}

.dropdown-item {
    color: var(--color-text-main);
}

.dropdown-item:hover {
    background-color: rgba(255, 204, 0, 0.1);
    color: var(--autobahn-yellow);
}

[data-theme="light"] .dropdown-item:hover {
    color: #eab308;
}

.dropdown-divider {
    border-top: 1px solid var(--color-card-border);
}

/* Card Styles */
.card {
    background: var(--color-card-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--color-card-border);
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    color: var(--color-text-main);
    margin-bottom: var(--spacing-md);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.card-header {
    background-color: rgba(0, 0, 0, 0.05);
    /* Works for both */
    border-bottom: 1px solid var(--color-card-border);
    color: var(--autobahn-yellow);
    font-weight: 600;
    text-transform: uppercase;
}

[data-theme="light"] .card-header {
    background-color: rgba(0, 0, 0, 0.03);
    color: #eab308;
}

/* Buttons */
.btn {
    border-radius: var(--btn-radius);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0.6rem 1.2rem;
    border: none;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: var(--autobahn-yellow);
    color: var(--color-text-inverse);
    box-shadow: 0 4px 15px rgba(255, 204, 0, 0.2);
}

.btn-primary:hover {
    background-color: var(--autobahn-yellow-hover);
    color: var(--color-text-inverse);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 204, 0, 0.3);
}

.btn-outline-primary {
    color: var(--autobahn-yellow);
    border: 1px solid var(--autobahn-yellow);
    background: transparent;
}

[data-theme="light"] .btn-outline-primary {
    color: #b45309;
    /* Darker than #eab308 */
    border-color: #b45309;
}

.btn-outline-primary:hover {
    background-color: var(--autobahn-yellow);
    color: var(--color-text-inverse);
}

[data-theme="light"] .btn-outline-primary:hover {
    background-color: #b45309;
    color: #ffffff;
    /* White text on dark orange hover */
}

/* Forms */
.form-control,
.form-select {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--input-text);
    border-radius: 8px;
}

.form-control:focus,
.form-select:focus {
    background-color: var(--input-focus-bg);
    border-color: var(--autobahn-yellow);
    box-shadow: 0 0 0 0.25rem rgba(255, 204, 0, 0.25);
    color: var(--input-text);
}

/* Select dropdown options - ensure visibility in dark mode */
.form-select option {
    background-color: #1a2b5e;
    color: #ffffff;
    padding: 8px;
}

.form-select option:hover,
.form-select option:checked {
    background-color: #0d1b3e;
    color: var(--autobahn-yellow);
}

[data-theme="light"] .form-select option {
    background-color: #ffffff;
    color: #0f172a;
}

[data-theme="light"] .form-select option:hover,
[data-theme="light"] .form-select option:checked {
    background-color: #f1f5f9;
    color: #0f172a;
}

.form-label {
    color: var(--color-text-muted);
}

[data-theme="light"] .form-label {
    color: var(--color-text-main);
}

/* Tables */
.table {
    color: var(--color-text-main);
    border-color: var(--table-border-color);
}

.table> :not(caption):not(.table-dark)>*>* {
    background-color: transparent !important;
    color: var(--color-text-main);
    border-bottom-color: var(--table-border-color);
}

/* Exclude table-dark header cells from transparent override */
.table> thead.table-dark>*>* {
    background-color: #0d1b3e !important;
    color: var(--autobahn-yellow) !important;
}

.table-light {
    background-color: var(--input-bg) !important;
    /* Use input bg (light/dark transparent) */
    color: var(--autobahn-yellow) !important;
}

[data-theme="light"] .table-light {
    color: #1e293b !important;
}

.table thead th {
    color: var(--autobahn-yellow);
    border-bottom: 2px solid var(--table-border-color);
    background-color: rgba(0, 0, 0, 0.1) !important;
}

[data-theme="light"] .table thead th {
    color: #1e293b;
}

/* Table Dark Header - Autobahn Dark Blue */
.table-dark,
.table-dark thead,
.table-dark th,
.table thead.table-dark,
.table thead.table-dark th,
.table thead.table-dark tr th,
.table> thead.table-dark>tr>th {
    background-color: #0d1b3e !important;
    color: var(--autobahn-yellow) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
}

[data-theme="light"] .table-dark,
[data-theme="light"] .table-dark thead,
[data-theme="light"] .table-dark th,
[data-theme="light"] .table thead.table-dark,
[data-theme="light"] .table thead.table-dark th,
[data-theme="light"] .table thead.table-dark tr th,
[data-theme="light"] .table> thead.table-dark>tr>th {
    background-color: #0d1b3e !important;
    color: #ffcc00 !important;
}

.table-hover tbody tr:hover td,
.table-hover tbody tr:hover th {
    color: var(--table-hover-text);
    background-color: var(--table-hover-bg) !important;
}

/* Fix for table-striped: ensure text is always readable */
.table-striped > tbody > tr:nth-of-type(odd) > * {
    color: var(--color-text-main) !important;
}

.table-striped > tbody > tr:nth-of-type(even) > * {
    color: var(--color-text-main) !important;
}

/* Override Bootstrap's striped background with theme-compatible colors */
.table-striped > tbody > tr:nth-of-type(odd) {
    --bs-table-accent-bg: rgba(255, 255, 255, 0.03);
}

.table-striped > tbody > tr:nth-of-type(even) {
    --bs-table-accent-bg: transparent;
}

/* Badges */
.bg-light {
    background-color: var(--badge-bg-light) !important;
    color: var(--color-text-main) !important;
}

/* Text Utilities Overrides */
.text-muted {
    color: var(--color-text-muted) !important;
}

/* In dark mode, text-dark becomes black. 
   In light mode, text-dark is simply black (default). 
   But wait, earlier I mapped text-dark to #000 for dark mode badges. 
   This remains correct. */
.text-dark {
    color: #000 !important;
}

.text-primary {
    color: var(--autobahn-yellow) !important;
}

[data-theme="light"] .text-primary {
    color: #eab308 !important;
}

.text-success {
    color: #4ade80 !important;
}

[data-theme="light"] .text-success {
    color: #16a34a !important;
}

/* Green 600 */

.text-warning {
    color: #facc15 !important;
}

[data-theme="light"] .text-warning {
    color: #ca8a04 !important;
}

/* Yellow 600 */

.text-danger {
    color: #f87171 !important;
}

[data-theme="light"] .text-danger {
    color: #dc2626 !important;
}

/* Red 600 */

.text-info {
    color: #38bdf8 !important;
}

[data-theme="light"] .text-info {
    color: #0284c7 !important;
}

.text-secondary {
    color: #94a3b8 !important;
}

[data-theme="light"] .text-secondary {
    color: #64748b !important;
}


/* Footer */
.footer {
    background-color: var(--navbar-bg) !important;
    border-top: 1px solid var(--color-card-border);
    color: var(--color-text-muted);
}

/* Background Soft Utilities (Ported & Adapted) */
.bg-soft-primary {
    background-color: rgba(255, 204, 0, 0.1);
    color: var(--autobahn-yellow);
}

[data-theme="light"] .bg-soft-primary {
    color: #ca8a04;
}

.bg-soft-success {
    background-color: rgba(34, 197, 94, 0.1);
    color: #4ade80;
}

[data-theme="light"] .bg-soft-success {
    color: #16a34a;
}

.bg-soft-warning {
    background-color: rgba(234, 179, 8, 0.1);
    color: #facc15;
}

[data-theme="light"] .bg-soft-warning {
    color: #ca8a04;
}

.bg-soft-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

[data-theme="light"] .bg-soft-danger {
    color: #dc2626;
}


/* Bootstrap Component Overrides */
.list-group-item {
    background-color: transparent;
    border: 1px solid var(--color-card-border);
    color: var(--color-text-main);
}

.list-group-item.bg-light {
    background-color: var(--badge-bg-light) !important;
}

.modal-content {
    background-color: var(--autobahn-blue-mid);
    border: 1px solid var(--color-card-border);
    color: var(--color-text-main);
}

/* Form controls inside modals need solid backgrounds for dropdown visibility */
.modal .form-select,
.modal .form-control {
    background-color: #1a2b5e;
    color: #ffffff;
}

.modal .form-select:focus,
.modal .form-control:focus {
    background-color: #0d1b3e;
}

[data-theme="light"] .modal .form-select,
[data-theme="light"] .modal .form-control {
    background-color: #ffffff;
    color: #0f172a;
}

.modal-header,
.modal-footer {
    border-color: var(--table-border-color);
}

.btn-close {
    filter: var(--invert-icon);
}

/* Alerts */
.alert-info {
    background-color: rgba(14, 165, 233, 0.2);
    border-color: rgba(14, 165, 233, 0.3);
    color: #e0f2fe;
}

[data-theme="light"] .alert-info {
    background-color: #e0f2fe;
    border-color: #bae6fd;
    color: #0369a1;
}

.alert-warning {
    background-color: rgba(234, 179, 8, 0.2);
    border-color: rgba(234, 179, 8, 0.3);
    color: #fef9c3;
}

[data-theme="light"] .alert-warning {
    background-color: #fef9c3;
    border-color: #fde047;
    color: #854d0e;
}

.alert-danger {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
    color: #fee2e2;
}

[data-theme="light"] .alert-danger {
    background-color: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

.alert-success {
    background-color: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.3);
    color: #dcfce7;
}

[data-theme="light"] .alert-success {
    background-color: #dcfce7;
    border-color: #86efac;
    color: #166534;
}


/* Utilities Override */
.bg-white {
    background-color: var(--input-bg) !important;
    color: var(--color-text-main) !important;
}

.border-white-50 {
    border-color: var(--table-border-color) !important;
}

.shadow-sm {
    box-shadow: var(--card-shadow) !important;
}

/* ==========================================
   Clickable Instance Rows/Cards
   ========================================== */
.instance-row:hover td,
.instance-row:focus-within td {
    background-color: rgba(255, 204, 0, 0.15) !important;
    transition: background-color 0.15s ease-in-out;
}

.instance-row:active td {
    background-color: rgba(255, 204, 0, 0.25) !important;
}

.instance-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.instance-card:active {
    transform: scale(0.98);
}

/* Ensure touch targets are accessible (min 44px) */
.instance-row td {
    padding-top: 12px;
    padding-bottom: 12px;
}

.instance-card .card-header {
    min-height: 56px;
}

/* ==========================================
   LiPo Locations Card Layout (12/19)
   ========================================== */
.lipo-location-card {
    border-radius: var(--card-radius);
    overflow: hidden;
}

.lipo-location-card .card-header {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 0.75rem 1rem;
    text-transform: none;
}

.lipo-location-card .battery-list {
    max-height: none;
}

.lipo-location-card .battery-item {
    background-color: transparent;
    transition: background-color 0.15s ease;
}

.lipo-location-card .battery-item:hover {
    background-color: rgba(255, 204, 0, 0.05);
}

[data-theme="light"] .lipo-location-card .battery-item:hover {
    background-color: rgba(0, 0, 0, 0.03);
}

@media (max-width: 991.98px) {
    .lipo-location-card {
        margin-bottom: 0.75rem;
        border-radius: 12px;
    }

    .lipo-location-card .card-header {
        padding: 0.5rem 0.75rem;
        font-size: 0.95rem;
    }

    .lipo-location-card .battery-item {
        padding: 0.5rem 0.75rem;
    }

    /* Ensure no horizontal scroll on tablet */
    .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

/* ==========================================
   Battery Overview - Compact Table Styles (15/19)
   ========================================== */

/* Utility: No-wrap for IDs and critical fields */
.nowrap {
    white-space: nowrap !important;
}

/* ID column specific styling */
.col-id {
    min-width: 7rem;
    max-width: 9rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap !important;
}

/* Battery overview table - compact styling */
.table-battery-overview {
    table-layout: auto;
}

.table-battery-overview td,
.table-battery-overview th {
    padding: 0.35rem 0.5rem;
    vertical-align: middle;
    line-height: 1.25;
    white-space: nowrap;
}

/* Explicitly allow wrapping for long text columns */
.table-battery-overview td.wrap-allowed,
.table-battery-overview th.wrap-allowed {
    white-space: normal;
    word-break: break-word;
}

/* Compact badges within battery tables */
.table-battery-overview .badge {
    padding: 0.2em 0.45em;
    font-size: 0.8em;
    font-weight: 500;
}

/* Status column - fixed width */
.table-battery-overview .col-status {
    width: 5.5rem;
    min-width: 5.5rem;
}

/* Type column */
.table-battery-overview .col-type {
    min-width: 4rem;
    max-width: 6rem;
}

/* Date column - compact */
.table-battery-overview .col-date {
    min-width: 6rem;
    max-width: 8rem;
    font-size: 0.85em;
}

/* Name/Person column */
.table-battery-overview .col-person {
    max-width: 8rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Location column - allowed to wrap */
.table-battery-overview .col-location {
    min-width: 6rem;
    max-width: 12rem;
    white-space: normal;
    word-break: break-word;
}

/* Actions column - minimal width */
.table-battery-overview .col-actions {
    width: 3rem;
    min-width: 3rem;
    text-align: center;
}

/* Capacity column - compact */
.table-battery-overview .col-capacity {
    min-width: 4rem;
    max-width: 5rem;
    text-align: center;
}

/* ==========================================
   Tablet Responsive - Battery Overview
   ========================================== */
@media (max-width: 1024px) {
    .table-battery-overview {
        font-size: 0.875rem;
    }

    .table-battery-overview td,
    .table-battery-overview th {
        padding: 0.3rem 0.4rem;
    }

    /* Hide secondary columns on tablet */
    .table-battery-overview .col-secondary {
        display: none;
    }

    /* Tighter ID column on tablet */
    .table-battery-overview .col-id {
        min-width: 5.5rem;
        max-width: 7rem;
    }

    /* Smaller badges on tablet */
    .table-battery-overview .badge {
        padding: 0.15em 0.35em;
        font-size: 0.75em;
    }
}

@media (max-width: 768px) {
    .table-battery-overview {
        font-size: 0.8rem;
    }

    .table-battery-overview td,
    .table-battery-overview th {
        padding: 0.25rem 0.35rem;
    }

    /* Even more compact on mobile */
    .table-battery-overview .col-id {
        min-width: 5rem;
        max-width: 6rem;
        font-size: 0.85em;
    }

    .table-battery-overview .col-location {
        max-width: 8rem;
    }
}

/* ==========================================
   Battery Status Contrast Fixes (User Request 16/19)
   ========================================== */

/* 1. Base Reset for all status rows to ensure overrides work */
.table-battery-overview tr[class*="status-"] {
    transition: background-color 0.2s ease, color 0.2s ease;
}

/* 2. Status: Active -> Two alternating blue tones matching dark background */
.table-battery-overview tr.status-active:nth-child(odd) {
    background-color: #1a3a5c !important;
    color: #ffffff !important;
}
.table-battery-overview tr.status-active:nth-child(even) {
    background-color: #122a48 !important;
    color: #ffffff !important;
}

/* 3. Status: Defect (Danger/Red) -> Requires White Text */
.table-battery-overview tr.status-defect {
    background-color: var(--bs-danger) !important;
    color: #ffffff !important;
}

/* 4. Status: Blocked (Warning/Yellow) -> Requires Dark Text */
.table-battery-overview tr.status-blocked {
    background-color: var(--bs-warning) !important;
    color: #212529 !important;
    /* Bootstrap gray-900 */
}

/* 5. Status: Transport/Other (Info/Blue) -> Requires White Text if Blue */
.table-battery-overview tr.status-transport,
.table-battery-overview tr.status-blue {
    background-color: #0dcaf0 !important;
    /* Cyan/Info */
    color: #000000 !important;
    /* Cyan is usually light, so dark text is safer. If dark blue, use white. */
}

/* If User specifically meant "Primary" blue which is often dark blue in other themes: */
.table-battery-overview tr.status-primary {
    background-color: #0d6efd !important;
    color: #ffffff !important;
}

/* 6. Content Inheritance & Overrides for High Contrast Rows (White Text) */
.table-battery-overview tr[class*="status-"] td,
.table-battery-overview tr[class*="status-"] th {
    border-color: rgba(255, 255, 255, 0.2);
}

/* For White Text Rows (Active, Defect) */
.table-battery-overview tr.status-active td,
.table-battery-overview tr.status-active a,
.table-battery-overview tr.status-active .text-muted,
.table-battery-overview tr.status-defect td,
.table-battery-overview tr.status-defect a,
.table-battery-overview tr.status-defect .text-muted {
    color: #ffffff !important;
}

.table-battery-overview tr.status-active a:hover,
.table-battery-overview tr.status-defect a:hover {
    text-decoration: underline;
    opacity: 0.9;
}

/* Badges in White Text Rows - use semi-transparent white */
.table-battery-overview tr.status-active .badge,
.table-battery-overview tr.status-defect .badge {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
    border: 1px solid rgba(255, 255, 255, 0.4);
}

/* For Dark Text Rows (Blocked/Warning) */
.table-battery-overview tr.status-blocked td,
.table-battery-overview tr.status-blocked a,
.table-battery-overview tr.status-blocked .text-muted {
    color: #212529 !important;
}

.table-battery-overview tr.status-blocked .badge {
    background-color: rgba(0, 0, 0, 0.1) !important;
    color: #000000 !important;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

/* 7. Zebra Striping Protection */
/* Ensure native stripe doesn't override status color */
.table-battery-overview tr[class*="status-"]:nth-child(even),
.table-battery-overview tr[class*="status-"]:nth-child(odd) {
    --bs-table-accent-bg: transparent !important;
}

/* Only apply striping to non-status rows if needed */
.table-battery-overview tr:not([class*="status-"]):nth-child(even) {
    background-color: rgba(0, 0, 0, 0.03);
    /* Or keep default bootstrap behavior, but ensure it doesn't clash */
}

/* 8. Fix specific icons/buttons inside status rows */
.table-battery-overview tr.status-active .btn-outline-primary,
.table-battery-overview tr.status-defect .btn-outline-primary {
    color: #ffffff;
    border-color: #ffffff;
}

.table-battery-overview tr.status-active .btn-outline-primary:hover,
.table-battery-overview tr.status-defect .btn-outline-primary:hover {
    background-color: #ffffff;
    color: var(--bs-primary);
}

/* ==========================================
   Sticky Table Headers (Fixed on Scroll)
   ========================================== */

/* On XL screens, remove overflow to allow sticky headers */
@media (min-width: 1200px) {
    .table-responsive {
        overflow: visible !important;
    }
}

/* Apply sticky to th elements directly (desktop only) */
@media (min-width: 992px) {
    .table thead th {
        position: sticky;
        top: 56px; /* Height of navbar */
        z-index: 100;
        background-color: var(--autobahn-blue-mid) !important;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    }
}

/* Mobile: no sticky headers (conflicts with table-responsive overflow) */
@media (max-width: 991.98px) {
    .table thead th {
        position: static;
        box-shadow: none;
    }
}

/* Second row header for multi-row headers (instance_overview) */
@media (min-width: 992px) {
    .table thead tr:nth-child(2) th {
        top: 99px; /* 56px navbar + ~43px first header row */
    }
}

.table thead.table-light th {
    background-color: rgba(13, 27, 62, 0.98) !important;
}

[data-theme="light"] .table thead th {
    background-color: #f8fafc !important;
    color: #1e293b !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .table thead.table-light th {
    background-color: #f1f5f9 !important;
    color: #1e293b !important;
}

/* ================================================
   HTMX Loading & Transition Styles (Project-wide)
   ================================================ */

.htmx-indicator {
    display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

.htmx-indicator.spinner {
    display: none;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--autobahn-yellow);
    border-right-color: transparent;
    border-radius: 50%;
    animation: htmx-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-left: 0.5rem;
}
.htmx-request .htmx-indicator.spinner {
    display: inline-block;
}
@keyframes htmx-spin {
    to { transform: rotate(360deg); }
}

.htmx-swapping {
    opacity: 0.5;
    transition: opacity 200ms ease-out;
}

.htmx-settling {
    opacity: 1;
    transition: opacity 200ms ease-in;
}

/* Loading overlay for HTMX content areas */
[data-htmx-loading].htmx-request {
    position: relative;
    pointer-events: none;
    min-height: 100px;
}
[data-htmx-loading].htmx-request::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(13, 27, 62, 0.35);
    z-index: 10;
    border-radius: 0.375rem;
}
[data-theme="light"] [data-htmx-loading].htmx-request::after {
    background: rgba(255, 255, 255, 0.6);
}

/* Table row being updated */
tr.htmx-swapping td {
    opacity: 0.3;
    transition: opacity 150ms ease-out;
}

/* Button loading state */
.btn.htmx-request {
    pointer-events: none;
    opacity: 0.65;
}

/* ==========================================
   Mobile Table Responsive Improvements
   ========================================== */

/* On mobile: ensure table-responsive always scrolls horizontally */
@media (max-width: 991.98px) {
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* Compact table cells on mobile */
    .table td, .table th {
        font-size: 0.8rem;
        padding: 0.4rem 0.5rem;
        white-space: nowrap;
    }

    /* Action buttons: stack vertically and keep accessible */
    .table td .d-flex.gap-1 {
        flex-direction: column;
        gap: 0.25rem !important;
        align-items: center;
    }

    .table td .d-flex.gap-1 .btn-sm {
        min-width: 32px;
        min-height: 32px;
        padding: 0.2rem 0.4rem;
    }

    /* Hide secondary columns on small screens */
    .col-hide-mobile {
        display: none !important;
    }
}