/* ============================================================
   BACKOFFICE — styles globaux
   · Le header est géré par header.css
   · La sidebar et le contenu du guide sont gérés par sidebar.css
   Ce fichier garde : variables du thème, mise en page (shell/main),
   décalages RTL, cadre de la barre du guide, modales/formulaires génériques.
============================================================ */

/* ─── RTL OVERRIDES ─── */

html[dir="rtl"] .shell {
    direction: rtl;
    width: 100%;
}

/* Main content should not be narrowed a second time */
html[dir="rtl"] .main {
    margin: 0 !important;
    width: auto !important;
    min-width: 0;
    padding: 20px 24px;
    overflow-x: auto;
}

/* Header content alignment */
html[dir="rtl"] .topbar-left,
html[dir="rtl"] .topbar-actions {
    flex-direction: row-reverse;
}

html[dir="rtl"] .topbar-user {
    align-items: flex-end;
    text-align: right;
}

html[dir="rtl"] .topbar-search input {
    text-align: right;
}

/* ─── DROPDOWN MENU POSITION ─── */
html[dir="rtl"] .admin-dropdown-menu {
    right: auto !important;
    left: 0 !important;
}

/* ─── DESKTOP (≥ 769px) : la sidebar est fixe → on décale le contenu ─── */
@media (min-width: 769px) {
    html[dir="rtl"] body {
        padding-left: 0 !important;
        padding-right: var(--sidebar-width);
        overflow-x: hidden;
    }

    html[dir="rtl"] .topbar {
        left: 0 !important;
        right: var(--sidebar-width) !important;
        width: auto !important;
        margin: 0 !important;
        box-sizing: border-box;
    }

    /* Sidebar réduite */
    html[dir="rtl"] body.sidebar-collapsed {
        padding-right: var(--sidebar-collapsed-width);
        padding-left: 0 !important;
    }

    html[dir="rtl"] body.sidebar-collapsed .topbar {
        right: var(--sidebar-collapsed-width) !important;
        left: 0 !important;
        width: auto !important;
    }

    html[dir="rtl"] body.sidebar-collapsed .sidebar {
        width: var(--sidebar-collapsed-width);
    }
}

/* ─── MOBILE (≤ 768px) : pas de sidebar fixe (tiroir) → AUCUN décalage ─── */
@media (max-width: 768px) {
    body,
    body.sidebar-collapsed,
    html[dir="rtl"] body,
    html[dir="rtl"] body.sidebar-collapsed {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .topbar,
    body.sidebar-collapsed .topbar,
    html[dir="rtl"] .topbar,
    html[dir="rtl"] body.sidebar-collapsed .topbar {
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        margin: 0 !important;
    }

    html[dir="rtl"] .main,
    .main {
        margin: 0 !important;
        width: auto !important;
    }
}

/* ============================================================
   VARIABLES GLOBALES (thème historique, utilisées par les pages
   pas encore migrées vers la charte)
============================================================ */
:root {
    --gold: #c9a84c;
    --gold2: #e8c97a;
    --gold3: #a0782a;
    --gold-dim: rgba(201, 168, 76, 0.12);
    --border: rgba(201, 168, 76, 0.2);
    --border2: rgba(201, 168, 76, 0.3);
    --bg: #0a0806;
    --bg2: #0e0c09;
    --bg3: #141209;
    --bg4: #1e2228;
    --card: #131109;
    --text: #f0ece3;
    --text2: #b0a08a;
    --text3: #7a6e5f;
    --radius: 12px;
    --radius-sm: 8px;
    --green: #10b981;
    --green-dim: rgba(74, 222, 128, 0.12);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.12);
    --teal: #2dd4bf;
    --teal-dim: rgba(45, 212, 191, 0.12);
    --amber: #fbbf24;
    --amber-dim: rgba(251, 191, 36, 0.12);
    --blue: #60a5fa;
    --blue-dim: rgba(96, 165, 250, 0.12);
    --purple: #a78bfa;
    --purple-dim: rgba(167, 139, 250, 0.12);
    --font-body: 'Inter', sans-serif;
    --font-mono: 'SF Mono', 'Menlo', monospace;
    --font-arabic: 'Cairo', sans-serif;
    --guide-height: 80px;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    padding-top: calc(var(--app-top-offset) + var(--app-top-gap)) !important;
    transition: padding-top 0.35s ease;
}

/* Layout */
.shell {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 20px 24px;
    overflow-x: auto;
}

/* Light mode */
body.light {
    --bg: #f7f4ef;
    --bg2: #edeae3;
    --bg3: #e3dfd6;
    --bg4: #e2e8f0;
    --card: #ffffff;
    --text: #1a1610;
    --text2: #5a5245;
    --text3: #9a8f80;
    --border: rgba(201, 168, 76, 0.2);
    --border2: rgba(0, 0, 0, 0.12);
}

.light-bg-overlay {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background: var(--bg);
}

/* ===== HEADER : variables de mise en page ===== */
:root {
    --header-height: 70px;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --guide-height: 80px;
    --app-top-offset: var(--header-height);
    --app-top-gap: 0px;
}

/* Responsive : hauteur du header et du guide */
@media (max-width: 768px) {
    :root {
        --header-height: 64px;
        --guide-height: 70px;
    }

    body {
        padding-top: calc(var(--app-top-offset) + var(--app-top-gap)) !important;
    }
}

@media (max-width: 576px) {
    :root {
        --header-height: 60px;
        --guide-height: 60px;
    }

    body {
        padding-top: calc(var(--app-top-offset) + var(--app-top-gap)) !important;
    }
}

/* ============================================================
   MODALES / FORMULAIRES / TOAST (génériques)
============================================================ */
.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9500;
    align-items: center;
    justify-content: center;
}
.modal.show { display: flex; }
.modal-content {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--text); }
.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--text3);
    cursor: pointer;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 13px;
    box-sizing: border-box;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-dim);
}
.form-textarea { resize: vertical; min-height: 100px; }
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--green);
    color: white;
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    z-index: 2000;
    animation: slideInRight 0.3s ease;
}
@keyframes slideInRight {
    from { transform: translateX(400px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--bg3);
}
::-webkit-scrollbar-thumb {
    background: var(--gold3);
    border-radius: 3px;
}

/* Fix extra left gap on large screens */
@media (min-width: 993px) {
    .main,
    .shell .main {
        margin-left: 0 !important;
        padding-left: 0 !important;
    }
}
