
/* ==========================
   1. VARIABLES DE DISEÑO
   ========================== */

:root {
    --fondo: #f2f2f7;
    --tarjeta: #ffffff;
    --oscuro: #111827;
    --texto: #1c1c1e;
    --secundario: #8e8e93;
    --verde: #16a34a;
    --rojo: #dc2626;
    --azul: #007aff;
    --borde: #e5e7eb;
}


/* ==========================
   2. CONFIGURACIÓN GENERAL
   ========================== */

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--fondo);
    color: var(--texto);

    font-family: -apple-system,
        BlinkMacSystemFont,
        "Helvetica Neue",
        Arial,
        sans-serif;

    -webkit-font-smoothing: antialiased;
}

[hidden] {
    display: none !important;
}


/* ==========================
   3. ENCABEZADO FLOTANTE
   ========================== */

header {
    background: var(--oscuro);
    color: white;

    margin: 24px auto 0;
    width: calc(100% - 48px);
    max-width: 802px;

    padding: 28px 24px;
    border-radius: 28px;

    box-shadow: 0 6px 20px rgba(0,0,0,0.10);
}

header h1 {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -1px;
    margin: 0 0 10px;
}

header p {
    color: #cbd5e1;
    font-size: 14px;
    margin: 0;
}


/* ==========================
   4. CONTENEDOR PRINCIPAL
   ========================== */

main {
    max-width: 850px;
    margin: auto;
    padding: 24px;
    padding-bottom: 40px;
}


/* ==========================
   5. TARJETAS
   ========================== */

.tarjeta {
    background: var(--tarjeta);
    padding: 24px;
    border-radius: 24px;
    margin-bottom: 20px;

    box-shadow: 0 4px 20px rgba(0,0,0,0.045);

    animation: aparecer 0.3s ease;
}

h2 {
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin: 0 0 20px;
}


/* ==========================
   6. INDICADORES DEL INVENTARIO
   ========================== */

.resumen {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.indicador {
    background: var(--tarjeta);
    border-radius: 22px;
    padding: 20px;

    box-shadow: 0 4px 20px rgba(0,0,0,0.045);
}

.indicador span {
    display: block;
    color: #64748b;
    font-size: 13px;
    font-weight: 500;
}

.indicador strong {
    display: block;
    margin-top: 8px;
    font-size: 30px;
    color: var(--oscuro);
}


/* ==========================
   7. CAMPOS DE FORMULARIO
   ========================== */

label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin: 16px 0 8px;
}

input,
select {
    width: 100%;
    min-height: 50px;
    padding: 14px 16px;

    background: var(--fondo);
    border: 1px solid transparent;
    border-radius: 14px;

    color: var(--texto);
    font-family: inherit;
    font-size: 16px;

    outline: none;
    transition: all 0.2s ease;
}

input::placeholder {
    color: var(--secundario);
}

input:focus,
select:focus {
    background: white;
    border-color: var(--verde);

    box-shadow: 0 0 0 3px rgba(22,163,74,0.12);
}


/* ==========================
   8. BUSCADOR
   ========================== */

#buscador {
    margin-bottom: 18px;
}


/* ==========================
   9. BOTONES ESTILO IOS
   ========================== */

button {
    appearance: none;
    -webkit-appearance: none;

    display: block;
    width: 100%;
    min-height: 48px;

    padding: 14px 20px;
    margin-top: 16px;

    border: none;
    border-radius: 16px;

    background: var(--verde);
    color: white;

    font-family: inherit;
    font-size: 16px;
    font-weight: 600;

    cursor: pointer;

    transition:
        transform 0.15s ease,
        opacity 0.15s ease,
        background 0.2s ease;

    -webkit-tap-highlight-color: transparent;
}

button:active {
    transform: scale(0.97);
    opacity: 0.85;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:focus-visible {
    outline: 2px solid var(--azul);
    outline-offset: 3px;
}

@media (hover: hover) {
    button:hover {
        filter: brightness(0.94);
    }
}


/* ==========================
   10. BOTONES ESPECÍFICOS
   ========================== */

#btnLogin,
#btnAgregar {
    background: var(--verde);
    color: white;
}

#btnActualizar {
    background: #334155;
    color: white;
}

#btnSalir {
    background: #fee2e2;
    color: var(--rojo);
}

#btnCancelar {
    background: #e5e7eb;
    color: #475569;
}


/* ==========================
   11. INICIO DE SESIÓN
   ========================== */

#pantallaLogin {
    max-width: 420px;
    margin: 30px auto;
}


/* ==========================
   12. TARJETAS DE PRODUCTOS
   ========================== */

.producto {
    display: flex;
    flex-direction: column;
    align-items: stretch;

    gap: 12px;
    padding: 16px;
    margin-bottom: 12px;

    background: var(--tarjeta);
    border: 1px solid var(--borde);
    border-radius: 18px;
}

.producto-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.producto-datos {
    min-width: 0;
}

.producto-nombre {
    font-size: 16px;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.producto-categoria {
    color: #64748b;
    font-size: 13px;
    margin-top: 5px;
    overflow-wrap: anywhere;
}


/* ==========================
   13. EXISTENCIAS
   ========================== */

.existencias {
    background: #dcfce7;
    color: #15803d;

    padding: 7px 12px;
    border-radius: 10px;

    font-size: 14px;
    font-weight: 700;

    white-space: nowrap;
    flex-shrink: 0;
}

.agotado {
    background: #fee2e2;
    color: var(--rojo);
}


/* ==========================
   14. ACCIONES DEL ADMINISTRADOR
   ========================== */

.acciones {
    display: flex;
    gap: 10px;
}

.acciones button {
    flex: 1;
    width: auto;
    min-width: 0;
    min-height: 44px;
    margin-top: 0;
    padding: 10px;

    font-size: 14px;
    border-radius: 12px;
}

.btnEditar {
    background: #e8f1ff;
    color: var(--azul);
}

.btnEliminar {
    background: #fee2e2;
    color: var(--rojo);
}


/* ==========================
   15. MENSAJES
   ========================== */

#mensajeLogin,
#mensajeInventario,
#mensajeFormulario {
    font-size: 13px;
    line-height: 1.5;
    color: #64748b;
    overflow-wrap: anywhere;
}


/* ==========================
   16. CONEXIÓN EN TIEMPO REAL
   ========================== */

.estado-realtime {
    display: flex;
    align-items: center;
    gap: 8px;

    margin-top: 12px;

    font-size: 12px;
    color: #cbd5e1;
}


/* Indicador amarillo: conectando */

#puntoRealtime {
    width: 8px;
    height: 8px;

    border-radius: 50%;
    background: #f59e0b;

    flex-shrink: 0;
}


/* Indicador verde: conectado */

.estado-realtime.conectado #puntoRealtime {
    background: #22c55e;

    box-shadow: 0 0 8px rgba(34,197,94,0.6);
}


/* Indicador rojo: desconectado */

.estado-realtime.desconectado #puntoRealtime {
    background: #ef4444;
}


/* ==========================
   17. ANIMACIONES
   ========================== */

@keyframes aparecer {

    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: reduce) {

    * {
        animation: none !important;
        transition: none !important;
    }
}


/* ==========================
   18. ADAPTACIÓN A CELULARES
   ========================== */

@media (max-width: 600px) {

    header {
        margin: 16px auto 0;
        width: calc(100% - 32px);
        border-radius: 24px;
        padding: 24px 20px;
    }

    header h1 {
        font-size: 26px;
    }

    main {
        padding: 16px;
        padding-bottom: 40px;
    }

    .tarjeta {
        padding: 20px;
        border-radius: 22px;
    }

    h2 {
        font-size: 20px;
    }

    #pantallaLogin {
        margin: 20px auto;
    }

    .resumen {
        gap: 12px;
    }

    .indicador {
        padding: 16px;
        border-radius: 18px;
    }

    .indicador strong {
        font-size: 26px;
    }

    .producto {
        padding: 14px;
    }

    .producto-nombre {
        font-size: 15px;
    }

    .existencias {
        font-size: 13px;
    }

    .estado-realtime {
        font-size: 12px;
    }
}
