/* ================================================================
   SysGestion - Control de Stock
   app.css — Estilos principales (mobile-first)
   ================================================================ */

/* ----------------------------------------------------------------
   Variables CSS (theming)
   ---------------------------------------------------------------- */
:root {
    --sg-primary:      #0d6efd;
    --sg-primary-dark: #0a58ca;
    --sg-success:      #198754;
    --sg-warning:      #ffc107;
    --sg-danger:       #dc3545;
    --sg-bg:           #f4f6f9;
    --sg-card-bg:      #ffffff;
    --sg-text:         #212529;
    --sg-text-muted:   #6c757d;
    --sg-border:       #dee2e6;
    --sg-radius:       12px;
    --sg-shadow:       0 2px 8px rgba(0, 0, 0, 0.08);
    --nav-height:      64px;  /* alto de la barra inferior */
    --top-height:      56px;  /* alto de la barra superior */
}

/* ----------------------------------------------------------------
   Reset y base
   ---------------------------------------------------------------- */
*, *::before, *::after {
    box-sizing: border-box;
}

html {
    /* Evitar que el contenido quede debajo de barras iOS */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

body {
    background-color: var(--sg-bg);
    color: var(--sg-text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}

/* ----------------------------------------------------------------
   Layout principal
   ---------------------------------------------------------------- */
.main-content {
    min-height: calc(100vh - var(--top-height) - var(--nav-height));
}

/* Padding inferior para no quedar tapado por la nav inferior */
.pb-nav {
    padding-bottom: calc(var(--nav-height) + 8px + env(safe-area-inset-bottom));
}

/* ----------------------------------------------------------------
   Barra de navegación inferior
   ---------------------------------------------------------------- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    height: var(--nav-height);
    background: #ffffff;
    border-top: 1px solid var(--sg-border);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
    /* Safe area iOS */
    padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--sg-text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: color 0.15s ease, transform 0.1s ease;
    -webkit-user-select: none;
    user-select: none;
}

.bottom-nav__item i {
    font-size: 20px;
    line-height: 1;
}

.bottom-nav__item span {
    line-height: 1;
}

.bottom-nav__item:active {
    transform: scale(0.92);
}

.bottom-nav__item.active {
    color: var(--sg-primary);
}

.bottom-nav__item.active i {
    font-size: 22px;
}

/* ----------------------------------------------------------------
   Cards de zona / resumen
   ---------------------------------------------------------------- */
.card {
    border: 1px solid var(--sg-border);
    border-radius: var(--sg-radius);
    box-shadow: var(--sg-shadow);
}

.card-zona {
    border-radius: var(--sg-radius);
    overflow: hidden;
    transition: box-shadow 0.2s ease, transform 0.1s ease;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.card-zona:active {
    transform: scale(0.98);
    box-shadow: var(--sg-shadow);
    color: inherit;
}

.card-zona .zona-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: #fff;
    flex-shrink: 0;
}

/* ----------------------------------------------------------------
   Tarjetas de KPI / resumen diario
   ---------------------------------------------------------------- */
.kpi-card {
    border-radius: var(--sg-radius);
    padding: 14px 16px;
    background: var(--sg-card-bg);
    box-shadow: var(--sg-shadow);
    border: 1px solid var(--sg-border);
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.kpi-card .kpi-label {
    font-size: 12px;
    color: var(--sg-text-muted);
    margin-top: 2px;
}

/* ----------------------------------------------------------------
   Tabla de artículos en conteo
   ---------------------------------------------------------------- */
.articulo-card {
    background: var(--sg-card-bg);
    border: 1px solid var(--sg-border);
    border-radius: var(--sg-radius);
    margin-bottom: 10px;
    overflow: hidden;
    transition: border-color 0.15s;
}

.articulo-card.highlight {
    border-color: var(--sg-primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.articulo-card .art-body {
    padding: 12px 14px;
}

.articulo-card .art-nombre {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 8px;
    line-height: 1.3;
}

.articulo-card .art-codigo {
    font-size: 11px;
    color: var(--sg-text-muted);
    font-family: monospace;
}

.info-pill {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--sg-bg);
    min-width: 60px;
}

.info-pill .pill-value {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.1;
}

.info-pill .pill-label {
    font-size: 10px;
    color: var(--sg-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

/* ----------------------------------------------------------------
   Input de cantidad con botones +/-
   ---------------------------------------------------------------- */
.qty-group {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1.5px solid var(--sg-border);
    border-radius: 8px;
    overflow: hidden;
    height: 44px;
}

.qty-group .qty-btn {
    background: var(--sg-bg);
    border: none;
    width: 44px;
    height: 44px;
    font-size: 20px;
    font-weight: 600;
    color: var(--sg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.qty-group .qty-btn:active {
    background: #e0e7ff;
}

.qty-group .qty-input {
    flex: 1;
    border: none;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
    height: 100%;
    min-width: 0;
    background: #fff;
    color: var(--sg-text);
    outline: none;
    padding: 0 4px;
}

.qty-group .qty-input:focus {
    background: #fff;
}

/* ----------------------------------------------------------------
   Badge de reposición
   ---------------------------------------------------------------- */
.badge-reponer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    padding: 0 10px;
}

.badge-reponer.reponer-ok {
    background: #d1fae5;
    color: #065f46;
}

.badge-reponer.reponer-needed {
    background: #fee2e2;
    color: #991b1b;
}

/* ----------------------------------------------------------------
   Página de login
   ---------------------------------------------------------------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0d6efd 0%, #0a3d8f 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 20px;
    padding: 36px 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo i {
    font-size: 48px;
    color: var(--sg-primary);
}

.login-logo h1 {
    font-size: 20px;
    font-weight: 700;
    margin-top: 10px;
    color: var(--sg-text);
}

.login-logo p {
    font-size: 13px;
    color: var(--sg-text-muted);
    margin: 0;
}

/* ----------------------------------------------------------------
   Scanner overlay
   ---------------------------------------------------------------- */
#scanner-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
    display: flex;
    flex-direction: column;
}

#scanner-view {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#scanner-view video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -60%);
    width: 240px;
    height: 160px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.scanner-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: #f00;
    animation: scan-line 2s ease-in-out infinite;
}

@keyframes scan-line {
    0%, 100% { top: 10px; }
    50%       { top: calc(100% - 12px); }
}

.scanner-footer {
    background: rgba(0, 0, 0, 0.85);
    padding: 18px 20px;
    padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

/* ----------------------------------------------------------------
   Estados vacíos
   ---------------------------------------------------------------- */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--sg-text-muted);
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
    opacity: 0.4;
}

.empty-state h5 {
    color: var(--sg-text);
    margin-bottom: 8px;
}

/* ----------------------------------------------------------------
   Botón flotante de acción (FAB)
   ---------------------------------------------------------------- */
.fab {
    position: fixed;
    bottom: calc(var(--nav-height) + 16px + env(safe-area-inset-bottom));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--sg-primary);
    color: #fff;
    font-size: 22px;
    box-shadow: 0 4px 16px rgba(13, 110, 253, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1020;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    text-decoration: none;
}

.fab:active, .fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.5);
    color: #fff;
}

/* ----------------------------------------------------------------
   Toast de notificación
   ---------------------------------------------------------------- */
#toast-container {
    position: fixed;
    top: calc(var(--top-height) + 8px);
    right: 12px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 320px;
}

.sg-toast {
    padding: 12px 16px;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--sg-shadow);
    animation: toast-in 0.25s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sg-toast.success { background: var(--sg-success); }
.sg-toast.error   { background: var(--sg-danger); }
.sg-toast.info    { background: var(--sg-primary); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ----------------------------------------------------------------
   Spinner de carga
   ---------------------------------------------------------------- */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(255, 255, 255, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ----------------------------------------------------------------
   Utilidades adicionales
   ---------------------------------------------------------------- */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.border-start-4 {
    border-left-width: 4px !important;
}

/* Ajuste tipográfico para números grandes */
.font-mono {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
}

/* Responsive: en pantallas grandes centrar la app como si fuera móvil */
@media (min-width: 768px) {
    body {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
    }
    .bottom-nav,
    #topNavbar,
    .loading-overlay,
    #scanner-overlay {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        width: 480px;
    }
    .fab {
        right: calc(50% - 480px/2 + 20px);
    }
}
