:root {
    /* Backwards-compat tokens (consumidos por .glass, .input-field, .toast). */
    --bg-base:      #060608;
    --bg-surface:   rgba(255,255,255,0.04);
    --bg-elevated:  rgba(255,255,255,0.07);
    --border:       rgba(255,255,255,0.08);
    --accent:       #19C6BF;
    --accent-hover: #11B5AE;
    --text-primary: #f1f5f9;
    --text-muted:   #64748b;
    --success:      #22c55e;
    --warning:      #f59e0b;
    --danger:       #ef4444;
    --info:         #3b82f6;

    /* Tokens de tema (los consumen las clases Tailwind via los tailwind.config inline). */
    --c-bg-base:           #060608;
    --c-bg-elevated:       #0a0a0f;
    --c-bg-surface:        rgba(255,255,255,0.04);
    --c-bg-surface-subtle: rgba(255,255,255,0.02);
    --c-bg-surface-strong: rgba(255,255,255,0.06);
    --c-text-primary:      #ffffff;
    --c-text-body:         #e2e8f0;
    --c-text-secondary:    #cbd5e1;
    --c-text-muted:        #94a3b8;
    --c-text-subtle:       #64748b;
    --c-text-faint:        #475569;
    --c-border-default:    rgba(255,255,255,0.08);
    --c-border-subtle:     rgba(255,255,255,0.06);
    --c-border-faint:      rgba(255,255,255,0.04);
}

:root[data-theme="light"] {
    /* Backwards-compat flipped (slate-200 para fondo, white para cards elevadas) */
    --bg-base:      #e2e8f0;
    --bg-surface:   rgba(15,23,42,0.04);
    --bg-elevated:  #ffffff;
    --border:       rgba(15,23,42,0.12);
    --text-primary: #0f172a;
    --text-muted:   #475569;

    /* Tokens de tema flipped: bg-base mas oscuro (slate-200), elevated white */
    --c-bg-base:           #e2e8f0;
    --c-bg-elevated:       #ffffff;
    --c-bg-surface:        rgba(15,23,42,0.04);
    --c-bg-surface-subtle: rgba(15,23,42,0.02);
    --c-bg-surface-strong: rgba(15,23,42,0.06);
    --c-text-primary:      #0f172a;
    --c-text-body:         #1e293b;
    --c-text-secondary:    #334155;
    --c-text-muted:        #475569;
    --c-text-subtle:       #64748b;
    --c-text-faint:        #94a3b8;
    --c-border-default:    rgba(15,23,42,0.12);
    --c-border-subtle:     rgba(15,23,42,0.08);
    --c-border-faint:      rgba(15,23,42,0.05);
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
    box-sizing: border-box;
}

/* Eliminar el delay de 300ms en toques sobre elementos interactivos.
   Sin esto, navegadores como Samsung Internet y WebView esperan para
   detectar doble-tap-zoom antes de disparar el click. */
a, button, input, select, textarea, label, [role="button"], [onclick] {
    touch-action: manipulation;
}

/* Feedback visual inmediato al presionar un boton: responde antes que
   cualquier llamada async, asi el usuario confirma que su toque registro
   sin esperar a que vuelva el servidor. */
button:active, [role="button"]:active, .is-clicking {
    transform: scale(0.97);
    opacity: 0.85;
    transition: transform 0.05s ease, opacity 0.05s ease;
}

/* Quitar highlight gris feo de iOS/Android al tocar */
a, button, [role="button"] {
    -webkit-tap-highlight-color: transparent;
}

/* Tooltip rapido sobre hover. Usa data-tooltip en lugar de title nativo
   para aparecer al instante (sin delay de 1s del navegador) y con estilo
   coherente con el theme. En moviles no se muestra (no hay :hover real). */
[data-tooltip] {
    position: relative;
}

@media (hover: hover) {
    [data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: calc(100% + 6px);
        left: 50%;
        transform: translateX(-50%);
        padding: 4px 8px;
        background: #1a1a22;
        color: #f1f5f9;
        font-size: 11px;
        font-weight: 500;
        white-space: nowrap;
        border-radius: 6px;
        border: 1px solid rgba(255,255,255,0.08);
        box-shadow: 0 4px 12px rgba(0,0,0,0.4);
        pointer-events: none;
        z-index: 1000;
        opacity: 0;
        animation: tooltipFadeIn 0.12s ease-out 0.1s forwards;
    }

    [data-tooltip]:hover::before {
        content: '';
        position: absolute;
        bottom: calc(100% + 2px);
        left: 50%;
        transform: translateX(-50%);
        border: 4px solid transparent;
        border-top-color: #1a1a22;
        pointer-events: none;
        z-index: 1000;
        opacity: 0;
        animation: tooltipFadeIn 0.12s ease-out 0.1s forwards;
    }
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(2px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

*::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

*::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
}

.glass {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.input-field {
    padding: 0.625rem 1rem;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 0.5rem;
    color: #f1f5f9;
    font-size: 0.875rem;
    transition: border-color 0.2s;
    width: 100%;
    min-width: 0;
}

.input-field::placeholder {
    color: #475569;
}

.input-field:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(25,198,191,0.15);
}

select.input-field {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
}

select.input-field option {
    background: #0a0a0f;
    color: #f1f5f9;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    left: auto;
    padding: 0.75rem 1.25rem;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    z-index: 100;
    animation: slideUp 0.3s ease;
    max-width: 400px;
}

.toast-success {
    background: rgba(34,197,94,0.15);
    border: 1px solid rgba(34,197,94,0.3);
    color: #22c55e;
}

.toast-error {
    background: rgba(239,68,68,0.15);
    border: 1px solid rgba(239,68,68,0.3);
    color: #ef4444;
}

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

/* Truncar textos largos en tablas */
td .truncate-cell {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Mobile responsive */
@media (max-width: 640px) {
    .toast {
        left: 1rem;
        right: 1rem;
        max-width: none;
    }

    /* Tablas legibles en mobile */
    table {
        font-size: 0.75rem;
    }
    table th {
        font-size: 0.6875rem;
        white-space: nowrap;
    }
    table td {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    /* Scroll hint en tablas */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }

    /* Inputs no forzar ancho minimo */
    [class*="min-w-"] {
        min-width: 0 !important;
    }
}

/* PWA safe area */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .toast {
        bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
}
