/* =========================================================================
   Mayorflow.Pedidos — App de preventa tablet.
   Estilos basados en el boceto: layout de 3 vistas, sidebar 380px, catálogo
   con tarjetas, stepper táctil y badges de stock.
   ========================================================================= */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

html, body {
    background-color: #f0f2f5;
    height: 100vh;
    overflow: hidden;
    touch-action: manipulation;
}

#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
    /* No usar align-items: center aquí: en flex-column el eje cruzado es el horizontal,
       y center dejaría de estirar los hijos al ancho completo (rompería el 100% de ancho).
       El contenido real (.app-shell) se dimensiona a sí mismo (height:100vh, width 100%).
       La pantalla de carga se centra con margin:auto en sus propias reglas. */
}

a { color: #007bff; }
.text-muted { color: #6c757d; font-size: 0.85rem; }

/* ── Pantalla de carga inicial (Blazor bootstrap) ──
   Centra el spinner vertical y horizontalmente usando margin:auto dentro de #app
   (flex column), sin afectar al ancho del contenido real cuando Blazor ya renderizó. */

.loading-progress {
    position: relative;
    display: block;
    width: 6rem;
    height: 6rem;
    margin: auto auto 0;
}

.loading-progress circle {
    fill: none;
    stroke-width: 0.5rem;
    stroke-linecap: round;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:nth-child(1) {
    stroke: #d4d8de;
}

.loading-progress circle:nth-child(2) {
    stroke: #0f6f4e;
    stroke-dasharray: 90, 150;
    stroke-dashoffset: 0;
    animation: loading-progress-rotate 1s ease-in-out infinite;
}

@keyframes loading-progress-rotate {
    0% { stroke-dasharray: 1, 150; stroke-dashoffset: 0; }
    50% { stroke-dasharray: 90, 150; stroke-dashoffset: -35; }
    100% { stroke-dasharray: 90, 150; stroke-dashoffset: -124; }
}

.loading-progress-text {
    margin: 0.6rem auto 0;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    color: #6c757d;
    width: 6rem;
}

/* ── UI de error de Blazor (no manejado) ── */
#blazor-error-ui {
    background: #fff;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
    border-left: 4px solid #dc3545;
    color: #212529;
    display: none;
    font-size: 0.9rem;
    padding: 1rem 1.25rem;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
}

#blazor-error-ui .reload {
    color: #0f6f4e;
    font-weight: 600;
    margin-left: 0.75rem;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    color: #6c757d;
    float: right;
    font-size: 1.1rem;
    margin-left: 0.75rem;
}

/* ── Shell con barra de conexión + contenido ── */
.app-shell { display: flex; flex-direction: column; height: 100vh; }
.app-content { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.conexion-bar {
    flex: 0 0 auto; display: flex; align-items: center; gap: 8px;
    padding: 5px 14px; font-size: .8rem; font-weight: 600; color: #fff;
}
.conexion-bar.online { background: #0f6f4e; }
.conexion-bar.offline { background: #b8650f; }
.conexion-dot { width: 9px; height: 9px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }

/* ── Botones ── */
.btn {
    background-color: #0f6f4e;
    color: #fff;
    padding: 16px;
    border: none;
    border-radius: 8px;
    font-size: 1.05rem;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    width: 100%;
    box-shadow: 0 4px 6px rgba(15, 111, 78, 0.15);
}
.btn:disabled { background-color: #adb5bd; opacity: .6; cursor: not-allowed; box-shadow: none; }
.btn-add { background-color: #17a2b8; padding: 12px; margin-top: 4px; }
.btn-add:hover { background-color: #117a8b; }
.btn-volver { background: none; border: none; color: #0f6f4e; font-size: .9rem; font-weight: 600; cursor: pointer; padding: 0 0 8px; text-align: left; }

/* =========================================================================
   VISTA 1: LOGIN (teclado numérico de 10 dígitos)
   ========================================================================= */
.login-view, .selection-view, .preventa-view {
    display: flex; height: 100%; width: 100%; flex: 1 1 auto; min-height: 0;
}

.login-container {
    margin: auto; background: #fff; padding: 40px; border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1); width: 100%; max-width: 420px; text-align: center;
}
.login-container h2 { margin-bottom: 8px; color: #1a1a1a; }
.login-subtitle { color: #6c757d; margin-bottom: 24px; font-size: .95rem; }

.pin-display { display: flex; justify-content: center; gap: 8px; margin-bottom: 28px; }
.pin-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #0f6f4e; background: #fff; }
.pin-dot.filled { background: #0f6f4e; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keypad-btn {
    background: #e9ecef; border: 1px solid #ced4da; border-radius: 12px;
    padding: 18px 0; font-size: 1.6rem; font-weight: bold; color: #212529; cursor: pointer;
}
.keypad-btn:active { background: #dee2e6; }
.keypad-btn:disabled { opacity: .5; }
.keypad-ok { background: #0f6f4e; color: #fff; border-color: #0f6f4e; }
.keypad-back { background: #f8d7da; border-color: #f5c6cb; color: #721c24; }

.login-error { color: #dc3545; margin-top: 16px; font-weight: 600; }
.login-sync { color: #0f6f4e; margin-top: 12px; }

/* =========================================================================
   VISTA 2: SELECCIÓN DE CLIENTE Y PUNTO
   ========================================================================= */
.selection-container {
    margin: auto; background: #fff; padding: 40px; border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1); width: 100%; max-width: 500px;
}
.selection-container h2 { margin-bottom: 20px; color: #1a1a1a; text-align: center; }

.form-group { margin-bottom: 20px; text-align: left; position: relative; }
.form-group label { display: block; font-size: .85rem; color: #555; text-transform: uppercase; margin-bottom: 8px; font-weight: bold; }

input[type="text"], input[type="date"], textarea, select {
    width: 100%; padding: 14px; border: 1px solid #ccd0d5; border-radius: 8px;
    font-size: 1rem; background-color: #f8f9fa;
}
textarea { resize: none; height: 70px; font-size: .9rem; }

/* Combo con buscador */
.search-select { position: relative; width: 100%; }
.search-select-input { padding-right: 40px; }
.search-select-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 1.1rem; color: #888; pointer-events: none; }
.search-select-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; background: #fff;
    border: 1px solid #ccd0d5; border-radius: 8px; max-height: 240px; overflow-y: auto;
    z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.1); margin-top: 4px;
}
.search-select-dropdown.show { display: block; }
.dropdown-item { padding: 12px 14px; cursor: pointer; font-size: .95rem; border-bottom: 1px solid #f1f3f5; display: flex; flex-direction: column; }
.dropdown-item small { color: #888; font-size: .8rem; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background-color: #0f6f4e; color: #fff; }
.dropdown-item:hover small { color: #cfe9dd; }
.dropdown-item.no-results { color: #888; background: #fff; cursor: default; }

/* =========================================================================
   VISTA 3: PREVENTA (sidebar + catálogo)
   ========================================================================= */
.sidebar {
    width: 380px; background: #fff; box-shadow: 2px 0 8px rgba(0,0,0,.15);
    display: flex; flex-direction: column; padding: 18px; z-index: 10;
    flex-shrink: 0; overflow-y: auto; height: 100%;
}
.sidebar-header h2 { margin-bottom: 12px; color: #1a1a1a; font-size: 1.3rem; }

.active-client-box { background: #e8f4fd; border: 1px solid #bfe3f8; padding: 14px; border-radius: 8px; margin-bottom: 18px; }
.active-client-box p { font-size: .92rem; color: #1c537a; margin-bottom: 4px; }
.active-client-box p strong { color: #0b2e47; }

.section-title { font-size: .82rem; color: #555; text-transform: uppercase; margin: 16px 0 8px; font-weight: bold; letter-spacing: .5px; }

/* Carrito */
.cart { display: flex; flex-direction: column; flex-shrink: 0; margin-top: 8px; }
.cart-items { max-height: 240px; overflow-y: auto; border-top: 1px solid #e9ecef; padding-top: 8px; margin-bottom: 12px; }
.cart-item { padding: 10px 0; border-bottom: 1px solid #f1f3f5; font-size: .92rem; display: flex; justify-content: space-between; align-items: center; }
.cart-item-info { flex-grow: 1; padding-right: 8px; }
.cart-item-info small { color: #6c757d; }
.cart-item-price { font-weight: bold; color: #333; text-align: right; margin-right: 8px; white-space: nowrap; }
.cart-empty { color: #888; justify-content: center; }
.btn-remove { background: none; border: none; color: #dc3545; cursor: pointer; font-weight: bold; padding: 8px; font-size: 1.3rem; line-height: 1; }

.cart-total-container { padding: 12px 0 4px; border-top: 2px solid #e9ecef; font-size: 1rem; color: #495057; }
.total-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.total-row.final { font-size: 1.25rem; font-weight: bold; color: #000; margin-top: 6px; padding-top: 6px; border-top: 1px dashed #ced4da; margin-bottom: 14px; }

/* Catálogo central */
.main-content { flex-grow: 1; padding: 22px; display: flex; flex-direction: column; overflow: hidden; }
.search-bar { width: 100%; padding: 14px; font-size: 1.05rem; margin-bottom: 14px; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.04); }

.families-grid { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; flex-shrink: 0; }
.family-btn { background: #e9ecef; color: #495057; padding: 10px 20px; border: 1px solid #ced4da; border-radius: 50px; cursor: pointer; font-weight: bold; font-size: .9rem; }
.family-btn.active { background: #0f6f4e; color: #fff; border-color: #0f6f4e; }
/* Botón "← Todas": navegación hacia atrás desde el nivel de subfamilias. */
.family-btn-back { background: #fff; color: #0f6f4e; border-color: #0f6f4e; }
.family-btn-back:hover { background: #e6f3ee; }

.products-scroll-container { flex-grow: 1; overflow-y: auto; }
.products-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 18px; padding-bottom: 18px; }

.product-card { background: #fff; border-radius: 12px; box-shadow: 0 4px 6px rgba(0,0,0,.05); padding: 16px; display: flex; flex-direction: column; border: 1px solid #e9ecef; }
.product-header { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 12px; }
.product-img { width: 70px; height: 70px; border-radius: 8px; object-fit: cover; border: 1px solid #dee2e6; flex-shrink: 0; }
.product-info-text { flex-grow: 1; }
.product-info-text h3 { margin-bottom: 4px; font-size: 1.1rem; color: #212529; }

.stock-badge { font-size: .72rem; font-weight: bold; padding: 3px 8px; border-radius: 4px; display: inline-block; margin-bottom: 6px; }
.stock-disponible { background: #d4edda; color: #155724; }
.stock-critico { background: #fff3cd; color: #856404; }
.stock-agotado { background: #f8d7da; color: #721c24; }

.product-options { display: flex; gap: 10px; margin-bottom: 10px; align-items: center; }
.format-select-container { flex: 1.4; }
.format-select-container select { height: 48px; padding: 10px; margin-bottom: 0; }
.qty-stepper { display: flex; align-items: center; background: #f1f3f5; border-radius: 8px; border: 1px solid #ced4da; overflow: hidden; height: 48px; flex: 1; }
.stepper-btn { background: none; border: none; width: 42px; height: 100%; font-size: 1.5rem; font-weight: bold; color: #495057; cursor: pointer; }
.stepper-btn:active { background: #e9ecef; }
.stepper-value { flex-grow: 1; text-align: center; font-weight: bold; font-size: 1.1rem; color: #212529; }

.equivalencia { font-size: .85rem; color: #495057; font-style: italic; min-height: 20px; margin-bottom: 8px; }

/* Botón primario hereda padding generoso del tema general */
.btn { padding: 14px; }

/* Loading / error states */
.p-4 { padding: 2rem; }
