/* ============================================================================
   PandaNexo Posadas — UI KIT
   Base, accesibilidad y componentes nativos compartidos (landing + admin).
   Requiere tokens.css. Cárgalo ANTES de posada.css / admin.css.

   Los primitivos nuevos usan el prefijo .ui- para no colisionar con las
   clases heredadas del proyecto.
   ============================================================================ */

/* ============================================================================
   BASE / RESET
   ============================================================================ */
*, *::before, *::after {
    box-sizing: border-box;
}

* {
    /* Quita el flash azul del tap en Android; lo sustituye el ripple. */
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
    /* Ancla los saltos internos por debajo de la barra superior fija. */
    scroll-padding-top: calc(var(--appbar-h) + var(--sp-4));
    /* Evita el "rebote" horizontal en móvil. */
    overscroll-behavior-y: none;
}

body {
    margin: 0;
    font-family: var(--font-body);
    font-size: var(--text-base);
    line-height: var(--lh-normal);
    color: var(--on-surface);
    background-color: var(--surface);
    /* Suaviza el render de fuentes como en apps nativas. */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: 'cv11', 'ss01';
    font-variant-numeric: tabular-nums;
    overflow-x: hidden;
    min-height: 100dvh;
    transition: background-color var(--tr-base), color var(--tr-base);
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: var(--fw-black);
    line-height: var(--lh-tight);
    letter-spacing: var(--ls-tighter);
    color: var(--on-surface-strong);
    /* Evita cortes tipográficos horribles en títulos. */
    text-wrap: balance;
}

p {
    margin: 0;
    text-wrap: pretty;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--tr-fast), background-color var(--tr-fast), opacity var(--tr-fast);
}

img, svg, video, canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

button {
    cursor: pointer;
    border: none;
    background: none;
}

ul, ol {
    margin: 0;
}

hr {
    border: none;
    border-top: 1px solid var(--outline);
    margin: var(--sp-4) 0;
}

::selection {
    background-color: var(--primary-container-alt);
    color: var(--on-primary-container);
}

/* Autofill de Chrome: por defecto pinta un amarillo que rompe el tema. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--on-surface);
    -webkit-box-shadow: 0 0 0 100px var(--surface-3) inset;
    caret-color: var(--on-surface);
    transition: background-color 9999s ease-out 0s;
}

/* Los selectores de fecha/hora nativos deben seguir el tema. */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator,
input[type="month"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    border-radius: var(--r-xs);
    opacity: 0.7;
    transition: opacity var(--tr-fast);
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator {
    filter: invert(1) brightness(1.6);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) input[type="date"]::-webkit-calendar-picker-indicator,
    :root:not([data-theme="light"]) input[type="time"]::-webkit-calendar-picker-indicator,
    :root:not([data-theme="light"]) input[type="datetime-local"]::-webkit-calendar-picker-indicator,
    :root:not([data-theme="light"]) input[type="month"]::-webkit-calendar-picker-indicator {
        filter: invert(1) brightness(1.6);
    }
}

/* ============================================================================
   BARRAS DE DESPLAZAMIENTO (discretas, estilo Android)
   ============================================================================ */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--outline-strong) transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

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

::-webkit-scrollbar-thumb {
    background-color: var(--outline-strong);
    border: 3px solid transparent;
    border-radius: var(--r-full);
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--on-surface-faint);
}

/* En móvil, el scroll táctil no necesita barra visible. */
@media (hover: none) and (pointer: coarse) {
    ::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

/* ============================================================================
   ACCESIBILIDAD
   ============================================================================ */

/* Anillo de foco visible sólo para teclado: no molesta al usar el ratón. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--outline-focus);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

:where(a, button, input, select, textarea, summary, [tabindex]):focus:not(:focus-visible) {
    outline: none;
}

/* Área táctil mínima de 48dp: se amplía la zona sensible sin alterar el diseño. */
@media (hover: none) and (pointer: coarse) {
    :where(button, a[role="button"], .ui-icon-btn, [data-touch-target]) {
        position: relative;
    }
    :where(button, a[role="button"], .ui-icon-btn, [data-touch-target])::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        width: 100%;
        height: 100%;
        pointer-events: none;
    }
}

/* Sólo para lectores de pantalla. */
.ui-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Salto directo al contenido para usuarios de teclado. */
.ui-skip-link {
    position: fixed;
    top: calc(var(--safe-t) + var(--sp-2));
    left: var(--sp-2);
    z-index: var(--z-tooltip);
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--r-sm);
    background-color: var(--primary);
    color: var(--on-primary);
    font-weight: var(--fw-bold);
    font-size: var(--text-md);
    box-shadow: var(--el-3);
    transform: translateY(-200%);
    transition: transform var(--tr-base);
}

.ui-skip-link:focus-visible {
    transform: translateY(0);
}

/* Respeta a quien pide menos animación (vestibular, ahorro de batería). */
@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .ui-ripple-ink {
        display: none !important;
    }
}

/* Modo alto contraste. */
@media (prefers-contrast: more) {
    :root {
        --outline:        var(--on-surface-muted);
        --outline-strong: var(--on-surface-variant);
    }
}

/* ============================================================================
   RIPPLE (retroalimentación táctil de Material)
   ============================================================================ */
.ui-ripple {
    position: relative;
    overflow: hidden;
    /* Necesario para que el ripple se recorte en Safari. */
    isolation: isolate;
}

.ui-ripple-ink {
    position: absolute;
    border-radius: 50%;
    background-color: var(--ripple-ink);
    transform: scale(0);
    opacity: 0.55;
    pointer-events: none;
    animation: ui-ripple-out var(--dur-slower) var(--ease-decelerate) forwards;
}

@keyframes ui-ripple-out {
    to {
        transform: scale(2.6);
        opacity: 0;
    }
}

/* Sobre fondos de color, la tinta debe ser clara. */
[data-ripple-light] .ui-ripple-ink {
    background-color: var(--ripple-ink-on-primary);
}

/* Hundimiento al pulsar: da sensación física, como los botones de Android. */
[data-press] {
    transition: transform var(--dur-fast) var(--ease-standard);
}

[data-press]:active {
    transform: scale(0.97);
}

/* ============================================================================
   UTILIDADES DE SUPERFICIE Y LAYOUT
   ============================================================================ */
.ui-surface {
    background-color: var(--surface-1);
    border: 1px solid var(--outline);
    border-radius: var(--r-lg);
}

.ui-el-1 { box-shadow: var(--el-1); }
.ui-el-2 { box-shadow: var(--el-2); }
.ui-el-3 { box-shadow: var(--el-3); }
.ui-el-4 { box-shadow: var(--el-4); }

.ui-container {
    width: 100%;
    max-width: var(--content-max);
    margin-inline: auto;
    padding-inline: max(var(--gutter), var(--safe-l), var(--safe-r));
}

.ui-container-narrow {
    max-width: var(--content-narrow);
}

.ui-stack {
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
}

.ui-row {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

.ui-row-wrap {
    flex-wrap: wrap;
}

.ui-spacer {
    flex: 1 1 auto;
}

/* Rejilla que se adapta sola: sin media queries y sin desbordes. */
.ui-autogrid {
    display: grid;
    gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(min(var(--col-min, 260px), 100%), 1fr));
}

.ui-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.ui-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ui-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ui-numeric {
    font-variant-numeric: tabular-nums;
    font-feature-settings: 'tnum';
}

.ui-scroll-x {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    /* Frena el scroll en cada elemento: sensación de carrusel nativo. */
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
}

.ui-scroll-x::-webkit-scrollbar {
    display: none;
}

.ui-scroll-x > * {
    scroll-snap-align: start;
}

/* Sangrado a pantalla completa: el carrusel toca los bordes en móvil. */
.ui-bleed {
    margin-inline: calc(var(--gutter) * -1);
    padding-inline: var(--gutter);
}

/* Visibilidad por tamaño: se oculta sólo donde toca, sin forzar un display
   concreto al mostrarse (así respeta el flex/grid original del elemento). */
@media (max-width: 991px) {
    .ui-hide-mobile { display: none !important; }
}

@media (min-width: 992px) {
    .ui-hide-desktop { display: none !important; }
}

/* ============================================================================
   TIPOGRAFÍA
   ============================================================================ */
.ui-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-wider);
    text-transform: uppercase;
    color: var(--primary);
}

.ui-title-lg {
    font-family: var(--font-display);
    font-size: var(--text-3xl);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-tighter);
    line-height: var(--lh-tight);
}

.ui-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-tight);
}

.ui-body {
    font-size: var(--text-base);
    color: var(--on-surface-variant);
    line-height: var(--lh-relaxed);
}

.ui-caption {
    font-size: var(--text-xs);
    color: var(--on-surface-muted);
}

.ui-label {
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: var(--fw-bold);
    letter-spacing: var(--ls-wide);
    text-transform: uppercase;
    color: var(--on-surface-muted);
}

/* ============================================================================
   BOTONES (jerarquía M3: filled → tonal → outlined → text)
   ============================================================================ */
.ui-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 44px;
    padding: 0 var(--sp-6);
    border: 1px solid transparent;
    border-radius: var(--r-full);
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--fw-bold);
    letter-spacing: var(--ls-tight);
    white-space: nowrap;
    cursor: pointer;
    overflow: hidden;
    isolation: isolate;
    transition: background-color var(--tr-fast), border-color var(--tr-fast),
                color var(--tr-fast), box-shadow var(--tr-base), transform var(--dur-fast) var(--ease-standard);
}

.ui-btn:active {
    transform: scale(0.97);
}

.ui-btn:disabled,
.ui-btn[aria-disabled="true"] {
    opacity: 0.42;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ui-btn i,
.ui-btn svg {
    font-size: 1em;
    flex-shrink: 0;
}

/* Filled — acción principal, una sola por pantalla. */
.ui-btn-filled {
    background-color: var(--primary);
    color: var(--on-primary);
    box-shadow: var(--el-1);
}
.ui-btn-filled:hover {
    background-color: var(--primary-hover);
    box-shadow: var(--el-primary);
}

/* Tonal — acción secundaria destacada. */
.ui-btn-tonal {
    background-color: var(--primary-container);
    color: var(--on-primary-container);
}
.ui-btn-tonal:hover {
    background-color: var(--primary-container-alt);
}

/* Outlined — alternativa neutra. */
.ui-btn-outlined {
    background-color: transparent;
    border-color: var(--outline-strong);
    color: var(--on-surface);
}
.ui-btn-outlined:hover {
    background-color: var(--state-hover);
    border-color: var(--primary);
    color: var(--primary);
}

/* Text — acción terciaria. */
.ui-btn-text {
    background-color: transparent;
    color: var(--primary);
    padding-inline: var(--sp-3);
}
.ui-btn-text:hover {
    background-color: var(--primary-container);
}

.ui-btn-wa {
    background-color: var(--wa);
    color: var(--on-wa);
    box-shadow: var(--el-1);
}
.ui-btn-wa:hover {
    background-color: var(--wa-hover);
    box-shadow: var(--el-wa);
}

.ui-btn-danger {
    background-color: var(--danger);
    color: var(--on-danger);
}
.ui-btn-danger:hover {
    filter: brightness(1.08);
}

.ui-btn-sm {
    min-height: 36px;
    padding-inline: var(--sp-4);
    font-size: var(--text-sm);
}

.ui-btn-lg {
    min-height: 52px;
    padding-inline: var(--sp-8);
    font-size: var(--text-lg);
}

.ui-btn-block {
    width: 100%;
}

/* Botón de icono cuadrado con área táctil garantizada. */
.ui-icon-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: var(--r-full);
    background-color: transparent;
    color: var(--on-surface-variant);
    font-size: var(--text-lg);
    cursor: pointer;
    overflow: hidden;
    transition: background-color var(--tr-fast), color var(--tr-fast), transform var(--dur-fast) var(--ease-standard);
}

.ui-icon-btn:hover {
    background-color: var(--state-hover);
    color: var(--on-surface);
}

.ui-icon-btn:active {
    transform: scale(0.92);
}

.ui-icon-btn-filled {
    background-color: var(--surface-3);
    border: 1px solid var(--outline);
}

/* ============================================================================
   FAB (botón de acción flotante)
   ============================================================================ */
.ui-fab {
    position: fixed;
    right: max(var(--sp-4), var(--safe-r));
    bottom: calc(var(--bottomnav-h) + var(--safe-b) + var(--sp-4));
    z-index: var(--z-bottomnav);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-width: 56px;
    height: 56px;
    padding-inline: var(--sp-4);
    border-radius: var(--r-lg);
    background-color: var(--primary);
    color: var(--on-primary);
    font-family: var(--font-display);
    font-weight: var(--fw-bold);
    font-size: var(--text-lg);
    box-shadow: var(--el-4);
    overflow: hidden;
    transition: transform var(--tr-base), box-shadow var(--tr-base), background-color var(--tr-fast);
}

.ui-fab:hover {
    transform: scale(1.04);
    box-shadow: var(--el-5);
}

.ui-fab:active {
    transform: scale(0.95);
}

/* Se esconde al bajar y reaparece al subir, como en apps nativas. */
.ui-fab.is-hidden {
    transform: translateY(calc(100% + var(--sp-8))) scale(0.85);
    opacity: 0;
    pointer-events: none;
}

/* ============================================================================
   CAMPOS DE FORMULARIO (estilo "outlined" de Material 3)
   ============================================================================ */
.ui-field {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-width: 0;
}

.ui-field-label {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: var(--fw-bold);
    letter-spacing: var(--ls-wide);
    text-transform: uppercase;
    color: var(--on-surface-muted);
}

.ui-field-label i {
    color: var(--primary);
}

.ui-required {
    color: var(--danger);
}

.ui-input,
.ui-select,
.ui-textarea {
    width: 100%;
    min-height: 48px;
    padding: var(--sp-3) var(--sp-4);
    border: 1.5px solid var(--outline-strong);
    border-radius: var(--r-md);
    background-color: var(--surface-1);
    color: var(--on-surface);
    /* 16px evita el zoom automático de iOS/Android al enfocar. */
    font-size: max(16px, var(--text-base));
    font-weight: var(--fw-medium);
    outline: none;
    transition: border-color var(--tr-fast), box-shadow var(--tr-fast), background-color var(--tr-fast);
}

.ui-textarea {
    min-height: 108px;
    resize: vertical;
    line-height: var(--lh-normal);
}

.ui-input::placeholder,
.ui-textarea::placeholder {
    color: var(--on-surface-faint);
    font-weight: var(--fw-regular);
}

.ui-input:hover,
.ui-select:hover,
.ui-textarea:hover {
    border-color: var(--on-surface-faint);
}

.ui-input:focus,
.ui-select:focus,
.ui-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-container);
    outline: none;
}

.ui-input:disabled,
.ui-select:disabled,
.ui-textarea:disabled {
    background-color: var(--surface-alt);
    color: var(--on-surface-faint);
    cursor: not-allowed;
}

.ui-input[aria-invalid="true"],
.ui-select[aria-invalid="true"] {
    border-color: var(--danger);
}

/* Flecha propia: la nativa es inconsistente entre navegadores. */
.ui-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: var(--sp-10);
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--sp-4) center;
    background-size: 18px;
    cursor: pointer;
}

.ui-field-hint {
    font-size: var(--text-xs);
    color: var(--on-surface-muted);
}

.ui-field-error {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    font-size: var(--text-xs);
    font-weight: var(--fw-semibold);
    color: var(--danger);
}

/* Campo con icono a la izquierda (búsqueda). */
.ui-field-icon {
    position: relative;
}

.ui-field-icon > i {
    position: absolute;
    left: var(--sp-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--on-surface-muted);
    pointer-events: none;
}

.ui-field-icon > .ui-input {
    padding-left: var(--sp-10);
}

/* Rejilla de formulario: 1 columna en móvil, se expande según el espacio real. */
.ui-form-grid {
    display: grid;
    gap: var(--sp-4);
    grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
}

.ui-form-grid > .ui-col-span-2 {
    grid-column: 1 / -1;
}

/* Interruptor tipo Android. */
.ui-switch {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-3);
    cursor: pointer;
    user-select: none;
}

.ui-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ui-switch-track {
    position: relative;
    width: 52px;
    height: 32px;
    flex-shrink: 0;
    border: 2px solid var(--outline-strong);
    border-radius: var(--r-full);
    background-color: var(--surface-alt);
    transition: background-color var(--tr-base), border-color var(--tr-base);
}

.ui-switch-track::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 6px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--on-surface-muted);
    transform: translateY(-50%);
    transition: transform var(--dur-base) var(--ease-spring),
                width var(--tr-base), height var(--tr-base), background-color var(--tr-base), left var(--tr-base);
}

.ui-switch input:checked + .ui-switch-track {
    background-color: var(--primary);
    border-color: var(--primary);
}

.ui-switch input:checked + .ui-switch-track::after {
    left: 4px;
    width: 22px;
    height: 22px;
    background-color: var(--on-primary);
    transform: translate(20px, -50%);
}

.ui-switch input:focus-visible + .ui-switch-track {
    outline: 2px solid var(--outline-focus);
    outline-offset: 3px;
}

/* Casilla seleccionable en forma de tarjeta (extras, filtros). */
.ui-check-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-4);
    border: 1.5px solid var(--outline);
    border-radius: var(--r-md);
    background-color: var(--surface-1);
    cursor: pointer;
    transition: border-color var(--tr-fast), background-color var(--tr-fast), box-shadow var(--tr-fast);
}

.ui-check-card:hover {
    border-color: var(--primary-outline);
    background-color: var(--state-hover);
}

.ui-check-card:has(input:checked) {
    border-color: var(--primary);
    background-color: var(--primary-container);
    box-shadow: 0 0 0 1px var(--primary);
}

.ui-check-card input[type="checkbox"],
.ui-check-card input[type="radio"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ============================================================================
   CHIPS
   ============================================================================ */
.ui-chip {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    min-height: 38px;
    padding: 0 var(--sp-4);
    border: 1px solid var(--outline-strong);
    border-radius: var(--r-full);
    background-color: var(--surface-1);
    color: var(--on-surface-variant);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: var(--fw-bold);
    white-space: nowrap;
    cursor: pointer;
    overflow: hidden;
    transition: background-color var(--tr-fast), border-color var(--tr-fast),
                color var(--tr-fast), transform var(--dur-fast) var(--ease-standard);
}

.ui-chip:hover {
    background-color: var(--state-hover);
    border-color: var(--on-surface-faint);
}

.ui-chip:active {
    transform: scale(0.96);
}

.ui-chip.is-active,
.ui-chip[aria-selected="true"] {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

/* ============================================================================
   BADGES / ETIQUETAS DE ESTADO
   ============================================================================ */
.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding: 3px var(--sp-2);
    border-radius: var(--r-xs);
    background-color: var(--surface-alt);
    color: var(--on-surface-variant);
    font-family: var(--font-display);
    font-size: var(--text-2xs);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-wide);
    text-transform: uppercase;
    white-space: nowrap;
    line-height: 1.5;
}

.ui-badge-success { background-color: var(--success-container); color: var(--on-success-container); }
.ui-badge-warning { background-color: var(--warning-container); color: var(--on-warning-container); }
.ui-badge-danger  { background-color: var(--danger-container);  color: var(--on-danger-container); }
.ui-badge-info    { background-color: var(--info-container);    color: var(--on-info-container); }
.ui-badge-primary { background-color: var(--primary-container); color: var(--on-primary-container); }

/* Punto pulsante para estados "en vivo". */
.ui-live-dot {
    position: relative;
    display: inline-block;
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 50%;
    background-color: var(--success);
}

.ui-live-dot::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background-color: inherit;
    animation: ui-pulse 2s var(--ease-decelerate) infinite;
}

@keyframes ui-pulse {
    0%   { transform: scale(1);   opacity: 0.7; }
    70%  { transform: scale(2.6); opacity: 0; }
    100% { transform: scale(2.6); opacity: 0; }
}

/* ============================================================================
   BARRA SUPERIOR (App Bar)
   ============================================================================ */
.ui-appbar {
    position: sticky;
    top: 0;
    z-index: var(--z-appbar);
    padding-top: var(--safe-t);
    background-color: var(--glass-bg);
    /* Translucidez con desenfoque: material real de Android 12+. */
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid transparent;
    transition: border-color var(--tr-base), box-shadow var(--tr-base), background-color var(--tr-base);
}

/* Al hacer scroll aparece la separación: jerarquía por elevación, no por borde. */
.ui-appbar.is-scrolled {
    border-bottom-color: var(--outline);
    box-shadow: var(--el-2);
}

/* Si el navegador no soporta desenfoque, se usa color sólido. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .ui-appbar {
        background-color: var(--surface-1);
    }
}

/* ============================================================================
   SCRIM + NAVIGATION DRAWER
   ============================================================================ */
.ui-scrim {
    position: fixed;
    inset: 0;
    z-index: var(--z-scrim);
    background-color: var(--scrim);
    opacity: 0;
    visibility: hidden;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity var(--tr-base), visibility var(--tr-base);
}

.ui-scrim.is-open {
    opacity: 1;
    visibility: visible;
}

.ui-drawer {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: var(--z-drawer);
    display: flex;
    flex-direction: column;
    width: min(88vw, 320px);
    padding: var(--safe-t) var(--sp-3) calc(var(--safe-b) + var(--sp-3));
    background-color: var(--surface-1);
    border-right: 1px solid var(--outline);
    box-shadow: var(--el-5);
    /* Fuera de pantalla por defecto, sin ocupar espacio ni ser enfocable. */
    transform: translateX(-102%);
    visibility: hidden;
    overscroll-behavior: contain;
    transition: transform var(--dur-slow) var(--ease-emphasized), visibility var(--dur-slow);
}

.ui-drawer.is-open {
    transform: translateX(0);
    visibility: visible;
}

/* Bloquea el scroll del fondo mientras hay una capa abierta. */
body.ui-locked {
    overflow: hidden;
    /* Compensa el ancho de la barra para que no salte el layout. */
    padding-right: var(--ui-scrollbar-w, 0px);
}

.ui-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-2);
    border-bottom: 1px solid var(--outline);
}

.ui-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3) 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ui-drawer-footer {
    padding-top: var(--sp-3);
    border-top: 1px solid var(--outline);
}

/* Ítem de lista de navegación (píldora activa, como Material 3). */
.ui-nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-height: 48px;
    padding: 0 var(--sp-4);
    border-radius: var(--r-full);
    color: var(--on-surface-variant);
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--fw-semibold);
    overflow: hidden;
    transition: background-color var(--tr-fast), color var(--tr-fast);
}

.ui-nav-item > i:first-child {
    width: 22px;
    flex-shrink: 0;
    text-align: center;
    font-size: var(--text-lg);
    color: var(--on-surface-muted);
    transition: color var(--tr-fast);
}

.ui-nav-item:hover {
    background-color: var(--state-hover);
    color: var(--on-surface);
}

.ui-nav-item.is-active {
    background-color: var(--primary-container);
    color: var(--on-primary-container);
    font-weight: var(--fw-bold);
}

.ui-nav-item.is-active > i:first-child {
    color: var(--primary);
}

.ui-nav-section {
    padding: var(--sp-4) var(--sp-4) var(--sp-1);
    font-family: var(--font-display);
    font-size: var(--text-2xs);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-wider);
    text-transform: uppercase;
    color: var(--on-surface-faint);
}

/* ============================================================================
   BARRA DE NAVEGACIÓN INFERIOR (patrón nativo de Android)
   ============================================================================ */
.ui-bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-bottomnav);
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--bottomnav-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background-color: var(--glass-bg);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--outline);
    box-shadow: 0 -1px 3px rgba(var(--shadow-rgb), calc(var(--shadow-alpha) * 0.5));
    transition: transform var(--tr-slow);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .ui-bottomnav {
        background-color: var(--surface-1);
    }
}

@media (min-width: 992px) {
    .ui-bottomnav {
        display: none;
    }
}

.ui-bottomnav-item {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: var(--sp-2) 2px;
    color: var(--on-surface-muted);
    font-family: var(--font-display);
    font-size: var(--text-2xs);
    font-weight: var(--fw-bold);
    text-align: center;
    overflow: hidden;
    transition: color var(--tr-fast);
}

/* Indicador tipo "pill" detrás del icono activo. */
.ui-bottomnav-icon {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 30px;
    border-radius: var(--r-full);
    font-size: var(--text-lg);
    transition: background-color var(--tr-base), color var(--tr-base), transform var(--dur-base) var(--ease-spring);
}

.ui-bottomnav-item.is-active {
    color: var(--on-primary-container);
}

.ui-bottomnav-item.is-active .ui-bottomnav-icon {
    background-color: var(--primary-container-alt);
    color: var(--primary);
    transform: translateY(-1px);
}

.ui-bottomnav-item:active .ui-bottomnav-icon {
    transform: scale(0.9);
}

.ui-bottomnav-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Contador de notificaciones. */
.ui-nav-badge {
    position: absolute;
    top: 2px;
    right: 12px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: var(--r-full);
    background-color: var(--danger);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: var(--fw-black);
    line-height: 17px;
    text-align: center;
}

/* Cuando existe barra inferior, el contenido necesita respiro al final. */
.ui-has-bottomnav {
    padding-bottom: calc(var(--bottomnav-h) + var(--safe-b));
}

@media (min-width: 992px) {
    .ui-has-bottomnav {
        padding-bottom: 0;
    }
}

/* ============================================================================
   BOTTOM SHEET + DIÁLOGO
   En móvil las capas suben desde abajo (nativo); en desktop se centran.
   ============================================================================ */
.ui-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--z-sheet);
    display: flex;
    flex-direction: column;
    max-height: 92dvh;
    padding-bottom: var(--safe-b);
    background-color: var(--surface-1);
    border-radius: var(--r-2xl) var(--r-2xl) 0 0;
    box-shadow: var(--el-5);
    transform: translateY(101%);
    visibility: hidden;
    overscroll-behavior: contain;
    transition: transform var(--dur-slow) var(--ease-emphasized), visibility var(--dur-slow);
}

.ui-sheet.is-open {
    transform: translateY(0);
    visibility: visible;
}

/* Asa de arrastre: indica que se puede deslizar para cerrar. */
.ui-sheet-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-3) 0 var(--sp-2);
    cursor: grab;
    touch-action: none;
}

.ui-sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    border-radius: var(--r-full);
    background-color: var(--outline-strong);
}

.ui-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-5) var(--sp-4);
    border-bottom: 1px solid var(--outline);
}

.ui-sheet-title {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--fw-black);
}

.ui-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-5);
    -webkit-overflow-scrolling: touch;
}

.ui-sheet-footer {
    display: flex;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--outline);
    background-color: var(--surface-1);
}

.ui-sheet-footer > * {
    flex: 1;
}

@media (min-width: 768px) {
    .ui-sheet {
        top: 50%;
        left: 50%;
        right: auto;
        bottom: auto;
        width: min(94vw, 640px);
        max-height: 88dvh;
        border-radius: var(--r-xl);
        transform: translate(-50%, -46%) scale(0.96);
        opacity: 0;
        transition: transform var(--dur-base) var(--ease-emphasized),
                    opacity var(--dur-base) var(--ease-standard), visibility var(--dur-base);
    }
    .ui-sheet.is-open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    .ui-sheet-handle {
        display: none;
    }
}

/* ============================================================================
   SNACKBAR / TOAST
   ============================================================================ */
.ui-snackbar-host {
    position: fixed;
    left: max(var(--sp-3), var(--safe-l));
    right: max(var(--sp-3), var(--safe-r));
    bottom: calc(var(--bottomnav-h) + var(--safe-b) + var(--sp-3));
    z-index: var(--z-snackbar);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    pointer-events: none;
}

@media (min-width: 768px) {
    .ui-snackbar-host {
        left: auto;
        right: var(--sp-6);
        bottom: var(--sp-6);
        width: min(92vw, 400px);
    }
}

.ui-snackbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4);
    border-radius: var(--r-md);
    background-color: var(--surface-inverse);
    color: var(--on-surface-inverse);
    font-size: var(--text-md);
    font-weight: var(--fw-medium);
    box-shadow: var(--el-4);
    pointer-events: auto;
    cursor: pointer;
    animation: ui-snack-in var(--dur-slow) var(--ease-emphasized) both;
}

.ui-snackbar.is-leaving {
    animation: ui-snack-out var(--dur-base) var(--ease-accelerate) both;
}

.ui-snackbar > i:first-child {
    font-size: var(--text-xl);
    flex-shrink: 0;
}

.ui-snackbar-success > i:first-child { color: var(--emerald-400); }
.ui-snackbar-danger  > i:first-child { color: var(--red-400); }
.ui-snackbar-warning > i:first-child { color: var(--amber-400); }
.ui-snackbar-info    > i:first-child { color: var(--sky-400); }

@keyframes ui-snack-in {
    from { transform: translateY(140%) scale(0.94); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes ui-snack-out {
    to { transform: translateY(60%) scale(0.96); opacity: 0; }
}

/* ============================================================================
   TABLAS RESPONSIVE
   En escritorio, tabla. En móvil, cada fila se convierte en tarjeta con
   etiquetas (data-label) — se lee cómodo sin scroll horizontal.
   ============================================================================ */
.ui-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--r-lg);
}

.ui-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-md);
    text-align: left;
}

.ui-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: var(--sp-3) var(--sp-4);
    background-color: var(--surface-alt);
    color: var(--on-surface-muted);
    font-family: var(--font-display);
    font-size: var(--text-2xs);
    font-weight: var(--fw-black);
    letter-spacing: var(--ls-wider);
    text-transform: uppercase;
    white-space: nowrap;
    border-bottom: 1px solid var(--outline);
}

.ui-table td {
    padding: var(--sp-4);
    border-bottom: 1px solid var(--outline-variant);
    color: var(--on-surface);
    vertical-align: middle;
}

.ui-table tbody tr {
    transition: background-color var(--tr-fast);
}

.ui-table tbody tr:hover {
    background-color: var(--state-hover);
}

.ui-table tbody tr:last-child td {
    border-bottom: none;
}

@media (max-width: 767px) {
    .ui-table-cards thead {
        display: none;
    }
    .ui-table-cards,
    .ui-table-cards tbody,
    .ui-table-cards tr,
    .ui-table-cards td {
        display: block;
        width: 100%;
    }
    .ui-table-cards tr {
        margin-bottom: var(--sp-3);
        padding: var(--sp-2) var(--sp-4);
        border: 1px solid var(--outline);
        border-radius: var(--r-lg);
        background-color: var(--surface-1);
        box-shadow: var(--el-1);
    }
    .ui-table-cards td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--sp-4);
        padding: var(--sp-3) 0;
        border-bottom: 1px solid var(--outline-variant);
        text-align: right;
    }
    .ui-table-cards td:last-child {
        border-bottom: none;
    }
    /* La etiqueta se toma del atributo data-label de la celda. */
    .ui-table-cards td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-family: var(--font-display);
        font-size: var(--text-2xs);
        font-weight: var(--fw-black);
        letter-spacing: var(--ls-wide);
        text-transform: uppercase;
        color: var(--on-surface-muted);
        text-align: left;
    }
    /* Celda destacada: ocupa todo el ancho, sin etiqueta (cabecera de tarjeta). */
    .ui-table-cards td[data-label=""]::before,
    .ui-table-cards td.ui-cell-hero::before {
        display: none;
    }
    .ui-table-cards td.ui-cell-hero {
        justify-content: flex-start;
        text-align: left;
        padding-top: var(--sp-4);
    }
}

/* ============================================================================
   ESTADO VACÍO
   ============================================================================ */
.ui-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--sp-3);
    padding: var(--sp-12) var(--sp-5);
    text-align: center;
}

.ui-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: var(--r-2xl);
    background-color: var(--surface-alt);
    color: var(--on-surface-faint);
    font-size: var(--text-3xl);
}

.ui-empty h3 {
    font-size: var(--text-xl);
}

.ui-empty p {
    max-width: 42ch;
    color: var(--on-surface-muted);
    font-size: var(--text-md);
}

/* ============================================================================
   ESQUELETO DE CARGA
   ============================================================================ */
.ui-skeleton {
    position: relative;
    overflow: hidden;
    border-radius: var(--r-sm);
    background-color: var(--surface-alt);
}

.ui-skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, var(--state-hover), transparent);
    animation: ui-shimmer 1.4s infinite;
}

@keyframes ui-shimmer {
    to { transform: translateX(100%); }
}

/* ============================================================================
   SEGMENTED BUTTONS (selector de pestañas nativo)
   ============================================================================ */
.ui-segmented {
    display: inline-flex;
    padding: 4px;
    gap: 4px;
    border: 1px solid var(--outline);
    border-radius: var(--r-md);
    background-color: var(--surface-alt);
}

.ui-segment {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    min-height: 40px;
    padding: 0 var(--sp-4);
    border: none;
    border-radius: var(--r-sm);
    background-color: transparent;
    color: var(--on-surface-muted);
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: var(--fw-bold);
    white-space: nowrap;
    cursor: pointer;
    overflow: hidden;
    transition: background-color var(--tr-fast), color var(--tr-fast), box-shadow var(--tr-fast);
}

.ui-segment.is-active {
    background-color: var(--surface-1);
    color: var(--primary);
    box-shadow: var(--el-1);
}

/* ============================================================================
   PAGINACIÓN
   ============================================================================ */
.ui-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: var(--sp-5) 0;
}

.ui-pagination a,
.ui-pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0 var(--sp-3);
    border: 1px solid var(--outline);
    border-radius: var(--r-sm);
    background-color: var(--surface-1);
    color: var(--on-surface-variant);
    font-family: var(--font-display);
    font-size: var(--text-md);
    font-weight: var(--fw-bold);
    transition: background-color var(--tr-fast), border-color var(--tr-fast), color var(--tr-fast);
}

.ui-pagination a:hover {
    border-color: var(--primary);
    background-color: var(--primary-container);
    color: var(--primary);
}

.ui-pagination .is-active,
.ui-pagination span.active {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--on-primary);
}

/* ============================================================================
   TOGGLE DE TEMA (claro / oscuro / automático)
   ============================================================================ */
.ui-theme-toggle {
    position: relative;
}

/* El icono cambia según el tema activo; sólo uno es visible. */
.ui-theme-toggle .ui-ico-light,
.ui-theme-toggle .ui-ico-dark,
.ui-theme-toggle .ui-ico-auto {
    display: none;
    line-height: 1;
}

:root[data-theme="light"] .ui-theme-toggle .ui-ico-light { display: block; }
:root[data-theme="dark"]  .ui-theme-toggle .ui-ico-dark  { display: block; }
:root:not([data-theme])   .ui-theme-toggle .ui-ico-auto  { display: block; }

/* Transición global suave al cambiar de tema (sólo mientras cambia). */
:root.ui-theming,
:root.ui-theming *,
:root.ui-theming *::before,
:root.ui-theming *::after {
    transition: background-color var(--dur-base) var(--ease-standard),
                border-color var(--dur-base) var(--ease-standard),
                color var(--dur-base) var(--ease-standard),
                fill var(--dur-base) var(--ease-standard) !important;
}

/* ============================================================================
   REVELADO AL HACER SCROLL (entrada sutil, no decorativa en exceso)
   ============================================================================ */
[data-reveal] {
    opacity: 0;
    transform: translateY(14px);
    transition: opacity var(--dur-slower) var(--ease-decelerate),
                transform var(--dur-slower) var(--ease-decelerate);
    transition-delay: var(--reveal-delay, 0ms);
}

[data-reveal].is-revealed {
    opacity: 1;
    transform: none;
}

/* Si no hay JS, todo debe verse igualmente. */
.no-js [data-reveal] {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    [data-reveal] {
        opacity: 1;
        transform: none;
    }
}

/* ============================================================================
   IMPRESIÓN (fichas de reserva, reportes)
   ============================================================================ */
@media print {
    .ui-appbar,
    .ui-bottomnav,
    .ui-drawer,
    .ui-scrim,
    .ui-fab,
    .ui-snackbar-host,
    [data-no-print] {
        display: none !important;
    }
    body {
        background: #FFFFFF !important;
        color: #000000 !important;
    }
    .ui-surface,
    .ui-table {
        box-shadow: none !important;
        border-color: #999999 !important;
    }
    a[href]::after {
        content: '';
    }
}
