:root {
    /* Brigada Militar Style Guide */
    --primary: #F4F4F1;
    --secondary: #555347;
    --secondary-light: #6a6859;
    --tertiary: #D9B022;
    --tertiary-hover: #b8951d;
    
    --bg-main: #F4F4F1;
    --bg-card: #FFFFFF;
    --text-main: #484848;
    --text-muted: #888888;
    --border: #dcdcdc;
    
    --success: #28A745;
    --warning: #FFC107;
    --danger: #DC3545;
    --info: #17A2B8;
    --dark: #484848;
    
    /* Identidade do Sistema Controle de Viatura (Header) */
    --system-brand: #3b3896; 

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
}

/* Layout */
#app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--secondary);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 0;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px;
    font-size: 1.2rem;
    font-weight: 700;
    color: white;
    background-color: rgba(0,0,0,0.1); /* Slightly darker for logo area */
    margin-bottom: 24px;
}

.logo i {
    color: var(--tertiary);
    font-size: 1.8rem;
}

nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 12px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #e0e0e0;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: 500;
    transition: all 0.2s ease;
}

.nav-item i {
    font-size: 1.25rem;
}

.nav-item:hover {
    color: white;
    background-color: var(--secondary-light);
}

.nav-item.active {
    color: white;
    background-color: rgba(0,0,0,0.2);
    border-left: 4px solid var(--tertiary);
}

.user-profile {
    margin: 12px;
    padding: 12px;
    background-color: rgba(0,0,0,0.15);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: white;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.user-role {
    font-size: 0.75rem;
    color: #d0d0d0;
}

#switchRoleBtn {
    background: transparent;
    border: none;
    color: #e0e0e0;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    transition: color 0.2s;
}

#switchRoleBtn:hover {
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background-color: var(--bg-main);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 40px;
    background-color: var(--system-brand);
    color: white;
    box-shadow: var(--shadow-sm);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.content-view {
    padding: 32px 40px;
    animation: fadeIn 0.3s ease-out;
}

.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background-color: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 20px;
    border: 1px solid var(--border);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
}

.bg-blue { background-color: var(--info); }
.bg-orange { background-color: var(--warning); }
.bg-green { background-color: var(--success); }

.stat-details h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--dark);
}

/* Common Card */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark);
    font-size: 0.9rem;
}
.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    background-color: #FAFAFA;
    transition: border-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--system-brand);
    background-color: #FFF;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.radio-group {
    display: flex;
    gap: 16px;
}
.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.form-section-title {
    font-size: 1.1rem;
    color: var(--dark);
    margin: 24px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.flex-column-gap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    font-family: inherit;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background-color: var(--tertiary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--tertiary-hover);
}

.btn-secondary {
    background-color: var(--border);
    color: var(--dark);
}

.btn-secondary:hover {
    background-color: #c0c0c0;
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(72, 72, 72, 0.5); /* Escura with opacity */
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    padding: 32px;
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h2 {
    margin-bottom: 8px;
    color: var(--dark);
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.role-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.role-btn {
    padding: 12px;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    text-align: left;
    color: var(--dark);
}

.role-btn:hover {
    border-color: var(--tertiary);
    background: #fdfaf0;
    color: var(--tertiary);
}

/* Alert Grouping Styles */
.alert-vtr-card {
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border-left-width: 4px;
    border-left-style: solid;
    user-select: none;
    min-width: 120px;
    text-align: center;
    gap: 8px;
}

.alert-vtr-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.alert-vtr-card.danger {
    background: linear-gradient(135deg, #fff0f3 0%, #ffe0e6 100%);
    border-left-color: var(--danger);
    color: #780000;
}

.alert-vtr-card.warning {
    background: linear-gradient(135deg, #fffdf2 0%, #fef1b8 100%);
    border-left-color: var(--warning);
    color: #9c7003;
}

.alert-vtr-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.9rem;
    font-weight: 600;
}

.alert-badge {
    background: rgba(0,0,0,0.1);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: bold;
}

.alert-vtr-details {
    background: #fff;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    padding: 16px;
    display: none; /* hidden by default */
    flex-direction: column;
    gap: 12px;
    margin-top: -4px; /* visually attach to the card above */
    margin-bottom: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.alert-vtr-details.open {
    display: flex;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.alert-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-main);
    border-radius: var(--radius-sm);
    border-left: 3px solid;
}

.alert-item.danger { border-left-color: var(--danger); }
.alert-item.warning { border-left-color: var(--warning); }

/* Dashboard Premium Styles */
.dash-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
}

.dash-card {
    background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: var(--radius-md);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}

.dash-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.08);
}

.dash-card-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
}

.dash-card-title {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dash-card-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--dark);
}

.dash-card.danger-card .dash-card-icon { background: #ffe0e6; color: var(--danger); }
.dash-card.warning-card .dash-card-icon { background: #fef1b8; color: var(--warning); }
.dash-card.success-card .dash-card-icon { background: #c6eed8; color: var(--success); }
.dash-card.info-card .dash-card-icon { background: #e0f2fe; color: var(--info); }


/* Portal Mode Styles */
body.portal-mode .sidebar { display: none !important; }
body.portal-mode .main-content { margin-left: 0; padding: 0; }
body.portal-mode header { display: none !important; }

#view-portal {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0A192F 0%, #000000 100%);
    padding: 24px;
    position: relative;
    color: #ffffff;
}

.portal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 32px;
    max-width: 800px;
    width: 100%;
}

.portal-card {
    background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 24px;
    padding: 48px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 24px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    text-decoration: none;
    color: #ffffff;
}

.portal-card:hover {
    transform: translateY(-8px) scale(1.02);
    box-shadow: 0 20px 40px rgba(0,0,0,0.8);
}

.portal-card.checklist {
    background: linear-gradient(135deg, #0052D4 0%, #4364F7 50%, #6FB1FC 100%);
}

.portal-card.abastecimento {
    background: linear-gradient(135deg, #FF416C 0%, #FF4B2B 100%);
}

.portal-icon {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.3);
}

.portal-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.portal-desc {
    color: rgba(255, 255, 255, 0.9);
    font-size: 1rem;
    line-height: 1.5;
}

.btn-voltar-portal {
    margin-bottom: 24px;
    display: none;
}
body.portal-mode .btn-voltar-portal {
    display: inline-flex;
}


.btn-portal-lock {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    padding: 8px 16px;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    backdrop-filter: blur(10px);
    transition: all 0.2s ease;
}
.btn-portal-lock:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}


/* ------------------------------------- */
/* MOBILE RESPONSIVENESS                 */
/* ------------------------------------- */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.d-mobile-only {
    display: none !important;
}

.btn-icon {
    padding: 8px;
    font-size: 1.5rem;
    background: transparent;
    border: none;
    color: var(--dark);
    cursor: pointer;
}

/* Make tables scrollable */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

@media (max-width: 768px) {
    /* Show mobile only elements */
    .d-mobile-only { display: inline-flex !important; }

    /* Sidebar transforms to mobile drawer */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 100;
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }

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

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    /* Main content adjusts to fill screen */
    .main-content {
        margin-left: 0;
    }

    /* Adjust grids for mobile */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    .dash-grid {
        grid-template-columns: 1fr;
    }

    .portal-grid {
        grid-template-columns: 1fr;
    }

    .portal-card {
        padding: 32px 24px;
        gap: 16px;
    }

    .portal-icon {
        width: 64px;
        height: 64px;
        font-size: 2rem;
    }

    #view-portal h1 {
        font-size: 2rem !important;
    }

    /* Ensure tables have wrapper for scroll if not already */
    .card {
        overflow-x: auto;
    }
}

