:root {
    --bg-color: #0b0f19;
    --sidebar-bg: #121824;
    --card-bg: rgba(22, 30, 49, 0.7);
    --border-color: rgba(255, 255, 255, 0.05);
    
    --primary: #10b981;
    --primary-glow: rgba(16, 185, 129, 0.15);
    
    --text-color: #f3f4f6;
    --text-muted: #6b7280;
    
    --orange: #f97316;
    --blue: #3b82f6;
    --purple: #8b5cf6;
    --red: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    /* S1 FIX: fontul Google Fonts scos (dependinta CDN) - stiva de fonturi de
       sistem acopera bine aceeasi estetica fara request extern */
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow-x: hidden;
    height: 100vh;
}

/* LOGIN WRAPPER */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: var(--bg-color);
}

.login-card {
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.brand-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
}

.login-error {
    color: var(--red);
    font-size: 12px;
    text-align: center;
    margin-top: 10px;
    font-weight: 600;
}

/* #10 FIX: banner de parola implicita */
.insecure-banner {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--red);
    color: var(--red);
    padding: 12px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 16px;
}

/* #15/#14: banner de alerte de siguranta neconfirmate - portocaliu, distinct
   de bannerul rosu de parola implicita */
.insecure-banner.safety-banner {
    background: rgba(249, 115, 22, 0.15);
    border-color: var(--orange);
    color: var(--orange);
}

/* #14: meniu hamburger mobil - ascuns implicit, aparent doar sub 600px */
.mobile-menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 18px;
    cursor: pointer;
    margin-bottom: 12px;
}

.mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1199;
}

.mobile-backdrop.active {
    display: block;
}

/* MAIN CONTAINER GRID */
.dashboard-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-box {
    background-color: var(--primary-glow);
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-icon {
    color: var(--primary);
    width: 24px;
    height: 24px;
}

.brand h2 {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background: rgba(239, 68, 68, 0.1);
    color: var(--red);
    margin-top: 2px;
    transition: all 0.3s;
}

.status-badge.online {
    background: rgba(16, 185, 129, 0.1);
    color: var(--primary);
}

/* Navigation Menu */
.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    background: transparent;
    border: none;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s;
    width: 100%;
}

.nav-item svg {
    width: 18px;
    height: 18px;
}

.nav-item:hover, .nav-item.active {
    color: var(--text-color);
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    border-left: 3px solid var(--primary);
}

.config-section h3, .quick-actions h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.config-section h3 svg, .quick-actions h3 svg {
    width: 14px;
    height: 14px;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    border-radius: 6px;
    color: var(--text-color);
    font-size: 13px;
    outline: none;
    transition: all 0.2s;
}

.form-group input:focus {
    border-color: var(--primary);
}

.checkbox-group {
    display: flex;
    align-items: center;
}

.btn {
    width: 100%;
    padding: 12px;
    border-radius: 6px;
    border: none;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

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

.btn-connect:hover {
    background-color: #059669;
}

.btn-action {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.btn-action:hover {
    background-color: rgba(255, 255, 255, 0.08);
}

.btn-action svg {
    width: 14px;
    height: 14px;
}

.btn-logout {
    background-color: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--red);
}

.btn-logout:hover {
    background-color: rgba(239, 68, 68, 0.15);
}

.quick-action-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.quick-action-row .btn {
    margin-bottom: 0;
    flex: 1;
}

/* info-icon "i" mic cu tooltip - hover pe desktop, click/tap pe mobil */
.info-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
}

.info-tooltip {
    display: none;
    position: absolute;
    bottom: 130%;
    right: 0;
    width: 220px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text-color);
    text-transform: none;
    letter-spacing: normal;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.info-icon:hover .info-tooltip,
.info-icon:focus .info-tooltip,
.info-icon.info-open .info-tooltip {
    display: block;
}

.last-updated {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 10px;
}

/* Main Panel Styling */
.main-content {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
    overflow-y: auto;
}

/* Tabs active logic */
.main-tab-content {
    display: none;
}

.main-tab-content.active-tab {
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100%;
}

/* Status Cards Row */
.status-cards {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
}

.card {
    position: relative;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    gap: 14px;
    align-items: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* #13f: toolbar de personalizare + drag&drop pt. widget-uri */
.widget-toolbar {
    display: flex;
    justify-content: flex-end;
}

.widget-drag-handle, .widget-visibility-toggle {
    display: none;
    position: absolute;
    top: 6px;
    z-index: 2;
    font-size: 13px;
    color: var(--text-muted);
}

.widget-drag-handle {
    left: 8px;
    cursor: grab;
}

.widget-visibility-toggle {
    right: 8px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.widget-grid.customize-mode .card {
    border-style: dashed;
    padding-top: 26px;
}

.widget-grid.customize-mode .widget-drag-handle,
.widget-grid.customize-mode .widget-visibility-toggle {
    display: block;
}

.widget-grid .widget-user-hidden {
    display: none;
}

.widget-grid.customize-mode .widget-user-hidden {
    display: flex;
    opacity: 0.4;
}

.card-icon-box {
    padding: 12px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-icon-box svg {
    width: 22px;
    height: 22px;
}

.card-icon-box.orange { background-color: rgba(249, 115, 22, 0.1); color: var(--orange); }
.card-icon-box.green { background-color: rgba(16, 185, 129, 0.1); color: var(--primary); }
.card-icon-box.blue { background-color: rgba(59, 130, 246, 0.1); color: var(--blue); }
.card-icon-box.purple { background-color: rgba(139, 92, 246, 0.1); color: var(--purple); }
.card-icon-box.red { background-color: rgba(239, 68, 68, 0.1); color: var(--red); }

.card-data .label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.card-data .value {
    font-size: 20px;
    font-weight: 800;
    margin-top: 4px;
}

.card-data .value small {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.card-data .sub-value {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* #13b/c/d: status live, baterie grafica, semnal bare, gauge generic */
.battery-graphic-box, .signal-bars-box {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
}

.signal-bar {
    fill: rgba(255, 255, 255, 0.12);
    transition: fill 0.3s;
}

.signal-bar.filled {
    fill: var(--primary);
}

.gauge-card {
    flex-direction: column;
    align-items: stretch;
}

.gauge-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 4px;
}

.gauge-value {
    font-size: 22px;
    font-weight: 800;
    margin-top: -20px;
}

.gauge-value small {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.gauge-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 20px;
    flex-grow: 1;
}

.map-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    height: 100%;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.card-header h3 {
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h3 svg {
    width: 16px;
    height: 16px;
    color: var(--primary);
}

.gps-coords {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    font-family: monospace;
}

#map {
    width: 100%;
    flex-grow: 1;
    background-color: #1a2230;
}

/* Leaflet Map adjustments to match dark mode */
.leaflet-container {
    background: #0f172a !important;
}
.leaflet-tile {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

.telemetry-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 20px;
}

.lean-widget-box {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lean-widget-box label {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.lean-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.lean-values {
    display: flex;
    gap: 24px;
    margin-top: 8px;
}

.lean-val-item {
    text-align: center;
}

.lean-val-item .label {
    display: block;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
}

.lean-val-item .value {
    font-size: 16px;
    font-weight: 800;
    color: var(--primary);
}

.diag-details-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.diag-detail-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    background-color: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 12px;
}

.diag-detail-item .label {
    color: var(--text-muted);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.diag-detail-item .label svg {
    width: 14px;
    height: 14px;
}

.diag-detail-item .value {
    font-weight: 700;
}

/* HISTORIC TAB & MAINTENANCE TAB TABLE */
.list-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 0;
    overflow: hidden;
}

.table-wrapper {
    overflow-x: auto;
    width: 100%;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.data-table th, .data-table td {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background-color: rgba(0, 0, 0, 0.15);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 0.5px;
}

.data-table tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

.data-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.02);
}

.btn-table-action {
    background-color: var(--primary-glow);
    color: var(--primary);
    border: 1px solid rgba(16, 185, 129, 0.2);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-table-action:hover {
    background-color: var(--primary);
    color: var(--bg-color);
}

.btn-table-action.btn-maint-reset {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--blue);
    border-color: rgba(59, 130, 246, 0.2);
}

.btn-table-action.btn-maint-reset:hover {
    background-color: var(--blue);
    color: #fff;
}

.form-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

/* #13a: Setari - subnav orizontal + subtab-uri, clase distincte fata de
   .nav-item/.main-tab-content ca sa nu interfereze cu switchMainTab() */
.settings-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    max-width: 520px;
}

.settings-subnav {
    display: flex;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.settings-subnav-item {
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 10px 2px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-subnav-item:hover {
    color: var(--text-color);
}

.settings-subnav-item.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.settings-subtab-content {
    display: none;
}

.settings-subtab-content.active-subtab {
    display: block;
}

/* #15: tab Loguri - filtru, paginare, detaliu JSON brut */
.logs-filter-bar {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logs-filter-bar .form-group {
    margin-bottom: 0;
    min-width: 140px;
}

.logs-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 14px;
    font-size: 12px;
    color: var(--text-muted);
}

.logs-details-short {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-muted);
    margin-right: 8px;
}

.logs-raw-json {
    white-space: pre-wrap;
    word-break: break-all;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.2);
    padding: 8px;
    border-radius: 6px;
    margin-top: 6px;
    max-width: 500px;
}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #0f172a;
    padding: 10px 20px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 14px;
    display: none;
    z-index: 1000;
}

.toast.toast-error {
    background: var(--red);
    color: #fff;
}

/* Modal de confirmare (inlocuieste confirm() nativ) */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1100;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background-color: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

.modal-box p {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 10px;
}

.modal-actions .btn {
    flex: 1;
    width: auto;
}

@media (max-width: 1024px) {
    .dashboard-container {
        grid-template-columns: 1fr;
        height: auto;
    }
    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        height: auto;
    }
    .main-content {
        height: auto;
    }
    .status-cards {
        grid-template-columns: 1fr 1fr;
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    #map, #history-map {
        height: 350px;
    }
}

/* #14: breakpoint telefon real - sidebar devine sertar (drawer) peste continut,
   deschis prin meniul hamburger, in loc de doar comprimat ca la 1024px */
@media (max-width: 600px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        z-index: 1200;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .status-cards {
        grid-template-columns: 1fr;
    }
}
