:root {
  --bg: #0E0C0D; --panel: #171315; --panel2: #1C1719; --panel3: #221C1F; --line: #2A2427; --line2: #342D30;
  --text: #EDE6E1; --strong: #F4ECE6; --muted: #A69C98; --muted2: #C9BFBA; --dim: #8F8581;
  --accent: #8E2D4A; --accent-hi: #A33657; --on-accent: #FFF6F8; --rose: #E3B9C6; --gold: #C9A66B;
  --ok: #9FD3AE; --ok-bg: #1E2A22; --warn: #F2B48C; --warn-bg: #3A1E14; --info: #A9C4F0; --info-bg: #1D2433; --gold-bg: #2E2618;
  --radius: 14px; --nav: 250px;
  --serif: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body { position: fixed; inset: 0; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; opacity: .45; }
:focus-visible { outline: 2px solid var(--rose); outline-offset: 2px; }
input::placeholder, textarea::placeholder { color: var(--dim); }
h1, h2, h3 { margin: 0; }
a { color: var(--rose); }
.boot { display: flex; align-items: center; justify-content: center; height: 100vh; color: var(--muted); font-family: var(--serif); font-size: 28px; }

/* ---------- Coque de l'application ---------- */
.shell { display: grid; grid-template-columns: var(--nav) minmax(0, 1fr); height: 100vh; height: 100dvh; }
.nav { background: #141113; border-right: 1px solid var(--line); padding: calc(18px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; }
.brand-mark { width: 42px; height: 42px; flex: none; border-radius: 11px; background: #5E1A2E; display: flex; align-items: center; justify-content: center; }
.brand-name { font-family: var(--serif); font-size: 23px; font-weight: 700; color: var(--strong); line-height: 1; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 1.3px; text-transform: uppercase; margin-top: 3px; }
.nav-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 0 14px; border-radius: 12px; border: 0; background: transparent;
  color: #B8ADA8; font-weight: 500; font-size: 15px; text-align: left; width: 100%; }
.nav-item.on { background: #2A1A20; color: var(--strong); box-shadow: inset 3px 0 0 var(--accent); }
.nav-item .count { margin-left: auto; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; background: var(--warn-bg); color: var(--warn); }
.nav-item .count.gold { background: var(--gold-bg); color: #E4C68E; }
.nav-foot { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.sync-chip { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 12px; color: var(--muted2); text-align: left; min-height: 44px; }
.sync-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--dim); }
.sync-dot.ok { background: var(--ok); } .sync-dot.warn { background: var(--warn); } .sync-dot.busy { background: var(--gold); }
.main { display: flex; flex-direction: column; min-width: 0; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 14px; padding: calc(14px + env(safe-area-inset-top)) calc(26px + env(safe-area-inset-right)) 14px 26px;
  border-bottom: 1px solid var(--line); background: rgba(14, 12, 13, .94); flex-wrap: wrap; }
.topbar h1 { font-family: var(--serif); font-size: 32px; font-weight: 600; color: var(--strong); line-height: 1.05; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.topbar .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 6px 0 4px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line2); }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; color: #fff; flex: none; }
.avatar.lg { width: 76px; height: 76px; font-size: 26px; }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 22px calc(26px + env(safe-area-inset-right)) calc(48px + env(safe-area-inset-bottom)) 26px; }
.banner { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.banner.info { background: var(--info-bg); color: var(--info); } .banner.warn { background: var(--warn-bg); color: var(--warn); } .banner.ok { background: var(--ok-bg); color: var(--ok); }
@media (max-width: 1000px) {
  :root { --nav: 88px; }
  .nav .label, .brand-text, .sync-chip .label { display: none; }
  .brand { justify-content: center; padding: 4px 0 18px; }
  .nav-item { justify-content: center; padding: 0; position: relative; }
  .nav-item .count { position: absolute; top: 2px; right: 6px; margin: 0; min-width: 20px; height: 20px; font-size: 11px; }
  .sync-chip { justify-content: center; }
  .topbar h1 { font-size: 28px; }
  .user-chip .uname { display: none; }
}

/* ---------- Éléments ---------- */
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); } .muted2 { color: var(--muted2); } .strong { color: var(--strong); font-weight: 600; } .small { font-size: 13px; } .tiny { font-size: 12px; }
.right { text-align: right; } .center { text-align: center; } .nowrap-t { white-space: nowrap; }
.serif { font-family: var(--serif); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpis:has(> :nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis:has(> :nth-child(2):last-child), .kpis:has(> :only-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpis:has(> :nth-child(5)) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1000px) {
  .kpis, .kpis:has(> :nth-child(5)) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis:has(> :nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis:has(> :nth-child(2):last-child), .kpis:has(> :only-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.card.pad0 { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card h2, .h2 { font-family: var(--serif); font-size: 25px; font-weight: 600; color: var(--strong); line-height: 1.1; }
.card h3, .h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; text-align: left; color: var(--text); min-width: 0; }
button.kpi:active { background: var(--panel2); }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.kpi .value { font-family: var(--serif); font-size: 36px; font-weight: 600; color: var(--strong); line-height: 1; }
.kpi .hint { font-size: 12.5px; color: var(--muted); }
.btn { min-height: 44px; padding: 0 18px; border-radius: 11px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text);
  font-weight: 500; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; }
.btn:active { filter: brightness(1.15); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); font-weight: 600; }
.btn.gold { background: var(--gold-bg); border-color: #5A4A2C; color: #E4C68E; font-weight: 600; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--rose); padding: 0 10px; }
.btn.danger { background: #2A1812; border-color: #5A3A2C; color: var(--warn); }
.btn.ok { background: #18241C; border-color: #2E4A36; color: var(--ok); }
.btn.big { min-height: 56px; font-size: 17px; padding: 0 24px; border-radius: 14px; }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn.icon { width: 44px; padding: 0; }
.btn.full { width: 100%; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; background: #120F11; border: 1px solid var(--line2); border-radius: 13px; padding: 3px; }
.seg button { min-height: 40px; padding: 0 14px; border-radius: 10px; border: 0; background: transparent; color: var(--muted2); font-size: 14px; font-weight: 500; white-space: nowrap; }
.seg button.on { background: var(--accent); color: var(--on-accent); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line2); background: transparent; color: var(--muted2); font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; }
.pill.on { border-color: var(--rose); background: #2A1A20; color: var(--strong); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.gold { background: var(--gold-bg); color: #E4C68E; } .badge.neutral { background: #2A2427; color: #D9CFCA; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.empty { text-align: center; padding: 44px 20px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty .serif { font-size: 24px; color: var(--muted2); }
hr.sep { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* ---------- Listes / tableaux ---------- */
.list { display: flex; flex-direction: column; }
.list-head { display: grid; gap: 12px; padding: 0 16px 10px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.1px; }
.list-row { display: grid; gap: 12px; align-items: center; padding: 10px 16px; min-height: 60px; border-top: 1px solid var(--line); width: 100%; text-align: left;
  background: none; border-left: 0; border-right: 0; border-bottom: 0; color: var(--text); font-size: 15px; }
button.list-row:active { background: var(--panel2); }
.list-group { position: sticky; top: -22px; z-index: 2; background: #120F11; padding: 10px 16px; font-family: var(--serif); font-size: 20px; font-weight: 600; color: var(--strong); border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.name-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-cell .t { font-weight: 500; color: var(--strong); line-height: 1.25; }
.name-cell .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chev { color: var(--dim); }

/* ---------- Formulaires ---------- */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field.span2 { grid-column: 1 / -1; }
.field > label, .label-t { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.field .help { font-size: 12.5px; color: var(--muted); }
.field .err { font-size: 13px; color: var(--warn); }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  height: 50px; padding: 0 14px; border-radius: 11px; border: 1px solid var(--line2); background: #120F11; color: var(--strong); font-size: 16px; width: 100%; min-width: 0; }
textarea { height: auto; min-height: 92px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 22px, calc(100% - 15px) 22px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 38px; }
input.invalid { border-color: var(--warn); }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; }
.check input { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }
.searchbox { position: relative; flex: 1 1 280px; max-width: 420px; }
.searchbox input { padding-left: 42px; }
.searchbox svg { position: absolute; left: 14px; top: 15px; color: var(--muted); }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper button { width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel2); color: var(--strong); font-size: 24px; line-height: 1; }
.stepper input { width: 72px; text-align: center; font-weight: 600; font-size: 19px; height: 48px; padding: 0 6px; }
.stepper.counted input { border-color: #2E4A36; background: #121a14; }

/* ---------- Fenêtres ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(8, 6, 7, .72); display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { width: min(720px, 100%); max-height: calc(100dvh - 40px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: 20px; padding: 26px; box-shadow: 0 24px 64px rgba(0, 0, 0, .55); }
.modal.wide { width: min(1080px, 100%); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.modal-head h2 { font-family: var(--serif); font-size: 30px; font-weight: 600; color: var(--strong); line-height: 1.1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.toasts { position: fixed; right: calc(22px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { background: var(--strong); color: #1A1416; padding: 13px 18px; border-radius: 12px; font-weight: 500; box-shadow: 0 12px 32px rgba(0, 0, 0, .45); max-width: 460px; }
.toast.warn { background: #F6D2BE; } .toast.info { background: #D6E3FA; }

/* ---------- Verrouillage ---------- */
.lock { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(360px, 1fr); height: 100vh; height: 100dvh; }
.lock-left { padding: calc(40px + env(safe-area-inset-top)) 44px 36px; display: flex; flex-direction: column; gap: 26px; overflow-y: auto; }
.lock-right { background: #141113; border-left: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; padding: 30px; }
.lock-title { font-family: var(--serif); font-size: 46px; font-weight: 600; color: var(--strong); line-height: 1; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.profile-tile { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 22px 12px; border-radius: 18px; border: 1px solid var(--line); background: var(--panel); color: var(--text); min-height: 160px; }
.profile-tile.on { border-color: var(--rose); background: #2A1A20; }
.profile-tile .n { font-weight: 600; color: var(--strong); font-size: 16px; text-align: center; }
.profile-tile .r { font-size: 12px; color: var(--muted); }
.pin-dots { display: flex; gap: 18px; height: 22px; align-items: center; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--rose); }
.pin-dots span.f { background: var(--rose); }
.keypad { display: grid; grid-template-columns: repeat(3, 86px); gap: 16px; }
.key { width: 86px; height: 86px; border-radius: 50%; border: 1px solid var(--line2); background: var(--panel2); color: var(--strong); font-size: 32px; font-weight: 400; display: flex; align-items: center; justify-content: center; }
.key:active { background: var(--accent); }
.key.blank { visibility: hidden; }
.key.small { font-size: 15px; font-weight: 500; }
.shake { animation: shake .4s; }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-10px); } 40%, 80% { transform: translateX(10px); } }
@media (max-width: 900px) and (orientation: portrait) {
  .lock { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .lock-right { border-left: 0; border-top: 1px solid var(--line); }
}
.setup { max-width: 760px; margin: 0 auto; padding: calc(36px + env(safe-area-inset-top)) 24px 60px; display: flex; flex-direction: column; gap: 22px; height: 100dvh; overflow-y: auto; }
.choice { display: flex; gap: 18px; align-items: flex-start; padding: 22px; border-radius: 16px; border: 1px solid var(--line2); background: var(--panel); text-align: left; color: var(--text); width: 100%; }
.choice.on { border-color: var(--rose); background: #2A1A20; }
.choice .t { font-family: var(--serif); font-size: 26px; font-weight: 600; color: var(--strong); }

/* ---------- Graphiques ---------- */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 190px; padding: 0 2px; border-bottom: 1px solid var(--line2); }
.bars .col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 5px; height: 100%; }
.bars .v { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bars .b { width: 100%; max-width: 40px; border-radius: 5px 5px 2px 2px; background: var(--accent); min-height: 2px; }
.bars .b.alt { background: var(--gold); }
.bar-labels { display: flex; gap: 5px; padding: 6px 2px 0; }
.bar-labels span { flex: 1 1 0; min-width: 0; text-align: center; font-size: 10.5px; color: var(--muted); overflow: hidden; white-space: nowrap; }
.meter { height: 6px; border-radius: 99px; background: #2A2427; overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 99px; background: var(--ok); }
.hbar { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Carte PDF ---------- */
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.pdf-page { background: #fff; border-radius: 6px; box-shadow: 0 10px 28px rgba(0, 0, 0, .5); min-height: 200px; }
.pdf-page canvas { display: block; border-radius: 6px; }
.progress { height: 8px; border-radius: 99px; background: #2A2427; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--gold); transition: width .2s; }
