/* ============================================================
   PolloCheff Inventario — responsive.css
   Optimización móvil-first: la app se usa principalmente
   desde el teléfono (PWA). Drawer, bottom nav, tablas→tarjetas,
   bottom sheets, safe-areas y objetivos táctiles grandes.
   ============================================================ */

/* ---------- Tablet ---------- */
@media (max-width: 1024px) {
    .app-content { padding: var(--space-5); }
    .dashboard-grid { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

/* ---------- Móvil / tablets pequeñas ---------- */
@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   MÓVIL (≤768px)
   ============================================================ */
@media (max-width: 768px) {
    /* ---------- Estructura ---------- */
    .app-main { margin-left: 0; }

    /* ---------- Sidebar → drawer deslizante ---------- */
    .sidebar {
        width: min(85vw, 320px);
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
        transition: transform 260ms cubic-bezier(0.32, 0.72, 0, 1);
    }
    .sidebar.open { transform: translateX(0); }
    body.sidebar-open { overflow: hidden; }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 99;
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--transition-base), visibility var(--transition-base);
    }
    .sidebar-backdrop.open { opacity: 1; visibility: visible; }

    /* Enlaces de navegación táctiles (≥48px) */
    .nav-link { min-height: 48px; font-size: 15px; padding: 12px 14px; }

    /* ---------- Bottom nav (navegación al pulgar) ---------- */
    .bottom-nav { display: flex; }

    /* ---------- Topbar compacto ---------- */
    .topbar {
        height: 56px;
        padding: env(safe-area-inset-top) var(--space-3) 0;
        gap: var(--space-2);
    }
    .topbar-title { font-size: 16px; }
    .theme-toggle { width: 40px; height: 40px; flex-shrink: 0; }
    .menu-btn { display: inline-flex; }
    .hide-mobile { display: none; }

    /* ---------- Contenido ---------- */
    .app-content { padding: var(--space-4) var(--space-4) 84px; }
    .page-title { font-size: 20px; }
    .page-subtitle { font-size: 13px; }

    /* ---------- Acciones de página: fila deslizable ---------- */
    .page-actions {
        display: flex;
        gap: var(--space-2);
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
        scrollbar-width: none;
    }
    .page-actions::-webkit-scrollbar { display: none; }
    .page-actions .btn { flex: 0 0 auto; }

    /* ---------- Tarjetas de estadística (Panel) ---------- */
    .stat-card { padding: var(--space-4); }
    .stat-value { font-size: 26px; }
    .stat-icon { width: 40px; height: 40px; }

    /* ---------- Botones táctiles ---------- */
    .btn { min-height: 46px; }
    .btn-sm { min-height: 40px; padding: 8px 12px; }

    /* ---------- Formularios ---------- */
    .form-control { min-height: 46px; font-size: 16px; } /* 16px evita zoom en iOS */
    .form-row { grid-template-columns: 1fr; }
    .checkbox { min-height: 44px; }

    /* ---------- Formularios de filtro apilados ---------- */
    .filter-form { grid-template-columns: 1fr; gap: var(--space-3); }
    .filter-form .filter-actions { flex-direction: column; }
    .filter-form .filter-actions .btn { width: 100%; }

    /* ---------- Tablas → tarjetas apiladas ---------- */
    .table-responsive thead { display: none; }
    .table-responsive,
    .table-responsive tbody,
    .table-responsive tr,
    .table-responsive td { display: block; width: 100%; }
    .table-responsive tr {
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        margin-bottom: var(--space-3);
        padding: var(--space-2) var(--space-3);
        background: var(--color-surface);
        box-shadow: var(--shadow-sm);
    }
    .table-responsive td {
        border: none;
        padding: 7px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--space-3);
        min-height: 36px;
    }
    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--color-text-secondary);
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        flex-shrink: 0;
        padding-right: var(--space-3);
    }
    /* Estado vacío dentro de tabla-tarjeta: ocupa toda la fila */
    .table-responsive td[colspan] { display: block; padding: 0; min-height: 0; }
    .table-responsive td[colspan]::before { content: none; }
    .table-responsive .actions { justify-content: flex-end; flex-wrap: wrap; gap: var(--space-2); }

    /* ---------- Modales → bottom sheet ---------- */
    .modal-backdrop { padding: 0; align-items: flex-end; }
    .modal {
        max-width: 100%;
        max-height: 92dvh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding-bottom: env(safe-area-inset-bottom);
        transform: translateY(24px);
    }
    .modal-backdrop.open .modal { transform: translateY(0); }
    /* Asa de agarre del bottom sheet */
    .modal::before {
        content: '';
        display: block;
        width: 44px;
        height: 5px;
        border-radius: var(--radius-full);
        background: var(--color-border-strong);
        opacity: 0.45;
        margin: 10px auto 4px;
        flex-shrink: 0;
    }
    .modal-footer { flex-direction: column-reverse; }
    .modal-footer .btn { width: 100%; }
    .modal-header { padding-top: var(--space-2); }

    /* ---------- Login móvil ---------- */
    .auth { min-height: 100dvh; }
    .auth-brand { display: none; }
    .auth-form { padding: var(--space-5) var(--space-4) calc(var(--space-6) + env(safe-area-inset-bottom)); align-items: flex-start; }
    .auth-card { max-width: 100%; }
    .auth-card .logo-mobile { display: flex; margin-bottom: var(--space-5); }
    .auth-card h2 { font-size: 22px; }
    .auth-card .btn-lg { min-height: 52px; }

    /* ---------- Toasts: por encima de la bottom nav ---------- */
    .toast-container {
        bottom: calc(76px + env(safe-area-inset-bottom));
        left: var(--space-3);
        right: var(--space-3);
        align-items: stretch;
    }
    .toast { max-width: none; }

    /* ---------- Escáner ---------- */
    .scanner-modal { max-width: 100%; }
    .scanner-modal .modal-footer { flex-direction: row; flex-wrap: wrap; }
    .scanner-modal .modal-footer .btn { flex: 1 1 45%; width: auto; }

    /* ---------- Precios inline (Stock) ---------- */
    .price-form { flex: 1; }
    .price-form .price-input { width: 100%; flex: 1; }
}

/* ============================================================
   MÓVIL PEQUEÑO (≤480px)
   ============================================================ */
@media (max-width: 480px) {
    .app-content { padding: var(--space-3) var(--space-3) 84px; }
    .page-title { font-size: 18px; }
    .stat-value { font-size: 24px; }
    .stat-card { padding: var(--space-3); }
    .stat-icon { width: 36px; height: 36px; }

    /* Tarjetas de estadística a 1 columna en pantallas muy estrechas */
    @media (max-width: 380px) {
        .stat-grid { grid-template-columns: 1fr; }
    }

    /* Topbar muy compacto */
    .topbar-title { max-width: 46vw; }

    /* Formularios: etiqueta + campo apilados */
    .card-body { padding: var(--space-4); }
    .card-header { padding: var(--space-3) var(--space-4); }

    /* Login */
    .auth-form { padding: var(--space-4) var(--space-3) calc(var(--space-5) + env(safe-area-inset-bottom)); }

    /* ---------- Stock: tarjetas apiladas en móvil ---------- */
    .stock-grid thead { display: none; }
    .stock-grid, .stock-grid tbody, .stock-grid tr, .stock-grid td { display: block; width: 100%; box-sizing: border-box; }
    .stock-grid { border-collapse: separate; border-spacing: 0; }
    .stock-grid tbody tr {
        background: var(--color-surface);
        border: 1px solid var(--color-border);
        border-radius: var(--radius-lg);
        padding: 6px 16px 12px;
        margin-bottom: 12px;
        box-shadow: var(--shadow-sm);
    }
    .stock-grid tbody tr > td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 7px 0;
        border-bottom: 1px dashed var(--color-border);
    }
    .stock-grid tbody tr > td:last-child { border-bottom: none; }
    .stock-grid tbody tr > td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--color-text-secondary);
    }
    .stock-grid tbody tr > td[data-label="Producto"] {
        display: block;
        text-align: left;
        padding: 12px 0 10px;
        border-bottom: 1px solid var(--color-border);
        margin-bottom: 4px;
    }
    .stock-grid tbody tr > td[data-label="Producto"]::before { display: none; }
    .stock-grid tbody tr > td[data-label="Producto"] a { font-size: 16px; font-weight: 700; }
    .stock-grid tbody tr > td[data-label="Stock"] { font-weight: 800; font-size: 17px; }
    .stock-grid td[data-label="Acciones"] {
        display: block;
        padding: 10px 0 2px;
    }
    .stock-grid td[data-label="Acciones"]::before { display: none; }
    .stock-grid td[data-label="Acciones"] .actions { justify-content: stretch; flex-wrap: wrap; }
    .stock-grid td[data-label="Acciones"] .actions .btn { flex: 1 1 100%; justify-content: center; }
}

/* ---------- Orientación horizontal en móvil ---------- */
@media (max-height: 500px) and (orientation: landscape) {
    .topbar { height: 52px; }
    .app-content { padding: var(--space-3) var(--space-3) 84px; }
    .stat-grid { grid-template-columns: repeat(4, 1fr); }
    .stat-value { font-size: 20px; }
    .bottom-nav { display: none; }
    .app-content { padding-bottom: var(--space-3); }
}
