/* Back-office Magix : feuille de style unique, locale (aucune police ni ressource externe). */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --line: #dde1e8;
  --brand: #0b6b4f;
  --brand-dark: #08523c;
  --brand-soft: #e5f4ee;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  --info-soft: #e8f0fe;
  --warn-soft: #fff4d6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Naskh Arabic", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; }
h2 { font-size: 1.2rem; margin: 0 0 .5rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .25rem; }
a { color: var(--brand-dark); }
code { background: #eef0f3; padding: .1rem .3rem; border-radius: 4px; font-size: .9em; word-break: break-all; }
pre { margin: 0; }
.muted { color: var(--muted); }
.lead { font-size: 1.05rem; }
.req { color: var(--danger); }

/* ------------ En-tête et menus ------------ */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; background: var(--brand); color: #fff; padding: .6rem 1rem; }
.topbar a { color: #fff; }
.topbar-plain { justify-content: center; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: #fff; }
.brand span { font-weight: 400; opacity: .85; }
.mainnav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.mainnav a { display: inline-flex; align-items: center; gap: .4rem; text-decoration: none; padding: .35rem .7rem; border-radius: 6px; }
.nav-icon { display: none; width: 24px; height: 24px; flex: none; }
.nav-short { display: none; }
.mainnav a:hover, .mainnav a[aria-current=page] { background: rgba(255,255,255,.18); }
.logout { display: flex; align-items: center; gap: .6rem; margin: 0; }
.who { font-size: .85rem; opacity: .9; }
.subnav { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; background: var(--surface); border-bottom: 1px solid var(--line); padding: .5rem 1rem; }
.subnav-head { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .6rem; margin-right: .75rem; }
.subnav-title { margin-right: 0; }

/* Menu « Administration » : replié, réservé à l'équipe technique */
.admin-menu { position: relative; margin: 0; }
.admin-menu > summary { cursor: pointer; list-style: none; font-weight: 400; font-size: .9rem; padding: .3rem .7rem; border: 1px solid rgba(255,255,255,.45); border-radius: 6px; color: #fff; }
.admin-menu > summary::-webkit-details-marker { display: none; }
.admin-menu > summary::after { content: " ▾"; }
.admin-menu[open] > summary { background: rgba(255,255,255,.18); }
.admin-panel { position: absolute; right: 0; top: calc(100% + .4rem); z-index: 20; min-width: 270px; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0,0,0,.18); padding: .5rem; display: flex; flex-direction: column; }
.admin-panel a { color: var(--text) !important; text-decoration: none; padding: .45rem .6rem; border-radius: 6px; }
.admin-panel a:hover, .admin-panel a[aria-current=page] { background: var(--brand-soft); }
.admin-title { margin: .1rem .6rem .35rem; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.subnav a { text-decoration: none; padding: .3rem .65rem; border-radius: 6px; color: var(--text); }
.subnav a:hover { background: var(--brand-soft); }
.subnav a[aria-current=page] { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.subnav-links { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; }
.back { margin: 0 0 .75rem; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .5rem; }
.actions, .form-actions, .tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.form-actions { margin-top: 1rem; }

/* ------------ Cartes ------------ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; }
.card.narrow, section.narrow { max-width: 520px; margin-left: auto; margin-right: auto; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.card-guide { border-color: var(--brand); background: #f7fcf9; }

/* ------------ Boutons ------------ */
.btn { display: inline-block; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .55rem 1rem; border-radius: 8px; min-height: 2.5rem; }
.btn:hover { background: #eef1f4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8c1d17; }
.btn-danger-outline { color: var(--danger); border-color: var(--danger); background: var(--surface); }
.btn-ghost { background: transparent; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,.5); }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.18); }
.btn-small { padding: .3rem .7rem; min-height: 2rem; font-size: .9rem; }
.inline-form { display: inline; margin: 0; }

/* ------------ Formulaires ------------ */
.field { margin: 0 0 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field-check label { display: flex; gap: .5rem; align-items: flex-start; font-weight: 600; }
.field-check input { margin-top: .3rem; }
.inline-check { display: inline-flex !important; gap: .4rem; font-weight: 400 !important; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=tel], input[type=datetime-local], select, textarea {
  width: 100%; font: inherit; padding: .55rem .7rem; border: 1px solid #b9c0cc; border-radius: 8px; background: #fff; color: var(--text);
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 3px solid #7fb9a4; outline-offset: 1px; }
input:disabled, select:disabled, textarea:disabled { background: #f0f2f5; color: var(--muted); }
.help { color: var(--muted); font-size: .88rem; margin: .25rem 0 0; }
.error-text { color: var(--danger); font-size: .9rem; margin: .25rem 0 0; font-weight: 600; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); background: var(--danger-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
details { margin: .5rem 0 1rem; }
summary { cursor: pointer; font-weight: 600; }
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.filter-bar select { width: auto; }

/* ------------ Messages d'information ------------ */
.notice { padding: .7rem 1rem; border-radius: 8px; margin: 0 0 1rem; border: 1px solid transparent; }
.notice ul { margin: .25rem 0 0 1.2rem; padding: 0; }
.notice-success { background: var(--brand-soft); border-color: #a9d8c4; }
.notice-error { background: var(--danger-soft); border-color: #f1b8b3; color: #6d1410; }
.notice-info { background: var(--info-soft); border-color: #b7cdf7; }

/* ------------ Tableaux ------------ */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .85rem; text-transform: none; color: var(--muted); background: #fafbfc; }
.table tr:last-child td { border-bottom: 0; }
.row-actions { white-space: nowrap; text-align: right; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .8rem; font-weight: 700; background: #e8ebf0; color: #3a4452; }
.badge-active, .badge-instant { background: var(--brand-soft); color: var(--brand-dark); }
.badge-paused, .badge-wheel { background: var(--warn-soft); color: #7a5a00; }
.badge-closed, .badge-purged { background: #e8ebf0; color: #3a4452; }
.badge-draft { background: var(--info-soft); color: #1a3e8a; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.pager { display: flex; gap: .5rem; margin-top: 1rem; }

/* ------------ Compteurs ------------ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stat { background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: .8rem; }
.stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-weight: 600; }
.stat-sub { font-size: .82rem; color: var(--muted); }

/* ------------ Guide ------------ */
.guide-steps { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: .75rem; }
.guide-steps li { display: flex; gap: .9rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .8rem; }
.guide-steps h3 { margin-top: 0; }
.guide-steps p { margin: .1rem 0 .5rem; }
.step-num { flex: none; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; }
.steps-list { padding-left: 1.2rem; }
.qr { display: flex; justify-content: center; margin: 1rem 0; }
.qr svg { width: 220px; height: 220px; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
.manual-key { margin-bottom: 1rem; }

/* ------------ Éditeur de messages ------------ */
.text-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: .75rem; padding: .75rem 0; border-top: 1px solid var(--line); }
.text-row:first-of-type { border-top: 0; }
.text-row-main { flex: 1; min-width: 240px; }
.text-row h3 { margin-top: 0; }
.excerpt { white-space: pre-wrap; font-family: inherit; background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin-top: .4rem; max-height: 9rem; overflow: auto; }
.excerpt-inline { margin: .3rem 0 0; }
.chip { display: inline-block; background: #eef0f3; border-radius: 99px; padding: .15rem .7rem; font-size: .9rem; }
.chip-button { border: 1px solid #c4cad4; background: #fff; cursor: pointer; font: inherit; font-size: .9rem; }
.chip-button:hover { background: var(--brand-soft); border-color: var(--brand); }
.insert-bar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: .5rem 0; }
.insert-label { font-weight: 600; font-size: .9rem; }
.counter { font-size: .85rem; color: var(--muted); margin: .3rem 0 0; }
.counter.over { color: var(--danger); font-weight: 700; }
.live-errors { list-style: none; margin: .5rem 0 0; padding: 0; color: var(--danger); font-weight: 600; font-size: .92rem; }
.live-errors li { padding: .15rem 0; }
.editor-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(280px, .85fr); gap: 1rem; align-items: start; }
.editor-form { margin-bottom: 0; }
.preview-pane { position: sticky; top: .5rem; }
.version { padding-bottom: .5rem; }

/* Aperçu façon WhatsApp (maquettes du cahier des charges) */
.wa-phone { background: #efeae2; border: 1px solid #cfc8bb; border-radius: 14px; overflow: hidden; }
.wa-phone::before { content: "Magix نجيمات العشرة · Business account"; display: block; background: #008069; color: #fff; padding: .55rem .8rem; font-weight: 600; font-size: .9rem; }
.wa-chat { padding: .8rem; min-height: 320px; max-height: 70vh; overflow: auto; display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.wa-bubble { background: #fff; border-radius: 10px; padding: .35rem .5rem .3rem; max-width: 100%; width: 100%; box-shadow: 0 1px 1px rgba(0,0,0,.13); font-size: .95rem; }
.wa-quote { display: flex; justify-content: space-between; gap: .5rem; background: #f5f6f6; border-left: 4px solid #06cf9c; border-radius: 6px; padding: .3rem .5rem; margin-bottom: .35rem; }
.wa-quote-title { color: #06a57d; font-weight: 700; font-size: .85rem; }
.wa-quote-line { color: #54656f; font-size: .85rem; }
.wa-quote-thumb { flex: none; width: 2.6rem; height: 2.6rem; border-radius: 4px; background: linear-gradient(135deg, #b9bdc2, #8a9099); }
.wa-body p { margin: .15rem 0; unicode-bidi: plaintext; text-align: start; }
.wa-body .wa-gap { height: .6rem; margin: 0; }
.wa-body code, .wa-body .wa-pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: #f0f2f5; border-radius: 6px; padding: .1rem .3rem; word-break: break-all; }
.wa-body .wa-pre { display: block; padding: .5rem .6rem; margin: .25rem 0; text-align: center; font-weight: 700; letter-spacing: .04em; }
.wa-legal { color: #667781; font-size: .78rem; margin-top: .35rem; line-height: 1.35; }
.wa-time { text-align: end; color: #667781; font-size: .72rem; margin-top: .1rem; direction: ltr; }
.wa-btn { background: #fff; color: #027eb5; text-align: center; font-weight: 700; padding: .55rem; border-radius: 8px; box-shadow: 0 1px 1px rgba(0,0,0,.13); width: 100%; }
.wa-btn-copy { opacity: .85; }

/* ------------ Petits écrans ------------ */
@media (max-width: 800px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stat-grid, .stat-grid-3 { grid-template-columns: 1fr 1fr; }
  .editor-grid { grid-template-columns: 1fr; }
  .preview-pane { position: static; }
  .who { display: none; }
  .topbar { padding: .5rem .75rem; }
  .mainnav { order: 3; flex-basis: 100%; }
  .mainnav a { padding: .3rem .5rem; }
  .logout { margin-left: auto; }
  .subnav { padding: .4rem .75rem; flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
  .subnav-head { margin-right: 0; }
  .subnav-links { min-width: 0; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: .25rem; padding-bottom: .15rem; }
  .subnav a { padding: .4rem .7rem; font-size: .95rem; white-space: nowrap; }
  .subnav-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .page-head { flex-direction: column; }
  .actions .btn, .form-actions .btn { flex: 1 1 auto; text-align: center; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--line); padding: .4rem 0; }
  .table td { border-bottom: 0; padding: .25rem 1rem; }
  .table td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: .85rem; }
  .row-actions { text-align: left; white-space: normal; }
}

/* ------------ BO-2 : stock, graphiques, vérification, roue ------------ */
.stat-low { border-color: var(--danger); background: var(--danger-soft); }
.stat-low .stat-value, .low-text { color: var(--danger); font-weight: 700; }
.chart { width: 100%; height: auto; max-height: 260px; display: block; }
.chart-bar { fill: var(--brand); }
.chart-line { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 10px; }
.chart-label { fill: var(--text); font-size: 12px; }
.review-photo { max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; display: block; margin: 0 auto; }
.pending-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 1rem; align-items: start; }
.pending-grid .card { margin: 0; }
.pending-grid .wa-chat { min-height: 0; max-height: 360px; }
.wheel-card { text-align: center; }
.wheel-card canvas { max-width: 100%; height: auto; }
.revealed { font-size: 1.15rem; letter-spacing: .03em; direction: ltr; unicode-bidi: plaintext; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem 1rem; list-style: none; padding: 0; margin: 1rem 0; }
.recovery-codes code { font-size: 1.05rem; padding: .35rem .6rem; display: block; text-align: center; letter-spacing: .08em; }
.temp-password { font-size: 1.3rem; padding: .6rem 1rem; display: block; text-align: center; letter-spacing: .06em; }

/* ------------ BO-3 : sections repliables, aides, coûts ------------ */
details.advanced > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary h2 { margin: 0; }
details.advanced > summary::after { content: "Afficher ▾"; color: var(--muted); font-weight: 400; font-size: .9rem; }
details.advanced[open] > summary::after { content: "Masquer ▴"; }
details.advanced[open] > summary { margin-bottom: .5rem; }
.info-box { background: var(--info-soft); border: 1px solid #b7cdf7; border-radius: 8px; padding: .6rem 1rem; margin: 0 0 1rem; }
.info-box h3 { margin-top: .25rem; }
.info-box dt { font-weight: 700; margin-top: .5rem; }
.info-box dd { margin: .15rem 0 .25rem; }
.table caption { text-align: left; padding: .7rem 1rem 0; }
[hidden] { display: none !important; }

/* ------------ Accueil « Que faire maintenant ? » ------------ */
.home-hello { font-size: 1.3rem; margin-bottom: .75rem; }
.next-card { padding: 1.25rem 1.3rem; }
.next-card h2 { font-size: 1.35rem; margin-bottom: .25rem; }
.next-state { margin: 0 0 .75rem; }
.next-text { font-size: 1.1rem; margin: 0 0 1rem; }
.next-button { margin: 0 0 1rem; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; }
.next-then { border-top: 1px solid var(--line); padding-top: .6rem; }
.next-then p { margin: 0 0 .25rem; }
.next-then li { border-bottom: 0; padding: .25rem 0; }
.btn-big { font-size: 1.15rem; padding: .8rem 1.6rem; min-height: 3.2rem; border-radius: 10px; }
.alerts { margin: 0 0 1rem; }
.alert-line { display: flex; gap: .6rem; background: var(--warn-soft); border: 1px solid #ecd68a; border-radius: 8px; padding: .6rem .9rem; margin: 0 0 .5rem; }
.alert-icon { flex: none; }
.today-line { margin: 0 0 .5rem; }
.welcome h2 { margin-bottom: .25rem; }

/* ------------ Page-carrefour « Réglages » ------------ */
.hub { margin-bottom: 1.5rem; }
.hub-cards { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.hub-card { display: flex; flex-direction: column; gap: .15rem; height: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; text-decoration: none; color: var(--text); }
.hub-card:hover { border-color: var(--brand); background: var(--brand-soft); }
.hub-card .muted { font-size: .9rem; }
.hub-status { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* ------------ Aide ------------ */
.faq-item { border-bottom: 1px solid var(--line); margin: 0; padding: .6rem 0; }
.faq-item:last-of-type { border-bottom: 0; }
.faq-item > p { margin: .4rem 0; }
.help-search input { max-width: 28rem; }
details.tour { margin: .75rem 0 0; }

/* ------------ Téléphone (moins de 480 px, document de conception, section 9) ------------ */
@media (max-width: 480px) {
  body { padding-bottom: 72px; }
  input, select, textarea { font-size: 16px; }
  .page { padding-left: 16px; padding-right: 16px; }
  .btn { min-height: 3rem; }
  .btn-small { min-height: 2.75rem; }
  .actions .btn, .form-actions .btn, .next-button .btn, .form-actions form, .form-actions .inline-form { width: 100%; text-align: center; }
  .form-actions form .btn { width: 100%; }
  /* Menu principal en bas d'écran : 4 entrées, icône et libellé */
  .mainnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; order: 0; flex-basis: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 10px rgba(0,0,0,.08); padding: 0; height: 60px; }
  .mainnav a { color: var(--muted); flex-direction: column; justify-content: center; gap: .1rem; min-height: 56px; padding: .25rem; border-radius: 0; font-size: .75rem; text-align: center; }
  .mainnav a:hover { background: transparent; }
  .mainnav a[aria-current=page] { background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }
  .nav-icon { display: block; }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  .topbar { padding: .45rem 16px; }
  .logout { display: none; }
  .admin-panel { right: auto; left: 0; max-width: calc(100vw - 32px); }
  .subnav { padding: .4rem 16px; }
  .btn-big { width: 100%; }
  .hub-cards { grid-template-columns: 1fr; }
}

/* Numéros WhatsApp : valeurs à recopier chez Meta, aides dépliables */
.copy-list { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1rem; align-items: center; margin: .5rem 0 1rem; }
.copy-list dt { font-weight: 600; }
.copy-list dd { margin: 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.copy-list code { word-break: break-all; background: var(--info-soft); padding: .2rem .4rem; border-radius: 4px; }
.help-details, .inline-details { margin: .25rem 0 1rem; }
.inline-details summary { font-weight: 400; font-size: .9rem; }
.inline-details .inline-form { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .4rem; }
@media (max-width: 640px) { .copy-list { grid-template-columns: 1fr; } }
