/* Reset y base */
*, *::before, *::after {
    box-sizing: border-box;
}

/* CSS Variables para Safe Areas - Compose las lee via JavaScript */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior: none;
}

/* =====================================================
   OPTIMIZACIONES PARA iOS / Safari PWA
   ===================================================== */

/* Eliminar delay de 300ms en taps (iOS Safari) */
html {
    touch-action: manipulation;
}

/* Evitar que iOS Safari añada estilos por defecto a elementos interactivos */
button, input, select, textarea, a {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/*
 * Canvas DEBE estar en (0,0) para que coordenadas de touch sean correctas.
 * Las safe areas se manejan DENTRO de Compose con WindowInsets.
 */
canvas {
    /* Forzar aceleración por hardware */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);

    /* Evitar que iOS intente "optimizar" el canvas */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;

    /* Permitir interacción táctil directa */
    touch-action: none;

    /* Optimizaciones adicionales para iOS */
    -webkit-perspective: 1000;
    perspective: 1000;

    will-change: contents;
    isolation: isolate;

    /* Canvas ocupa toda la pantalla, anclado en (0,0) */
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;

    /* Evitar highlight en touch */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* App container */
#app {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
}

/* Prevenir zoom en inputs en iOS */
input, select, textarea {
    font-size: 16px !important;
}

/* Deshabilitar selección de texto en elementos UI */
button, [role="button"] {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Mejor scroll en iOS */
.scrollable {
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
}

/* Animaciones suaves */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* Pull-to-refresh deshabilitado en PWA */
body {
    overscroll-behavior-y: contain;
}

/* Ocultar scrollbars pero mantener funcionalidad */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Asegurar que el canvas pueda recibir eventos de teclado */
canvas:focus {
    outline: none;
}


/* Offline indicator */
.offline-indicator {
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    background: #f44336;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 14px;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* Update available banner */
.update-banner {
    position: fixed;
    bottom: env(safe-area-inset-bottom, 0);
    left: 0;
    right: 0;
    background: #00796B;
    color: white;
    text-align: center;
    padding: 12px;
    z-index: 9999;
    display: none;
}

.update-banner.show {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.update-banner button {
    background: white;
    color: #00796B;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
}

/* Focus visible para accesibilidad */
:focus-visible {
    outline: 2px solid #00796B;
    outline-offset: 2px;
}

/* Reducir animaciones si el usuario lo prefiere */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}