/* =========================================
   MATERIAL DESIGN 3 TOKENS & RESET
   ========================================= */
:root {
    /* Tipografía */
    --font-family: 'Roboto', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Light Mode (Default) */
    --md-sys-color-primary: #006e1c;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #95f996;
    --md-sys-color-on-primary-container: #002204;

    --md-sys-color-secondary: #52634f;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #d5e8cf;
    --md-sys-color-on-secondary-container: #111f0f;

    --md-sys-color-tertiary: #38656a;
    --md-sys-color-tertiary-container: #bcebf0;
    --md-sys-color-on-tertiary-container: #002023;

    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;

    --md-sys-color-background: #fdfdf5;
    --md-sys-color-on-background: #1a1c19;

    --md-sys-color-surface: #fdfdf5;
    --md-sys-color-on-surface: #1a1c19;
    --md-sys-color-surface-variant: #dee5d8;
    --md-sys-color-on-surface-variant: #424940;
    --md-sys-color-outline: #72796f;

    --md-sys-color-surface-container-low: #f8fbf2;
    --md-sys-color-surface-container: #f2f6ec;
    --md-sys-color-surface-container-high: #ecf0e7;

    /* Elevation shadows */
    --elevation-1: 0px 1px 3px 1px rgba(0, 0, 0, 0.15), 0px 1px 2px 0px rgba(0, 0, 0, 0.30);
    --elevation-3: 0px 4px 8px 3px rgba(0, 0, 0, 0.15), 0px 1px 3px 0px rgba(0, 0, 0, 0.30);
    --elevation-modal: 0px 8px 12px 6px rgba(0, 0, 0, 0.15), 0px 4px 4px 0px rgba(0, 0, 0, 0.30);

    /* Radii */
    --radius-s: 8px;
    --radius-m: 12px;
    --radius-l: 16px;
    --radius-xl: 28px;
    --radius-full: 9999px;

    /* Transitions */
    --motion-duration-short: 200ms;
    --motion-duration-medium: 400ms;
    --motion-easing-standard: cubic-bezier(0.2, 0.0, 0, 1.0);
}

/* Dark Mode Tokens */
[data-theme="dark"] {
    --md-sys-color-primary: #7ada7c;
    --md-sys-color-on-primary: #00390a;
    --md-sys-color-primary-container: #005313;
    --md-sys-color-on-primary-container: #95f996;

    --md-sys-color-secondary: #baccb4;
    --md-sys-color-on-secondary: #253423;
    --md-sys-color-secondary-container: #3b4b38;
    --md-sys-color-on-secondary-container: #d5e8cf;

    --md-sys-color-background: #1a1c19;
    --md-sys-color-on-background: #e2e3dd;

    --md-sys-color-surface: #121212;
    --md-sys-color-on-surface: #e2e3dd;
    --md-sys-color-surface-variant: #424940;
    --md-sys-color-on-surface-variant: #c2c9bd;
    --md-sys-color-outline: #8c9388;

    --md-sys-color-surface-container-low: #1a1c19;
    --md-sys-color-surface-container: #1e201d;
    --md-sys-color-surface-container-high: #282b27;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    transition: background-color var(--motion-duration-medium) var(--motion-easing-standard);
    min-height: 100vh;
    overscroll-behavior-y: none;
}

/* CLASE CRÍTICA PARA EVITAR SCROLL DE FONDO */
body.no-scroll {
    overflow: hidden;
    height: 100vh;
}

/* =========================================
   SPLASH SCREEN
   ========================================= */
#splash-screen {
    position: fixed;
    inset: 0;
    background-color: var(--md-sys-color-surface);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity var(--motion-duration-medium);
}

.splash-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.splash-logo {
    width: 120px;
    height: auto;
    animation: fadeScale 0.8s ease-out;
}

.loading-spinner svg {
    width: 48px;
    height: 48px;
    animation: rotate 2s linear infinite;
}

.loading-spinner circle {
    stroke: var(--md-sys-color-primary);
    stroke-width: 4;
    stroke-dasharray: 1, 200;
    stroke-dashoffset: 0;
    animation: dash 1.5s ease-in-out infinite;
    stroke-linecap: round;
}

@keyframes rotate { 100% { transform: rotate(360deg); } }
@keyframes dash {
    0% { stroke-dasharray: 1, 200; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 89, 200; stroke-dashoffset: -35px; }
    100% { stroke-dasharray: 89, 200; stroke-dashoffset: -124px; }
}

@keyframes fadeScale {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* =========================================
   LAYOUT & TYPOGRAPHY
   ========================================= */
.app-container {
    padding-bottom: 88px; /* Espacio para bottom nav */
    max-width: 800px;
    margin: 0 auto;
    border-left: 1px solid transparent;
    border-right: 1px solid transparent;
}

@media (min-width: 801px) {
    .app-container {
        border-color: var(--md-sys-color-outline);
        background-color: var(--md-sys-color-surface-container-low);
        min-height: 100vh;
        box-shadow: var(--elevation-1);
    }
}

.headline-small { font-size: 24px; font-weight: 400; line-height: 32px; }
.title-large { font-size: 22px; font-weight: 400; line-height: 28px; }
.label-large { font-size: 14px; font-weight: 500; line-height: 20px; letter-spacing: 0.1px; }
.label-medium { font-size: 12px; font-weight: 500; line-height: 16px; letter-spacing: 0.5px; }
.body-medium { font-size: 14px; font-weight: 400; line-height: 20px; letter-spacing: 0.25px; }

.hidden { display: none !important; }

/* =========================================
   COMPONENTS
   ========================================= */

/* Top App Bar */
.top-app-bar {
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    transition: background-color 0.3s;
}

.top-app-bar.scrolled {
    background-color: var(--md-sys-color-surface-container);
    box-shadow: var(--elevation-1);
}

.headline-container { display: flex; align-items: center; gap: 12px; }
.header-logo { height: 32px; width: auto; }

/* Icon Buttons */
.icon-button {
    background: transparent;
    border: none;
    color: var(--md-sys-color-on-surface-variant);
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.icon-button:hover { background-color: rgba(var(--md-sys-color-on-surface-rgb), 0.08); }
.icon-button svg { width: 24px; height: 24px; }
.icon-button-small { @extend .icon-button; width: 32px; height: 32px; padding: 4px; }

/* Buttons */
.btn-filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    border: none;
    height: 40px;
    border-radius: var(--radius-full);
    padding: 0 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: box-shadow 0.2s, transform 0.1s;
}

.btn-filled:active { transform: scale(0.98); }

.btn-tonal {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border: none;
    height: 40px;
    border-radius: var(--radius-full);
    padding: 0 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-text {
    background: transparent;
    border: none;
    color: var(--md-sys-color-primary);
    height: 40px;
    border-radius: var(--radius-full);
    padding: 0 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.btn-icon { width: 18px; height: 18px; fill: currentColor; }
.w-100 { width: 100%; }
.mb-2 { margin-bottom: 8px; }

/* Cards */
.card-outlined {
    background-color: var(--md-sys-color-surface);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--radius-l);
    padding: 24px;
}

.centered-card {
    max-width: 400px;
    margin: 40px auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Inputs & Selects */
.select-wrapper {
    position: relative;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 4px 4px 0 0;
    border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
}

.m3-select {
    width: 100%;
    height: 56px;
    background: transparent;
    border: none;
    padding: 0 16px;
    font-size: 16px;
    color: var(--md-sys-color-on-surface);
    appearance: none;
    outline: none;
}

.select-arrow {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    fill: var(--md-sys-color-on-surface-variant);
    pointer-events: none;
}

/* Lists (Catalog) */
.catalog-list {
    /* AUMENTAMOS EL PADDING BOTTOM PARA QUE EL ULTIMO ITEM NO QUEDE OCULTO POR LOS FABS */
    padding: 0 16px 140px 16px;
    content-visibility: auto;
    contain-intrinsic-size: 1000px;
}

.category-section { margin-top: 24px; }
.category-header {
    color: var(--md-sys-color-primary);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.product-item {
    display: flex;
    align-items: center;
    gap: 12px; /* Espacio entre imagen e info */
    padding: 12px 0;
    border-bottom: 1px solid var(--md-sys-color-surface-variant);
    animation: slideIn 0.3s ease-out;
}

/* NUEVO: IMAGEN DE PRODUCTO */
.product-img-placeholder {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    background-color: var(--md-sys-color-surface-container-high);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--md-sys-color-on-surface-variant);
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}

.product-img-placeholder img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.product-info { flex: 1; }
.product-name { font-size: 16px; color: var(--md-sys-color-on-surface); margin-bottom: 2px; }
.product-code { font-size: 12px; color: var(--md-sys-color-on-surface-variant); }

.product-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    background-color: var(--md-sys-color-surface-container-high);
    padding: 4px;
    border-radius: var(--radius-full);
}

.control-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    box-shadow: var(--elevation-1);
}

.control-btn:active { background: var(--md-sys-color-primary-container); }
.quantity-display { font-weight: 500; min-width: 24px; text-align: center; }

/* Chips */
.sucursal-header { padding: 16px; display: flex; align-items: center; justify-content: space-between; }
.chip-assist {
    display: inline-flex;
    align-items: center;
    height: 32px;
    padding: 0 16px;
    gap: 8px;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
}
.chip-icon, .chip-trailing { width: 18px; height: 18px; fill: var(--md-sys-color-primary); }

/* =========================================
   NAVIGATION BAR
   ========================================= */
.navigation-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background-color: var(--md-sys-color-surface-container);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-destination {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 64px;
    cursor: pointer;
    color: var(--md-sys-color-on-surface-variant);
}

.nav-icon-container {
    width: 64px;
    height: 32px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s, width 0.2s;
    position: relative;
}

.nav-icon { width: 24px; height: 24px; fill: currentColor; }
.nav-destination.active { color: var(--md-sys-color-on-surface); }
.nav-destination.active .nav-icon-container {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}

.badge {
    position: absolute;
    top: -4px;
    right: 10px;
    background-color: var(--md-sys-color-error);
    color: white;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
}

/* =========================================
   MODALS & DIALOGS
   ========================================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0,0,0,0.5);
    z-index: 2000;
    display: flex;
    transition: opacity 0.3s;
    overscroll-behavior: contain;
}

/* Bottom Sheet */
.bottom-sheet {
    margin-top: auto;
    width: 100%;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    background-color: var(--md-sys-color-surface);
    border-radius: 28px 28px 0 0;
    padding: 16px 16px 0 16px;
    animation: slideUp 0.3s cubic-bezier(0.2, 0, 0, 1);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    height: auto;
}

@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.sheet-handle {
    width: 32px;
    height: 4px;
    background-color: var(--md-sys-color-outline);
    opacity: 0.4;
    border-radius: 2px;
    align-self: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.sheet-list {
    overflow-y: auto;
    flex: 1;
    margin-bottom: 16px;
    padding-bottom: 20px;
}

.sheet-actions {
    flex-shrink: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    background: var(--md-sys-color-surface);
}

.sheet-item {
    padding: 16px;
    font-size: 16px;
    border-bottom: 1px solid var(--md-sys-color-outline);
    opacity: 0.8;
    cursor: pointer;
}

/* ESTILOS PARA RESUMEN DE CATEGORÍAS EN MODAL */
.sheet-category-header {
    padding: 12px 16px;
    background-color: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-primary);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-radius: 8px;
    margin-bottom: 4px;
    margin-top: 12px;
}
.sheet-category-header:first-child {
    margin-top: 0;
}

/* Full Screen Dialog (Search) */
.full-screen-dialog {
    position: fixed;
    inset: 0;
    background-color: var(--md-sys-color-surface-container-high);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease-in-out;
}

.full-screen-dialog.active { transform: translateY(0); }

.dialog-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 4px;
    gap: 8px;
}

.dialog-header input {
    flex: 1;
    height: 48px;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--md-sys-color-on-surface);
    outline: none;
}

/* Alert Dialog */
.alert-dialog {
    background-color: var(--md-sys-color-surface-container-high);
    padding: 24px;
    border-radius: 28px;
    max-width: 312px;
    width: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: var(--elevation-modal);
}

.dialog-icon { width: 24px; height: 24px; fill: var(--md-sys-color-secondary); margin-bottom: 16px; }

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    width: 100%;
    gap: 8px;
    margin-top: 24px;
}

/* Install Banner */
.install-banner {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 16px;
    border-radius: 16px;
    box-shadow: var(--elevation-1);
}

.install-content { display: flex; gap: 16px; align-items: center; }
.install-content img { width: 40px; height: 40px; }

/* Toast */
.toast {
    background-color: var(--md-sys-color-on-surface);
    color: var(--md-sys-color-surface);
    padding: 14px 16px;
    border-radius: 4px;
    margin-top: 8px;
    font-size: 14px;
    box-shadow: var(--elevation-3);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-width: 300px;
    animation: fadeUp 0.3s;
}

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

#toast-container {
    position: fixed;
    bottom: 100px; /* Encima del nav */
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
}

/* =========================================
   FAB ROW CONTAINER (Nuevo Estilo)
   ========================================= */
.fab-row-container {
    position: fixed;
    bottom: 100px; /* Encima de la barra de navegación */
    right: 16px;
    /* Ahora es row (fila) */
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    z-index: 900;
    pointer-events: none; /* El contenedor es invisible a clicks */
}

/* Botones Extendidos iguales */
.fab-extended {
    height: 56px;
    border-radius: 16px;
    border: none;
    box-shadow: var(--elevation-3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 0 20px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 500;
    gap: 8px;
    letter-spacing: 0.1px;
}

.fab-extended:active {
    transform: scale(0.96);
    box-shadow: var(--elevation-1);
}

.fab-extended svg {
    width: 24px;
    height: 24px;
    fill: currentColor;
}

/* Colores Específicos */
.fab-primary {
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

.fab-secondary {
    background-color: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
}