/* --- Variáveis de Design System --- */
:root {
    /* Cores Principais */
    --primary-color: #dc2626;
    /* Vermelho Hammes */
    --primary-hover: #b91c1c;
    --primary-light: rgba(220, 38, 38, 0.1);

    /* Cores Neutras (Light Mode) */
    --bg-body: #f1f5f9;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;

    /* Efeitos */
    --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.3);

    /* Layout */
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --header-height: 64px;
    --transition-speed: 0.3s;
    --border-radius: 12px;
}

/* --- Dark Mode Variables --- */
body.dark-mode {
    --bg-body: #0f172a;
    --bg-sidebar: #1e293b;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ── Tema NATIVO do navegador (barra de rolagem, seletor de data, lista do select) ──
   As cores da aplicação saem dos tokens acima, mas a barra de rolagem quem desenha é o
   NAVEGADOR — e sem esta declaração ele usa o tema claro do sistema. Resultado: barra
   branca no meio de uma tela escura, em toda área rolável (modal de programação de
   viagem, tabelas da Disponibilidade da Frota, listas longas). A `.sidebar-content`
   não sofria porque tem estilo próprio, logo abaixo; o resto da aplicação, sim.

   `color-scheme` foi escolhido no lugar de espalhar `::-webkit-scrollbar` global
   justamente para NÃO disputar especificidade: as barras que já têm estilo próprio
   (a da sidebar e as dos módulos) continuam ganhando onde existem, e todas as outras
   passam a nascer no tom certo sem nenhuma regra nova.

   Declarado em três lugares de propósito: no <html> claro por padrão (torna o tema
   claro imune ao sistema operacional em modo escuro); no <html> escuro via :has(),
   que é de onde o valor propaga para a área fora do <body>; e no próprio body, para
   valer também onde :has() não for suportado.

   EFEITO ALÉM DA BARRA: no modo escuro os controles nativos que o CSS não alcança
   (lista aberta do <select>, seletor de data/hora, checkbox sem estilo) passam a ser
   desenhados escuros. Hoje eles saem claros sobre fundo escuro — é a mesma falha,
   pelo mesmo motivo. */
html { color-scheme: light; }
html:has(body.dark-mode) { color-scheme: dark; }
body.dark-mode { color-scheme: dark; }

/* ── Dark mode para módulos com Tailwind cru (grupo "Rotas e Locais" etc.) ──
   O tema escuro troca os tokens CSS, mas as utilitárias do Tailwind têm cor
   FIXA e não seguem o tema. Aqui mapeamos SÓ as neutras (fundo/texto/borda)
   para os tokens no modo escuro; cores semânticas (bg-blue-500, text-white,
   badges) ficam intactas. */
body.dark-mode .bg-white { background-color: var(--bg-card) !important; }
body.dark-mode .bg-gray-50 { background-color: var(--bg-body) !important; }
body.dark-mode .bg-gray-100 { background-color: var(--bg-body) !important; }
body.dark-mode .hover\:bg-gray-50:hover,
body.dark-mode .hover\:bg-gray-100:hover { background-color: var(--bg-body) !important; }
body.dark-mode .text-gray-900,
body.dark-mode .text-gray-800,
body.dark-mode .text-gray-700 { color: var(--text-main) !important; }
body.dark-mode .text-gray-600,
body.dark-mode .text-gray-500,
body.dark-mode .text-gray-400 { color: var(--text-secondary) !important; }
body.dark-mode .border-gray-100,
body.dark-mode .border-gray-200,
body.dark-mode .border-gray-300 { border-color: var(--border-color) !important; }
body.dark-mode .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: var(--border-color) !important; }
/* Campos de formulário no escuro — POR ELEMENTO: garante fundo/texto legíveis mesmo
   quando o input NÃO tem classe de fundo (branco padrão do navegador nos módulos
   Tailwind). Nos módulos com tokens o valor já é o mesmo, então é no-op lá. */
body.dark-mode input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]):not([type=file]):not([type=submit]):not([type=button]),
body.dark-mode select,
body.dark-mode textarea {
    background-color: var(--bg-body) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color);
}
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder { color: var(--text-secondary); opacity: 1; }

/* --- Reset & Base --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    outline: none;
}

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

a {
    text-decoration: none;
    color: inherit;
}

ul {
    list-style: none;
}

/* --- Sidebar --- */
.app-sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    min-height: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.brand-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    overflow: hidden;
    white-space: nowrap;
    cursor: pointer;
}

.brand-logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 6px;
}

.brand-icon {
    font-size: 1.5rem;
    color: var(--primary-color);
    min-width: 32px;
    display: flex;
    justify-content: center;
}

.brand-text h1 {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-main);
}

.brand-text span {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    font-weight: 600;
}

/* --- Search Bar --- */
.search-container {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input {
    width: 100%;
    padding: 10px 12px 10px 40px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.search-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* --- Menu Items --- */
.sidebar-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: 24px;
    /* Barra fina que só APARECE quando o mouse repousa sobre o menu — mantém o
       visual "clean". Por padrão fica invisível (thumb transparente). */
    scrollbar-width: thin;
    scrollbar-color: transparent transparent;
    transition: scrollbar-color .25s ease;
}
.sidebar-content:hover { scrollbar-color: rgba(100, 116, 139, .45) transparent; }
body.dark-mode .sidebar-content:hover { scrollbar-color: rgba(148, 163, 184, .4) transparent; }

.sidebar-content::-webkit-scrollbar {
    width: 9px;
}
.sidebar-content::-webkit-scrollbar-track {
    background: transparent;
}
/* O thumb começa transparente; a borda de 3px + background-clip deixam ele fino. */
.sidebar-content::-webkit-scrollbar-thumb {
    background-color: transparent;
    border-radius: 9px;
    border: 3px solid transparent;
    background-clip: padding-box;
    transition: background-color .25s ease;
}
.sidebar-content:hover::-webkit-scrollbar-thumb { background-color: rgba(100, 116, 139, .45); }
.sidebar-content:hover::-webkit-scrollbar-thumb:hover { background-color: rgba(100, 116, 139, .7); }
body.dark-mode .sidebar-content:hover::-webkit-scrollbar-thumb { background-color: rgba(148, 163, 184, .4); }
body.dark-mode .sidebar-content:hover::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 163, 184, .62); }

@media (prefers-reduced-motion: reduce) {
    .sidebar-content, .sidebar-content::-webkit-scrollbar-thumb { transition: none; }
}

.menu-section-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin: 20px 0 8px 12px;
    font-weight: 700;
}

.menu-item {
    margin-bottom: 4px;
}

.menu-link {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
}

.menu-link:hover {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.menu-link.active {
    background-color: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
}

.menu-icon {
    font-size: 1.1rem;
    min-width: 24px;
    margin-right: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.menu-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chevron-icon {
    font-size: 0.75rem;
    transition: transform 0.2s;
    opacity: 0.7;
}

.menu-link[aria-expanded="true"] .chevron-icon {
    transform: rotate(180deg);
}

/* --- Submenu --- */
.submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
    padding-left: 24px;
    /* Indent subitems */
}

.submenu.open {
    max-height: max-content; /* handled mainly by JS but this acts as fallback */
}

.submenu-link {
    display: flex;
    align-items: center;
    padding: 8px 12px 8px 24px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-left: 1px solid var(--border-color);
    margin-left: 11px;
    transition: all 0.2s;
}

/* ==========================================================================
   Bolinha de notificação pendente no menu.
   Marca o módulo que tem notificação não lida. No item PAI ela também
   aparece, senão com o submenu fechado ninguém veria.
   ========================================================================== */
.nav-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-left: auto;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: nav-dot-pulsa 2s ease-out infinite;
}

/* No item pai o chevron já ocupa a direita — a bolinha entra antes dele. */
.menu-link .nav-dot {
    margin-left: auto;
    margin-right: 8px;
}

@keyframes nav-dot-pulsa {
    0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.65); }
    70%  { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Respeita quem pediu menos animação no sistema (acessibilidade). */
@media (prefers-reduced-motion: reduce) {
    .nav-dot { animation: none; }
}

.submenu-link:hover {
    color: var(--text-main);
    border-left-color: var(--text-secondary);
    background: linear-gradient(90deg, var(--bg-body) 0%, transparent 100%);
}

.submenu-link.active {
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 600;
    background: linear-gradient(90deg, var(--primary-light) 0%, transparent 100%);
}

/* Os contadores `.menu-badge` do menu foram removidos junto com os listeners que
   os alimentavam. O aviso de item não lido agora é só a `.nav-dot`. */

/* --- Footer / User Profile --- */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.user-card {
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: var(--bg-body);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: all 0.3s;
}

.user-card-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--text-main);
    color: var(--bg-body);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-size: 0.9rem;
    font-weight: 600;
    display: block;
    /* Mostra o nome completo: quebra em mais de uma linha em vez de cortar. */
    white-space: normal;
    word-break: break-word;
    line-height: 1.2;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 6px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
}

.action-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-main);
}

/* Toolbar do rodapé: 4 botões iguais, largura distribuída, hover uniforme. */
.user-actions .action-btn {
    flex: 1;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-size: 0.95rem;
    padding: 0;
}

.user-actions .action-btn:hover {
    background: var(--border-color);
    color: var(--text-main);
}

.user-actions .logout-btn:hover {
    background: var(--primary-light);
    color: var(--primary-color);
}

/* Desktop (com mouse): os botões ficam OCULTOS e surgem ao passar o mouse
   sobre o card (foto + nome). No toque (sem hover) seguem sempre visíveis,
   senão ficariam inacessíveis no celular. */
/* Dica de reveal: os botões surgem, seguram e recolhem quando o app abre. */
@keyframes userActionsHint {
    0% { max-height: 0; opacity: 0; margin-top: 0; padding-top: 0; border-top-color: transparent; }
    18% { max-height: 60px; opacity: 1; margin-top: 12px; padding-top: 10px; border-top-color: var(--border-color); }
    72% { max-height: 60px; opacity: 1; margin-top: 12px; padding-top: 10px; border-top-color: var(--border-color); }
    100% { max-height: 0; opacity: 0; margin-top: 0; padding-top: 0; border-top-color: transparent; }
}

@media (hover: hover) {
    .user-actions {
        max-height: 0;
        margin-top: 0;
        padding-top: 0;
        border-top-color: transparent;
        opacity: 0;
        overflow: hidden;
        pointer-events: none;
    }

    /* Ao abrir o app (perms-ready): dica visual — os botões surgem, ficam um
       instante e recolhem, mostrando que existem ali. A animação roda UMA vez
       (sem fill-mode, então ao terminar o hover volta a funcionar). A transição
       cuida do reveal no hover. */
    body.perms-ready .user-actions {
        transition: max-height 0.25s ease, opacity 0.2s ease,
            margin-top 0.2s ease, padding-top 0.2s ease;
        animation: userActionsHint 1.8s ease;
    }

    .user-card:hover .user-actions,
    .user-card:focus-within .user-actions {
        max-height: 200px;
        margin-top: 12px;
        padding-top: 10px;
        border-top-color: var(--border-color);
        opacity: 1;
        pointer-events: auto;
    }
}

/* --- Main Content Area --- */
.app-main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    width: 100%;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
    position: relative;
}

.page-header {
    margin-bottom: 24px;
    animation: fadeIn 0.4s ease-out;
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 12px;
}

.page-title i {
    color: var(--primary-color);
    font-size: 1.5rem;
}

.page-description {
    color: var(--text-secondary);
    margin-top: 4px;
}

.content-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    animation: slideUp 0.4s ease-out;
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Collapsed State --- */
.app-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.app-sidebar.collapsed .brand-text,
.app-sidebar.collapsed .brand-logo-img,
.app-sidebar.collapsed .search-input,
.app-sidebar.collapsed .menu-text,
.app-sidebar.collapsed .chevron-icon,
.app-sidebar.collapsed .menu-section-label,
.app-sidebar.collapsed .submenu,
.app-sidebar.collapsed .user-info {
    display: none;
}

.app-sidebar.collapsed .brand-wrapper {
    justify-content: center;
}

.app-sidebar.collapsed .menu-link {
    justify-content: center;
    padding: 12px;
}

.app-sidebar.collapsed .menu-icon {
    margin-right: 0;
    font-size: 1.25rem;
}

.app-sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.app-sidebar.collapsed .search-container {
    padding: 16px 0;
    display: flex;
    justify-content: center;
}

.app-sidebar.collapsed .search-icon {
    position: static;
    font-size: 1.2rem;
    cursor: pointer;
}

.app-sidebar.collapsed .user-card {
    padding: 8px;
    justify-content: center;
    flex-direction: column;
    gap: 8px;
}

.app-sidebar.collapsed .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
}

.app-sidebar.collapsed .user-card-top {
    justify-content: center;
}

.app-sidebar.collapsed .user-actions {
    flex-direction: column;
}

.app-sidebar.collapsed .user-actions .action-btn {
    flex: none;
    width: 100%;
}

/* --- Tooltips for Collapsed Mode (Optional enhancement) --- */
.app-sidebar.collapsed .menu-link:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-sidebar);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    margin-left: 10px;
    z-index: 100;
}

/* --- Mobile Styles --- */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-overlay.active {
    opacity: 1;
}

.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    margin-bottom: 24px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 0 16px;
    box-shadow: var(--shadow-sm);
}

.mobile-menu-btn {
    background: transparent;
    border: none;
    font-size: 1.25rem;
    color: var(--text-main);
    cursor: pointer;
    padding: 8px;
}

.mobile-brand-text {
    font-weight: 700;
    color: var(--text-main);
}

.mobile-user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
}

@media (max-width: 768px) {
    .app-sidebar {
        position: fixed;
        left: -280px;
        height: 100vh;
        width: 280px !important;
        /* Force width */
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .app-sidebar.mobile-open {
        left: 0;
        box-shadow: var(--shadow-lg);
    }

    .mobile-overlay {
        display: block;
        pointer-events: none;
    }

    .mobile-overlay.active {
        pointer-events: auto;
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        padding: 16px;
    }

    .page-title {
        font-size: 1.5rem;
    }

    .form-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ========== Report Modal ========== */
.report-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.report-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.report-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

.report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.report-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.report-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.report-close:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

.report-body {
    padding: 24px;
}

.report-body .filter-group {
    margin-bottom: 16px;
}

.report-body .filter-group label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-main);
    margin-bottom: 6px;
}

.report-body .filter-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.9rem;
}

.report-body .filter-group select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.report-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-body);
}

@media (max-width: 768px) {
    .report-modal {
        max-width: 100%;
    }
}

/* --- Global Module Styles (Consolidated) --- */
.module-container {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    animation: fadeIn 0.4s ease-out;
}

.module-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

/* --- Buttons (Enhanced) --- */
.btn {
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

/* --- Forms & Inputs --- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 0;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    display: block;
    margin-bottom: 4px;
}

/* Checkbox/radio ficam DE FORA: senão viram caixas full-width com borda dentro de
   qualquer .form-group (ex.: lista de pessoas do compartilhar). */
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group select,
.form-group textarea {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* textarea nao herda a fonte por padrao (fica monospace em alguns navegadores) */
.form-group textarea {
    font-family: inherit;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* --- Input Wrapper with Icons --- */
.input-wrapper {
    position: relative;
}

/* Precisa de MAIS especificidade que o `.form-group input:not([type=checkbox]):not([type=radio])`
   la de cima: cada :not() conta como classe, entao aquela regra e (0,3,1) e o
   `padding: 10px 12px` dela apagava este padding-left, deixando o icone em cima
   do texto (bug do "Editar Usuario"). Com o .form-group na frente esta fica
   (0,4,1)/(0,3,1) e vence. A versao sem .form-group cobre wrapper solto. */
.input-wrapper input,
.input-wrapper select,
.form-group .input-wrapper input:not([type="checkbox"]):not([type="radio"]),
.form-group .input-wrapper select {
    padding-left: 36px;
}

/* Estes selects usam a setinha do FontAwesome (fa-chevron-down) à direita.
   Remove a seta NATIVA do navegador em TODOS os motores (Chrome/Firefox/Safari),
   senão aparece uma seta dupla. */
.input-wrapper select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.input-wrapper i {
    pointer-events: none;
}

/* --- Tables --- */
.table-container {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--bg-body);
}

th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
    vertical-align: middle;
}

tbody tr:hover {
    background: var(--bg-body);
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
}

.badge-tipo {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

/* Role Badges */
.badge-admin {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

.badge-programador {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.badge-gerente {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
}

.badge-operador {
    background: rgba(34, 197, 94, 0.1);
    color: #16a34a;
}

.badge-cadastro {
    background: rgba(251, 191, 36, 0.1);
    color: #f59e0b;
}

.badge-manutencao {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.stat-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--bg-body);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.pendencia-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 600;
    margin: 2px;
}


/* --- Actions & Icons --- */
.actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

/* --- Filters Bar --- */
.filters-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.filters-bar select,
.filters-bar input {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.9rem;
}

/* --- Toggles --- */
.toggle-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle {
    position: relative;
    width: 48px;
    height: 26px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--border-color);
    border-radius: 26px;
    transition: 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.toggle input:checked+.toggle-slider {
    background: #16a34a;
}

.toggle input:checked+.toggle-slider::before {
    transform: translateX(22px);
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

/* --- Modals (Consolidated) --- */
.veiculo-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9998;
    padding: 20px;
}

.veiculo-modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.veiculo-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
}

.veiculo-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.veiculo-modal-body {
    padding: 24px;
}

/* --- Mobile Adjustments --- */
@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr !important;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .veiculo-modal {
        max-width: 100%;
    }
}

/* --- Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== Motorista Edit Modal ========== */
.motorista-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 20px;
}

.motorista-modal-overlay.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.motorista-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: slideUp 0.3s ease;
    overflow: hidden;
}

.motorista-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 24px 16px;
    border-bottom: 1px solid var(--border-color);
}

.motorista-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.motorista-modal-close:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

.motorista-modal-body {
    padding: 24px;
}

.motorista-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-body);
}

@media (max-width: 768px) {
    .motorista-modal {
        max-width: 100%;
    }
}

/* ========== Notification System ========== */

/* Bell Button */
.notif-bell-btn {
    position: relative;
}

.notif-bell-btn i {
    font-size: 1rem;
    transition: transform 0.3s ease;
}

.notif-bell-btn:hover i {
    transform: rotate(15deg);
    color: var(--primary-color);
}

/* Badge */
.notif-badge {
    position: absolute;
    top: -2px;
    right: -4px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    font-size: 0.6rem;
    font-weight: 800;
    min-width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    animation: notifBadgePulse 2s ease-in-out infinite;
    z-index: 5;
    border: 2px solid var(--bg-body);
}

@keyframes notifBadgePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 2px 12px rgba(239, 68, 68, 0.8);
    }
}

/* Dropdown */
.notif-dropdown {
    position: fixed;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    width: 340px;
    max-height: 400px;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.notif-dropdown.active {
    display: flex;
    animation: notifSlideUp 0.25s ease-out;
}

@keyframes notifSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Dropdown Header */
.notif-dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-main);
}

.notif-dropdown-header span {
    display: flex;
    align-items: center;
    gap: 8px;
}

.notif-dropdown-header span i {
    color: var(--primary-color);
}

.notif-mark-all-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.notif-mark-all-btn:hover {
    background: var(--primary-light);
}

/* Dropdown List */
.notif-dropdown-list {
    overflow-y: auto;
    flex: 1;
    scrollbar-width: thin;
    scrollbar-color: var(--text-secondary) transparent;
}

/* Notification Item */
.notif-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.notif-item:last-child {
    border-bottom: none;
}

.notif-item:hover {
    background: var(--bg-body);
}

.notif-item:hover .notif-avatar {
    transform: scale(1.05);
}

/* Avatar */
.notif-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color) 0%, #f87171 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

/* Content */
.notif-content {
    flex: 1;
    min-width: 0;
}

.notif-text {
    font-size: 0.82rem;
    color: var(--text-main);
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notif-time {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.notif-time i {
    font-size: 0.6rem;
}

/* Unread Dot */
.notif-dot {
    width: 8px;
    height: 8px;
    min-width: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    box-shadow: 0 0 6px rgba(220, 38, 38, 0.4);
}

/* Empty State */
.notif-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
    color: var(--text-secondary);
}

.notif-empty i {
    font-size: 2rem;
    opacity: 0.4;
    margin-bottom: 10px;
}

.notif-empty p {
    font-size: 0.85rem;
    font-weight: 500;
}

/* Dark Mode Adjustments */
body.dark-mode .notif-dropdown {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.dark-mode .notif-badge {
    border-color: var(--bg-sidebar);
}

/* Collapsed sidebar: hide dropdown */
.app-sidebar.collapsed .notif-dropdown {
    display: none !important;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .notif-dropdown {
        left: 8px;
        right: 8px;
        max-height: 320px;
    }
}

/* ========== Toasts System ========== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    /* Toast é transiente e SEMPRE precisa aparecer — acima de qualquer modal
       do sistema (os módulos usam até 10040, ex. .estd-modal do Estoque; os
       componentes de O.S. usam 10000-10003). Só o confirm fica acima dele. */
    z-index: 10055;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast-item {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    padding: 14px 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 250px;
    max-width: 400px;
    pointer-events: auto;
    animation: toastSlideIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    border-left: 4px solid var(--primary-color);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast-item.toast-success {
    border-left-color: #10b981;
}

.toast-item.toast-error {
    border-left-color: #ef4444;
}

.toast-item.toast-info {
    border-left-color: #3b82f6;
}

.toast-icon {
    font-size: 1.2rem;
}

.toast-success .toast-icon {
    color: #10b981;
}

.toast-error .toast-icon {
    color: #ef4444;
}

.toast-info .toast-icon {
    color: #3b82f6;
}

.toast-content {
    flex: 1;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.toast-close:hover {
    color: var(--text-main);
}

.toast-item.toast-hiding {
    opacity: 0;
    transform: translateX(100%);
}

body.dark-mode .toast-item {
    background: rgba(30, 41, 59, 0.95);
    color: #f8fafc;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 4px 10px rgba(0, 0, 0, 0.2);
}

body.dark-mode .toast-content {
    color: #f8fafc;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========== Custom Confirm Modal ========== */
.custom-confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    /* Acima do toast e de TODOS os modais (até 10040): um confirm renderizado
       por baixo de um modal aberto fica invisível e inclicável — a reprova de
       requisição de O.S. travava exatamente assim (revisão da fase 9). */
    z-index: 10060;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.custom-confirm-overlay.active {
    opacity: 1;
    visibility: visible;
}

.custom-confirm {
    background: var(--bg-card, #ffffff);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    padding: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 1px solid var(--border-color, #e2e8f0);
}

.custom-confirm-overlay.active .custom-confirm {
    transform: scale(1) translateY(0);
}

.custom-confirm-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.custom-confirm-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.custom-confirm-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main, #1e293b);
    margin: 0;
}

.custom-confirm-message {
    color: var(--text-secondary, #64748b);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 24px;
}

.custom-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.custom-confirm-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.custom-confirm-cancel {
    background: var(--bg-body, #f8fafc);
    color: var(--text-main, #1e293b);
    border: 1px solid var(--border-color, #e2e8f0);
}

.custom-confirm-cancel:hover {
    background: #e2e8f0;
}

.custom-confirm-confirm {
    background: var(--primary-color, #3b82f6);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.custom-confirm-confirm:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

body.dark-mode .custom-confirm {
    background: var(--bg-card, #1e293b);
}
body.dark-mode .custom-confirm-cancel {
    background: rgba(255,255,255,0.05);
    color: #f8fafc;
}
body.dark-mode .custom-confirm-cancel:hover {
    background: rgba(255,255,255,0.1);
}

/* --- Loading Utilities --- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

/* Spinner CSS puro — usado por admin-links-gr, jornada */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    flex-shrink: 0;
}

.spinner.spinner-sm {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.spinner.spinner-lg {
    width: 28px;
    height: 28px;
    border-width: 3px;
}

/* Skeleton shimmer — para placeholders de conteúdo enquanto carrega */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--border-color) 25%,
        var(--bg-body)      50%,
        var(--border-color) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: 6px;
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton * {
    visibility: hidden;
}

body.dark-mode .skeleton {
    background: linear-gradient(
        90deg,
        #334155 25%,
        #1e293b 50%,
        #334155 75%
    );
    background-size: 200% 100%;
}