:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #f3f4f6;
    --bg-app: #f9fafb;
    --bg-surface: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    overflow: hidden;
}

/* App Layout */
.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    z-index: 10;
}

.sidebar-header {
    padding: 0 20px 30px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--primary);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.logo-icon {
    font-size: 1.5rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 0 10px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: var(--transition);
}

.nav-item:hover {
    background-color: var(--secondary);
    color: var(--text-main);
}

.nav-item.active {
    background-color: #eef2ff;
    color: var(--primary);
}

.sidebar-footer {
    padding: 20px;
    margin-top: auto;
}

.btn-whatsapp {
    width: 100%;
    padding: 12px;
    background-color: #25D366;
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-whatsapp:hover {
    background-color: #128C7E;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-main);
    cursor: pointer;
    margin-right: 15px;
}

.topbar {
    height: 70px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    z-index: 5;
}

.topbar h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.views-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    position: relative;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cards & Dashboard */
.card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-lg);
    background-color: #eef2ff;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.bg-success { background-color: #d1fae5; color: var(--success); }
.bg-warning { background-color: #fef3c7; color: var(--warning); }
.bg-info { background-color: #dbeafe; color: var(--info); }

.stat-info h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 700;
    margin-top: 5px;
}

.text-sm {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 400;
}

.dashboard-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
}

/* Activity List */
.activity-list {
    list-style: none;
    margin-top: 15px;
}

.activity-list li {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.activity-list li:last-child {
    border-bottom: none;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    font-style: italic;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    font-size: 0.9rem;
}

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

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

.btn-secondary {
    background-color: var(--secondary);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #e5e7eb;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}
.btn-danger:hover {
    background-color: #b91c1c;
}

.btn-block {
    width: 100%;
    justify-content: center;
    margin-top: 15px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* View Header */
.view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.search-box {
    display: flex;
    align-items: center;
    background-color: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 15px;
    width: 300px;
}

.search-box i {
    color: var(--text-muted);
    margin-right: 10px;
}

.search-box input {
    border: none;
    outline: none;
    width: 100%;
    font-size: 0.9rem;
}

/* Tables */
.table-card {
    padding: 0;
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    padding: 15px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background-color: #f8fafc;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

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

.badge {
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-disponivel { background-color: #d1fae5; color: var(--success); }
.badge-alugada { background-color: #fee2e2; color: var(--danger); }
.badge-manutencao { background-color: #fef3c7; color: var(--warning); }
.badge-ativo { background-color: #d1fae5; color: var(--success); }
.badge-encerrado { background-color: #e5e7eb; color: var(--text-muted); }


/* Kanban Board */
.kanban-board {
    display: flex;
    gap: 20px;
    height: calc(100vh - 220px);
    overflow-x: auto;
    padding-bottom: 10px;
}

.kanban-column {
    flex: 1;
    min-width: 280px;
    background-color: #f1f5f9;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.kanban-header {
    padding: 15px;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border);
}

.kanban-header .badge {
    background-color: var(--border);
    color: var(--text-muted);
}

.kanban-cards {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.k-card {
    background-color: var(--bg-surface);
    padding: 15px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    cursor: grab;
    border-left: 4px solid var(--primary);
    transition: var(--transition);
}

.k-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.k-card h4 {
    font-size: 0.95rem;
    margin-bottom: 5px;
}

.k-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.k-card .meta {
    margin-top: 10px;
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

.modal-lg {
    max-width: 800px;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.modal-body {
    padding: 20px;
    max-height: 80vh;
    overflow-y: auto;
}

.split-perfil {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

/* Forms */
.form-group {
    margin-bottom: 15px;
}

.form-group.row {
    display: flex;
    gap: 15px;
}

.form-group.row .col {
    flex: 1;
}

label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--text-main);
}

input, select, textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Perfil & Notes */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    background-color: #e0e7ff;
    color: var(--primary);
}

.mt-2 { margin-top: 10px; }

.notes-list {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.note-item {
    background-color: var(--secondary);
    padding: 10px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
}

.note-item .date {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 3px;
    display: block;
}

.add-note-box {
    border-top: 1px solid var(--border);
    padding-top: 15px;
}

.note-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
}

.hint-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: block;
}

.highlight-val {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    background-color: #f1f5f9;
    padding: 8px;
    border-radius: var(--radius-md);
    text-align: center;
}

/* ================================
   MOBILE RESPONSIVENESS
=================================== */
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 9;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

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

@media (max-width: 768px) {
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 8px;
        font-size: 1.25rem;
        cursor: pointer;
    }
    
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        width: 285px !important;
        max-width: 86vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        transform: translateX(-100%) !important;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45) !important;
        z-index: 10000 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

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

    .sidebar-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important;
        background: rgba(0, 0, 0, 0.65) !important;
        backdrop-filter: blur(2px) !important;
        -webkit-backdrop-filter: blur(2px) !important;
        z-index: 9998 !important;
    }

    .topbar {
        padding: 8px 12px !important;
        height: auto !important;
        min-height: 58px !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    #page-title {
        font-size: 1rem !important;
        max-width: 130px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    .user-profile span#logged-user-name {
        display: none !important;
    }
    
    .user-profile i.fa-chevron-down {
        display: none !important;
    }

    /* Redução amigável de botões no topo mobile */
    .topbar .btn-sm {
        padding: 6px 10px !important;
        font-size: 0.74rem !important;
    }

    /* Previne zoom automático desagradável no iOS Safari */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* Modais fluidas e scrolláveis no iOS e Android */
    .modal {
        padding: 10px !important;
    }

    .modal-content {
        max-height: 90dvh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 14px !important;
        padding: 20px 16px !important;
    }

    .views-container {
        padding: 12px !important;
    }

    .dashboard-cards {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .dashboard-charts {
        grid-template-columns: 1fr !important;
    }

    .split-perfil {
        grid-template-columns: 1fr !important;
    }

    .form-group.row {
        flex-direction: column !important;
        gap: 0 !important;
    }

    .view-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    .search-box {
        width: 100% !important;
    }

    .btn {
        min-height: 44px; /* Touch target recomendado Apple/Google */
        justify-content: center;
    }
    
    .table-card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .data-table th, .data-table td {
        padding: 12px 10px !important;
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }

    .kanban-board {
        padding-bottom: 20px !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .kanban-column {
        min-width: 85vw !important;
    }
}

/* ================================
   FROTA DASHBOARD, RASTREADOR & ÓLEO (1.000 KM)
=================================== */
.alert-banner-oleo {
    background: linear-gradient(90deg, #fef2f2 0%, #fffbeb 100%);
    border: 1px solid #fecaca;
    border-left: 5px solid var(--danger);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.alert-banner-oleo.warning-only {
    background: linear-gradient(90deg, #fffbeb 0%, #fefce8 100%);
    border-color: #fde68a;
    border-left-color: var(--warning);
}

.section-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.section-card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.gps-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.gps-online {
    background: #d1fae5;
    color: #065f46;
}

.gps-preconfig {
    background: #dbeafe;
    color: #1e40af;
}

.gps-blocked {
    background: #fee2e2;
    color: #991b1b;
}

.gps-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    display: inline-block;
    animation: pulseGps 1.8s infinite;
}

@keyframes pulseGps {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.45; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}

.km-progress-wrap {
    width: 100%;
    min-width: 140px;
    max-width: 220px;
}

.km-progress-bar {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin: 5px 0;
}

.km-progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 0.3s ease;
}

.km-inline-input {
    width: 95px;
    padding: 5px 8px;
    font-size: 0.82rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-weight: 600;
}

/* ================================
   CONTRATO PADRÃO & GOV.BR PREVIEW
=================================== */
.contrato-paper {
    background: #ffffff;
    color: #111827;
    padding: 36px 42px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    font-family: 'Arial', 'Helvetica Neue', sans-serif;
    line-height: 1.55;
    font-size: 13.5px;
    max-height: 72vh;
    overflow-y: auto;
}

.contrato-paper h2 {
    text-align: center;
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.contrato-paper .sub-header {
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 18px;
}

.contrato-paper h4 {
    font-size: 13.5px;
    font-weight: 700;
    margin-top: 18px;
    margin-bottom: 8px;
    text-transform: uppercase;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 3px;
}

.contrato-paper p {
    margin-bottom: 8px;
    text-align: justify;
}

.govbr-sign-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 22px;
    margin-bottom: 18px;
    page-break-inside: avoid;
}

.govbr-sign-box {
    border: 2px dashed #2563eb;
    background: #f8fafc;
    border-radius: 8px;
    padding: 14px;
    text-align: center;
    min-height: 115px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.govbr-sign-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    color: #1d4ed8;
    background: #dbeafe;
    padding: 3px 10px;
    border-radius: 999px;
    margin: 0 auto 8px;
}

.contrato-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.contrato-tab-btn {
    padding: 9px 14px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-size: 0.84rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}

.contrato-tab-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.tracker-telemetry-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.telemetry-box {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.telemetry-box span {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.telemetry-box strong {
    font-size: 0.98rem;
    color: var(--text-main);
}

/* ==================================================
   MARCADOR DA MOTO & RADAR CHIP IOT NO MAPA AO VIVO
===================================================== */
.leaflet-marker-icon.moto-live-div-icon {
    background: transparent !important;
    border: none !important;
    transition: transform 1.8s linear;
}

.moto-iot-marker-wrap {
    position: relative;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.moto-iot-pulse-ring {
    position: absolute;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(16, 185, 129, 0.28);
    border: 2px solid #10b981;
    animation: motoRadarPulse 1.8s infinite ease-out;
    pointer-events: none;
}

.moto-iot-pulse-ring.blocked {
    background: rgba(239, 68, 68, 0.28);
    border-color: #ef4444;
}

@keyframes motoRadarPulse {
    0% {
        transform: scale(0.65);
        opacity: 1;
    }
    100% {
        transform: scale(1.85);
        opacity: 0;
    }
}

.moto-iot-pin {
    position: relative;
    z-index: 3;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0284c7 0%, #0f172a 100%);
    border: 3px solid #ffffff;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.05rem;
}

.moto-iot-pin.blocked {
    background: linear-gradient(135deg, #dc2626 0%, #7f1d1d 100%);
}

.moto-iot-floating-card {
    position: absolute;
    bottom: 54px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.94);
    color: #f8fafc;
    padding: 6px 11px;
    border-radius: 8px;
    border: 1.5px solid #38bdf8;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
    font-family: 'Inter', sans-serif;
    font-size: 0.73rem;
    line-height: 1.35;
    z-index: 4;
    pointer-events: none;
}

.moto-iot-floating-card::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #38bdf8 transparent transparent transparent;
}

