/* Custom CSS for Viagem Legal - Minimals UI Kit Style */

/* ============================================
   Base Styles
   ============================================ */

:root {
    --mobile-bottom-nav-height: 68px;
}

/* Smooth scrolling - only for users without motion preference */
@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* Content visibility for below-fold elements */
.below-fold {
    content-visibility: auto;
    contain-intrinsic-size: 0 500px;
}

/* Custom scrollbar - Minimals style */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--grey-400);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--grey-500);
}

/* Thin scrollbar for sidebar */
.scrollbar-thin::-webkit-scrollbar {
    width: 4px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: rgba(145, 158, 171, 0.3);
}

/* Focus styles for accessibility - using primary color */
*:focus-visible {
    outline: 2px solid var(--primary-main);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   Sidebar Navigation - Minimals Dark Style
   ============================================ */

/* Sidebar Navigation Item */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color var(--transition-fast),
                color var(--transition-fast);
}

.sidebar-nav-item:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

.sidebar-nav-item.active {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
}

.sidebar-nav-item.active .sidebar-nav-icon {
    color: var(--sidebar-text-active);
}

/* Sidebar Icon */
.sidebar-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    color: inherit;
}

.sidebar-nav-icon svg {
    width: 100%;
    height: 100%;
}

/* Sidebar Text */
.sidebar-nav-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   Header Styles
   ============================================ */

/* Header Icon Button */
.header-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    background-color: transparent;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast);
}

.header-icon-btn:hover {
    background-color: var(--grey-200);
    color: var(--text-primary);
}

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

/* Shadow for dropdown menus */
.shadow-dropdown {
    box-shadow: var(--shadow-dropdown);
}

.shadow-dialog {
    box-shadow: var(--shadow-dialog);
}

/* ============================================
   Legacy Sidebar Styles (for compatibility)
   ============================================ */

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    display: flex;
}

.sidebar-panel {
    width: 280px;
    max-width: 85vw;
    height: 100%;
    background-color: var(--sidebar-bg);
    box-shadow: var(--shadow-z24);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1.5rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    overflow-y: auto;
    flex: 1;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background-color var(--transition-fast),
                color var(--transition-fast);
}

.sidebar-item:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

.sidebar-item.active {
    background-color: var(--sidebar-bg-active);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.sidebar-item-danger {
    color: #FF5630;
}

.sidebar-item-danger:hover {
    background-color: rgba(255, 86, 48, 0.08);
    color: #FF5630;
}

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

.sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-full);
    color: var(--sidebar-text);
    transition: background-color var(--transition-fast),
                color var(--transition-fast);
}

.sidebar-close:hover {
    background-color: var(--sidebar-bg-hover);
    color: var(--sidebar-text-hover);
}

/* ============================================
   No-JS Fallback
   ============================================ */

.no-js [x-cloak] {
    display: none !important;
}

.no-js .hamburger-btn {
    display: none !important;
}

noscript .no-js-fallback {
    display: block !important;
}

noscript .js-only {
    display: none !important;
}

/* ============================================
   Hamburger Button
   ============================================ */

.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    background-color: transparent;
    border: none;
    cursor: pointer;
    transition: background-color var(--transition-fast),
                color var(--transition-fast);
}

.hamburger-btn:hover {
    background-color: var(--grey-200);
    color: var(--text-primary);
}

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

/* Prevent body scroll when sidebar is open */
body.sidebar-open {
    overflow: hidden;
}

/* ============================================
   Touch-Friendly Targets (Mobile)
   ============================================ */

@media (pointer: coarse) {
    .sidebar-item,
    .sidebar-nav-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .hamburger-btn,
    .header-icon-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ============================================
   High Contrast Mode
   ============================================ */

@media (prefers-contrast: high) {
    .sidebar-item.active,
    .sidebar-nav-item.active {
        background-color: var(--primary-main);
        color: #fff;
    }

    .sidebar-item:hover,
    .sidebar-nav-item:hover {
        background-color: var(--grey-600);
        color: #fff;
    }
}

/* WCAG 2.1 AA Compliance - Color Contrast Verification
 * 
 * Color combinations used (all meet 4.5:1 minimum for AA):
 * - text-gray-900 (#111827) on white: 15.3:1 ✓
 * - text-gray-700 (#374151) on white: 10.5:1 ✓  
 * - text-gray-600 (#4B5563) on white: 7.5:1 ✓
 * - text-blue-600 (#2563EB) on white: 4.5:1 ✓
 * - white on bg-blue-600 (#2563EB): 4.5:1 ✓
 * - text-gray-900 on bg-gray-50 (#F9FAFB): 14.8:1 ✓
 * 
 * Focus indicators:
 * - outline: 2px solid #3B82F6 with 2px offset: clearly visible
 * 
 * Link underlines:
 * - Navigation links have sufficient contrast in all states
 */

/* PWA Install Banner Styles */
#pwa-install-banner {
    animation: slideUp 0.3s ease-out;
}

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

#pwa-install-banner.hidden {
    display: none !important;
}

/* ============================================
   Mobile Bottom Navigation
   ============================================ */

.mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    background-color: var(--bg-paper);
    border-top: 1px solid var(--grey-300);
    box-shadow: 0 -8px 16px 0 rgba(145, 158, 171, 0.12);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-bottom-nav-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    height: var(--mobile-bottom-nav-height);
    padding: 0.5rem 0.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.mobile-bottom-nav-item:hover {
    color: var(--text-primary);
    background-color: var(--grey-100);
}

.mobile-bottom-nav-item.active {
    color: var(--primary-main);
}

.mobile-bottom-nav-item.active .mobile-bottom-nav-icon {
    transform: translateY(-1px);
}

.mobile-bottom-nav-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--transition-fast);
}

.mobile-bottom-nav-icon svg {
    width: 100%;
    height: 100%;
}

.mobile-bottom-nav-label {
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    letter-spacing: 0.01em;
}

@media (max-width: 1023.98px) {
    .layout-main-content {
        padding-bottom: calc(var(--mobile-bottom-nav-height) + 16px + env(safe-area-inset-bottom)) !important;
    }

    #pwa-install-banner.pwa-banner-with-bottom-nav {
        bottom: calc(var(--mobile-bottom-nav-height) + env(safe-area-inset-bottom));
    }
}

/* PWA Standalone Mode Styles */
body.pwa-standalone {
    -webkit-tap-highlight-color: transparent;
    /* Bottom safe area for gesture bar */
    padding-bottom: env(safe-area-inset-bottom);
}

/* Hide install banner when already installed */
@media (display-mode: standalone) {
    #pwa-install-banner {
        display: none !important;
    }
}

/* ============================================
   Tab Button Style - Minimals
   ============================================ */

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all 150ms;
    border: none;
    background: transparent;
    cursor: pointer;
}

.tab-btn:hover {
    color: var(--text-primary);
    background-color: var(--grey-100);
}

.tab-btn.active {
    color: var(--text-primary);
    background-color: var(--grey-200);
}

/* ============================================
   Vehicle Card Icon Background
   ============================================ */

.vehicle-icon-bg {
    background-color: rgba(0, 167, 111, 0.08);
}

.vehicle-icon-bg-inactive {
    background-color: var(--grey-200);
}

/* ============================================
   PWA Native-Like Behavior
   ============================================ */

/* Prevenir zoom por pinça e bounce */
html {
    /* Evita bounce/overscroll no iOS e pull-to-refresh no Android */
    overscroll-behavior: none;
    /* Altura total considerando safe areas */
    height: 100%;
}

body {
    /* Evita bounce no body */
    overscroll-behavior: none;
    /* Altura mínima com safe areas */
    min-height: 100%;
    min-height: 100dvh; /* Dynamic viewport height para mobile */
    /* Previne context menu no long press */
    -webkit-touch-callout: none;
}

/* Container de scroll interno (evita bounce no conteúdo) */
main {
    overscroll-behavior: contain;
}

/* ============================================
   Desabilitar seleção em elementos de UI
   ============================================ */

button,
a,
nav,
.sidebar-item,
.sidebar-nav-item,
.mobile-bottom-nav-item,
.header-icon-btn,
.hamburger-btn,
.tab-btn,
.minimals-btn,
[role="button"],
[role="tab"],
[role="menuitem"] {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    /* Melhora responsividade do tap (remove delay de 300ms) */
    touch-action: manipulation;
    /* Remove highlight no tap (iOS/Android) */
    -webkit-tap-highlight-color: transparent;
    /* Previne menu de contexto no long press */
    -webkit-touch-callout: none;
}

/* Manter seleção em campos de input e conteúdo textual */
input,
textarea,
[contenteditable="true"],
p,
span,
h1, h2, h3, h4, h5, h6,
article,
.selectable {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ============================================
   Prevenir menu de contexto em imagens
   ============================================ */

img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    pointer-events: none;
}

/* Permitir clique em imagens que são links */
a img {
    pointer-events: auto;
}

/* ============================================
   Touch Feedback Aprimorado
   ============================================ */

/* Feedback visual no tap */
button:active,
a:active,
.sidebar-item:active,
.sidebar-nav-item:active,
.header-icon-btn:active,
.hamburger-btn:active,
.tab-btn:active,
.minimals-btn:active,
[role="button"]:active {
    transform: scale(0.98);
    transition: transform 0.1s ease-out;
}

/* Respeitar preferência de movimento reduzido */
@media (prefers-reduced-motion: reduce) {
    button:active,
    a:active,
    .sidebar-item:active,
    .sidebar-nav-item:active,
    .header-icon-btn:active,
    .hamburger-btn:active,
    .tab-btn:active,
    .minimals-btn:active,
    [role="button"]:active {
        transform: none;
    }
}

/* ============================================
   Safe Areas Aprimoradas (Notch/Dynamic Island)
   ============================================ */

/* Header com safe area no topo */
header {
    padding-top: env(safe-area-inset-top, 0px);
}

/* Footer e elementos fixos no bottom */
footer,
.fixed-bottom,
#pwa-install-banner {
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Sidebar com safe areas laterais */
.sidebar-panel {
    padding-left: env(safe-area-inset-left, 0px);
}

/* Conteúdo principal com safe areas */
@media (display-mode: standalone), (display-mode: fullscreen) {
    body {
        /* Bottom/lateral safe areas only — top is handled by the header */
        padding-bottom: env(safe-area-inset-bottom, 0px);
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }

    /* Ajuste para landscape em dispositivos com notch */
    @media (orientation: landscape) {
        .lg\:ml-\[280px\] {
            margin-left: calc(280px + env(safe-area-inset-left, 0px));
        }
    }
}

/* ============================================
   Modo Standalone - Status Bar iOS
   ============================================ */

@media (display-mode: standalone) {
    /* Background estendido para a status bar no iOS */
    html {
        background-color: var(--sidebar-bg, #212B36);
    }

    body {
        background-color: var(--bg-default, #F4F6F8);
    }
}

/* ============================================
   Dashboard cards and quick actions
   ============================================ */

.dashboard-quick-link {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    min-height: 116px;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.dashboard-quick-link:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-z8);
}

.dashboard-quick-link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius-sm);
}

.dashboard-quick-link-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.dashboard-live-card {
    border: 1px solid rgba(0, 167, 111, 0.3);
    background: linear-gradient(145deg, #ffffff 0%, #f1fbf7 100%);
}

.dashboard-sonar-dot {
    position: relative;
    display: inline-flex;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 9999px;
    background-color: var(--primary-main);
}

.dashboard-sonar-ring {
    position: absolute;
    inset: -0.35rem;
    border-radius: 9999px;
    background-color: rgba(0, 167, 111, 0.28);
    animation: dashboard-sonar 2s cubic-bezier(0, 0, 0.2, 1) infinite;
    pointer-events: none;
}

.dashboard-sonar-ring-delay {
    animation-delay: 0.4s;
}

.dashboard-history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border: 1px solid var(--grey-300);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.dashboard-history-row:hover {
    border-color: var(--primary-main);
    background-color: rgba(0, 167, 111, 0.04);
}

@keyframes dashboard-sonar {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }
    100% {
        transform: scale(1.9);
        opacity: 0;
    }
}

/* Fix: preserve Tailwind side paddings on minimals inputs with prefix/suffix */
.minimals-input.pl-10 {
    padding-left: 2.5rem;
}

.minimals-input.pl-12 {
    padding-left: 3rem;
}

.minimals-input.pr-8 {
    padding-right: 2rem;
}
