/* Custodia : styles. Palette médicale blanc et bleu (depuis le 20/09/2026). */
:root {
  --bg: #F4F7FB;
  --surface: #FFFFFF;
  --surface-2: #E9EFF7;
  --ink: #10233F;
  --ink-2: #3A4D6B;
  --muted: #6B7C94;
  --line: #D8E1EE;
  --accent: #0F6CBD;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EEFA;
  --good: #1F8A5B;   --good-soft: #DDF3E8;
  --warn: #B26A00;   --warn-soft: #FBEBD2;
  --bad: #C8372D;    --bad-soft: #FADEDC;
  --info: #1B7F8C;   --info-soft: #DCF1F3;
  --shadow: 0 1px 2px rgba(16,35,63,.06), 0 6px 20px rgba(16,35,63,.07);
  --radius: 12px;
  --font-display: 'Lora', Georgia, 'Times New Roman', serif;
  --font-body: 'Nunito Sans', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1626; --surface: #16213A; --surface-2: #1F2C48;
    --ink: #E8EFFA; --ink-2: #B7C4DA; --muted: #8494B0; --line: #2A3A5A;
    --accent: #5AA3F5; --accent-ink: #0B1730; --accent-soft: #1B355C;
    --good: #5CC48F; --good-soft: #173A2A; --warn: #E6B35A; --warn-soft: #3E3220;
    --bad: #F08A80; --bad-soft: #4A2320; --info: #5AC1CC; --info-soft: #173A3E;
    --shadow: 0 1px 2px rgba(0,0,0,.45), 0 6px 20px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1626; --surface: #16213A; --surface-2: #1F2C48;
  --ink: #E8EFFA; --ink-2: #B7C4DA; --muted: #8494B0; --line: #2A3A5A;
  --accent: #5AA3F5; --accent-ink: #0B1730; --accent-soft: #1B355C;
  --good: #5CC48F; --good-soft: #173A2A; --warn: #E6B35A; --warn-soft: #3E3220;
  --bad: #F08A80; --bad-soft: #4A2320; --info: #5AC1CC; --info-soft: #173A3E;
  --shadow: 0 1px 2px rgba(0,0,0,.45), 0 6px 20px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--font-body); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.eyebrow { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }

/* ----- Coque de l'application ----- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.shell { display: flex; min-height: 100%; }
.sidebar { display: none; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px; display: flex; align-items: center; gap: 12px; justify-content: space-between;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-family: var(--font-display); font-weight: 600; font-size: .95rem; }
.content { flex: 1; padding: 16px 16px 96px; max-width: 1100px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--line);
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.tabbar button, .sidebar button.nav {
  background: none; border: 0; padding: 6px 2px; border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: .68rem; font-weight: 700;
}
.tabbar button svg, .sidebar button.nav svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active, .sidebar button.nav.active { color: var(--accent); }
.fab {
  position: fixed; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom, 0px)); z-index: 25;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 12px 18px; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; display: flex; align-items: center; gap: 8px;
}
@media (min-width: 900px) {
  .sidebar { display: flex; flex-direction: column; gap: 4px; width: 220px; padding: 20px 12px; border-right: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; height: 100vh; }
  .sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
  .sidebar button.nav { flex-direction: row; gap: 10px; font-size: .92rem; padding: 9px 10px; justify-content: flex-start; color: var(--ink-2); }
  .sidebar button.nav.active { background: var(--accent-soft); color: var(--accent); }
  .sidebar .spacer { flex: 1; }
  .tabbar { display: none; }
  .topbar .brand { display: none; }
  .content { padding-bottom: 32px; }
  .fab { bottom: 24px; right: 24px; }
}

/* ----- Composants ----- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card.flat { background: transparent; border: 0; padding: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; }
.grid.kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 700px) { .grid.kpi { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 800px) { .grid.two { grid-template-columns: 1fr 1fr; } }

.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi .value { font-family: var(--font-display); font-size: 1.35rem; font-weight: 600; letter-spacing: -.01em; }
.kpi .value small { font-family: var(--font-body); font-size: .75rem; font-weight: 700; color: var(--muted); margin-left: 3px; }
.kpi.accent { border-color: transparent; background: var(--accent-soft); }
.kpi .sub { font-size: .78rem; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.paye { background: var(--good-soft); color: var(--good); }
.pill.partiel { background: var(--warn-soft); color: var(--warn); }
.pill.attendu { background: var(--info-soft); color: var(--info); }
.pill.annule { background: var(--surface-2); color: var(--muted); }
.pill.retard { background: var(--bad-soft); color: var(--bad); }
.pill.brouillon { background: var(--surface-2); color: var(--ink-2); }
.pill.valide { background: var(--good-soft); color: var(--good); }
.pill.conteste { background: var(--bad-soft); color: var(--bad); }
.pill.plain::before { display: none; }
.pill.en_salle { background: var(--accent-soft); color: var(--accent); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.list { display: flex; flex-direction: column; }
.list .item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 11px 0; border-bottom: 1px solid var(--line); text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; cursor: pointer; color: inherit;
}
.list .item:last-child { border-bottom: 0; }
.list .item .t { font-weight: 700; }
.list .item .s { font-size: .82rem; color: var(--muted); }
.list .item .amt { font-family: var(--font-display); font-size: 1.05rem; text-align: right; }
.list .item .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.list .item.static { cursor: default; }

table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); font-weight: 700; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl-wrap { overflow-x: auto; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar { display: grid; grid-template-columns: 130px 1fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); border-radius: 5px; }
.bar .fill.good { background: var(--good); }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad-soft); background: var(--bad-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); padding-left: 6px; padding-right: 6px; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .item:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.block { width: 100%; justify-content: center; }

.form { display: grid; gap: 12px; }
.form .cols { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: .78rem; font-weight: 700; color: var(--ink-2); }
.field input, .field select, .field textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
.field input[type="number"] { font-variant-numeric: tabular-nums; }
.field textarea { min-height: 70px; resize: vertical; }
.field .hint { font-size: .76rem; color: var(--muted); }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.search { position: relative; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 14px; }
.suggest { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; margin-top: 4px; overflow: hidden; box-shadow: var(--shadow); }
.suggest button { display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: none; cursor: pointer; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest button.new { color: var(--accent); font-weight: 700; }

.banner { border-radius: 10px; padding: 10px 14px; font-size: .86rem; display: flex; gap: 10px; align-items: center; }
.banner.demo { background: var(--warn-soft); color: var(--warn); }
.banner.error { background: var(--bad-soft); color: var(--bad); }
.banner.ok { background: var(--good-soft); color: var(--good); }
.banner.info { background: var(--info-soft); color: var(--info); }

.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav button { border: 0; background: var(--surface); border: 1px solid var(--line); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; }
.month-nav .label { font-family: var(--font-display); font-weight: 600; min-width: 140px; text-align: center; text-transform: capitalize; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.detail-grid .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.detail-grid .v { font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: .9rem; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: .88rem; z-index: 50; box-shadow: var(--shadow); }
@media (min-width: 900px) { .toast { bottom: 24px; } }

.back { background: none; border: 0; color: var(--accent); font-weight: 700; cursor: pointer; padding: 0; display: inline-flex; align-items: center; gap: 4px; }

/* Écran de connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.login h1 { margin-bottom: 4px; }

/* Note d'honoraires imprimable */
.note { background: #fff; color: #222; padding: 28px; border-radius: var(--radius); border: 1px solid var(--line); font-family: var(--font-body); }
.note h2 { font-family: var(--font-display); color: #222; }
.note .head { display: flex; justify-content: space-between; gap: 16px; border-bottom: 2px solid #0F6CBD; padding-bottom: 12px; margin-bottom: 16px; }
.note table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.note td, .note th { padding: 8px; border-bottom: 1px solid #ddd; text-align: left; }
.note .total { font-size: 1.1rem; font-weight: 700; text-align: right; }
@media print {
  body * { visibility: hidden; }
  .note, .note * { visibility: visible; }
  .note { position: absolute; inset: 0; border: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Salle d'attente */
.queue { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.queue.en_consultation { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
.queue-head { display: flex; gap: 12px; align-items: flex-start; }
.queue-num { width: 28px; height: 28px; border-radius: 50%; background: var(--info-soft); color: var(--info); display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.queue .t { font-weight: 700; font-size: 1.02rem; }
.queue .motif { color: var(--ink-2); }
.queue .s { font-size: .8rem; }
.queue-time { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; color: var(--info); white-space: nowrap; font-variant-numeric: tabular-nums; }
.queue-time.late { color: var(--bad); }
.queue-time.cons { color: var(--accent); font-size: .9rem; font-family: var(--font-body); font-weight: 700; }
.queue-actions { gap: 6px; }
.card.live { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 8px; vertical-align: middle; box-shadow: 0 0 0 0 var(--good); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 45%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
input[type="date"].chip, input[type="time"] { min-height: 34px; }

/* Bloc opératoire */
.board { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .board { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); } }
.room { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.room-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.room-head h3 { font-size: 1rem; }
.room.busy { border-color: var(--accent); }
.room.free .room-state { color: var(--good); }
.room-state { font-size: .78rem; font-weight: 700; color: var(--accent); }
.op { border: 1px solid var(--line); border-left: 4px solid var(--info); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.op.arrive { border-left-color: var(--warn); }
.op.en_salle { border-left-color: var(--accent); background: color-mix(in srgb, var(--accent-soft) 55%, var(--surface)); }
.op.termine { border-left-color: var(--good); opacity: .85; }
.op.reporte, .op.annule { border-left-color: var(--muted); opacity: .7; }
.op .time { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.op .t { font-weight: 700; }
.op .s { font-size: .8rem; color: var(--muted); }
.op-head { display: flex; gap: 10px; align-items: flex-start; }
.op-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.op-actions select.chip { padding: 5px 10px; font-size: .8rem; }
.day-group { display: flex; flex-direction: column; gap: 6px; }
.day-group .day { font-weight: 700; font-size: .85rem; color: var(--ink-2); text-transform: capitalize; margin-top: 6px; }

/* Documents */
.list .item.doc { grid-template-columns: auto 1fr auto; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: .7rem; font-weight: 700; color: var(--muted); letter-spacing: .04em; }
.doc-preview { padding: 8px; text-align: center; }
.doc-preview img { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.ocr { white-space: pre-wrap; font: .82rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--ink-2); margin: 10px 0 0; max-height: 320px; overflow: auto; }
details.card summary { cursor: pointer; font-weight: 700; }
.tbl tr.anormal td { background: color-mix(in srgb, var(--bad-soft) 60%, transparent); }
label.btn { cursor: pointer; }

#toast-box[hidden] { display: none; }
