:root {
  --ink: #1b2430; --muted: #6b7684; --line: #e3e7ec; --bg: #f5f6f8; --card: #fff;
  --navy: #1f3a5f; --accent: #2f6fb0; --pub: #1f6f5c; --priv: #8a5a1f; --ai: #6a4bc4; --danger: #c0392b; --ok: #1f8a4c;
  --r: 12px; font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Arabic', 'Amiri', sans-serif; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* barre du haut */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 18px; background: var(--navy); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 1.15rem; letter-spacing: .2px; }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; opacity: .85; white-space: nowrap; }
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, .14); opacity: 1; }

main { max-width: 1500px; margin: 0 auto; }

/* parcours */
.flow, .page { padding: 28px 20px 60px; max-width: 980px; margin: 0 auto; }
.hero h1 { margin: 0 0 6px; font-size: 1.7rem; }
.hero p { margin: 0 0 22px; color: var(--muted); }
.crumbs { margin-bottom: 18px; color: var(--muted); }
.crumbs a { color: var(--accent); text-decoration: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.card { display: flex; flex-direction: column; gap: 6px; padding: 26px 22px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); text-decoration: none; border-top: 5px solid var(--accent); transition: transform .12s, box-shadow .12s; min-height: 130px; }
.card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(20, 40, 70, .08); }
.card-public { border-top-color: var(--pub); }
.card-prive { border-top-color: var(--priv); }
.card-title { font-size: 1.2rem; font-weight: 700; }
.card-ar { font-family: 'Amiri', serif; font-size: 1.15rem; color: var(--muted); }
.card-meta { margin-top: auto; font-size: .85rem; color: var(--muted); }
.h-sub { font-size: 1.05rem; margin: 30px 0 10px; }

/* listes */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head input[type=search] { flex: 1; max-width: 360px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.row-main { flex: 1; display: flex; flex-direction: column; text-decoration: none; min-width: 0; }
.row-title { font-weight: 600; }
.row-sub { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: .75rem; padding: 3px 9px; border-radius: 999px; background: #eef1f5; color: var(--muted); white-space: nowrap; }
.pill-finalise, .pill-ok { background: #e5f5ec; color: var(--ok); }
.pill-ia { background: #efeafc; color: var(--ai); }
.icon { border: 0; background: none; cursor: pointer; font-size: 1rem; padding: 6px; border-radius: 8px; color: var(--muted); }
.icon:hover { background: #f0f2f5; }
.icon.danger:hover { color: var(--danger); }

/* boutons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: #c9d1db; }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.ghost { background: transparent; }
.btn.ai { background: var(--ai); color: #fff; border-color: var(--ai); }
.btn.sm { padding: 5px 10px; font-size: .88rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.busy::after { content: ''; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 1px 7px; font-size: .78rem; cursor: pointer; }

/* formulaires */
.fld { display: flex; flex-direction: column; gap: 4px; }
.fld > span { font-size: .82rem; color: var(--muted); font-weight: 600; }
.fld input, .fld select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }
.fld input:focus, .fld select:focus, textarea:focus { outline: 2px solid #b9d3f0; border-color: var(--accent); }
.fld small { color: var(--muted); }
textarea { resize: vertical; line-height: 1.5; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }

/* éditeur */
.editor { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1fr); gap: 0; height: calc(100vh - 52px); }
.ed-form { overflow-y: auto; padding: 16px 18px 80px; border-inline-end: 1px solid var(--line); }
.ed-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.ed-head > div { flex: 1; }
.ed-title { font-weight: 700; }
.back { text-decoration: none; font-size: 1.3rem; padding: 2px 8px; border-radius: 8px; }
.back:hover { background: #e9edf2; }
.statut { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.blk { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; padding: 0 14px; }
.blk > summary { cursor: pointer; padding: 12px 0; font-weight: 700; list-style: none; }
.blk > summary::-webkit-details-marker { display: none; }
.blk > summary::before { content: '▸ '; color: var(--muted); }
.blk[open] > summary::before { content: '▾ '; }
.blk[open] { padding-bottom: 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.fld-wide { grid-column: span 2; }
.row-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }

.g-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.g-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 4px; vertical-align: middle; }
.g-sec { border-top: 1px solid var(--line); padding: 8px 0; }
.g-sec-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; font-size: .92rem; }
.g-fill { display: flex; gap: 4px; flex-shrink: 0; }
.g-subh { font-style: italic; color: var(--muted); font-size: .82rem; margin: 6px 0 2px; }
.g-item { display: flex; align-items: center; gap: 10px; padding: 5px 4px; border-radius: 8px; }
.g-item:hover { background: #f7f8fa; }
.g-item.from-ia { background: #f6f3fe; }
.g-text { flex: 1; font-size: .88rem; line-height: 1.35; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-shrink: 0; }
.seg button { border: 0; background: #fff; padding: 5px 8px; min-width: 32px; cursor: pointer; font-size: .82rem; font-weight: 600; color: var(--muted); border-inline-start: 1px solid var(--line); }
.seg button:first-child { border-inline-start: 0; }
.seg button.on { background: var(--c); color: #fff; }
.g-item.from-ia .seg button.on { outline: 2px dashed var(--ai); outline-offset: -3px; }

.sec { border-top: 1px solid var(--line); padding: 10px 0; }
.sec:first-of-type { border-top: 0; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.sec-notes summary { font-size: .82rem; color: var(--muted); cursor: pointer; margin-bottom: 4px; }
.sec-actions { display: flex; gap: 8px; margin: 6px 0; }
.editor.is-ar .sec textarea[data-stext] { font-family: 'Amiri', serif; font-size: 1.08rem; }

.ed-preview { display: flex; flex-direction: column; background: #e9ecf0; min-width: 0; }
.pv-bar { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #f3f5f8; flex-wrap: wrap; }
.pv-scroll { overflow: auto; flex: 1; padding: 12px; }
.pv-scale { --k: .6; width: calc(210mm * var(--k)); margin: 0 auto; }
.pv-scale > .r-sheet { transform: scale(var(--k)); transform-origin: top left; box-shadow: 0 6px 24px rgba(0, 0, 0, .12); margin-bottom: calc(-297mm * (1 - var(--k))); }
.pv-toggle { display: none; }

/* réglages */
.settings .logos { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.logo-set { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; font-size: .9rem; }
.logo-box { height: 70px; display: flex; align-items: center; justify-content: center; background: #fafbfc; border-radius: 8px; overflow: hidden; }
.logo-box img { max-height: 66px; max-width: 100%; }
.settings .btn { margin: 4px 6px 4px 0; }

/* toasts */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translate(-50%, 20px); opacity: 0; background: #1f2a37; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 99; transition: .25s; max-width: 92vw; box-shadow: 0 8px 30px rgba(0, 0, 0, .2); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--danger); }
.toast-ok { background: var(--ok); }

/* mobile */
@media (max-width: 920px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .ed-form { border: 0; padding-bottom: 90px; }
  .ed-preview { display: none; position: fixed; inset: 52px 0 0 0; z-index: 15; }
  .editor.show-preview .ed-preview { display: flex; }
  .pv-toggle { display: block; position: fixed; bottom: 18px; inset-inline-end: 18px; z-index: 16; background: var(--navy); color: #fff; border: 0; border-radius: 999px; padding: 12px 20px; font-weight: 700; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
  .editor.show-preview .pv-toggle::after { content: ' ✕'; }
  .fld-wide { grid-column: auto; }
  .top { gap: 10px; padding: 10px 12px; }
  .brand span { display: none; }
}
