:root {
  --ink: #0f1f24;
  --ink2: #45585e;
  --mute: #7b8b90;
  --line: #dfe7e8;
  --bg: #f3f6f6;
  --card: #ffffff;
  --accent: #0f766e;
  --accent2: #e6f4f2;
  --warn: #b45309;
  --warnbg: #fff4e0;
  --danger: #b42318;
  --dangerbg: #fdecea;
  --ok: #15803d;
  --okbg: #e8f6ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 40, 44, .06), 0 4px 16px rgba(16, 40, 44, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); font-weight: 650; }
.muted { color: var(--mute); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.err { color: var(--danger); min-height: 1em; margin: 6px 0; }

#app { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.side { background: #0f2a2e; color: #cfe1e0; display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; color: #2dd4bf; }
.brand b { color: #fff; display: block; font-size: 16px; }
.brand small { color: #8fb3b1; display: block; font-size: 12px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; gap: 10px; align-items: center; color: #cfe1e0; text-decoration: none; padding: 9px 10px; border-radius: 8px; }
#nav a span { width: 18px; text-align: center; opacity: .8; }
#nav a:hover { background: rgba(255,255,255,.06); }
#nav a.on { background: #134e4a; color: #fff; }
.viewbox { display: flex; flex-direction: column; gap: 6px; padding: 0 4px; }
.viewbox label { font-size: 11px; color: #8fb3b1; text-transform: uppercase; letter-spacing: .05em; }
.viewbox select { background: #134e4a; border-color: #1f5f5a; color: #fff; font-size: 13px; padding: 6px 8px; }
.userbox { margin-top: auto; border-top: 1px solid rgba(255,255,255,.08); padding: 12px 6px 0; font-size: 12.5px; }
.userbox b { color: #fff; display: block; font-size: 13.5px; }
.userbox small { color: #8fb3b1; display: block; }
.userbox .row { margin-top: 8px; }
.userbox button { color: #cfe1e0; border-color: rgba(255,255,255,.15); background: transparent; font-size: 12px; padding: 4px 9px; }
main { overflow: auto; padding: 22px 28px 40px; }

.top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.top .grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; }
button:hover { border-color: #b9c9cb; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #115e59; }
button.danger { color: var(--danger); }
button.ghost { background: transparent; }
button.sm { padding: 4px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; padding: 4px 6px; color: var(--ink2); }

input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #99d5cf; border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
input[type=checkbox] { width: auto; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink2); font-weight: 600; }
label.f > span { display: flex; justify-content: space-between; }
label.chk { display: flex; gap: 8px; align-items: center; font-size: 13px; cursor: pointer; }
fieldset { border: 0; padding: 0; margin: 0; }
.form-section { margin-bottom: 18px; }
.search { max-width: 360px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--mute); font-weight: 650; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid #edf2f2; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7fbfa; }
.empty { text-align: center; color: var(--mute); padding: 30px; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: #eef2f2; color: var(--ink2); white-space: nowrap; }
.pill.ok { background: var(--okbg); color: var(--ok); }
.pill.warn { background: var(--warnbg); color: var(--warn); }
.pill.danger { background: var(--dangerbg); color: var(--danger); }
.pill.accent { background: var(--accent2); color: var(--accent); }

.kpi .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--mute); font-size: 12px; }
.bar { height: 8px; background: #edf2f2; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }

/* fiche patient */
.phead { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--accent2); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 24px; flex: none; border: 2px solid #fff; box-shadow: var(--shadow); }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; border-width: 1px; }
.phead .meta { color: var(--ink2); display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.alerts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.balance { margin-left: auto; text-align: right; }
.balance .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; border-radius: 0; background: none; padding: 10px 14px; color: var(--ink2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button .c { font-size: 11px; background: #eef2f2; border-radius: 99px; padding: 0 6px; margin-left: 4px; }

/* schéma dentaire */
.odonto { display: grid; gap: 6px; justify-content: center; padding: 8px 0; }
.arch { display: flex; gap: 3px; justify-content: center; }
.arch .gap { width: 14px; }
.tooth { width: 34px; height: 44px; border: 1px solid #cfdcdd; border-radius: 8px 8px 12px 12px; background: #fff; font-size: 11px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 3px 0; position: relative; }
.arch.lower .tooth { border-radius: 12px 12px 8px 8px; flex-direction: column-reverse; }
.tooth::before { content: ""; width: 16px; height: 16px; border-radius: 50%; background: #f1f5f5; border: 1px solid #dde6e7; }
.tooth.has::before { background: #99d5cf; border-color: var(--accent); }
.tooth.plan::before { background: #fde7c3; border-color: var(--warn); }
.tooth.sel { border-color: var(--accent); background: var(--accent2); box-shadow: 0 0 0 2px #99d5cf; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--mute); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* images */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.ph { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.ph .img { aspect-ratio: 4/3; background: #0f1f24; display: grid; place-items: center; color: #9fb4b6; font-size: 12px; overflow: hidden; }
.ph .img img { width: 100%; height: 100%; object-fit: cover; }
.ph .cap { padding: 7px 9px; font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.ph:hover { border-color: var(--accent); }
.acq { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.acq button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px; text-align: left; border-radius: var(--radius); }
.acq button b { font-size: 14px; }
.acq button small { color: var(--mute); font-size: 12px; }
.acq button .ic { font-size: 20px; margin-bottom: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chips button { border-radius: 99px; padding: 4px 11px; font-size: 12px; }
.chips button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.viewer { display: grid; grid-template-columns: 1fr 280px; gap: 16px; height: min(78vh, 760px); }
.viewer .stage { background: #0b1416; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; position: relative; }
.viewer .stage img { max-width: 100%; max-height: 100%; transition: transform .15s; cursor: zoom-in; }
.viewer .side2 { overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.cam video, .cam canvas { width: 100%; border-radius: var(--radius); background: #000; max-height: 60vh; }
.folder-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; max-height: 50vh; overflow: auto; }
.folder-list label { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: pointer; font-size: 11.5px; }
.folder-list label .img { aspect-ratio: 4/3; background: #eef2f2; display: grid; place-items: center; color: var(--mute); }
.folder-list label img { width: 100%; height: 100%; object-fit: cover; }
.folder-list label div.n { padding: 5px 7px; display: flex; gap: 6px; align-items: center; word-break: break-all; }
.folder-list label:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px #99d5cf; }

/* agenda */
.week { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.day { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); min-height: 300px; display: flex; flex-direction: column; }
.day.today { border-color: var(--accent); }
.day header { padding: 8px 10px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; }
.day .list { padding: 6px; display: flex; flex-direction: column; gap: 6px; }
.appt { border-left: 3px solid var(--accent); background: var(--accent2); border-radius: 6px; padding: 6px 8px; font-size: 12px; cursor: pointer; }
.appt.honore { border-color: var(--ok); background: var(--okbg); }
.appt.annule, .appt.absent { border-color: #c4cfd0; background: #f3f6f6; color: var(--mute); text-decoration: line-through; }
.appt b { display: block; font-size: 12.5px; }

/* modale & divers */
.modal { position: fixed; inset: 0; background: rgba(9, 24, 27, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal-box { background: #fff; border-radius: 14px; padding: 20px; width: min(560px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-box.wide { width: min(1100px, 100%); }
.foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-box .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-box .head h2 { margin: 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }
.login { position: fixed; inset: 0; background: linear-gradient(160deg, #0f2a2e, #134e4a); display: grid; place-items: center; z-index: 100; }
.login-box { background: #fff; padding: 30px; border-radius: 16px; width: 340px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.login-box h2 { margin: 6px 0 0; }
.login-box p { margin: 0; }
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 5; max-height: 220px; overflow: auto; }
.ac-list div { padding: 7px 10px; cursor: pointer; }
.ac-list div:hover { background: var(--accent2); }
.busy { display: inline-block; width: 14px; height: 14px; border: 2px solid #cfe; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .acq { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .week { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .viewer { grid-template-columns: 1fr; height: auto; }
  .viewer .stage { height: 55vh; }
}

/* impression (fiche patient, reçu) */
#print { display: none; }
@media print {
  body { background: #fff; }
  #app, .modal, .toast, .login { display: none !important; }
  #print { display: block; font-size: 12px; color: #000; }
  #print h1 { font-size: 18px; }
  #print table td, #print table th { border-bottom: 1px solid #ccc; padding: 4px 6px; }
  #print .pbox { border: 1px solid #999; padding: 10px; margin: 10px 0; }
}

/* comptes */
.acc-clinic { margin-bottom: 14px; }
.acc-clinic header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.acc-clinic header h2 { margin: 0; }
.role { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.role.global { background: #1f2937; color: #fff; }
.role.clinique { background: var(--accent2); color: var(--accent); }
.role.medecin { background: #eef2ff; color: #4338ca; }

/* écrans d'activation et de configuration */
.gate-box { background: #fff; padding: 28px 30px; border-radius: 18px; width: min(560px, calc(100vw - 32px)); max-height: 94vh; overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.35); }
.gate-box h2 { font-size: 22px; margin: 18px 0 4px; }
.gate-brand { display: flex; gap: 10px; align-items: center; }
.gate-brand b { display: block; font-size: 17px; }
.gate-brand small { color: var(--mute); }
.machine { font-family: Consolas, monospace; font-size: 15px; background: var(--accent2); color: var(--accent); padding: 6px 10px; border-radius: 8px; }
.edbadge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #2dd4bf; border: 1px solid rgba(45,212,191,.4); border-radius: 99px; padding: 1px 8px; margin-bottom: 6px; }
.edbadge.big { color: var(--accent); border-color: #99d5cf; background: var(--accent2); font-size: 12px; padding: 4px 12px; margin: 0; }

/* langues */
select.langsel { width: auto; padding: 4px 8px; font-size: 12px; }
.userbox select.langsel { background: #134e4a; border-color: #1f5f5a; color: #fff; margin-top: 6px; }
html.rtl body { font-family: "Segoe UI", Tahoma, "Arial", sans-serif; }
html.rtl .right, html.rtl .num { text-align: left; }
html.rtl th { text-align: right; }
html.rtl .balance { margin-left: 0; margin-right: auto; text-align: left; }
html.rtl .appt { border-left: 0; border-right: 3px solid var(--accent); }
html.rtl .toast { direction: rtl; }
html.rtl .ac-list, html.rtl .modal-box { text-align: right; }
html.rtl #nav a span { margin-left: 2px; }
html.rtl .odonto, html.rtl .arch, html.rtl .machine, html.rtl code, html.rtl input[type=date], html.rtl input[type=time] { direction: ltr; }

/* lecteur de carte d'identité */
.eidbtn { white-space: nowrap; font-weight: 500; font-size: 13px; }
h3 .eidbtn { text-transform: none; letter-spacing: 0; }
.eidinfo { display: flex; gap: 12px; align-items: center; padding: 10px 12px; margin: 0 0 12px; border: 1px solid var(--line, #dde3ea);
  border-radius: 10px; background: var(--soft, rgba(0, 120, 200, .05)); }
.eidinfo img { width: 54px; height: 70px; object-fit: cover; border-radius: 6px; }
.eidinfo .chk { margin-top: 4px; }

/* démonstration publique */
.demo-ribbon { position: fixed; top: 0; left: 0; right: 0; z-index: 60; background: #0f766e; color: #fff; text-align: center;
  font-size: 13px; padding: 5px 10px; }
.demo-ribbon a { color: #fff; font-weight: 600; text-decoration: underline; }
body.is-demo { padding-top: 28px; }
body.is-demo .side { top: 28px; }
.demo-box { display: grid; gap: 8px; margin: 6px 0 10px; }
.demo-t { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted, #64748b); }
.demo-acc { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line, #dfe7e8);
  border-radius: 10px; text-decoration: none; color: inherit; background: var(--card, #fff); }
.demo-acc:hover { border-color: #0f766e; }
.demo-acc span { font-size: 12px; color: var(--muted, #64748b); }

.essai-badge { display: inline-block; margin: 4px 0 6px; padding: 2px 8px; border-radius: 999px; background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 700 }
