/* Charte IDELIS (idelis.fr) : vert #02A65A, vert foncé #027332, vert clair #70CCA1,
   gris #F5F7F7 / #3E5959 / #3B393A, violet #312E54 ; polices Ubuntu et Exo 2. */
@import url("/static/fonts/fonts.css");

:root {
  --idelis-green: #02a65a;
  --idelis-green-dark: #027332;
  --idelis-green-light: #70cca1;
  --idelis-violet: #312e54;
  --idelis-violet-dark: #1e1c33;

  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #3b393a;
  --heading: #312e54;
  --muted: #5f7373;
  --border: #d4d4d4;
  --primary: var(--idelis-green);
  --primary-hover: var(--idelis-green-dark);
  --primary-ink: #ffffff;
  --primary-soft: #e3f5ec;
  --link: var(--idelis-green-dark);
  --topbar-bg: #ffffff;
  --topbar-ink: var(--idelis-violet);
  --ok: #027332;
  --ok-soft: #e3f5ec;
  --warn: #9a5b00;
  --warn-soft: #fff4d6;
  --danger: #c0303f;
  --danger-soft: #fbe6e8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(49, 46, 84, .06), 0 2px 6px rgba(49, 46, 84, .06);
  --font-body: "Ubuntu", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: "Exo 2", "Ubuntu", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141323;
    --surface: #1e1c33;
    --surface-2: #2a2746;
    --text: #ecebf3;
    --heading: #ffffff;
    --muted: #a7a4c0;
    --border: #3b3764;
    --primary: var(--idelis-green);
    --primary-hover: #03bf68;
    --primary-ink: #ffffff;
    --primary-soft: #173a2e;
    --link: var(--idelis-green-light);
    --topbar-bg: linear-gradient(-200deg, #1e1c33, #312e54);
    --topbar-ink: #ffffff;
    --ok: #70cca1;
    --ok-soft: #173a2e;
    --warn: #f3c159;
    --warn-soft: #3b3018;
    --danger: #f28b93;
    --danger-soft: #42202a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-title); font-weight: 700; color: var(--heading); line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
a { color: var(--link); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: .75rem; }

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--topbar-bg); color: var(--topbar-ink);
  border-bottom: 3px solid var(--idelis-green);
  box-shadow: 0 2px 8px rgba(49, 46, 84, .08);
}
.topbar .brand { flex: none; display: flex; align-items: center; }
.topbar .brand img { height: 22px; width: auto; display: block; }
.topbar .brand + .title { padding-left: .75rem; border-left: 1px solid var(--border); }
.topbar .title { font-family: var(--font-title); font-weight: 600; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar button, .topbar a { color: var(--topbar-ink); }
.icon-btn {
  background: transparent; border: 0; padding: .4rem .55rem; border-radius: 8px;
  font: inherit; font-size: 1rem; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: .35rem;
}
.icon-btn svg { display: block; }
.icon-btn:hover { background: var(--primary-soft); }
@media (max-width: 420px) {
  .topbar .brand + .title { font-size: 0; border-left: 0; padding-left: 0; }
  .topbar .back + .brand { display: none; }
  .topbar .back + .brand + .title { font-size: 1.05rem; }
}

main { max-width: 760px; margin: 0 auto; padding: 1rem 1rem calc(6rem + env(safe-area-inset-bottom)); }
main.wide { max-width: 1200px; }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.card + .card { margin-top: .75rem; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .6rem 1rem; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--link); }
.btn.block { width: 100%; }
.btn.lg { min-height: 54px; font-size: 1.05rem; }
.btn.sm { min-height: 34px; padding: .3rem .7rem; font-size: .875rem; }

/* ---------- Champs ---------- */
label.field { display: block; }
label.field > span { display: block; font-weight: 600; margin-bottom: .3rem; font-size: .925rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search],
select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .75rem; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
.search-input { font-size: 1.1rem; min-height: 54px !important; padding-left: 2.6rem !important;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' fill='none' stroke='%237a8796' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='9' cy='9' r='6'/%3E%3Cpath d='m14 14 4 4'/%3E%3C/svg%3E") no-repeat .8rem center !important; }

/* ---------- Bandeaux ---------- */
.banner { padding: .65rem .9rem; border-radius: 10px; font-size: .925rem; margin-bottom: .75rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.banner.info { background: var(--primary-soft); color: var(--link); }

.pill { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Liste de conducteurs ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex; align-items: center; gap: .75rem; width: 100%; text-align: left;
  padding: .8rem .9rem; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: .5rem; cursor: pointer; font: inherit; color: inherit;
}
.list-item:active { background: var(--surface-2); }
.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--link); font-weight: 700; font-size: .95rem;
}
.list-item .main { flex: 1; min-width: 0; }
.list-item .name { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: .875rem; }

/* ---------- Fiche conducteur ---------- */
.kv { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: .35rem .75rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .875rem; }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- Formulaire d'évaluation ---------- */
.section-title { font-family: var(--font-title); font-weight: 600; margin: 1.5rem 0 .6rem; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--link); }
.question { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .6rem; }
.question.invalid { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger); }
.question .q-label { font-weight: 600; display: block; margin-bottom: .55rem; }
.question .q-help { color: var(--muted); font-size: .85rem; margin: -.35rem 0 .55rem; }
.req { color: var(--danger); margin-left: .15rem; }
.q-error { color: var(--danger); font-size: .85rem; margin-top: .4rem; }

.choices { display: flex; flex-wrap: wrap; gap: .45rem; }
.choices.vertical { flex-direction: column; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span {
  display: flex; align-items: center; gap: .5rem; min-height: 46px; padding: .55rem .95rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); cursor: pointer;
  user-select: none; font-weight: 500;
}
.choices.vertical .choice span { width: 100%; }
.choice input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.choice input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.choice.check span::before {
  content: ""; flex: none; width: 20px; height: 20px; border: 2px solid var(--border); border-radius: 5px; background: var(--surface);
  display: grid; place-items: center; font-size: 13px; font-weight: 900; line-height: 1;
}
.choice.check input:checked + span::before {
  content: "✓"; border-color: var(--primary-ink); background: var(--primary-ink); color: var(--primary);
}
.rating .choice span { min-width: 50px; justify-content: center; font-weight: 700; }

.toggle { display: flex; align-items: center; gap: .75rem; cursor: pointer; min-height: 44px; }
.toggle input { width: 24px; height: 24px; accent-color: var(--primary); flex: none; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-bar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: .5rem; }

.big-status { text-align: center; padding: 2rem 1rem; }
.big-status .icon { font-size: 3.2rem; line-height: 1; margin-bottom: .75rem; }
.score { font-family: var(--font-title); font-size: 2.6rem; font-weight: 700; color: var(--primary); }

.center-box { max-width: 400px; margin: 8vh auto 0; }
.logo { display: grid; place-items: center; margin-bottom: 1rem; }

/* ---------- Admin ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: .7rem 1rem; font: inherit; font-family: var(--font-title); font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab.active { color: var(--link); border-bottom-color: var(--primary); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .925rem; }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.q-editor { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .9rem; margin-bottom: .6rem; }
.q-editor.archived { opacity: .6; border-style: dashed; }
.q-editor .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; }
.q-editor .head { display: flex; gap: .5rem; align-items: center; margin-bottom: .6rem; }
.q-editor .head .idx { font-weight: 700; color: var(--muted); }
.opt-row { display: grid; grid-template-columns: 1fr 1.6fr 90px 40px; gap: .4rem; margin-bottom: .35rem; }
.opt-row input { min-height: 38px; padding: .35rem .55rem; }

dialog { border: 0; border-radius: var(--radius); padding: 0; max-width: min(720px, 94vw); width: 100%; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog .dlg-head { display: flex; align-items: center; padding: .9rem 1rem; border-bottom: 1px solid var(--border); }
dialog .dlg-body { padding: 1rem; max-height: 70vh; overflow-y: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(5.5rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .2); max-width: 90vw; font-size: .925rem;
}
label.field small { display: block; margin-top: .25rem; font-size: .8rem; }
