/* Questionnaire médical — feuille commune (page patient + administration). Mobile d'abord, thème clair/sombre. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --text: #1c2630;
  --muted: #5d6b78;
  --border: #d6dde3;
  --accent: #1f5f8b;
  --accent-strong: #174a6d;
  --accent-soft: #e3eef6;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --success: #1e7a46;
  --success-soft: #e5f4ea;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --focus: #2d7fc0;
  --ink: #111111;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  --tap: 44px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b;
    --surface: #1a2128;
    --surface-2: #222b33;
    --text: #e5ebf0;
    --muted: #9aa8b4;
    --border: #33404b;
    --accent: #6fb1e3;
    --accent-strong: #8cc3ec;
    --accent-soft: #1d3446;
    --on-accent: #0b1620;
    --danger: #f2a49c;
    --danger-soft: #3a1f1c;
    --success: #8fd4a8;
    --success-soft: #19301f;
    --warn: #f0c56b;
    --warn-soft: #33290f;
    --focus: #8cc3ec;
    --ink: #e5ebf0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .5rem; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.small { font-size: .875rem; }
.muted { color: var(--muted); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ───────── Barre supérieure ───────── */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto; padding: .6rem 16px;
  display: flex; align-items: center; gap: 1rem; min-height: 52px;
}
.brand { font-weight: 650; color: var(--accent); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cabinet-logo { flex: 0 0 auto; height: 40px; width: auto; max-width: 160px; object-fit: contain; }
.cabinet-logo[hidden] { display: none; }
.logo-preview { display: block; max-height: 80px; max-width: 240px; object-fit: contain; padding: .4rem; background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; }
.progress { display: flex; align-items: center; gap: .5rem; flex: 0 0 auto; }
.progress-track { width: 96px; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }
.progress-text { font-size: .8rem; color: var(--muted); min-width: 3ch; text-align: right; }

/* ───────── Mise en page ───────── */
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.loading { color: var(--muted); text-align: center; padding: 3rem 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.intro h1 { color: var(--accent); }
.tagline { font-weight: 500; }

.message { text-align: center; padding: 2.5rem 1.25rem; }
.message.success h1 { color: var(--success); }
.message.warn h1 { color: var(--warn); }

/* ───────── Sections et questions ───────── */
.section-title { color: var(--accent); padding-bottom: .5rem; border-bottom: 1px solid var(--border); margin-bottom: .75rem; }
.section-desc { color: var(--muted); font-size: .925rem; }

.question { padding: .65rem 0; }
.question + .question { border-top: 1px dashed var(--border); }
.q-label { display: block; font-weight: 600; margin: 0 0 .4rem; }
.req { color: var(--danger); }
.help { color: var(--muted); font-size: .85rem; margin-top: -.2rem; }
.q-error, .form-error { color: var(--danger); font-size: .875rem; margin: .35rem 0 0; }
.q-error:empty, .form-error:empty { display: none; }
.question.has-error input:not([type=radio]):not([type=checkbox]), .question.has-error textarea { border-color: var(--danger); }
.question.info p { color: var(--muted); font-style: italic; }

input[type=text], input[type=tel], input[type=email], input[type=date], input[type=number], input[type=password], textarea, select {
  width: 100%;
  min-height: var(--tap);
  padding: .55rem .75rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
textarea { resize: vertical; min-height: 88px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=date] { max-width: 14rem; }

.with-unit { display: flex; align-items: center; gap: .5rem; max-width: 14rem; }
.unit { color: var(--muted); }

/* Oui / Non */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: flex; align-items: center; justify-content: center;
  min-width: 72px; min-height: var(--tap); padding: 0 1rem;
  background: var(--surface); cursor: pointer; user-select: none;
}
.seg + .seg span { border-left: 1px solid var(--border); }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: -3px; }

/* Choix */
.options { display: grid; gap: .35rem; }
@media (min-width: 600px) { .options:not(.scale) { grid-template-columns: 1fr 1fr; } }
.option { display: flex; flex-direction: column; gap: .3rem; }
.opt {
  display: flex; align-items: flex-start; gap: .65rem;
  min-height: var(--tap); padding: .55rem .7rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); cursor: pointer;
}
.opt input { width: 20px; height: 20px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.detail { margin-left: 0; }

/* Grille oui/non, tableau, classement */
.grid-rows, .table-rows { display: grid; gap: .5rem; }
.grid-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.grid-label { flex: 1 1 200px; }
.table-row { display: grid; gap: .35rem; }
.table-cells { display: grid; gap: .35rem; padding-left: 2.2rem; }
@media (min-width: 600px) { .table-cells { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); } }

.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.rank-item { display: flex; align-items: center; gap: .6rem; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.rank-num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; flex: 0 0 auto; }
.rank-label { flex: 1; }
.rank-actions { display: flex; gap: .25rem; }

/* Signature */
.certify { margin-bottom: .75rem; }
.signature-box { position: relative; border: 2px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.signature-canvas { display: block; width: 100%; height: 190px; cursor: crosshair; --ink: var(--ink); }
.signature-hint { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; text-align: center; padding: 1rem; }
.signature-actions { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin: .5rem 0; flex-wrap: wrap; }

/* ───────── Boutons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: 0 1.1rem;
  font: inherit; font-weight: 600; text-decoration: none;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn.small { min-height: 36px; padding: 0 .75rem; font-size: .875rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.danger { color: var(--danger); }

/* ───────── Administration ───────── */
.admin .topbar-inner, .admin .page { max-width: 1280px; }
.tabs { display: flex; gap: .25rem; overflow-x: auto; }
.tab { padding: .5rem .8rem; border-radius: var(--radius-sm); border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 40px; }
.tab[aria-selected=true] { background: var(--accent-soft); color: var(--accent); }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.list { display: grid; gap: .75rem; }
@media (min-width: 800px) { .list.cols { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); } }
.item { display: flex; flex-direction: column; gap: .5rem; margin: 0; }
.item-head { display: flex; justify-content: space-between; gap: .5rem; align-items: flex-start; }
.item-title { font-weight: 650; }
.item-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.created, .badge.opened { background: var(--accent-soft); color: var(--accent); }
.badge.submitted { background: var(--success-soft); color: var(--success); }
.badge.expired, .badge.revoked { background: var(--warn-soft); color: var(--warn); }
.badge.N { background: var(--danger-soft); color: var(--danger); }
.badge.O { background: var(--accent-soft); color: var(--accent); }
.badge.P { background: var(--warn-soft); color: var(--warn); }

.fields { display: grid; gap: .75rem; }
@media (min-width: 640px) { .fields.two { grid-template-columns: 1fr 1fr; } .fields.three { grid-template-columns: repeat(3, 1fr); } }
.field label, .field .label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
.check { display: inline-flex; align-items: center; gap: .45rem; min-height: 36px; font-size: .9rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.notice { padding: .75rem 1rem; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); margin-bottom: 1rem; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.success { background: var(--success-soft); color: var(--success); }
.notice ul { margin: .25rem 0 0; padding-left: 1.2rem; }

.login { max-width: 420px; margin: 8vh auto 0; }

.link-result { display: grid; gap: 1rem; align-items: center; }
@media (min-width: 640px) { .link-result { grid-template-columns: 180px 1fr; } }
.qr { width: 180px; height: 180px; background: #fff; border-radius: var(--radius-sm); padding: 6px; }
.url-box { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; word-break: break-all; padding: .5rem .75rem; background: var(--surface-2); border-radius: var(--radius-sm); }

table.data { width: 100%; border-collapse: collapse; font-size: .925rem; }
table.data th, table.data td { text-align: left; padding: .55rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { color: var(--muted); font-weight: 600; font-size: .8rem; }
@media (max-width: 720px) {
  table.data thead { display: none; }
  table.data tr { display: block; border-bottom: 1px solid var(--border); padding: .5rem 0; }
  table.data td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem 0; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
}

/* Éditeur */
.editor-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.editor-head .title-input { flex: 1 1 260px; font-size: 1.1rem; font-weight: 600; }
.editor { display: grid; gap: 1rem; }
@media (min-width: 1100px) {
  .editor { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
  .editor .preview-pane { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
  .editor-switch { display: none; }
}
@media (max-width: 1099px) {
  .editor[data-view=edit] .preview-pane, .editor[data-view=preview] .edit-pane { display: none; }
}
.preview-pane { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.preview-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .5rem; }

.sec-card { padding: 0; overflow: hidden; }
.sec-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; background: var(--surface-2); flex-wrap: wrap; }
.sec-head .grow { flex: 1 1 180px; min-width: 0; }
.sec-head input.sec-title { font-weight: 650; }
.sec-body { padding: .75rem; display: grid; gap: .75rem; }
.sec-card.inactive .sec-head { opacity: .65; }
.q-row { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.q-row.inactive { opacity: .6; }
.q-summary { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; cursor: pointer; }
.q-summary .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-type { font-size: .72rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; }
.q-detail { padding: .75rem; border-top: 1px solid var(--border); display: grid; gap: .75rem; }
.opt-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto auto; gap: .35rem; align-items: center; }
.cond { display: grid; gap: .5rem; }
@media (min-width: 640px) { .cond { grid-template-columns: 2fr 1fr 1.5fr; } }
.row-actions { display: flex; gap: .25rem; flex: 0 0 auto; }
details.mentions summary { cursor: pointer; font-weight: 600; color: var(--accent); }
