/* ============================================================
   SHELL CSS — v4 design system
   Consolida el shell de la app v4 (antes cargado vía css/main.css
   -> css/layout.css legacy): box-sizing base + .main-content,
   .sticky-footer, .footer-btn*, .kx-sheet*, .kx-account*.
   Fuente: css/reset.css (bloque *) + css/layout.css (íntegro).
   Ver plan de unificación del design system, sección 4.3.
   ============================================================ */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

/* ===== LAYOUT CSS ===== */
/* Main layout structure with navbar and footer */

/* ===== MAIN CONTENT — V2 ===== */
.main-content {
    margin-top: 0;
    margin-bottom: 76px;
    min-height: calc(100vh - 76px);
    background: var(--bg);
    overflow-y: auto;
}

/* ===== STICKY FOOTER — V2 ===== */
.sticky-footer {
    height: 76px;
    background: var(--surface-1);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-fixed, 90);
    box-shadow: none;
    padding: 0 4px;
}

.footer-btn {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border: none;
    background: transparent;
    color: var(--fg-3);
    text-decoration: none;
    cursor: pointer;
    transition: color 0.15s;
    font-family: var(--font-body, 'Inter', sans-serif);
    padding: 8px 4px;
}

.footer-btn:hover {
    color: var(--fg-1);
    background: transparent;
}

/* Active: indicador terracota en top, texto oscuro */
.footer-btn.active {
    color: var(--fg-1);
    background: transparent;
    font-weight: 600;
}

.footer-btn.active::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: var(--accent);
    border-radius: 0 0 3px 3px;
    animation: footer-slide-in 0.25s ease;
}

@keyframes footer-slide-in {
    from { width: 0; opacity: 0; }
    to { width: 40px; opacity: 1; }
}

.footer-btn i,
.footer-btn svg {
    width: 22px !important;
    height: 22px !important;
}

.footer-btn span {
    font-size: 11px;
    font-weight: inherit;
    letter-spacing: 0.01em;
}

.footer-btn:active {
    transform: scale(0.95);
}

/* ===== POS CENTER BUTTON — raised circle ===== */
.footer-btn--pos {
    justify-content: center;
    padding: 0 4px 6px;
    color: var(--fg-3);
    overflow: visible;
    gap: 3px;
}

.footer-btn--pos .footer-pos-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    box-shadow:
        0 4px 14px color-mix(in srgb, var(--accent) 35%, transparent),
        0 2px 6px rgba(0,0,0,0.12);
    transition: transform 0.2s cubic-bezier(.2,.8,.2,1.2), box-shadow 0.2s;
}

.footer-btn--pos .footer-pos-circle i,
.footer-btn--pos .footer-pos-circle svg {
    width: 24px !important;
    height: 24px !important;
}

.footer-btn--pos:hover .footer-pos-circle {
    transform: translateY(-3px) scale(1.04);
    box-shadow:
        0 8px 20px color-mix(in srgb, var(--accent) 45%, transparent),
        0 4px 10px rgba(0,0,0,0.14);
}

.footer-btn--pos:active .footer-pos-circle {
    transform: scale(0.94);
}

/* POS active: no top line — circle color is the indicator */
.footer-btn--pos.active::before {
    display: none;
}

.footer-btn--pos.active {
    color: var(--fg-2);
}

/* ===== LEGACY: COMPACT HEADER (for backwards compatibility) ===== */
.header {
    background: var(--surface-elevated);
    padding: 8px 20px;
    height: var(--header-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: var(--z-fixed);
}

.store-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.store-icon-vivid {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.store-icon-vivid i {
    color: var(--text-inverse);
}

.store-name {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-button-compact {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: var(--surface-store);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-button-compact:active {
    transform: scale(0.92);
}

/* ===== LEGACY: MAIN CONTAINER (for backwards compatibility) ===== */
.main-container {
    padding-bottom: 120px;
    min-height: calc(100vh - var(--header-height));
}

.view-container {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view-container.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-elevated);
    padding: 12px 20px 16px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    border-top: 1px solid var(--border);
    z-index: var(--z-fixed);
    height: var(--bottom-nav-height);
}

.nav-buttons {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 600px;
    margin: 0 auto;
}

.nav-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.nav-button:hover {
    background: var(--surface-store);
}

.nav-button.active {
    color: var(--color-price-blue);
    background: var(--color-price-blue-light);
}

.nav-button-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-button-label {
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-primary);
}

.nav-button:active {
    transform: scale(0.95);
}

/* ===== PAYMENT DRAWER ===== */
.payment-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-elevated);
    border-radius: 32px 32px 0 0;
    box-shadow: 0 -8px 48px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 200;
    max-height: 80vh;
    overflow-y: auto;
}

.payment-drawer.open {
    transform: translateY(0);
}

.payment-drawer-header {
    padding: 32px;
    text-align: center;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface-elevated);
    z-index: 1;
}

.payment-drawer-title {
    font-size: 32px;
    font-weight: 900;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.payment-drawer-total {
    font-size: 56px;
    font-weight: 900;
    color: var(--color-price-blue);
}

.payment-methods {
    padding: 32px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.payment-method {
    background: var(--surface-store);
    border-radius: 20px;
    padding: 32px;
    text-align: center;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s ease;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.payment-method:hover {
    transform: scale(1.05);
}

.payment-method:active {
    transform: scale(0.95);
}

.payment-method.cash {
    border-color: var(--warn);
}

.payment-method.cash:hover {
    background: color-mix(in srgb, var(--warn) var(--tint-bg-amt), var(--surface-1));
    border-color: var(--warn);
}

.payment-method.card {
    border-color: var(--color-price-blue-light);
}

.payment-method.card:hover {
    background: var(--color-price-blue-light);
    border-color: var(--color-price-blue);
}

.payment-method.transfer {
    border-color: var(--color-action-purple-light);
}

.payment-method.transfer:hover {
    background: var(--color-action-purple-light);
    border-color: var(--color-action-purple);
}

.payment-method-icon {
    width: 72px;
    height: 72px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.payment-method-name {
    font-size: 24px;
    font-weight: 800;
    color: var(--text-primary);
}

.close-drawer {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--color-remove-red);
    color: var(--text-inverse);
    position: absolute;
    top: 20px;
    right: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all 0.2s ease;
}

.close-drawer:active {
    transform: scale(0.9);
}

/* ===== SUCCESS OVERLAY ===== */
.success-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.success-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.success-content {
    text-align: center;
    color: var(--text-inverse);
    animation: success-pop 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes success-pop {
    from {
        transform: scale(0);
    }
    to {
        transform: scale(1);
    }
}

.success-icon {
    width: 140px;
    height: 140px;
    margin: 0 auto 24px;
}

.success-text {
    font-size: 56px;
    font-weight: 900;
    margin-bottom: 12px;
}

.success-subtext {
    font-size: 24px;
    font-weight: 600;
    opacity: 0.9;
}

/* Shake animation for cart */
.shake {
    animation: shake 0.3s ease;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .nav-button-label {
        font-size: 11px;
    }

    .payment-methods {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .payment-drawer-total {
        font-size: 42px;
    }

    .success-text {
        font-size: 42px;
    }
}

/* ============================================================
   FOOTER "MÁS" — badge de alertas
   ============================================================ */
.footer-btn__icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.footer-badge {
    position: absolute;
    top: -7px;
    right: -10px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    background: var(--bad);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 17px;
    text-align: center;
    border-radius: 9px;
    border: 2px solid var(--surface-1);
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
}

/* ============================================================
   TARJETA DE CUENTA (kx-account) — identidad + acciones
   Reutilizada en "Más" (admin) y en la hoja de Perfil (cajero/bodega).
   Naming sin sufijo "-card" para evitar la trampa de redesign.css.
   ============================================================ */
.kx-account {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg, 18px);
    padding: 14px 16px;
    display: grid;
    grid-template-areas:
        "top top"
        "user actions";
    grid-template-columns: 1fr auto;
    gap: 10px 12px;
}

.kx-account__top {
    grid-area: top;
    display: flex;
    align-items: center;
    gap: 10px;
}

.kx-account__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
    flex-shrink: 0;
}

.kx-account__company {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

.kx-account__company-name {
    font-family: var(--font-display, 'Fraunces', Georgia, serif);
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.015em;
    color: var(--fg-1);
    line-height: 1.1;
}

.kx-account__role {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    padding: 2px 7px;
    border-radius: 999px;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.kx-account__user {
    grid-area: user;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    background: var(--surface-2);
    border-radius: 12px;
}

.kx-account__avatar {
    width: 34px;
    height: 34px;
    background: var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.kx-account__avatar i,
.kx-account__avatar svg {
    width: 17px !important;
    height: 17px !important;
}

.kx-account__user-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.kx-account__user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.kx-account__user-email {
    font-size: 11px;
    color: var(--fg-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.kx-account__actions {
    grid-area: actions;
    display: flex;
    flex-direction: column;
    gap: 5px;
    align-self: center;
}

.kx-account__logout-form {
    margin: 0;
}

.kx-account__btn {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-1);
    color: var(--fg-1);
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-body, 'Inter', sans-serif);
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.08s;
}

.kx-account__btn i,
.kx-account__btn svg {
    width: 15px !important;
    height: 15px !important;
    flex-shrink: 0;
}

.kx-account__btn:hover {
    background: var(--surface-2);
    border-color: var(--surface-3);
}

.kx-account__btn:active {
    transform: scale(0.985);
}

.kx-account__btn--danger {
    color: var(--bad);
    border-color: color-mix(in srgb, var(--bad) 28%, transparent);
}

.kx-account__btn--danger:hover {
    background: color-mix(in srgb, var(--bad) 10%, transparent);
    border-color: color-mix(in srgb, var(--bad) 45%, transparent);
}

/* ============================================================
   CHIP DE CUENTA — versión compacta para el slot del page_header
   Uso: actions_template='v4/components/_account_chip.html'
   ============================================================ */
.kx-account-chip {
    position: relative;
    display: inline-flex;
}

.kx-account-chip__trigger {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px 6px 6px;
    background: var(--surface-1);
    border: 1.5px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.kx-account-chip__trigger:hover {
    background: var(--surface-2);
    border-color: var(--surface-3);
}

.kx-account-chip__avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kx-account-chip__avatar i,
.kx-account-chip__avatar svg {
    width: 13px !important;
    height: 13px !important;
}

.kx-account-chip__name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--fg-1);
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kx-account-chip__role {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    padding: 2px 6px;
    border-radius: 999px;
    white-space: nowrap;
}

.kx-account-chip__chevron {
    width: 14px !important;
    height: 14px !important;
    color: var(--fg-3);
    flex-shrink: 0;
    transition: transform 0.18s ease;
}

.kx-account-chip__chevron.is-open {
    transform: rotate(180deg);
}

/* ── Dropdown menu ── */
.kx-account-chip__menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 220px;
    background: var(--surface-1);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.06);
    z-index: 500;
    overflow: hidden;
}

.kx-account-chip__menu-header {
    padding: 12px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kx-account-chip__menu-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-1);
    font-family: var(--font-body, 'Inter', sans-serif);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kx-account-chip__menu-email {
    font-size: 11px;
    color: var(--fg-3);
    font-family: var(--font-body, 'Inter', sans-serif);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kx-account-chip__menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0;
}

.kx-account-chip__menu-actions {
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kx-account-chip__menu-item-form {
    margin: 0;
}

.kx-account-chip__menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--fg-1);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-body, 'Inter', sans-serif);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.1s;
    text-align: left;
}

.kx-account-chip__menu-item i,
.kx-account-chip__menu-item svg {
    width: 15px !important;
    height: 15px !important;
    flex-shrink: 0;
    color: var(--fg-2);
}

.kx-account-chip__menu-item:hover {
    background: var(--surface-2);
}

.kx-account-chip__menu-item--danger {
    color: var(--bad);
}

.kx-account-chip__menu-item--danger i,
.kx-account-chip__menu-item--danger svg {
    color: var(--bad);
}

.kx-account-chip__menu-item--danger:hover {
    background: color-mix(in srgb, var(--bad) 8%, transparent);
}

/* ── Transiciones Alpine ── */
.kx-chip-enter {
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.kx-chip-enter-start {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
}
.kx-chip-enter-end {
    opacity: 1;
    transform: translateY(0) scale(1);
}

/* ============================================================
   HOJA DE CUENTA (bottom-sheet) — cajero/bodega
   ============================================================ */
.kx-sheet {
    position: fixed;
    inset: 0;
    z-index: var(--z-popover, 600);
    display: flex;
    align-items: flex-end;
}

.kx-sheet__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: opacity 0.2s ease;
}

.kx-sheet__panel {
    position: relative;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    background: var(--surface-1);
    border-top-left-radius: 22px;
    border-top-right-radius: 22px;
    padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.22);
    transition: opacity 0.25s ease, transform 0.25s cubic-bezier(.2, .8, .2, 1);
}

.kx-sheet__grip {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--surface-3);
    margin: 4px auto 14px;
    cursor: pointer;
}

/* Dentro de la hoja la tarjeta no necesita su propio marco */
.kx-sheet__panel .kx-account {
    border: none;
    border-radius: 0;
    padding: 0;
}

/* Helpers de transición Alpine para la hoja */
.kx-fade-start { opacity: 0; }
.kx-fade-end { opacity: 1; }
.kx-sheet-start { opacity: 0; transform: translateY(100%); }
.kx-sheet-end { opacity: 1; transform: translateY(0); }
