/* AE Hub — interface admin */
:root {
  --bg: #0c0d10; --surface: #14161b; --surface-2: #1b1e25; --surface-3: #22262f; --border: #282c35; --border-2: #343945;
  --text: #ece9e2; --muted: #8f95a0; --faint: #5f6570;
  --gold: #c9a45c; --gold-2: #e2c387; --gold-bg: #231d11; --gold-border: #5b4a26;
  --ok: #3fb37f; --ok-bg: #14251c; --ok-border: #2a5a40;
  --err: #e5544b; --err-bg: #261614; --err-border: #5a2a27;
  --info: #5b9cf5; --info-bg: #121c2b; --info-border: #24406a;
  --radius: 12px; --nav-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--gold-2); text-decoration: none; }
button { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; } .tiny { font-size: 11.5px; }
.r { text-align: right; } .nowrap { white-space: nowrap; } .pad { padding: 10px 12px; }
.gold { color: var(--gold-2); } .ok { color: #8fe3b9; } .err { color: #ffb4ae; }
.hide { display: none !important; }

/* ---------- Structure ---------- */
.shell { display: flex; min-height: 100vh; }
.nav { width: var(--nav-w); flex: 0 0 var(--nav-w); background: #0f1014; border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.nav .brand { padding: 4px 10px 20px; }
.nav .brand .logo { font-weight: 800; letter-spacing: .22em; font-size: 14px; color: var(--gold-2); text-transform: uppercase; }
.nav .brand .sub { font-size: 11px; color: var(--faint); letter-spacing: .14em; text-transform: uppercase; margin-top: 2px; }
.nav a.item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: var(--muted); font-weight: 600; position: relative; }
.nav a.item:hover { background: var(--surface); color: var(--text); }
.nav a.item.on { background: var(--surface-2); color: var(--text); }
.nav a.item.on::before { content: ''; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: var(--gold); }
.nav .ico { width: 20px; height: 20px; flex: 0 0 20px; }
.nav .count { margin-left: auto; background: var(--gold); color: #17130a; border-radius: 999px; font-size: 11px; font-weight: 800; padding: 1px 7px; }
.nav .spacer { flex: 1; }
.nav .me { padding: 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.main { flex: 1; min-width: 0; }
.page { max-width: 1240px; margin: 0 auto; padding: 22px 26px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .grow { flex: 1; }
.tabbar { display: none; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.split > *, .grid > * { min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: #17130a; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: #ffb4ae; border-color: var(--err-border); background: var(--err-bg); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.ghost.err { color: #ffb4ae; }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); border: 1px solid var(--border-2); color: var(--muted); white-space: nowrap; }
.badge.s-confirme, .badge.s-payee, .badge.s-acceptee, .badge.s-termine, .badge.s-convertie, .badge.s-envoye, .badge.s-livre { color: #8fe3b9; border-color: var(--ok-border); background: var(--ok-bg); }
.badge.s-demande, .badge.s-envoyee, .badge.s-partielle, .badge.s-en_attente { color: var(--gold-2); border-color: var(--gold-border); background: var(--gold-bg); }
.badge.s-en_cours, .badge.s-simule { color: #a9cbff; border-color: var(--info-border); background: var(--info-bg); }
.badge.s-annule, .badge.s-annulee, .badge.s-refusee, .badge.s-expiree, .badge.s-echec, .badge.s-absent { color: #ffb4ae; border-color: var(--err-border); background: var(--err-bg); }
.pill { white-space: nowrap; font-size: 10.5px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 5px; background: var(--surface-3); color: var(--muted); }
.notice { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--gold-border); background: var(--gold-bg); color: var(--gold-2); font-size: 14px; }
.notice.err { border-color: var(--err-border); background: var(--err-bg); color: #ffb4ae; }
.notice.info { border-color: var(--info-border); background: var(--info-bg); color: #cfe0ff; }
.empty { color: var(--muted); padding: 26px 16px; text-align: center; border: 1px dashed var(--border-2); border-radius: 12px; }
.loading { color: var(--muted); padding: 30px; text-align: center; }
hr.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* KPI */
a.kpi { color: var(--text); display: block; }
a.kpi:hover { border-color: var(--border-2); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.kpi .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.kpi .val { font-size: 26px; font-weight: 800; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* Listes */
.list { display: flex; flex-direction: column; }
a.li { color: var(--text); }
.list .li { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list .li:last-child { border-bottom: 0; }
.list .li:hover { background: rgba(255,255,255,.015); }
.li .main-col { flex: 1; min-width: 0; }
.li .t1 { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .t2 { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 54px; color: var(--gold-2); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-3); color: var(--gold-2); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; flex: 0 0 36px; border: 1px solid var(--border-2); }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.tbl th.r, table.tbl td.r { text-align: right; }
table.tbl tr.click { cursor: pointer; } table.tbl tr.click:hover td { background: rgba(255,255,255,.02); }
.num { font-variant-numeric: tabular-nums; }

/* Formulaires */
.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.field input, .field select, .field textarea, .inp {
  width: 100%; min-height: 40px; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font: 15px var(--font); }
.field textarea { min-height: 80px; resize: vertical; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus, .inp:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,164,92,.15); }
.hint { font-size: 12px; color: var(--faint); margin-top: 4px; line-height: 1.4; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.fields-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 12px; }
.check { display: flex; gap: 9px; align-items: center; font-size: 14px; margin: 6px 0 10px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--gold); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.search { position: relative; }
.search input { padding-left: 34px; }
.search::before { content: '⌕'; position: absolute; left: 12px; top: 8px; color: var(--muted); font-size: 17px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.seg button.on { background: var(--surface-3); color: var(--text); }
.picker { position: relative; }
.picker input { width: 100%; min-height: 40px; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font: 15px var(--font); }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--surface-2); border: 1px solid var(--border-2); border-radius: 10px; margin-top: 4px; overflow: hidden; box-shadow: 0 12px 30px rgba(0,0,0,.4); }
.picker-list:empty { display: none; }
.picker-list button { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 9px 12px; border: 0; background: none; cursor: pointer; text-align: left; border-bottom: 1px solid var(--border); }
.picker-list button:hover { background: var(--surface-3); }
.picker-list button span { font-size: 12.5px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 650; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--text); border-bottom-color: var(--gold); }

/* Modales */
.modal-wrap { position: fixed; inset: 0; background: rgba(5,6,8,.72); backdrop-filter: blur(3px); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: var(--surface); border: 1px solid var(--border-2); border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,.55); }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h3 { flex: 1; }
.modal-body { padding: 18px; }
#toasts { position: fixed; z-index: 200; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--surface-3); border: 1px solid var(--ok-border); color: var(--text); padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.4); transition: opacity .4s, transform .4s; font-weight: 600; }
.toast.err { border-color: var(--err-border); color: #ffd1cd; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* Détails */
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13.5px; } .dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Calendrier ---------- */
.cal-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.cal-toolbar .range { font-weight: 750; font-size: 17px; margin: 0 6px; display: inline-block; }
.cal-toolbar .range::first-letter { text-transform: uppercase; }
.cal { --hour: 52px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-head { display: grid; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.cal-head div { padding: 9px 6px; text-align: center; font-size: 12.5px; color: var(--muted); border-left: 1px solid var(--border); text-transform: capitalize; }
.cal-head div:first-child { border-left: 0; }
.cal-head div.today { color: var(--gold-2); font-weight: 800; }
.cal-head .dnum { display: block; font-size: 19px; font-weight: 800; color: var(--text); }
.cal-head .today .dnum { color: var(--gold-2); }
.cal-body { display: grid; position: relative; max-height: calc(100vh - 190px); overflow-y: auto; padding-top: 8px; }
.cal-hours div { height: var(--hour); font-size: 11px; color: var(--faint); text-align: right; padding: 0 6px; transform: translateY(-7px); }
.cal-col { position: relative; border-left: 1px solid var(--border); background-image: repeating-linear-gradient(to bottom, var(--border) 0 1px, transparent 1px calc(var(--hour) / 2), rgba(40,44,53,.45) calc(var(--hour) / 2) calc(var(--hour) / 2 + 1px), transparent calc(var(--hour) / 2 + 1px) var(--hour)); cursor: copy; }
.cal-col.closed { background-color: rgba(0,0,0,.25); }
.cal-col.today { background-color: rgba(201,164,92,.035); }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--err); z-index: 3; pointer-events: none; }
.cal-now::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--err); }
.ev { position: absolute; border-radius: 8px; padding: 5px 7px; font-size: 12px; line-height: 1.25; overflow: hidden; cursor: pointer; z-index: 2;
  background: #2a2418; border: 1px solid var(--gold-border); border-left: 3px solid var(--gold); color: var(--text); }
.ev:hover { filter: brightness(1.15); }
.ev .t { font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev .s { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.st-demande { background: repeating-linear-gradient(135deg, #2a2418 0 8px, #241f15 8px 16px); border-style: dashed; }
.ev.st-en_cours { background: #162236; border-color: var(--info-border); border-left-color: var(--info); }
.ev.st-termine { background: #15241c; border-color: var(--ok-border); border-left-color: var(--ok); opacity: .8; }
.ev.st-absent, .ev.st-annule { background: #241614; border-color: var(--err-border); border-left-color: var(--err); opacity: .6; }

/* ---------- Messagerie ---------- */
.inbox { display: grid; grid-template-columns: 330px minmax(0, 1fr); height: calc(100vh - 120px); min-height: 480px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.convs { border-right: 1px solid var(--border); overflow-y: auto; }
.conv { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.on { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--gold); }
.conv .main-col { flex: 1; min-width: 0; }
.conv .top { display: flex; justify-content: space-between; gap: 6px; }
.conv .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .prev { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .name::after { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); margin-left: 6px; vertical-align: middle; }
.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.inbox > * { min-height: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.thread-msgs { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 14px; overflow-wrap: anywhere; font-size: 14.5px; }
.bubble .txt { white-space: pre-wrap; }
.bubble.in { align-self: flex-start; background: var(--surface-3); border-bottom-left-radius: 4px; }
.bubble.out { align-self: flex-end; background: #2b2416; border: 1px solid var(--gold-border); border-bottom-right-radius: 4px; }
.bubble .meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; font-size: 11px; color: var(--muted); }
.bubble .subj { font-weight: 700; margin-bottom: 3px; }
.composer { border-top: 1px solid var(--border); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { width: 100%; min-height: 64px; max-height: 200px; resize: vertical; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font: 15px var(--font); }
.composer textarea:focus { outline: none; border-color: var(--gold); }
.composer .row { display: flex; gap: 8px; align-items: center; }

/* ---------- Éditeur de documents ---------- */
.items-tbl input { width: 100%; min-height: 36px; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font: 14.5px var(--font); }
.items-tbl input:focus { outline: none; border-color: var(--gold); }
.items-tbl td { padding: 6px 5px; border-bottom: 1px solid var(--border); vertical-align: top; }
.items-tbl th { padding: 6px 5px; }
.items-tbl .qty { width: 90px; } .items-tbl .price { width: 120px; } .items-tbl .tot { width: 110px; text-align: right; padding-top: 14px; }
.totals-box { margin-left: auto; width: 300px; max-width: 100%; }
.totals-box .tr { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals-box .tr.grand { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; font-weight: 800; font-size: 18px; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(ellipse at top, #1c1810 0%, var(--bg) 60%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login .logo { font-weight: 800; letter-spacing: .26em; text-transform: uppercase; color: var(--gold-2); text-align: center; font-size: 17px; }
.login .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 4px 0 22px; }

/* ---------- Cellulaire ---------- */
@media (max-width: 980px) {
  .split { grid-template-columns: minmax(0, 1fr); }
  .g4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 800px) {
  .nav { display: none; }
  .page { padding: 16px 14px calc(90px + var(--safe-b)); }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: rgba(15,16,20,.96); backdrop-filter: blur(10px); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + var(--safe-b)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--muted); padding: 4px 0; position: relative; font-weight: 600; }
  .tabbar a.on { color: var(--gold-2); }
  .tabbar .ico { width: 23px; height: 23px; }
  .tabbar .count { position: absolute; top: 0; left: 55%; background: var(--gold); color: #17130a; border-radius: 999px; font-size: 10px; font-weight: 800; padding: 0 5px; }
  .g2, .g3, .fields-2, .fields-3 { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: 1fr 1fr; }
  .kpi .val { font-size: 21px; }
  h1 { font-size: 20px; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 150px - var(--safe-b)); }
  .inbox.has-thread .convs { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  .modal-wrap { padding: 0; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; overflow-y: auto; }
  .modal-head { position: sticky; top: 0; background: var(--surface); z-index: 2; }
  .dl { grid-template-columns: 1fr; gap: 0; } .dl dd { margin-bottom: 9px; }
  table.tbl .hide-sm { display: none; }
  .items-tbl thead { display: none; }
  .items-tbl tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); align-items: start; }
  .items-tbl td { border: 0; padding: 0; }
  .items-tbl td.desc { grid-column: 1 / -1; }
  .items-tbl .qty, .items-tbl .price, .items-tbl .tot { width: auto; }
  .items-tbl .tot { padding-top: 9px; }
  .cal-body { max-height: calc(100vh - 230px - var(--safe-b)); }
  .btn { min-height: 42px; }
  .field input, .field select, .field textarea { font-size: 16px; }
}
