/* =====================================================================
   Café Manager — styles applicatifs (mobile-first, au-dessus de Bootstrap 5)
   ===================================================================== */

:root {
    --cm-primary: #6b4430;          /* brun café */
    --cm-primary-hover: #573625;
    --cm-primary-soft: #f3ebe5;
    --cm-accent: #c98a2c;           /* caramel */
    --cm-bg: #f6f4f1;
    --cm-surface: #ffffff;
    --cm-border: #e6e1db;
    --cm-text: #2a211c;
    --cm-muted: #6e645d;
    --cm-topbar-h: 56px;
    --cm-bottomnav-h: 64px;
    --cm-sidebar-w: 248px;
    --cm-radius: 14px;

    --bs-primary: var(--cm-primary);
    --bs-primary-rgb: 107, 68, 48;
    --bs-body-bg: var(--cm-bg);
    --bs-body-color: var(--cm-text);
    --bs-secondary-color: var(--cm-muted);
    --bs-border-color: var(--cm-border);
    --bs-link-color: var(--cm-primary);
    --bs-link-color-rgb: 107, 68, 48;
    --bs-link-hover-color: var(--cm-primary-hover);
    --bs-border-radius: 10px;
    --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

/* L'attribut hidden doit toujours l'emporter (les utilitaires Bootstrap .d-flex utilisent !important). */
[hidden] { display: none !important; }

body { background: var(--cm-bg); color: var(--cm-text); -webkit-tap-highlight-color: transparent; }

.btn-primary {
    --bs-btn-bg: var(--cm-primary); --bs-btn-border-color: var(--cm-primary);
    --bs-btn-hover-bg: var(--cm-primary-hover); --bs-btn-hover-border-color: var(--cm-primary-hover);
    --bs-btn-active-bg: var(--cm-primary-hover); --bs-btn-active-border-color: var(--cm-primary-hover);
    --bs-btn-disabled-bg: var(--cm-primary); --bs-btn-disabled-border-color: var(--cm-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--cm-primary); --bs-btn-border-color: var(--cm-primary);
    --bs-btn-hover-bg: var(--cm-primary); --bs-btn-hover-border-color: var(--cm-primary);
    --bs-btn-active-bg: var(--cm-primary-hover);
}
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: #b58b72; box-shadow: 0 0 0 .2rem rgba(107, 68, 48, .2);
}
.form-check-input:checked { background-color: var(--cm-primary); border-color: var(--cm-primary); }

/* Cibles tactiles confortables (≥ 44 px) */
.btn, .form-control, .form-select { min-height: 44px; }
.btn-sm { min-height: 36px; }
.form-control-lg { font-size: 1rem; }  /* évite le zoom iOS tout en gardant la hauteur */

.card { border: 1px solid var(--cm-border); border-radius: var(--cm-radius); box-shadow: 0 1px 2px rgba(42, 33, 28, .04); }

.skip-link { position: absolute; top: .5rem; inset-inline-start: .5rem; z-index: 2000; background: #fff; padding: .5rem 1rem; border-radius: 8px; }

/* ---------- Barre supérieure ---------- */
.app-topbar {
    position: sticky; top: 0; z-index: 1030;
    height: var(--cm-topbar-h);
    display: flex; align-items: center; gap: .5rem;
    padding: 0 .5rem 0 .5rem;
    padding-top: env(safe-area-inset-top);
    background: var(--cm-surface); border-bottom: 1px solid var(--cm-border);
}
.app-brand { display: flex; align-items: center; gap: .6rem; min-width: 0; color: var(--cm-text); text-decoration: none; font-weight: 600; }
.app-brand-mark {
    width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
    display: grid; place-items: center; background: var(--cm-primary); color: #fff; font-size: 1.05rem;
}
.app-brand-name { max-width: 60vw; }
.btn-icon {
    width: 44px; height: 44px; padding: 0; display: inline-grid; place-items: center;
    border-radius: 12px; color: var(--cm-text); font-size: 1.35rem; border: 0;
}
.btn-icon:hover, .btn-icon:focus-visible { background: var(--cm-primary-soft); color: var(--cm-primary); }

/* ---------- Structure ---------- */
.app-shell { display: flex; min-height: calc(100vh - var(--cm-topbar-h)); }
.app-main { flex: 1; min-width: 0; padding-bottom: calc(var(--cm-bottomnav-h) + 1rem + env(safe-area-inset-bottom)); }
.app-container { max-width: 1200px; margin: 0 auto; padding: 1rem; }

.app-sidebar {
    width: var(--cm-sidebar-w); flex-shrink: 0;
    position: sticky; top: var(--cm-topbar-h); height: calc(100vh - var(--cm-topbar-h)); overflow-y: auto;
    background: var(--cm-surface); border-inline-end: 1px solid var(--cm-border); padding: 1rem .75rem;
}
.app-offcanvas { --bs-offcanvas-width: 290px; }

.app-menu .nav-link {
    display: flex; align-items: center; gap: .75rem;
    min-height: 44px; padding: .55rem .85rem; border-radius: 10px;
    color: var(--cm-text); font-weight: 500;
}
.app-menu .nav-link i { font-size: 1.15rem; color: var(--cm-muted); width: 1.25rem; text-align: center; }
.app-menu .nav-link:hover { background: var(--cm-primary-soft); }
.app-menu .nav-link.active { background: var(--cm-primary-soft); color: var(--cm-primary); }
.app-menu .nav-link.active i { color: var(--cm-primary); }

/* ---------- Navigation basse (mobile) ---------- */
.app-bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
    display: flex; justify-content: space-around;
    height: calc(var(--cm-bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--cm-surface); border-top: 1px solid var(--cm-border);
    box-shadow: 0 -2px 10px rgba(42, 33, 28, .05);
}
.app-bottomnav a, .app-bottomnav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--cm-muted); text-decoration: none; font-size: .72rem; font-weight: 500;
    background: none; border: 0; min-width: 0;
}
.app-bottomnav i { font-size: 1.35rem; }
.app-bottomnav .active { color: var(--cm-primary); }
.app-bottomnav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }

@media (min-width: 992px) {
    .app-main { padding-bottom: 1.5rem; }
    .app-container { padding: 1.5rem 2rem; }
}

/* ---------- En-têtes de page ---------- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.page-title { font-size: 1.4rem; font-weight: 650; margin: 0; }
.page-subtitle { color: var(--cm-muted); margin: .15rem 0 0; }
.page-subtitle::first-letter { text-transform: uppercase; }
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: .85rem; }
.form-narrow { max-width: 640px; }

/* ---------- Actions rapides ---------- */
.quick-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
@media (min-width: 576px) { .quick-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 992px) { .quick-grid { grid-template-columns: repeat(4, 1fr); } }
.quick-action {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: .5rem;
    min-height: 92px; padding: .9rem; border-radius: var(--cm-radius);
    background: var(--cm-surface); border: 1px solid var(--cm-border);
    color: var(--cm-text); text-decoration: none; font-weight: 600; font-size: .95rem;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.quick-action i { font-size: 1.4rem; color: var(--cm-primary); }
a.quick-action:hover { border-color: #cdb8a8; box-shadow: 0 4px 14px rgba(42, 33, 28, .08); }
a.quick-action:active { transform: scale(.98); }
.quick-action.is-disabled { color: var(--cm-muted); cursor: not-allowed; background: #faf9f7; }
.quick-action.is-disabled i { color: #b9aea6; }
.quick-action .badge { position: absolute; top: .6rem; inset-inline-end: .6rem; font-weight: 500; border: 1px solid var(--cm-border); }
/* Téléphone : tuiles compactes (icône à côté du libellé) pour laisser les indicateurs visibles sans défiler */
@media (max-width: 575.98px) {
    .quick-grid { gap: .5rem; }
    .quick-action { flex-direction: row; align-items: center; gap: .6rem; min-height: 56px; padding: .55rem .75rem; font-size: .9rem; line-height: 1.2; }
    .quick-action i { font-size: 1.25rem; flex-shrink: 0; }
}

/* ---------- Cartes statistiques (tableau de bord) ---------- */
.stat-card .stat-label { color: var(--cm-muted); font-size: .85rem; }
.stat-card .stat-value { font-size: clamp(1.1rem, .95rem + 1vw, 1.35rem); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.activity-list li { padding: .6rem 0; border-bottom: 1px solid var(--cm-border); }
.activity-list li:last-child { border-bottom: 0; }

/* ---------- Tableaux responsives : empilés sur mobile ---------- */
@media (max-width: 767.98px) {
    .table-stack thead { display: none; }
    .table-stack tr { display: block; padding: .6rem .9rem; border-bottom: 1px solid var(--cm-border); }
    .table-stack td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; text-align: end; }
    .table-stack td::before { content: attr(data-label); color: var(--cm-muted); font-weight: 500; text-align: start; }
    /* 1re colonne (produit, date, numéro...) = titre de la carte, sans libellé répété */
    .table-stack tbody td:first-child { display: block; text-align: start; font-weight: 600; padding-bottom: .3rem; }
    .table-stack tbody td:first-child::before { display: none; }
}
.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Authentification ---------- */
.auth-body { background: radial-gradient(1200px 600px at 50% -10%, #efe4da 0%, var(--cm-bg) 60%); min-height: 100vh; }
.auth-wrapper { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 1.5rem 1rem; }
.auth-card { width: 100%; max-width: 420px; margin: 0 auto; box-shadow: 0 10px 30px rgba(42, 33, 28, .08); }
.auth-logo {
    display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 18px;
    background: var(--cm-primary); color: #fff; font-size: 1.9rem;
}

/* Bouton en cours d'envoi (anti double clic) */
.btn.is-loading { pointer-events: none; opacity: .75; }

/* ---------- Composants catalogue ---------- */
.min-w-0 { min-width: 0; }
.sub-tabs { gap: .25rem; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.sub-tabs .nav-link { white-space: nowrap; color: var(--cm-muted); border-radius: 999px; padding: .45rem .9rem; min-height: 40px; display: inline-flex; align-items: center; }
.sub-tabs .nav-link.active { background: var(--cm-primary); color: #fff; }

.chip {
    display: inline-flex; align-items: center; min-height: 34px; padding: .25rem .8rem; border-radius: 999px;
    border: 1px solid var(--cm-border); background: var(--cm-surface); color: var(--cm-text); text-decoration: none;
}
.chip.active { background: var(--cm-primary-soft); border-color: #cdb8a8; color: var(--cm-primary); font-weight: 600; }
.chip-warning.active { background: #fff3cd; border-color: #f0d58a; color: #7a5a00; }
/* Groupes de filtres : une seule ligne qui défile horizontalement sur téléphone (sauf période personnalisée ouverte) */
@media (max-width: 575.98px) {
    .chip-scroll { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; padding-block: 2px; }
    .chip-scroll::-webkit-scrollbar { display: none; }
    .chip-scroll > * { flex-shrink: 0; white-space: nowrap; }
    .chip-scroll:has(.period-custom[open]) { flex-wrap: wrap !important; overflow: visible; }
}
.chip-img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; margin-inline: -.45rem .4rem; }

.product-list .list-group-item { padding: 0; }
.product-row { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; color: inherit; text-decoration: none; min-height: 64px; }
.product-row:hover { background: #faf8f6; }
.product-row.is-inactive { opacity: .6; }
.product-thumb {
    width: 44px; height: 44px; flex-shrink: 0; border-radius: 10px; overflow: hidden;
    display: grid; place-items: center; background: var(--cm-primary-soft); color: var(--cm-primary); font-size: 1.2rem;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }
.product-thumb-lg { width: 64px; height: 64px; font-size: 1.6rem; border-radius: 14px; }
.product-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.product-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-meta { color: var(--cm-muted); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-side { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; flex-shrink: 0; }
.product-price { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.type-picker { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 576px) { .type-picker { grid-template-columns: repeat(4, 1fr); } }
.type-picker .btn { min-height: 48px; font-size: .9rem; }

.form-actions {
    position: sticky; bottom: calc(var(--cm-bottomnav-h) + env(safe-area-inset-bottom)); z-index: 5;
    display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 0; background: linear-gradient(transparent, var(--cm-bg) 30%);
}
@media (min-width: 992px) { .form-actions { bottom: 0; } }

.detail-list { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: .45rem .75rem; }
.detail-list dt { color: var(--cm-muted); font-weight: 500; }
.detail-list dd { margin: 0; }

/* ---------- Achats ---------- */
.purchase-line { padding: .75rem 0; border-bottom: 1px dashed var(--cm-border); }
.purchase-line:first-child { padding-top: 0; }
details > summary { cursor: pointer; min-height: 32px; }

/* ---------- Écran de vente ---------- */
.pos { display: block; }
.pos-toolbar { position: sticky; top: var(--cm-topbar-h); z-index: 5; background: var(--cm-bg); padding-bottom: .5rem; }
.pos-categories { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem 0 .25rem; scrollbar-width: none; }
.pos-categories .chip { flex-shrink: 0; cursor: pointer; }
.pos-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; padding-bottom: 5rem; }
@media (min-width: 576px) { .pos-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .pos-grid { grid-template-columns: repeat(4, 1fr); } }
.pos-product {
    position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; text-align: start;
    min-height: 96px; padding: .7rem; border: 1px solid var(--cm-border); border-radius: var(--cm-radius);
    background: var(--cm-surface); color: var(--cm-text); transition: transform .1s, border-color .15s;
}
.pos-product:active { transform: scale(.97); }
.pos-product:hover { border-color: #cdb8a8; }
.pos-product img { width: 100%; height: auto; aspect-ratio: 16 / 10; object-fit: cover; border-radius: 8px; }
.pos-product-name { font-weight: 600; line-height: 1.2; }
.pos-product-price { color: var(--cm-primary); font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-stock { font-size: .72rem; color: var(--cm-muted); }
.pos-stock.is-out { color: #b02a37; font-weight: 600; }
.pos-product.is-disabled { opacity: .5; cursor: not-allowed; }
.pos-in-cart {
    position: absolute; top: .4rem; inset-inline-end: .4rem; min-width: 1.6rem; height: 1.6rem; padding: 0 .4rem; border-radius: 999px;
    background: var(--cm-primary); color: #fff; font-size: .8rem; font-weight: 700; display: grid; place-items: center;
}
.pos-cart { --bs-offcanvas-height: 88vh; }
.pos-cart-body { padding: 1rem; overflow-y: auto; }
.pos-line { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; padding: .5rem 0; border-bottom: 1px solid var(--cm-border); }
.pos-line-name { font-weight: 600; min-width: 0; }
.pos-qty { display: flex; align-items: center; gap: .3rem; }
.pos-qty .btn { width: 36px; min-height: 36px; padding: 0; font-size: 1.1rem; }
.pos-qty-value { min-width: 2rem; text-align: center; font-weight: 600; }
.pos-line-total { min-width: 5.5rem; text-align: end; font-weight: 600; }
.pos-totals { margin-top: .75rem; }
.pos-total { font-size: 1.5rem; font-weight: 800; color: var(--cm-primary); }
.pos-methods { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; }
.pos-methods .btn { min-height: 44px; white-space: normal; line-height: 1.15; }
.pos-cart-bar {
    position: fixed; left: .75rem; right: .75rem; z-index: 1035;
    bottom: calc(var(--cm-bottomnav-h) + env(safe-area-inset-bottom) + .5rem);
    display: flex; justify-content: space-between; align-items: center; padding: .85rem 1.1rem;
    border: 0; border-radius: 14px; background: var(--cm-primary); color: #fff; font-size: 1rem;
    box-shadow: 0 8px 24px rgba(42, 33, 28, .25);
}
@media (min-width: 992px) {
    .pos { display: grid; grid-template-columns: 1fr 380px; gap: 1.25rem; align-items: start; }
    .pos-grid { padding-bottom: 1rem; }
    .pos-cart { position: sticky; top: calc(var(--cm-topbar-h) + 1rem); background: var(--cm-surface); border: 1px solid var(--cm-border); border-radius: var(--cm-radius); }
    .pos-cart-body { max-height: calc(100vh - var(--cm-topbar-h) - 2rem); }
}

/* ---------- Impression (récapitulatifs) ---------- */
.print-body { background: #fff; }
.print-toolbar { max-width: 760px; margin: 1rem auto 0; padding: 0 1rem; text-align: end; }
.print-page { max-width: 760px; margin: 0 auto; padding: 1rem; color: #000; }
.print-page .table { --bs-table-bg: transparent; }
@media print {
    @page { margin: 12mm; }
    .print-page { max-width: none; padding: 0; }
    .app-topbar, .app-sidebar, .app-bottomnav, .d-print-none { display: none !important; }
}

/* ---------- Tableau de bord et rapports ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box-sm { height: 240px; }
@media (min-width: 992px) { .chart-box { height: 320px; } }
.period-custom > summary { list-style: none; }
.period-custom > summary::-webkit-details-marker { display: none; }
.summary-table th { font-weight: 400; }
.summary-table .summary-total th, .summary-table .summary-total td { font-weight: 700; border-top: 1px solid var(--cm-border); }
.summary-table .summary-grand th, .summary-table .summary-grand td { font-weight: 800; font-size: 1.1rem; border-top: 2px solid var(--cm-text); }
.summary-table .summary-info th, .summary-table .summary-info td { color: var(--cm-muted); font-size: .9rem; }
.summary-table .summary-info-total th, .summary-table .summary-info-total td { color: var(--cm-muted); font-weight: 700; }
.summary-table tr.summary-info:first-of-type th { padding-top: 1.25rem; }
@media print {
    .card { border: 0; box-shadow: none; }
    .report-table { font-size: 11px; }
}

/* Arabe (dir="rtl") : police lisible et icônes directionnelles retournées */
[dir="rtl"] body { --bs-body-font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", Arial, sans-serif; }
[dir="rtl"] .bi-arrow-left, [dir="rtl"] .bi-arrow-right, [dir="rtl"] .bi-chevron-left, [dir="rtl"] .bi-chevron-right,
[dir="rtl"] .bi-box-arrow-right, [dir="rtl"] .bi-arrow-return-left { display: inline-block; transform: scaleX(-1); }
