/* =====================================================================================
 * ERP DJILWEB — THÈME
 *
 * Le design vient d'erp_djilweb (projet 1) : coque sombre à gauche, surface claire à
 * droite, accent violet #534AB7, cartes à bordure 0,5 px. L'architecture reste celle
 * du socle gamma (Bootstrap 5 + DataTables + modales) : ce fichier ne fait que
 * REPEINDRE Bootstrap, il ne remplace aucun de ses composants.
 *
 * Rien ici n'est une classe utilitaire : chaque règle habille un élément déjà
 * produit par le socle. On ne touche donc jamais au JS pour changer l'apparence.
 * ===================================================================================== */

:root {
    --ink: #1C1B20;
    /* fond de la coque latérale   */
    --accent: #534AB7;
    /* violet Djilweb              */
    --accent-dark: #453D9E;
    --surface: #F5F4F0;
    /* fond de page                */
    --card: #FFFFFF;
    --line: #E8E7E3;
    /* bordure 0,5 px des cartes   */
    --text: #1A1A1A;
    --muted: #6B6A66;
    --ok-bg: #EAF3DE;
    --ok-fg: #27500A;
    --err-bg: #FCEBEB;
    --err-fg: #791F1F;
    --warn-bg: #FAEEDA;
    --warn-fg: #633806;
    --info-bg: #E6F1FB;
    --info-fg: #0C447C;
    --sidebar-w: 220px;
    --sidebar-w-collapsed: 56px;
}

/* ── Coque ───────────────────────────────────────────────────────────────────── */

body {
    background: var(--surface);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans Arabic', sans-serif;
    font-size: 13px;
    margin: 0;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

/* ── Barre latérale ──────────────────────────────────────────────────────────── */

.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--ink);
    display: flex;
    flex-direction: column;
    transition: width .2s, min-width .2s;
    overflow: hidden;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.app-shell.collapsed .sidebar {
    width: var(--sidebar-w-collapsed);
    min-width: var(--sidebar-w-collapsed);
}

.app-shell.collapsed .sidebar .hide-on-collapse {
    display: none !important;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem .75rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.logo-icon {
    color: var(--accent);
    font-size: 18px;
    flex-shrink: 0;
}

.logo-text {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collapse-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, .4);
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
}

.collapse-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .5rem 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 3px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .15);
    border-radius: 2px;
}

.nav-group-label {
    display: block;
    padding: .7rem .9rem .2rem;
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: rgba(255, 255, 255, .3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: .5rem .75rem;
    color: rgba(255, 255, 255, .65);
    text-decoration: none;
    border-radius: 7px;
    margin: 1px .4rem;
    font-size: 12px;
    transition: background .12s, color .12s;
    white-space: nowrap;
    cursor: pointer;
    background: none;
    border: none;
    width: calc(100% - .8rem);
    text-align: start;
}

.nav-item i {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
}

.sidebar-footer {
    padding: .6rem .5rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.lang-switch {
    display: flex;
    gap: 4px;
    margin-bottom: .6rem;
}

.lang-btn {
    flex: 1;
    text-align: center;
    padding: .3rem 0;
    font-size: 11px;
    font-weight: 600;
    border-radius: 6px;
    text-decoration: none;
    color: rgba(255, 255, 255, .5);
    border: 1px solid rgba(255, 255, 255, .12);
}

.lang-btn:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

.lang-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: .4rem .3rem .6rem;
    min-width: 0;
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-meta {
    overflow: hidden;
}

.user-name {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-email {
    display: block;
    font-size: 10px;
    color: rgba(255, 255, 255, .4);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: .45rem .75rem;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255, 255, 255, .5);
    font-size: 12px;
    border-radius: 6px;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
}

/* ── Zone principale ─────────────────────────────────────────────────────────── */

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: #fff;
    border-bottom: .5px solid var(--line);
    padding: .65rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 52px;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.page-heading {
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    margin: 0;
    flex: 1;
}

.page-content {
    flex: 1;
    padding: 1.25rem 1.5rem;
}

.page-content.no-pad {
    padding: 0;
}

/* ── Cartes, tables, boutons : on repeint Bootstrap ──────────────────────────── */

.card {
    background: var(--card);
    border: .5px solid var(--line);
    border-radius: 12px;
    box-shadow: none;
}

.card-header {
    background: transparent;
    border-bottom: .5px solid var(--line);
    padding: .75rem 1rem;
}

.card-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
}

.btn {
    font-size: 12px;
    border-radius: 8px;
}

.btn-info {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-info:hover,
.btn-info:focus {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.btn-outline-secondary {
    border-color: var(--line);
    color: var(--muted);
}

.btn-outline-secondary:hover {
    background: var(--surface);
    border-color: #D5D3CC;
    color: var(--text);
}

table.dataTable {
    font-size: 12.5px;
    border-collapse: separate !important;
}

table.dataTable thead th {
    background: var(--surface);
    border-bottom: .5px solid var(--line) !important;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}

table.dataTable tbody td {
    border-top: .5px solid var(--line);
    vertical-align: middle;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border: .5px solid var(--line);
    border-radius: 8px;
    padding: .25rem .5rem;
    font-size: 12px;
}

.form-control,
.form-select,
.ss-main {
    border: .5px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
}

.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 .15rem rgba(83, 74, 183, .12);
}

.form-control-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.modal-content {
    border: none;
    border-radius: 14px;
}

.modal-header {
    border-bottom: .5px solid var(--line);
}

.modal-footer {
    border-top: .5px solid var(--line);
}

.modal-title {
    font-size: 13px;
    font-weight: 600;
}

/* Pastilles d'état — reprises telles quelles du projet 1. */
.pill {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 9px;
    border-radius: 20px;
    white-space: nowrap;
}

.pill-ok {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.pill-err {
    background: var(--err-bg);
    color: var(--err-fg);
}

.pill-warn {
    background: var(--warn-bg);
    color: var(--warn-fg);
}

.pill-info {
    background: var(--info-bg);
    color: var(--info-fg);
}

.pill-muted {
    background: #F1EFE8;
    color: #444441;
}

.pill-accent {
    background: #EEEDFE;
    color: #3C3489;
}

/* ── Sens d'écriture ─────────────────────────────────────────────────────────── */

[dir="rtl"] .nav-item,
[dir="rtl"] .logout-btn {
    text-align: right;
}

[dir="rtl"] .sidebar {
    order: 2;
}

[dir="rtl"] .main-area {
    order: 1;
}

/* ── RTL : les NOMBRES restent en LTR ─────────────────────────────────────────────
 * Le séparateur de milliers (espace) découpe un nombre en plusieurs « runs » que
 * l'algorithme bidi réordonne en contexte RTL : « 15 549,25 » s'affichait « 549,25 15 ».
 * On isole les nombres en LTR partout où ils apparaissent : cellules de montant
 * (text-end / text-nowrap), champs numériques, badges et pastilles. Le texte arabe,
 * lui, n'est jamais aligné ainsi dans ce projet, donc rien n'est cassé côté prose. */
[dir="rtl"] input[type="number"] {
    direction: ltr;
    text-align: right;
}
[dir="rtl"] td.text-end,
[dir="rtl"] th.text-end,
[dir="rtl"] .text-nowrap,
[dir="rtl"] .amount,
[dir="rtl"] .num,
[dir="rtl"] .money {
    direction: ltr;
    unicode-bidi: isolate;
}
/* Chiffres alignés en colonnes : même chasse, lecture plus nette. */
[dir="rtl"] td.text-end,
[dir="rtl"] .text-nowrap {
    font-variant-numeric: tabular-nums;
}

/* =====================================================================================
 * RESPONSIVE
 *
 * La coque du projet 1 était pensée pour un écran de bureau : une barre latérale de
 * 220 px, toujours là. Sur un téléphone de 360 px, elle mange 60 % de la largeur.
 *
 * Sous 992 px, elle devient donc un TIROIR : masquée par défaut, ouverte par le
 * bouton hamburger de la barre du haut, refermée dès qu'on choisit une entrée.
 * C'est le seul comportement qui rende l'application utilisable debout, une main
 * sur le téléphone — ce que fait un magasinier dans un rayon.
 *
 * Le repli manuel (chevron) est masqué en dessous de ce seuil : réduire un tiroir
 * déjà invisible n'a aucun sens, et le bouton n'aurait servi qu'à dérouter.
 * ===================================================================================== */

.burger {
    display: none;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 17px;
    padding: 4px 8px;
    border-radius: 6px;
    line-height: 1;
    cursor: pointer;
}

.burger:hover {
    background: var(--surface);
    color: var(--text);
}

.backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 1040;
}

/* ── Tablette et mobile ─────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {

    .burger {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, .3);
    }

    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
    }

    .app-shell.drawer-open .sidebar {
        transform: none;
    }

    .app-shell.drawer-open .backdrop {
        display: block;
    }

    /* Dans le tiroir, la barre n'est JAMAIS réduite : elle est soit absente, soit
       entière. Un tiroir de 56 px d'icônes sans libellés ne s'utilise pas au doigt. */
    .app-shell.collapsed .sidebar {
        width: var(--sidebar-w);
        min-width: var(--sidebar-w);
    }

    .app-shell.collapsed .sidebar .hide-on-collapse {
        display: revert !important;
    }

    .collapse-btn {
        display: none;
    }

    .topbar {
        padding: .6rem .9rem;
    }

    .page-content {
        padding: 1rem .85rem;
    }
}

/* ── Mobile étroit ──────────────────────────────────────────────────────────── */
@media (max-width: 575.98px) {

    .page-content {
        padding: .75rem .5rem;
    }

    .topbar {
        min-height: 46px;
    }

    .page-heading {
        font-size: 13.5px;
    }

    .card {
        border-radius: 10px;
    }

    .card-header {
        padding: .6rem .7rem;
    }

    /* Les boutons d'en-tête passent à la ligne au lieu de déborder. */
    .card-header .text-end {
        text-align: start !important;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .modal-dialog {
        margin: .5rem;
    }

    /* Les modales « lg » et « xl » n'ont pas de sens sur 360 px : elles prennent
       toute la largeur disponible, comme n'importe quelle modale. */
    .modal-lg,
    .modal-xl {
        max-width: none;
    }

    /* Le formulaire horizontal devient vertical : un label de 3 colonnes en face
       d'un champ de 8 sur un téléphone donne deux colonnes illisibles. */
    .modal-body .row.form-group>div,
    .modal-body .row.align-items-center>div {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    table.dataTable {
        font-size: 12px;
    }
}

/* ── Terminal de caisse ─────────────────────────────────────────────────────── */
/* Ses deux panneaux sont en col-lg-7 / col-lg-5 : sous 992 px ils s'EMPILENT.
   Mais #pos garde une hauteur figée (100vh − 130px) et les colonnes un h-100 :
   empilés, les deux panneaux réclament chacun toute la hauteur, et le second
   sort de l'écran. On rend la hauteur au contenu. */
@media (max-width: 991.98px) {

    #pos {
        height: auto !important;
        min-height: 0 !important;
    }

    #pos .panel {
        height: auto !important;
        min-height: 320px;
        margin-bottom: .75rem;
    }
}

/* =====================================================================================
 * GALERIE D'IMAGES PRODUIT
 * ===================================================================================== */

.gallery-drop {
    border: 2px dashed var(--line);
    border-radius: 12px;
    padding: 1.6rem 1rem;
    text-align: center;
    color: var(--muted);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.gallery-drop:hover,
.gallery-drop.over {
    border-color: var(--accent);
    background: var(--surface);
    color: var(--text);
}

.gallery-drop i {
    font-size: 26px;
    display: block;
    margin-bottom: .4rem;
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}

.gallery-item {
    position: relative;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
    cursor: grab;
}

.gallery-item.primary {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.gallery-item img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    display: block;
}

/* Pendant le glisser : l'élément déplacé s'efface, pour qu'on voie où il va tomber. */
.gallery-item.dragging {
    opacity: .35;
}

.gallery-actions {
    display: flex;
    justify-content: space-between;
    padding: 4px 6px;
    font-size: 11px;
}

.gallery-badge {
    position: absolute;
    top: 5px;
    left: 5px;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
}

/* Pastille de couleur d'une variante */
.variant-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, .18);
    vertical-align: -1px;
    margin-inline-end: 3px;
}

/* Vignette produit dans les listes et la grille du POS */
.thumb-sm {
    width: 34px;
    height: 34px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--line);
}
