/* ============================================================
   Smart Inventory — Mobile Responsive Overhaul (Sprint 1)
   Single-file overrides to fix overflows on:
   - Réconciliation (Contrôle Logistique)
   - Workflow Intelligence
   - Marge Prévisionnelle
   - Scan workflow (Phase 3+D)
   - Dashboard cards (forced col-6 for demandes)
   - Stock — labeled separator band
   ============================================================ */

/* ----- GLOBAL TABLET (≤ 1024px) ----- */
@media (max-width: 1024px) {
    .bento-grid { gap: 12px; }
    .bento-cell.span-3 { grid-column: span 6; }
    .bento-cell.span-6 { grid-column: span 12; }
    .lc-table { font-size: 12.5px; }
    .lc-table th, .lc-table td { padding: 8px 10px; }
}

/* ----- MOBILE (≤ 768px) ----- */
@media (max-width: 768px) {

    /* Page hero stacked + smaller */
    .page-hero {
        flex-direction: column;
        align-items: flex-start;
        padding: 14px 16px;
        gap: 10px;
    }
    .page-hero-left { width: 100%; }
    .page-hero-title { font-size: 18px !important; line-height: 1.25; }
    .page-hero-subtitle { font-size: 12px !important; }
    .page-hero-icon { width: 38px !important; height: 38px !important; font-size: 18px !important; }
    .page-hero-actions {
        width: 100%;
        display: flex; flex-wrap: wrap; gap: 6px;
    }
    .page-hero-actions .btn { flex: 1 1 auto; font-size: 12px; padding: 7px 10px; }
    .page-hero-actions .btn i { margin-right: 4px; }

    /* Bento — force 1 column for most cells */
    .bento-grid { gap: 10px; }
    .bento-cell { grid-column: span 12 !important; }
    /* But: DASHBOARD DEMANDES cards stay 2 per row (col-6 as requested) */
    .dashboard-grid .bento-cell.dash-half,
    .dashboard-grid .bento-cell.is-compact,
    .bento-grid .bento-cell.span-3.is-compact { grid-column: span 6 !important; }
    /* Stat-cards on dashboard: 2 per row on phone */
    .dashboard-demandes-grid,
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    .dashboard-demandes-grid .stat-card,
    .stats-grid .stat-card { padding: 10px 12px !important; }
    .dashboard-demandes-grid .stat-card .stat-value,
    .stats-grid .stat-card .stat-value { font-size: 20px !important; }
    .dashboard-demandes-grid .stat-card .stat-label,
    .stats-grid .stat-card .stat-label { font-size: 11px !important; line-height: 1.2; }

    /* Tables — horizontal scroll instead of overflow */
    .lc-table-wrap, .table-wrap, .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -8px;
        padding: 0 8px;
    }
    .lc-table { font-size: 11.5px; min-width: 540px; }
    .lc-table th { font-size: 10.5px; letter-spacing: 0.02em; }
    .lc-table th, .lc-table td { padding: 7px 8px; white-space: nowrap; }
    .lc-table td:first-child { white-space: normal; }

    /* Buttons / btn-group containers wrap properly */
    .btn-group, .actions-row, [class*="-actions"] {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }
    .btn { font-size: 12.5px; padding: 7px 11px; }
    .btn-sm { font-size: 11.5px; padding: 5px 8px; }
    .btn-xs { font-size: 11px; padding: 4px 7px; }

    /* ===== Réconciliation / Contrôle Logistique ===== */
    .recon-group {
        padding: 12px !important;
        margin-bottom: 12px;
    }
    .recon-group-head {
        flex-direction: column;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .recon-group-head > div:first-child { font-size: 13.5px; line-height: 1.35; }
    .recon-group-head > div:last-child {
        display: flex; flex-wrap: wrap; gap: 4px;
        justify-content: flex-start;
    }
    .recon-group-head .btn { flex: 1 1 calc(50% - 4px); min-width: 0; }
    .recon-group-head .btn i { font-size: 12px; }
    /* Compact table headers in recon list */
    .recon-group .lc-table th { font-size: 10px; padding: 6px 4px; }
    .recon-group .lc-table td { padding: 6px 4px; }

    /* Recon hero */
    .recon-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        gap: 0 !important;
        padding-bottom: 4px;
    }
    .recon-tabs .recon-tab {
        flex-shrink: 0;
        font-size: 12px;
        padding: 8px 12px;
    }

    /* ===== Phase 3 Scan — split becomes stack ===== */
    .scan-split { grid-template-columns: 1fr !important; gap: 12px !important; }
    .scan-method-tabs { gap: 4px; }
    .scan-method-tab { min-width: calc(50% - 4px) !important; font-size: 11.5px; padding: 9px 8px; }
    .scan-input { font-size: 16px; padding: 11px 13px; }
    .scan-progress-pct { font-size: 28px !important; }
    .scan-progress-stats { font-size: 11.5px; }
    .scan-progress-head { flex-direction: column; align-items: stretch; gap: 6px; }
    .scan-progress-stats { text-align: left; }
    .scan-cand { padding: 9px 10px; }
    .scan-cand-main { font-size: 12.5px; gap: 5px; }
    .scan-cand-lockbadge { margin-left: 0; }

    /* ===== Workflow Intelligence ===== */
    .wf-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        padding-bottom: 4px;
    }
    .wf-tab { flex-shrink: 0; font-size: 11.5px; padding: 8px 12px; }
    .wf-bytype-row { grid-template-columns: 1fr !important; gap: 6px; }
    .wf-pattern-row { flex-direction: column; align-items: stretch; gap: 6px; }

    /* ===== Marge Prévisionnelle ===== */
    .lc-table-wrap table thead th:nth-child(8),
    .lc-table-wrap table tbody td:nth-child(8) {
        /* Hide "Ajustements" column on phone (low info density) */
        display: none;
    }

    /* ===== Dashboard cards spacing ===== */
    .stat-card, .dashboard-card {
        padding: 12px;
    }
    .stat-card-value, .dashboard-card-value { font-size: 22px !important; }
    .stat-card-label, .dashboard-card-label { font-size: 11px !important; }

    /* ===== Modal sizing on phone ===== */
    .modal {
        max-width: calc(100vw - 16px) !important;
        max-height: calc(100vh - 32px);
        margin: 8px auto;
        overflow-y: auto;
    }
    .modal-body { padding: 14px; }
    .modal-header h3 { font-size: 15px; }
    .modal-footer { flex-wrap: wrap; gap: 6px; }
    .modal-footer .btn { flex: 1 1 auto; }

    /* ===== Forms ===== */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; }

/* ============================================================
   Sprint 2.4 — Fix débordement cards stat (dashboard + intelligence)
   ============================================================ */

/* Dashboard demandes grid : 5 cards mobile → 2 cols et la dernière en span complet */
@media (max-width: 640px) {
    .dashboard-demandes-grid {
        grid-template-columns: 1fr 1fr !important;
    }
    .dashboard-demandes-grid > .stat-card:nth-child(5) {
        grid-column: 1 / -1;
    }
}

/* Intelligence opérationnelle (page Coût Logistique PO) : score chips
   ne doivent pas s'étirer verticalement quand la cellule voisine est haute */
.rec-scores-row {
    align-content: start;
    align-items: start;
}
.rec-score-chip {
    align-self: start;
    min-height: auto !important;
}

/* Bento cells : si une cellule a peu de contenu, elle ne doit pas s'étirer
   pour matcher la voisine — laisser respirer */
.bento-cell { align-self: start; }

/* Compact dashboard cards (dashboard cards) : limiter la hauteur naturelle */
.dashboard-demandes-grid > .stat-card {
    min-height: auto;
    align-self: start;
}

    .form-input { font-size: 14px; }

    /* ===== Sidebar / topbar (already responsive on mobile via existing CSS) ===== */
    .app-topbar h1, .app-topbar .topbar-title { font-size: 15px; }

    /* ===== Empty states ===== */
    .empty-state { padding: 18px 14px; }
    .empty-state i { font-size: 28px; }
    .empty-state h3 { font-size: 14px; }

    /* ===== Hide floating help on data-heavy pages ===== */
    body[data-page="reconciliation"] #floating-help-btn,
    body[data-page="reconciliation"] .help-tooltip-panel,
    body[data-page="reconciliation"] .onboarding-tooltip,
    body.recon-session #floating-help-btn,
    body.recon-session .help-tooltip-panel,
    body.recon-session .onboarding-tooltip,
    body[data-page="scan"] #floating-help-btn,
    body[data-page="scan"] .help-tooltip-panel,
    body[data-page="scan"] .onboarding-tooltip {
        display: none !important;
    }
}

/* ----- HIDE THE HELP TOOLTIP ON SCAN + RECON ON ALL SCREENS ----- */
body.recon-session .onboarding-tooltip,
body.recon-session #onboarding-tooltip,
body.scan-page-active .onboarding-tooltip,
body.scan-page-active #onboarding-tooltip {
    display: none !important;
}

/* ===== STOCK PAGE — separator with right-aligned background label ===== */
.stock-separator {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 18px 0 12px;
}
.stock-separator-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border-color, rgba(0,0,0,.12)));
}
.stock-separator-label {
    padding: 6px 14px;
    background: linear-gradient(135deg, rgba(59,130,246,.12), rgba(124,58,237,.10));
    border: 1px solid rgba(59,130,246,.25);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    white-space: nowrap;
}
[data-theme="dark"] .stock-separator-label {
    background: linear-gradient(135deg, rgba(59,130,246,.18), rgba(124,58,237,.15));
}

/* ===== Small mobile (≤ 480px) ===== */
@media (max-width: 480px) {
    .page-hero-title { font-size: 16px !important; }
    .btn { padding: 6px 9px; font-size: 12px; }
    .btn-xs { padding: 4px 6px; }
    .bento-head { gap: 8px; }
    .bento-icon { width: 32px !important; height: 32px !important; font-size: 14px !important; }
    .bento-title { font-size: 13px; }
    .bento-sub { font-size: 11px; }
    /* Recon group head 4 actions → 2x2 grid */
    .recon-group-head .btn { flex: 1 1 calc(50% - 4px); }
}
