/* ====================================================================
   mobile-compact.css — Compact single-line mobile table rows + detail popup
   Applied only to tables with class "mobile-compact-table"
   Breakpoint: 820px (matches global style.css)
   ==================================================================== */

/* ---- DETAIL POPUP (bottom-sheet) ---- */
.mobile-detail-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.35);
    z-index: 10000;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.mobile-detail-overlay.open { display: block; }

.mobile-detail-popup {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    max-height: 75vh;
    background: #fff;
    border-radius: 14px 14px 0 0;
    z-index: 10001;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.mobile-detail-popup.open { transform: translateY(0); }

.mobile-detail-popup .detail-handle {
    width: 28px; height: 3px;
    background: #cbd5e1;
    border-radius: 2px;
    margin: 8px auto 0;
    flex-shrink: 0;
}

.mobile-detail-popup .detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px 6px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
}
.mobile-detail-popup .detail-header h4 {
    margin: 0;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 40px);
}
.mobile-detail-popup .detail-close-btn {
    width: 28px; height: 28px;
    border: none;
    background: #f1f5f9;
    border-radius: 50%;
    font-size: 12px;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}
.mobile-detail-popup .detail-close-btn:hover { background: #e2e8f0; }

.mobile-detail-popup .detail-body {
    padding: 10px 14px 18px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}

/* Thumbnail in popup */
.mobile-detail-popup .detail-thumb {
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
}
.mobile-detail-popup .detail-thumb img {
    width: 90px; height: 90px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid #e2e8f0;
}

/* Label:value grid inside popup */
.mobile-detail-popup .detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
}
.mobile-detail-popup .detail-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.mobile-detail-popup .detail-item.full-width {
    grid-column: 1 / -1;
}
.mobile-detail-popup .detail-item .detail-label {
    font-size: 9px;
    font-weight: 500;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.mobile-detail-popup .detail-item .detail-value {
    font-size: 11px;
    font-weight: 400 !important;
    color: #1e293b;
    word-break: break-word;
}

/* Also strip bold from any children inside detail-value */
.mobile-detail-popup .detail-value * {
    font-weight: 400 !important;
}

/* Editable inputs inside popup detail */
.mobile-detail-popup .detail-value input,
.mobile-detail-popup .detail-value select,
.mobile-detail-popup .detail-value textarea {
    font-weight: 600 !important;
    color: #0f172a;
    background: #f8fafc;
    transition: border-color 0.15s;
    width: 100%;
    min-height: 44px;
    font-size: 16px; /* prevents iOS zoom */
    padding: 10px 12px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    box-sizing: border-box;
}
.mobile-detail-popup .detail-value input:focus,
.mobile-detail-popup .detail-value select:focus,
.mobile-detail-popup .detail-value textarea:focus {
    border-color: #06b6d4 !important;
    outline: none;
    background: #fff;
}

/* Actions row inside popup */
.mobile-detail-popup .detail-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}
.mobile-detail-popup .detail-actions button,
.mobile-detail-popup .detail-actions .action-btn {
    min-height: 34px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: #fff;
}

/* Status badge inside popup */
.mobile-detail-popup .detail-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 500;
}

/* ---- COLLAPSIBLE FILTER BAR ---- */
.mc-filter-toggle {
    display: none; /* Hidden on desktop */
}

/* ---- Eye button in compact rows ---- */
.mc-eye-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 11px;
    padding: 8px;
    border-radius: 6px;
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}
.mc-eye-btn:active { background: #f1f5f9; }

/* ==========================
   MOBILE ONLY — 820px
   ========================== */
@media (max-width: 820px) {

/* Override global card-stacking for compact tables */
.mobile-compact-table thead { display: none !important; }
.mobile-compact-table,
.mobile-compact-table tbody { display: block; }

.mobile-compact-table tr {
    display: flex !important;
    align-items: center;
    gap: 6px;
    padding: 7px 10px;
    margin-bottom: 0;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
    min-height: 38px;
}
.mobile-compact-table tr:last-child { border-bottom: none; }
.mobile-compact-table tr:active { background: #f8fafc; }

/* All cells hidden by default */
.mobile-compact-table td {
    display: none !important;
    padding: 0;
    border: none;
    min-height: unset;
}
.mobile-compact-table td::before { display: none !important; }

/* Visible cells only */
.mobile-compact-table td[data-mc-show] {
    display: flex !important;
    align-items: center;
    font-size: 11px;
    font-weight: 400;
    color: #475569;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-height: unset;
    min-width: 0;
}

/* Thumbnail cell: compact */
.mobile-compact-table td[data-mc-show="thumb"] {
    flex-shrink: 0;
    width: 36px;
}
.mobile-compact-table td[data-mc-show="thumb"] .art-thumb {
    width: 32px; height: 32px;
    border-radius: 6px;
}
.mobile-compact-table td[data-mc-show="thumb"] .art-thumb-placeholder {
    width: 32px; height: 32px;
    border-radius: 6px;
    font-size: 12px;
}

/* Bigger thumbnails when in search mode */
.mc-search-active .mobile-compact-table td[data-mc-show="thumb"] {
    width: 48px;
}
.mc-search-active .mobile-compact-table td[data-mc-show="thumb"] .art-thumb,
.mc-search-active .mobile-compact-table td[data-mc-show="thumb"] .art-thumb-placeholder {
    width: 44px; height: 44px;
}

/* Primary cell (designation, client name) — grows to fill, NO BOLD */
.mobile-compact-table td[data-mc-show="primary"] {
    flex: 1;
    min-width: 0;
    font-weight: 400;
    font-size: 11px;
    color: #334155;
    line-height: 1.3;
    white-space: normal;
    display: -webkit-box !important;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mobile-compact-table td[data-mc-show="primary"] .mc-sub {
    display: block;
    font-size: 9px;
    font-weight: 400;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Secondary cell (price, qty, etc.) — NO BOLD, smaller */
.mobile-compact-table td[data-mc-show="secondary"] {
    flex-shrink: 0;
    font-weight: 400;
    font-size: 10px;
    color: #64748b;
    text-align: right;
    white-space: nowrap;
}

/* Tertiary cell (BL, ref number...) — lighter */
.mobile-compact-table td[data-mc-show="tertiary"] {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 400;
    color: #6366f1;
    white-space: nowrap;
}

/* Eye button cell — smaller */
.mobile-compact-table td[data-mc-show="eye"] {
    flex-shrink: 0;
    width: 28px;
    justify-content: center;
}

/* Action cell for inline critical actions (trash, etc.) */
.mobile-compact-table td[data-mc-show="inline-action"] {
    flex-shrink: 0;
    white-space: nowrap;
}
.mobile-compact-table td[data-mc-show="inline-action"] button {
    font-size: 10px;
    padding: 4px 6px;
    min-height: 26px;
    min-width: 26px;
}

/* Status badge inline — smaller */
.mobile-compact-table td[data-mc-show="status"] {
    flex-shrink: 0;
}
.mobile-compact-table td[data-mc-show="status"] .status-badge,
.mobile-compact-table td[data-mc-show="status"] .badge {
    font-size: 9px;
    padding: 1px 6px;
    font-weight: 500;
}

/* Empty / error state rows span full width */
.mobile-compact-table tr td[colspan] {
    display: block !important;
    text-align: center;
    padding: 20px 10px;
    font-size: 11px;
}

/* Alternating hover for scannable feel */
.mobile-compact-table tr:nth-child(even) { background: #fafbfc; }

/* Filter toggle — smaller */
.mc-filter-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    font-size: 11px;
    font-weight: 400;
    color: #475569;
    cursor: pointer;
    min-height: 34px;
    width: 100%;
    justify-content: center;
    margin-bottom: 8px;
}
.mc-filter-toggle i { font-size: 12px; color: #0ea5e9; }
.mc-filter-toggle .mc-filter-chevron { margin-left: auto; transition: transform 0.2s; }
.mc-filter-toggle.open .mc-filter-chevron { transform: rotate(180deg); }

.mc-filters-collapsible {
    display: none;
    flex-direction: column;
    gap: 6px;
}
.mc-filters-collapsible.open {
    display: flex;
}

/* ---- Global mobile typography overrides for compact pages ---- */
.mobile-compact-table * {
    font-weight: 400 !important;
}
.mobile-compact-table b,
.mobile-compact-table strong {
    font-weight: 400 !important;
}

/* On desktop, filters always visible */
} /* end @media 820px */

/* Desktop: filters always visible regardless of .open */
@media (min-width: 821px) {
    .mc-filters-collapsible { display: flex !important; flex-wrap: wrap; }
    .mc-eye-btn { display: none; }
}

/* Safe area padding for bottom sheet on notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-detail-popup .detail-body {
        padding-bottom: calc(18px + env(safe-area-inset-bottom));
    }
}

/* ---- Global mobile improvements (only on mobile) ---- */
@media (max-width: 820px) {

    /* ── FIX MOBILE SCROLL ──
       Body is display:flex with min-height:100vh.  overflow-x:hidden in
       style.css computes overflow-y to 'auto', turning body into a scroll
       container.  Combined with overscroll-behavior-y:contain the touch
       gesture gets captured by body (which has zero scroll range because
       .main-content fills it via flex:1) and scroll-chaining is blocked
       → page appears frozen.
       Fix: lock body at viewport height + overflow:hidden so it is NOT a
       scroll container, and make .main-content the sole scroller. */
    html {
        overflow: hidden;
        height: 100%;
    }
    body {
        height: 100%;
        height: 100dvh;
        overflow: hidden;
        min-height: 0; /* override style.css min-height:100vh */
    }
    .main-content {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain; /* prevent pull-to-refresh */
    }

    /* Shrink page titles */
    .top-bar h2 {
        font-size: 14px !important;
        font-weight: 500 !important;
    }
    .top-bar p {
        font-size: 10px !important;
    }

    /* Shrink card padding on mobile */
    .card {
        padding: 10px !important;
        border-radius: 10px !important;
    }
    .main-content {
        padding-left: 8px !important;
        padding-right: 8px !important;
        padding-top: 60px !important;
        /* padding-bottom kept from style.css body.has-mobile-nav rule */
        /* overflow-y: auto already set in the scroll-fix block above */
    }

    /* Shrink KPI / stat cards on mobile */
    .stats-grid, .kpi-grid {
        gap: 8px !important;
    }
    .stats-grid > *, .kpi-grid > *, .stat-card {
        padding: 8px 10px !important;
        border-radius: 8px !important;
    }
    .stats-grid [style*="font-size:24px"],
    .stats-grid [style*="font-size: 24px"],
    .kpi-grid [style*="font-size:24px"],
    .kpi-grid [style*="font-size: 24px"],
    .stat-card [style*="font-size:24px"],
    .stat-card [style*="font-size: 24px"] {
        font-size: 16px !important;
        font-weight: 500 !important;
    }

    /* Commande form grid — collapse to single column on mobile */
    .commande-add-grid,
    div[style*="grid-template-columns: 2fr 1fr 1fr auto"] {
        grid-template-columns: 1fr !important;
    }

    /* Commande order summary — smaller */
    .order-summary .total-lines {
        font-size: 20px !important;
    }
    .order-summary {
        padding: 12px !important;
    }

    /* Commande btn-remove-line — bigger tap target */
    .btn-remove-line {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 8px !important;
    }

    /* Make empty-order/placeholder text smaller */
    .empty-order { padding: 20px !important; }
    .empty-order i { font-size: 30px !important; }

    /* Suivi/magasinage stats row - compact */
    .stats-row {
        gap: 6px !important;
    }
    .stats-row > div {
        padding: 6px 8px !important;
    }

    /* Slim down bottom navigation */
    .mobile-bottom-nav {
        height: calc(58px + env(safe-area-inset-bottom)) !important;
        padding: 4px 6px calc(4px + env(safe-area-inset-bottom)) !important;
    }
    .mobile-bottom-nav__item .nav-icon {
        width: 30px !important;
        height: 30px !important;
        font-size: 15px !important;
    }
    .mobile-bottom-nav__item {
        font-size: 9px !important;
        gap: 2px !important;
    }
}
