/* CORTEX GCAR - Sistema de Gestao de Carros */
/* Cores originais do GCAR mantidas.
   Do CORTEX Saúde vieram apenas a tipografia e os tokens de forma
   (raio, sombra, espacamento) — nao a paleta. */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #0ea5e9;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --dark: #1e293b;
    --light: #f8fafc;
    --gray: #64748b;
    --gray-light: #e2e8f0;

    /* Forma, herdada do design system do CORTEX Saúde */
    --radius: 14px;
    --radius-sm: 10px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 4px 16px rgba(15, 23, 42, 0.12);

    --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --sidebar-width: 232px;
}

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

body {
    font-family: var(--font);
    background-color: #f1f5f9;
    color: var(--dark);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Numeros tabulares onde ha coluna de dados: sem isso a coluna "danca". */
.table td, .table th, .num, .stat-value { font-variant-numeric: tabular-nums; }

/* Login Page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dark);
    padding: 20px;
}

.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.login-logo p {
    color: var(--gray);
    font-size: 13px;
}

.tenant-info {
    background: var(--light);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
    text-align: center;
    display: none;
}

.tenant-info.active {
    display: block;
}

.tenant-info .tenant-name {
    font-weight: 600;
    color: var(--dark);
}

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--gray-light);
    border-radius: var(--radius);
    font-family: var(--font);
    background: #fff;
    color: var(--dark);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

.form-control.error {
    border-color: var(--danger);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 15px;
    min-height: 36px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s;
}

.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

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

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

.btn-secondary {
    background: #fff;
    color: var(--dark);
    border-color: var(--gray-light);
}

.btn-secondary:hover { background: var(--light); }

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

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

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: white;
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 12px 16px;
    background: var(--light);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 73px;
}

.sidebar-logo {
    max-width: 180px;
    height: auto;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 12px;
}

.nav-section-title {
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
    padding: 8px 20px;
    letter-spacing: 0.04em;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.2s;
}

.nav-link:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

.nav-link i {
    font-size: 16px;
    width: 24px;
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 13px;
}

.user-role {
    font-size: 11px;
    color: rgba(255,255,255,0.5);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

/* Top Bar */
.topbar {
    background: white;
    padding: 11px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 500;
    min-height: 73px;
}

.tenant-name-header {
    font-size: 11px;
    color: var(--gray);
    font-weight: 500;
    margin-left: 16px;
    padding-left: 16px;
    border-left: 1px solid var(--gray-light);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 21px;
    cursor: pointer;
    color: var(--dark);
}

.page-title {
    font-size: 19px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--light);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--gray);
    position: relative;
}

.btn-icon:hover {
    background: var(--gray-light);
}

.btn-icon .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Content Area */
.content {
    padding: 20px;
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.stat-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.stat-card-icon.primary { background: rgba(79,70,229,0.1); color: var(--primary); }
.stat-card-icon.success { background: rgba(34,197,94,0.1); color: var(--success); }
.stat-card-icon.warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.stat-card-icon.danger { background: rgba(239,68,68,0.1); color: var(--danger); }

.stat-value {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}

.stat-label {
    color: var(--gray);
    font-size: 13px;
    font-weight: 400;
}

.stat-change {
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 8px;
}

.stat-change.positive { color: var(--success); }
.stat-change.negative { color: var(--danger); }

/* Card */
.card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.card-header {
    padding: 13px 16px;
    border-bottom: 1px solid var(--gray-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 16px;
    font-weight: 600;
}

.card-body {
    padding: 16px;
}

/* Rotulo de campo: mesmo tratamento do .label do CORTEX Saúde */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--gray);
    margin-bottom: 5px;
}

/* Table */
.table-responsive {
    overflow-x: auto;
}

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

.table th,
.table td {
    padding: 9px 13px;
    text-align: left;
    border-bottom: 1px solid var(--gray-light);
}

.table tbody tr:hover { background: var(--light); }

.table th {
    font-size: 12px;
    text-transform: uppercase;
    color: var(--gray);
    font-weight: 500;
    letter-spacing: 0.04em;
    background: transparent;
    white-space: nowrap;
}

.table tbody tr:hover {
    background: var(--light);
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 999px;
}

.badge-success { background: rgba(34,197,94,0.1); color: var(--success); }
.badge-warning { background: rgba(245,158,11,0.1); color: var(--warning); }
.badge-danger { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-primary { background: rgba(79,70,229,0.1); color: var(--primary); }
.badge-secondary { background: rgba(100,116,139,0.1); color: var(--gray); }
.badge-info { background: rgba(14,165,233,0.1); color: var(--secondary); }

/* Map */
.map-container {
    height: 400px;
    border-radius: var(--radius);
    overflow: hidden;
}

#map {
    height: 100%;
    width: 100%;
    z-index: 1 !important;
}

/* Força o mapa a ficar abaixo do header */
.leaflet-pane,
.leaflet-map-pane,
.leaflet-tile-pane,
.leaflet-overlay-pane,
.leaflet-shadow-pane,
.leaflet-marker-pane,
.leaflet-tooltip-pane,
.leaflet-popup-pane {
    z-index: 1 !important;
}

.leaflet-top,
.leaflet-bottom {
    z-index: 10 !important;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Modal dentro de overlay - sempre visível quando overlay ativo */
.modal-overlay .modal {
    display: flex !important;
    flex-direction: column;
    position: static;
    width: auto;
    height: auto;
    background: white;
    border-radius: 16px;
    max-width: 90vw;
    max-height: 85vh;
    animation: modalSlideIn 0.3s ease forwards;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
    overflow: auto;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
}

/* Modal standalone (sem overlay) */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal.show {
    display: flex !important;
}

.modal .modal-content {
    background: white;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease forwards;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

@keyframes modalSlideIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

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

.modal-title {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 21px;
    cursor: pointer;
    color: var(--gray);
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--gray-light);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-shrink: 0;
}

/* Alert/Toast */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background: white;
    border-radius: 10px;
    padding: 16px 20px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info { border-left: 4px solid var(--primary); }

/* Loading */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--gray-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}

.empty-state i {
    font-size: 52px;
    color: var(--gray-light);
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 16px;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--gray);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

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

    .main-content {
        margin-left: 0;
    }

    .menu-toggle {
        display: block;
    }

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

/* Notificações */
.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.notification-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    width: 380px;
    max-height: 500px;
    display: none;
    z-index: 1000;
    overflow: hidden;
}

.notification-dropdown.active {
    display: block;
}

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

.notification-header h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.notification-list {
    max-height: 400px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    gap: 12px;
    padding: 14px 20px;
    cursor: pointer;
    transition: background 0.2s;
    border-bottom: 1px solid var(--gray-light);
}

.notification-item:hover {
    background: var(--light);
}

.notification-item.unread {
    background: #f0f9ff;
}

.notification-item.unread:hover {
    background: #e0f2fe;
}

.notification-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
}

.notification-icon i {
    font-size: 15px;
}

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font-weight: 600;
    font-size: 12px;
    margin-bottom: 2px;
    color: var(--dark);
}

.notification-message {
    font-size: 11px;
    color: var(--gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-time {
    font-size: 10px;
    color: var(--gray);
    margin-top: 4px;
}

/* Celular: tabela vira cartões (rótulo de cada célula vem do cabeçalho, ver base.html)
   e barras de filtro quebram linha em vez de alargar a página. */
@media (max-width: 768px) {
    html, body { overflow-x: hidden; }
    .main-content, .content { max-width: 100vw; }
    .content > div[style*="display:flex"], .content > div[style*="display: flex"] { flex-wrap: wrap; gap: 8px !important; }
    .content > div[style*="display:flex"] > div, .content > div[style*="display: flex"] > div { flex-wrap: wrap; }
    .content .form-control[style*="width"] { width: 100% !important; max-width: 100% !important; }
    .table-responsive .table thead { display: none; }
    .table-responsive .table, .table-responsive .table tbody { display: block; width: 100%; }
    .table-responsive .table tr { display: block; border: 1px solid #e2e8f0; border-radius: 10px;
        margin: 10px; padding: 6px 10px; background: #fff; }
    .table-responsive .table td { display: flex; justify-content: space-between; align-items: center;
        gap: 12px; border: none; padding: 6px 0; text-align: right !important; width: auto !important; }
    .table-responsive .table td::before { content: attr(data-label); font-weight: 600; color: #64748b;
        font-size: 12px; text-align: left; flex: 0 0 40%; }
    .table-responsive .table td[colspan] { display: block; text-align: center !important; }
    .table-responsive .table td[colspan]::before, .table-responsive .table td:not([data-label])::before { content: none; }
}
@media (max-width: 768px) {
    .topbar { flex-wrap: wrap; gap: 6px; max-width: 100vw; }
    .topbar-left { min-width: 0; flex: 1 1 auto; flex-wrap: wrap; gap: 6px; }
    .tenant-name-header { display: none; }
}
