:root {
    /* Colores Corporativos Premium */
    --primary: #0f172a;
    /* Azul noche muy oscuro */
    --accent: #3b82f6;
    /* Azul vibrante */
    --success: #10b981;
    /* Verde esmeralda */
    --warning: #f59e0b;
    /* Ambar */
    --danger: #ef4444;
    /* Rojo */
    --secondary: #64748b;
    /* Gris azulado para acciones secundarias */
    --bg: #f8fafc;
    /* Gris muy claro, casi blanco */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
}

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

body {
    background-color: var(--bg);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    height: 100dvh; /* iPad/Safari: respeta la barra dinámica del navegador */
    overflow: hidden;
}

/* Scrollbar Style */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transition: all 0.3s ease;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: white;
}

.brand span {
    color: var(--accent);
}

.nav-links {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    /* Firefox */
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
    height: 100%;
    /* Asegurar que ocupe el espacio disponible */
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: all 0.2s;
    font-weight: 500;
}

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

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

.user-profile {
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

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

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    /* iPad/Safari: deja MÁS aire arriba para que el header y los botones de acción
       no queden bajo la barra de pestañas del navegador. */
    padding-top: max(3.75rem, calc(env(safe-area-inset-top) + 2.25rem));
    overflow-y: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.page-title h1 {
    font-size: 1.8rem;
    color: var(--text-main);
}

.page-title p {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    transition: transform 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

/* Estilos específicos para badges de severidad */
.severity-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.severity-low {
    background: #e0f2fe;
    color: #0369a1;
}

.severity-med {
    background: #ffedd5;
    color: #c2410c;
}

.severity-high {
    background: #fee2e2;
    color: #991b1b;
}

.severity-fatal {
    background: #1c1917;
    color: #f5f5f5;
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-success {
    background-color: #d1fae5;
    color: #065f46;
}

.status-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.status-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Empresas List */
.section-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.table-container {
    background: var(--card-bg);
    border-radius: 1rem;
    overflow-x: auto;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
}

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

th,
td {
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}

th {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.875rem;
}

tr:last-child td {
    border-bottom: none;
}

.company-name {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
}

.company-icon {
    width: 32px;
    height: 32px;
    background-color: #e2e8f0;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.action-btn {
    padding: 0.5rem 1rem;
    background-color: white;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-main);
    transition: all 0.2s;
}

.action-btn:hover {
    background-color: #f8fafc;
    border-color: #94a3b8;
}

/* Icon placeholders */
.icon {
    font-style: normal;
}

/* Semáforo visual */
.traffic-light {
    display: flex;
    gap: 4px;
}

.light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #e2e8f0;
}

.light.active-green {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.light.active-yellow {
    background-color: var(--warning);
    box-shadow: 0 0 8px var(--warning);
}

.light.active-red {
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
}

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

.modal-content {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    width: 100%;
    max-width: 550px;
    max-height: 90vh;
    max-height: 88dvh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: slideUp 0.3s ease;
    position: relative;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    line-height: 1.5;
    background-color: white;
    transition: border-color 0.2s;
    height: auto;
    /* Allow padding to define height */
    min-height: 40px;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn-cancel {
    background: white;
    border: 1px solid #cbd5e1;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
}

.btn-save {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 500;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.toast {
    background: white;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 300px;
    border-left: 4px solid var(--accent);
    animation: slideInRight 0.3s ease forwards;
    opacity: 0;
    transform: translateX(100%);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

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

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(10px);
    }
}

/* Utility to hide sections initially with animation capability */
.hidden-section {
    display: none;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.visible-section {
    display: grid;
    /* restored to grid or block via JS */
    opacity: 1;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* ============================ */
/* NEW WIZARD STYLES (ADDED)    */
/* ============================ */

/* Botones y Estilos Globales Extra */
.action-btn:hover {
    transform: translateY(-1px);
}

.next-btn {
    background: var(--primary);
    color: white;
    border: none;
    font-size: 1.1rem;
    padding: 0.75rem 1.5rem;
}

.next-btn:hover {
    background: var(--primary);
    /* Maintain color but allow transform from global */
    opacity: 0.9;
}

/* Wizard Styles */
.option-card {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 1rem;
    padding: 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text-main);
}

.option-card:hover {
    border-color: var(--primary);
    background: #f0fdf4;
    /* Light green tint */
    transform: translateY(-3px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.option-card.selected {
    border-color: var(--primary);
    background: #dcfce7;
    box-shadow: 0 0 0 2px var(--primary);
}

.tag-pill {
    background: #f1f5f9;
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-weight: 500;
    color: var(--text-muted);
}

.tag-pill:hover {
    background: #e2e8f0;
    border-color: var(--text-muted);
    color: var(--text-main);
}

.tag-pill:active {
    background: var(--primary);
    color: white;
}

/* Animation for Voice Recording */
@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.pulse-animation {
    animation: pulse-red 1.5s infinite;
}

/* ============================ */
/* PRINT OPTIMIZATION           */
/* ============================ */
@media print {
    body {
        visibility: hidden;
        background-color: white;
        height: auto;
        overflow: visible;
    }

    /* Ocultar todo lo que no sea el modal de vista previa */
    .sidebar,
    .toast-container,
    .header,
    .dashboard-grid,
    .view-section,
    #ai-widget-btn,
    #ai-widget-panel,
    .no-print {
        display: none !important;
    }

    /* Hacer visible y posicionar el modal */
    #modalPDFPreview {
        display: block !important;
        visibility: visible !important;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: auto;
        background: white !important;
        z-index: 9999;
        overflow: visible !important;
    }

    #modalPDFPreview .modal-content {
        visibility: visible !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        width: 100% !important;
        height: auto !important;
        background: white !important;
    }

    /* Ocultar la barra superior del modal (Cerrar, Imprimir) */
    #modalPDFPreview .modal-content>div:first-child {
        display: none !important;
    }

    /* El área de impresión (hoja blanca) */
    #pdf-content {
        visibility: visible !important;
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        min-height: auto !important;
        padding: 0 !important;
        background: white !important;
    }

    /* Ocultar toolbar de descarga al imprimir */
    #acta-toolbar {
        display: none !important;
    }

    /* Asegurar visibilidad de hijos */
    #pdf-content * {
        visibility: visible !important;
    }

    @page {
        size: letter portrait;
        margin: 25mm 25mm 25mm 30mm;
    }
}

/* ============================ */
/* LOGIN SCREEN STYLES (NEW)    */
/* ============================ */
.login-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle at top left, #1e293b, #0f172a),
        url('https://images.unsplash.com/photo-1550751827-4bd374c3f58b?auto=format&fit=crop&q=80&w=2070') center/cover;
    background-blend-mode: multiply;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.login-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 3rem;
    border-radius: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-header {
    margin-bottom: 2rem;
}

.login-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    background: #f1f5f9;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem auto;
}

.login-header h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 0.25rem;
}

.btn-login {
    width: 100%;
    background: var(--accent);
    color: white;
    padding: 1rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 1rem;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.4);
}

.btn-login:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.5);
}

.login-footer {
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.login-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

/* AI Thinking Animation */
@keyframes thinking-pulse {
    0% {
        opacity: 0.4;
        transform: scale(0.95);
    }

    50% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0.4;
        transform: scale(0.95);
    }
}

/* Vision AI Specifics */
#vision-container {
    border: 4px solid #333;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.2);
    background: #000;
}

#ai-vision-logs::-webkit-scrollbar {
    width: 4px;
}

#ai-vision-logs::-webkit-scrollbar-thumb {
    background: #10b981;
}

/* Glassmorphism for AI Widget */
#ai-widget-panel {
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.95) !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Premium Card Overlays */
.card {
    position: relative;
    overflow: hidden;
}

.card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.3s;
}

.card:hover::after {
    opacity: 1;
}

/* Specific view transition */
.view-section {
    animation: fadeInSlide 0.4s ease-out;
}

@keyframes fadeInSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-thinking {
    display: flex;
    gap: 4px;
    padding: 10px;
    background: #f1f5f9;
    border-radius: 10px 10px 10px 0;
    width: fit-content;
    animation: thinking-pulse 1.5s infinite;
}

.ai-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
}

/* ============================ */
/* GUEST MODE (MOBILE FORM VIEW)*/
/* ============================ */
body.guest-mode .sidebar,
body.guest-mode .brand,
body.guest-mode .user-profile,
body.guest-mode .header,
body.guest-mode #active-company-indicator,
body.guest-mode #ai-widget-btn,
body.guest-mode .toast-container {
    display: none !important;
}

body.guest-mode .sidebar,
body.guest-mode .header,
body.guest-mode .user-profile,
body.guest-mode .nav-links {
    display: none !important;
}

body.guest-mode .main-content {
    margin-left: 0 !important;
    width: 100vw !important;
}

body.guest-mode {
    overflow: auto !important;
}

body.guest-mode .main-content {
    padding: 0 !important;
    margin: 0 !important;
    background: #f1f5f9;
    height: 100vh;
    width: 100vw;
}

body.guest-mode .modal-overlay {
    position: relative !important;
    display: flex !important;
    background: none !important;
    backdrop-filter: none !important;
    z-index: 1 !important;
    padding: 0 !important;
    width: 100%;
    height: 100%;
}

body.guest-mode .modal-content {
    max-width: 100% !important;
    width: 100% !important;
    height: 100% !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    display: flex;
    flex-direction: column;
}

body.guest-mode #formInspeccion {
    flex: 1;
    max-height: none !important;
    padding: 20px !important;
}

/* ============================ */
/* RESPONSIVE MOBILE             */
/* ============================ */
@media (max-width: 768px) {
    /* Sidebar se oculta y sale como drawer desde la izquierda */
    .sidebar {
        position: fixed !important;
        left: -280px !important;
        top: 0 !important;
        height: 100vh !important;
        width: 260px !important;
        z-index: 9998 !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
    }
    .sidebar.sidebar-open {
        left: 0 !important;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3) !important;
    }
    /* Overlay oscuro detrás del sidebar cuando está abierto */
    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.45);
        z-index: 9997;
    }
    #sidebar-overlay.active {
        display: block;
    }
    /* Botón hamburguesa visible solo en móvil */
    #mobile-menu-btn {
        display: flex !important;
    }
    /* Main content ocupa todo el ancho */
    .main-content {
        padding: 1rem !important;
        width: 100vw !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }
    /* Modal full-screen en móvil */
    .modal-content {
        max-width: 100vw !important;
        width: 100vw !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
    /* Tabla horizontal scroll en móvil */
    .table-container {
        overflow-x: auto !important;
    }
}