/* Manasik — interface d'administration. Propriétés logiques : fonctionne en RTL (arabe) et LTR (français). */
:root {
    --bg: #f4f2ec;
    --surface: #ffffff;
    --surface-2: #faf9f5;
    --text: #1d2420;
    --muted: #6b736e;
    --border: #e4e1d8;
    --primary: #0f5c3f;
    --primary-hover: #0b4a32;
    --primary-soft: #e3efe8;
    --accent: #b88a2e;
    --danger: #b3261e;
    --danger-soft: #fbe9e7;
    --success: #1d7a4a;
    --success-soft: #e2f3e9;
    --warning-soft: #fdf3dc;
    --sidebar: #0e2a20;
    --sidebar-text: #c9d6cf;
    --sidebar-active: #1a4433;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 1px 1px rgba(20, 30, 25, .04);
    --font: "Tajawal", "Segoe UI", Tahoma, system-ui, sans-serif;
    --sidebar-w: 248px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 700; }
small { font-size: .82rem; }
.muted { color: var(--muted); }
.block { display: block; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .9em; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }
.center { text-align: center; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Structure ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w);
    background: var(--sidebar); color: var(--sidebar-text); overflow-y: auto; z-index: 30;
    padding: 18px 12px; transition: transform .2s ease;
}
.main { flex: 1; min-width: 0; margin-inline-start: var(--sidebar-w); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.05rem; padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand img { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 8px; padding: 3px; }
.brand-mark { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: #fff; font-size: 1.15rem; }
.nav-title { font-size: .74rem; letter-spacing: .04em; text-transform: uppercase; color: #8aa397; padding: 16px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-text); }
.nav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav-link.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
[dir="rtl"] .nav-link.active { box-shadow: inset -3px 0 0 var(--accent); }

.topbar {
    position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center; justify-content: space-between;
    padding-inline: 20px; background: rgba(244, 242, 236, .92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border);
}
.topbar-end { display: flex; align-items: center; gap: 14px; }
.icon-btn { display: none; border: 0; background: none; padding: 8px; border-radius: 8px; color: var(--text); cursor: pointer; }
.icon-btn:hover { background: var(--surface); }
.lang-switch { font-size: .9rem; font-weight: 500; }
.content { padding: 24px; width: 100%; max-width: 1280px; }
.content.narrow { max-width: 1120px; margin-inline: auto; }

.impersonation { position: fixed; inset-block-start: 0; inset-inline: 0; z-index: 50; background: var(--accent); color: #fff; text-align: center; padding: 6px 12px; font-size: .9rem; }
.impersonation + .sidebar, .impersonation ~ .main { padding-top: 34px; }
button.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }

/* Menu utilisateur */
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 999px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; font-weight: 700; }
.dropdown { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.08); padding: 6px; }
.dropdown-head { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; display: grid; }
.dropdown a, .dropdown button { display: block; width: 100%; text-align: start; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; }
.dropdown a:hover, .dropdown button:hover { background: var(--surface-2); text-decoration: none; }

/* ---------- Composants ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.form-card .card-head:not(:first-child) { margin-top: 18px; }
.table-card { padding: 0; overflow-x: auto; }
.stack { display: grid; gap: 14px; }
.stack > .card { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; }
.align-start { align-items: start; }
.span-2 { grid-column: span 2; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 38px;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); border-color: #cfcabd; text-decoration: none; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger-soft { color: var(--danger); border-color: #f0c9c5; background: var(--danger-soft); }
.btn-danger-soft:hover { background: #f8dcd8; border-color: #e8b1ab; }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: .86rem; }
.btn-block { width: 100%; }

.field { display: grid; gap: 5px; align-content: start; }
.field > span { font-weight: 500; font-size: .9rem; }
input, select, textarea {
    width: 100%; font: inherit; color: var(--text); background: #fff; border: 1px solid #d6d2c6; border-radius: var(--radius-sm);
    padding: 8px 11px; min-height: 40px;
}
input[type="checkbox"], input[type="radio"] { width: 17px; height: 17px; min-height: 0; accent-color: var(--primary); padding: 0; }
input[type="file"] { padding: 6px; }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; }
.is-invalid input, .is-invalid select, .is-invalid textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .84rem; }
.hint { color: var(--muted); font-size: .82rem; margin: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input, .inline-form select { min-height: 34px; padding-block: 4px; }

.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: start; font-weight: 600; color: var(--muted); font-size: .82rem; background: var(--surface-2); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid #efece5; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fcfbf8; }
.col-actions { text-align: end; white-space: nowrap; }
.col-actions > * { margin-inline-start: 4px; }
.empty { text-align: center; color: var(--muted); padding: 28px !important; }

.badge { display: inline-block; white-space: nowrap; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); vertical-align: middle; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: #c6e6d3; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: #f0c9c5; }
.badge-muted { background: #f1efe9; color: var(--muted); }
.badge-manager { background: var(--warning-soft); color: #8a6417; border-color: #eedcae; }
.badge-supervisor { background: var(--primary-soft); color: var(--primary); border-color: #c8ddd1; }

.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; }
.alert-success { background: var(--success-soft); border-color: #c6e6d3; color: #145c37; }
.alert-error { background: var(--danger-soft); border-color: #f0c9c5; color: #8c1d17; }
.alert-info { background: var(--info-soft); border-color: #c4d9ea; color: var(--info); }
.alert-warning { background: var(--warning-soft); border-color: #eedcae; color: #6e4f0f; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 4px; box-shadow: var(--shadow); border-inline-start: 4px solid var(--primary); }
.stat-label { color: var(--muted); font-size: .88rem; }
.stat-value { font-size: 1.7rem; font-variant-numeric: tabular-nums; }

.timeline, .list { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; gap: 2px; padding: 9px 0; border-bottom: 1px solid #efece5; }
.timeline li:last-child { border-bottom: 0; }
.timeline small { color: var(--muted); }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid #efece5; }

.popover { position: relative; display: inline-block; }
.popover summary { list-style: none; }
.popover summary::-webkit-details-marker { display: none; }
/* Fenêtre centrée : jamais coupée par un tableau défilant */
body.modal-open::after { content: ""; position: fixed; inset: 0; background: rgba(15, 25, 20, .35); z-index: 40; }
.popover-body { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 41; width: min(360px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 16px 40px rgba(0,0,0,.18); padding: 18px; text-align: start; display: grid; gap: 12px; white-space: normal; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filters-actions { display: flex; gap: 8px; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 8px; }
.kv-cell { max-width: 280px; font-size: .82rem; }
.kv { display: block; overflow-wrap: anywhere; }
.kv b { color: var(--muted); font-weight: 600; }
.logo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.logo-preview { width: 72px; height: 72px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; padding: 4px; background: #fff; }

/* ---------- Pages invitées ---------- */
.guest { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 500px at 50% -10%, #dfe9e2, var(--bg)); }
.guest-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 12px 40px rgba(15, 40, 30, .08); padding: 28px; }
.guest-lang { text-align: end; margin-bottom: 8px; font-size: .9rem; }
.guest-head { margin-bottom: 20px; }
.guest-head p { color: var(--muted); margin: 6px 0 0; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--primary); }

/* ---------- Plateforme ---------- */
.platform-bar { display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; background: var(--sidebar); color: #fff; }
.platform-bar .muted { color: var(--sidebar-text); }
.platform-bar .lang-switch { color: #fff; }
.platform-bar .brand { padding: 0; }

/* ---------- Composants communs des modules (lots 2+) ---------- */
:root { --warning: #8a6417; --info: #1f5d8c; --info-soft: #e5eff7; --whatsapp: #1f8f4e; }
.topbar-start { display: flex; align-items: center; gap: 10px; min-width: 0; }
.shortcuts { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.shortcuts::-webkit-scrollbar { display: none; }
.shortcut .icon { width: 16px; height: 16px; }

/* Cloche des notifications */
.popover-menu { position: relative; }
.popover-menu summary { list-style: none; cursor: pointer; }
.popover-menu summary::-webkit-details-marker { display: none; }
.bell summary { position: relative; display: inline-flex; padding: 8px; border-radius: 8px; color: var(--text); }
.bell summary:hover { background: var(--surface); }
.bell-count { position: absolute; inset-block-start: 2px; inset-inline-end: 0; min-width: 18px; height: 18px; padding-inline: 4px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center; line-height: 1; }
.bell-dropdown { width: min(340px, calc(100vw - 24px)); max-height: 70vh; overflow-y: auto; inset-inline-end: -60px; }
.bell-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.small-link { font-size: .82rem; color: var(--primary); }
.bell-item button { display: grid; gap: 2px; }
.bell-item.unread button { background: var(--primary-soft); }
.bell-item + .bell-item { margin-top: 2px; }
.bell-title { display: flex; gap: 8px; align-items: flex-start; }
.bell-type { margin-top: 3px; color: var(--primary); }
.bell-item small { color: var(--muted); padding-inline-start: 26px; }
.bell-empty { padding: 10px; margin: 0; }
.bell-all { text-align: center !important; font-weight: 500; border-top: 1px solid var(--border); margin-top: 4px; color: var(--primary) !important; }
.row-unread td { background: #f7fbf8; font-weight: 500; }

/* Bandeaux (app/Views/banners) */
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid #eedcae; background: var(--warning-soft); color: var(--warning); }
.banner-danger { border-color: #f0c9c5; background: var(--danger-soft); color: #8c1d17; }
.banner-info { border-color: #c4d9ea; background: var(--info-soft); color: var(--info); }
.banner .btn { margin-inline-start: auto; }

/* Badges et cartes : tons */
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: #eedcae; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: #c4d9ea; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: #c8ddd1; }
.stat-label { display: flex; align-items: center; gap: 6px; }
.stat-success { border-inline-start-color: var(--success); }
.stat-warning { border-inline-start-color: var(--accent); }
.stat-danger { border-inline-start-color: var(--danger); }
.stat-accent { border-inline-start-color: var(--accent); }
.stat-info { border-inline-start-color: var(--info); }
.stat-value { overflow-wrap: anywhere; }

/* Onglets */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: thin; }
.tab { padding: 9px 14px; color: var(--muted); font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .75rem; text-align: center; }

/* Tableaux : totaux, montants */
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border); }
.num, .table td.num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* Boutons */
.btn .icon { width: 16px; height: 16px; }
.btn-whatsapp { color: #fff; background: var(--whatsapp); border-color: var(--whatsapp); }
.btn-whatsapp:hover { background: #18773f; border-color: #18773f; }
.print-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.error-list { margin: 0; padding-inline-start: 18px; }

/* Capture caméra */
.camera-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.camera-controls { display: grid; gap: 6px; flex: 1; min-width: 0; }
.camera-preview { width: 84px; height: 84px; object-fit: cover; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.camera-overlay { position: fixed; inset: 0; z-index: 60; background: rgba(10, 15, 12, .8); display: grid; place-items: center; padding: 16px; }
.camera-box { width: min(640px, 100%); display: grid; gap: 12px; }
.camera-box video { width: 100%; max-height: 70vh; border-radius: var(--radius); background: #000; }
.camera-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Tableau de bord (widgets des modules) et menu de la plateforme ---------- */
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.dashboard-cell { min-width: 0; }
.dashboard-cell > .card { margin-bottom: 0; height: 100%; }
.dashboard-cell.wide { grid-column: 1 / -1; }
.platform-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.platform-nav a { color: var(--sidebar-text); text-decoration: none; padding-block: 4px; }
.platform-nav a.active, .platform-nav a:hover { color: #fff; }

/* ---------- Mobile ---------- */
.sidebar-backdrop { display: none; }
@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    [dir="rtl"] .sidebar { transform: translateX(100%); }
    .sidebar-open .sidebar { transform: none; }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
    .main { margin-inline-start: 0; }
    .icon-btn { display: inline-flex; }
    .user-name { display: none; }
    .content { padding: 16px; }
    .grid-2, .grid-3, .dashboard-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .platform-bar { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
    .inline-form { flex-wrap: wrap; }
    .topbar { padding-inline: 12px; }
    .topbar-end { gap: 8px; }
    .shortcut span { display: none; }
    .bell-dropdown { position: fixed; inset-inline: 12px; inset-block-start: 60px; width: auto; }
}
@media (max-width: 480px) {
    .page-head h1 { font-size: 1.25rem; }
    .filters { grid-template-columns: 1fr 1fr; }
    .filters-actions { grid-column: 1 / -1; flex-wrap: wrap; }
    .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat { padding: 12px; }
    .stat-value { font-size: 1.3rem; }
}
@media print {
    .sidebar, .topbar, .impersonation, .banner, .filters, .print-actions, .no-print { display: none !important; }
    .main { margin: 0; }
}
