/* ============================================================================
   BASE COMPONENTS - Layout, Animacoes, Busca, Touch
   Extraido de base.html em 08/02/2026
   Conteudo: Density, Safe Areas, Animacoes, Search Results, Touch UI
   ============================================================================ */

/* 📐 SISTEMA DE DENSIDADE ESCALÁVEL (Compact/Cozy/Comfy) */
/* Ativa via: document.documentElement.dataset.density = 'cozy' */

/* Default: Compact (40px) */
:root {
    --item-h: 40px;
    --pad-x: 8px;
    --pad-y: 10px;
}

/* Cozy: 48px - Mais espaçoso */
:root[data-density="cozy"] {
    --item-h: 48px;
    --pad-x: 10px;
    --pad-y: 12px;
}

/* Comfy: 56px - Máximo espaçamento */
:root[data-density="comfy"] {
    --item-h: 56px;
    --pad-x: 12px;
    --pad-y: 14px;
}

/* 🚫 Aplicação automática nos itens do menu - MOVIDO para sidebar.html */


/* Safe area para iOS */
@supports (padding: max(0px)) {
    .safe-top {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    .safe-bottom {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    .safe-left {
        padding-left: max(1rem, env(safe-area-inset-left));
    }
    .safe-right {
        padding-right: max(1rem, env(safe-area-inset-right));
    }
}

/* 📱 IMERSÃO NATIVE-LIKE (01/02/2026)
   ================================================================
   Header com top negativo para se estender acima da viewport
   e padding-top para compensar e manter conteúdo visível.
   ================================================================ */

/* Header mobile: posição negativa + padding para compensar */
@media (max-width: 1023px) {
    header.fixed.safe-top {
        top: -50px !important;  /* Puxa o header 50px para cima */
        padding-top: 50px !important;  /* Compensa com padding */
    }
}

/* 📱 BOTTOM NAV - Safe Area para iOS (iPhone X+) */
.bottom-nav {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

/* 📱 CORREÇÃO: Menu oculto por padrão em mobile (antes do Alpine.js carregar) */
/* x-cloak esconde elementos até Alpine.js inicializar */
/* Prevenir zoom em inputs no iOS */
@media screen and (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* Classes para modo economia */
.reduced-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

/* 🎯 A11Y: Respeitar preferência de movimento reduzido do usuário */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

.battery-saver .animate-pulse,
.battery-saver .animate-spin {
    animation: none !important;
}

/* Modo offline */
.offline-mode {
    filter: grayscale(0.5);
}

.offline-mode::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #ef4444;
    z-index: 9999;
}

/* Animações mobile */
@keyframes slideInUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

@keyframes slideInDown {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

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

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Animações para modais customizados */
@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@keyframes modalOut {
    from {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
    to {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
}

/* Touch feedback */
.touchable {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    touch-action: manipulation;
}

/* ========================================
   DROPDOWN DE RESULTADOS DA BUSCA
   ======================================== */
.search-results-dropdown {
    background: #ffffff;
    border-color: rgba(99, 102, 241, 0.15);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.15),
                0 2px 8px rgba(0, 0, 0, 0.08);
}

.dark .search-results-dropdown {
    background: #18181b;
    border-color: rgba(129, 140, 248, 0.2);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4),
                0 2px 8px rgba(129, 140, 248, 0.1);
}

/* Header dos resultados */
.search-results-header {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.05) 0%, rgba(99, 102, 241, 0.02) 100%);
    border-color: rgba(99, 102, 241, 0.1);
}

.search-results-header p {
    color: #1e293b;
    font-weight: 600;
}

.dark .search-results-header {
    background: linear-gradient(135deg, rgba(129, 140, 248, 0.08) 0%, rgba(129, 140, 248, 0.03) 100%);
    border-color: rgba(129, 140, 248, 0.15);
}

.dark .search-results-header p {
    color: #f4f4f5;
}

/* Badge de contagem */
.search-count-badge {
    background: rgba(99, 102, 241, 0.12);
    color: var(--color-primary-600);
    font-weight: 600;
}

.dark .search-count-badge {
    background: rgba(129, 140, 248, 0.15);
    color: var(--color-primary-500);
}

/* Body dos resultados */
.search-results-body {
    background: transparent;
}

/* Scrollbar personalizada para dropdown */
.search-results-body::-webkit-scrollbar {
    width: 6px;
}

.search-results-body::-webkit-scrollbar-track {
    background: transparent;
}

.search-results-body::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2);
    border-radius: 3px;
}

.search-results-body::-webkit-scrollbar-thumb:hover {
    background: rgba(99, 102, 241, 0.3);
}

.dark .search-results-body::-webkit-scrollbar-thumb {
    background: rgba(129, 140, 248, 0.2);
}

.dark .search-results-body::-webkit-scrollbar-thumb:hover {
    background: rgba(129, 140, 248, 0.3);
}

/* Item de resultado na busca */
.search-result-item {
    display: flex;
    align-items: center;
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.25rem;
    border-radius: 0.5rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
    background: transparent;
    /* Animação de entrada */
    animation: slideInResult 0.3s ease-out forwards;
    opacity: 0;
}

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

.search-result-item:last-child {
    margin-bottom: 0;
}

.search-result-item:hover,
.search-result-item.selected {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.2);
    transform: translateX(4px);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.1);
}

.dark .search-result-item:hover,
.dark .search-result-item.selected {
    background: rgba(129, 140, 248, 0.1);
    border-color: rgba(129, 140, 248, 0.25);
    box-shadow: 0 2px 8px rgba(129, 140, 248, 0.15);
}

/* Estado selected mais destacado */
.search-result-item.selected {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.3);
}

.dark .search-result-item.selected {
    background: rgba(129, 140, 248, 0.15);
    border-color: rgba(129, 140, 248, 0.35);
}

.search-result-item i {
    color: var(--color-primary-600);
    font-size: 1.25rem;
    width: 2.5rem;
    min-width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex-shrink: 0;
    border-radius: 0.5rem;
    background: rgba(99, 102, 241, 0.08);
    transition: all 0.2s ease;
}

.dark .search-result-item i {
    color: var(--color-primary-500);
    background: rgba(129, 140, 248, 0.1);
}

.search-result-item:hover i {
    background: rgba(99, 102, 241, 0.15);
    transform: scale(1.05);
}

.dark .search-result-item:hover i {
    background: rgba(129, 140, 248, 0.18);
}

.search-result-item .result-text {
    color: #1e293b;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.4;
}

.dark .search-result-item .result-text {
    color: #f4f4f5;
}

.search-result-item .result-path {
    color: #64748b;
    font-size: 0.6875rem;
    margin-top: 0.125rem;
    font-weight: 500;
    line-height: 1.3;
}

.dark .search-result-item .result-path {
    color: #a1a1aa;
}

/* Destaque do texto buscado */
.search-highlight {
    background: rgba(99, 102, 241, 0.2);
    color: var(--color-primary-600);
    font-weight: 700;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
}

.dark .search-highlight {
    background: rgba(129, 140, 248, 0.25);
    color: var(--color-primary-500);
}

/* Mensagem de nenhum resultado */
.search-no-results {
    color: #64748b;
}

.dark .search-no-results {
    color: #a1a1aa;
}

/* Footer dos resultados */
.search-results-footer {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.02) 0%, rgba(99, 102, 241, 0.05) 100%);
    border-color: rgba(99, 102, 241, 0.1);
}

.search-results-footer p {
    color: #64748b;
    font-weight: 500;
}

.dark .search-results-footer {
    background: linear-gradient(180deg, rgba(129, 140, 248, 0.03) 0%, rgba(129, 140, 248, 0.08) 100%);
    border-color: rgba(129, 140, 248, 0.15);
}

.dark .search-results-footer p {
    color: #a1a1aa;
}

/* Teclas do teclado (kbd) */
.keyboard-key {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.125rem;
    padding: 0 0.25rem;
    font-size: 0.625rem;
    font-weight: 600;
    font-family: ui-monospace, monospace;
    border-radius: 0.25rem;
    background: rgba(99, 102, 241, 0.1);
    color: var(--color-primary-600);
    border: 1px solid rgba(99, 102, 241, 0.2);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.dark .keyboard-key {
    background: rgba(129, 140, 248, 0.12);
    color: var(--color-primary-500);
    border-color: rgba(129, 140, 248, 0.25);
}

/* ========================================
   HEADER DO MENU - TÍTULO E BOTÕES
   ======================================== */
/* Título do menu - CORES DIRETAS */
:not(.dark) .menu-title {
    color: #1e293b !important;
}

.dark .menu-title {
    color: #f4f4f5 !important;
}

/* Botões de ação do header */
.header-action-btn {
    color: var(--menu-icon);
    background: transparent;
}

.header-action-btn:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--menu-text);
}

.dark .header-action-btn:hover {
    background: rgba(129, 140, 248, 0.1);
}

.header-action-btn:active {
    background: rgba(99, 102, 241, 0.12);
    transform: scale(0.95);
}

.dark .header-action-btn:active {
    background: rgba(129, 140, 248, 0.15);
}

/* ========================================
   USER FOOTER - MOVIDO PARA menu.html
   ======================================== */
/* Estilos do user-footer foram movidos para
   project/templates/menu.html para arquitetura
   100% autônoma do componente (05/02/2026) */

/* ═══════════════════════════════════════════════════════════════
   🚫 ÍCONES E INDICADORES DO ASIDE - REMOVIDOS
   ═══════════════════════════════════════════════════════════════
   Todas as regras aside .bg-primary, aside .bg-white/*, e
   cores de ícones por módulo (aside nav a[href*="..."] i.bi)
   foram REMOVIDAS. O sidebar.html tem essas regras com
   seletor #sidebar-component (maior especificidade).
   Removido em 05/02/2026 para arquitetura 100% autônoma.
   ═══════════════════════════════════════════════════════════════ */

/* Botões otimizados para touch */
.btn, button {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* ⚠️ CRÍTICO: Inputs DEVEM ter touch-action: auto para funcionar em mobile */
input, textarea, select {
    touch-action: auto !important;
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* Custom scrollbar mobile */
.custom-scrollbar {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

/* Bottom navigation safe area */
.bottom-nav {
    padding-bottom: calc(1rem + var(--safe-area-bottom));
}

/* Swipe indicator */
.swipe-indicator {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 134px;
    height: 5px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 100px;
}

.dark .swipe-indicator {
    background: rgba(255, 255, 255, 0.3);
}

/* PWA styles */
@media (display-mode: standalone) {
    .pwa-padding {
        padding-top: calc(1rem + var(--safe-area-top));
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .landscape-hidden {
        display: none !important;
    }
    /* aside max-width removido - sidebar.html tem seu próprio CSS */
}

/* Input focus no zoom */
input:focus,
select:focus,
textarea:focus {
    font-size: 16px !important;
}

/* Ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::before {
    width: 300px;
    height: 300px;
}

/* Estilos para modais customizados */
.modal-backdrop {
    animation: fadeIn 0.3s ease;
}

.modal-content {
    animation: modalIn 0.3s ease;
}

.modal-content.closing {
    animation: modalOut 0.2s ease;
}

/* Estilos para input do prompt */
.prompt-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.2s ease;
    background: white;
    color: #111827;
}

.dark .prompt-input {
    background: #1f2937;
    border-color: #374151;
    color: #f3f4f6;
}

.prompt-input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.dark .prompt-input:focus {
    border-color: #a78bfa;
    box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.1);
}

.empresa-badge {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

@media (max-width: 768px) {
    .empresa-badge {
        max-width: 120px;
        font-size: 0.7rem;
    }
}
