/* =========================================================================
   Presences - feuille de style unique, mobile d'abord.

   Principes d'ergonomie retenus :
     - texte large et contraste, pour une lecture a bout de bras ;
     - cibles tactiles de 48 px minimum (56 px pour les actions frequentes) ;
     - une action principale toujours visible et evidente ;
     - aucune information portee par la seule couleur.
   ========================================================================= */

:root {
  --accent: #2f6fed;
  --accent-soft: #e8f0ff;
  --accent-ink: #ffffff;

  --bg: #f2f5fb;
  --surface: #ffffff;
  --surface-2: #f4f7fc;
  --surface-3: #eaeff8;
  --ink: #101725;
  --ink-2: #3f4b61;
  --muted: #6b7891;
  --line: #e1e7f1;
  --line-strong: #cbd5e6;

  --ok: #0f7a44;
  --ok-soft: #e2f6ea;
  --warn: #96600a;
  --warn-soft: #fdf1d8;
  --danger: #c02730;
  --danger-soft: #fdeaea;

  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 18px rgba(16, 24, 40, .06);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .22);

  /* Cibles tactiles */
  --tap: 48px;
  --tap-lg: 56px;
  --field-h: 52px;

  --nav-h: 68px;
  --header-h: 60px;
  --sidebar-w: 250px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent-soft: #1c2e52;
    --bg: #0c1017;
    --surface: #161c25;
    --surface-2: #1d2530;
    --surface-3: #26303d;
    --ink: #eef2f8;
    --ink-2: #bcc6d6;
    --muted: #8c99ac;
    --line: #2a3341;
    --line-strong: #3a4658;
    --ok: #4ad48c;
    --ok-soft: #123425;
    --warn: #e8b452;
    --warn-soft: #33280f;
    --danger: #ff8a8a;
    --danger-soft: #3a1c1e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .45), 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

/* Taille par defaut des icones.

   Sans cette regle, un SVG depourvu d'attribut `width` occupe toute la
   largeur disponible : le chevron d'une ligne de liste devient un dessin
   plein ecran.

   L'unite est `em` et non `px` : l'icone suit la taille du texte qu'elle
   accompagne. Un bouton, un bouton compact et une tablette (racine a 17 px)
   obtiennent ainsi des proportions coherentes sans regle dediee. Les
   contextes ou l'icone n'accompagne pas un texte (barre d'onglets, action
   flottante, etat vide) fixent leur propre taille plus bas. */
svg { width: 1.25em; height: 1.25em; flex: none; vertical-align: middle; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { padding-bottom: env(safe-area-inset-bottom); }

h1, h2, h3, h4 { margin: 0 0 .4rem; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }

/* ------------------------------------------------------------- amorcage */

.boot {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1rem; color: var(--muted); background: var(--bg); z-index: 50;
}
.boot-logo {
  width: 64px; height: 64px; border-radius: 18px;
  background: linear-gradient(160deg, #4f92ff, #1f4fd8);
  box-shadow: 0 10px 30px rgba(47, 111, 237, .28);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .5; transform: scale(.94); } 50% { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* --------------------------------------------------------------- shell */

.shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  min-height: var(--header-h);
  padding: 0 .5rem 0 .85rem;
  padding-top: env(safe-area-inset-top);
  /* Opaque d'abord : un navigateur sans color-mix garde une barre lisible. */
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
@supports not (backdrop-filter: blur(1px)) { .appbar { background: var(--surface); } }

.appbar .brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.02rem; min-width: 0; }
.appbar .brand img { width: 32px; height: 32px; border-radius: 9px; object-fit: cover; }
.appbar .brand .dot { width: 30px; height: 30px; border-radius: 9px; background: linear-gradient(160deg, #4f92ff, #1f4fd8); flex: none; }
.appbar .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar .spacer { flex: 1; }

.main { flex: 1; padding: 1rem .85rem calc(var(--nav-h) + 1.6rem); max-width: 1180px; width: 100%; margin: 0 auto; }

/* Navigation basse (telephone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -2px 14px rgba(16, 24, 40, .05);
}
@supports not (backdrop-filter: blur(1px)) { .tabbar { background: var(--surface); } }

.tabbar a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  height: var(--nav-h); text-decoration: none; color: var(--muted);
  font-size: .72rem; font-weight: 600; letter-spacing: .005em;
  -webkit-tap-highlight-color: transparent;
}
/* L'etiquette d'onglet est volontairement petite : l'icone se cale sur la
   racine (17 px sur tablette) plutot que sur ce texte. */
.tabbar a svg { width: 1.55rem; height: 1.55rem; }
.tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active svg { stroke-width: 2.4; }
/* Pastille active : repere non colore, lisible aussi en niveaux de gris. */
.tabbar a.active::before {
  content: ''; position: absolute; top: 6px; width: 34px; height: 30px;
  border-radius: 999px; background: var(--accent-soft); z-index: -1;
}
.tabbar a.active svg { position: relative; }

.sidebar { display: none; }

/* Tablette / bureau : barre laterale */
@media (min-width: 860px) {
  .shell { flex-direction: row; }
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: .2rem;
    width: var(--sidebar-w); flex: none;
    padding: 1rem .7rem; background: var(--surface);
    border-right: 1px solid var(--line);
    position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto;
  }
  .sidebar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.05rem; padding: .3rem .5rem 1.1rem; }
  .sidebar .brand img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
  .sidebar .brand .dot { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(160deg, #4f92ff, #1f4fd8); flex: none; }
  .sidebar a {
    display: flex; align-items: center; gap: .7rem;
    padding: .7rem .75rem; border-radius: var(--radius-sm); min-height: 46px;
    color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .95rem;
  }
  .sidebar a svg { width: 1.3em; height: 1.3em; }
  .sidebar a:hover { background: var(--surface-2); }
  .sidebar a.active { background: var(--accent-soft); color: var(--accent); }
  .sidebar .grow { flex: 1; }
  .shell > .col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .main { padding: 1.4rem 1.6rem 3rem; }
}

/* Tablette : on respire davantage sans passer en barre laterale. */
@media (min-width: 600px) and (max-width: 859px) {
  html, body { font-size: 17px; }
  .main { padding: 1.2rem 1.4rem calc(var(--nav-h) + 2rem); }
  .tabbar a { font-size: .78rem; }
}

/* ------------------------------------------------------------ etat reseau */

.netbar {
  display: flex; align-items: center; gap: .5rem;
  padding: .5rem .85rem; font-size: .85rem; font-weight: 600;
}
.netbar.offline { background: var(--warn-soft); color: var(--warn); }
.netbar.pending { background: var(--accent-soft); color: var(--accent); }
.netbar.error { background: var(--danger-soft); color: var(--danger); }

/* Pastille de synchronisation dans la barre du haut. */
.syncbtn {
  gap: .4rem; padding: .35rem .7rem; min-height: 38px;
  border-radius: 999px; background: var(--surface-2); color: var(--ink-2);
}
.syncbtn .tiny { font-weight: 650; }

.syncdot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); flex: none; }
.syncdot.off { background: var(--muted); }
.syncdot.warn { background: var(--warn); }
.syncdot.busy { background: var(--accent); animation: pulse 1s infinite; }
.syncdot.err { background: var(--danger); }

/* ---------------------------------------------------------------- cartes */

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: .9rem;
  box-shadow: var(--shadow);
}
.card.flat { box-shadow: none; }
.card > h2, .card > h3 { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .8rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }
.card-head .spacer { flex: 1; }

.section-title {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 700; margin: 1.3rem 0 .55rem;
}

.grid { display: grid; gap: .7rem; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.tight { gap: .35rem; }
.row.between { justify-content: space-between; }
.row .spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: .6rem; }

/* En-tete de page : titre + action principale, jamais tronques. */
.page-head { display: flex; align-items: flex-start; gap: .7rem; flex-wrap: wrap; margin-bottom: .9rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); font-size: .88rem; margin: .1rem 0 0; }
.page-head .spacer { flex: 1; }

/* ---------------------------------------------------------------- tuiles */

.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .8rem .9rem;
}
.kpi .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 1.9rem; font-weight: 750; line-height: 1.1; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: .76rem; color: var(--muted); }
.kpi.accent { background: var(--accent-soft); border-color: transparent; }
.kpi.accent .value { color: var(--accent); }
.kpi.accent .label { color: var(--accent); opacity: .85; }
.kpi.danger { background: var(--danger-soft); border-color: transparent; }
.kpi.danger .value, .kpi.danger .label { color: var(--danger); }
.kpi.ok .value { color: var(--ok); }

/* -------------------------------------------------------------- boutons */

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-weight: 650; font-size: .95rem;
  padding: .6rem 1rem; min-height: var(--tap);
  border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: filter .12s, background .12s, transform .06s;
}
button:hover, .btn:hover { filter: brightness(.97); }
button:active, .btn:active { transform: scale(.98); }
button:disabled, .btn:disabled { opacity: .45; cursor: not-allowed; }
/* Les icones de bouton suivent la regle generale (1.25em) : `.btn-sm`, plus
   petit en texte, obtient automatiquement une icone plus petite. */

.btn-primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 32%, transparent);
}
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn-sm { min-height: 40px; padding: .35rem .7rem; font-size: .87rem; }
.btn-icon { min-height: var(--tap); width: var(--tap); padding: 0; }
.btn-sm.btn-icon { min-height: 40px; width: 40px; }
.btn-block { width: 100%; }

/* Action flottante. La variante `.labeled` porte un texte : sur un ecran
   tactile, une icone seule laisse trop souvent l'utilisateur hesitant. */
.btn-fab {
  position: fixed; right: 1rem; bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 22; width: 60px; height: 60px; min-height: 60px; padding: 0;
  border-radius: 999px; font-size: 1rem; font-weight: 700;
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: var(--shadow-lg);
}
.btn-fab svg { width: 1.6em; height: 1.6em; }
.btn-fab.labeled { width: auto; padding: 0 1.3rem 0 1.05rem; }
@media (min-width: 860px) { .btn-fab { bottom: 1.8rem; right: 1.8rem; } }

/* Grandes actions de l'accueil : deux cibles impossibles a manquer. */
.bigaction {
  flex-direction: column; align-items: flex-start; gap: .25rem;
  padding: .95rem 1rem; min-height: 94px; text-align: left;
  border-radius: var(--radius);
}
.bigaction .t { display: flex; align-items: center; gap: .55rem; font-weight: 750; font-size: 1.05rem; }
.bigaction .t svg { width: 1.3em; height: 1.3em; }
.bigaction .s { font-size: .84rem; font-weight: 550; opacity: .78; padding-left: 2.1rem; }

.minilink {
  flex-direction: column; gap: .4rem; padding: .85rem .5rem; min-height: 80px;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius); font-size: .87rem; font-weight: 650; color: var(--ink-2);
}
/* Icone dominante, au-dessus du libelle : elle se cale sur la racine et non
   sur le petit texte qui la suit. */
.minilink svg { width: 1.6rem; height: 1.6rem; color: var(--accent); }

/* Navigateur de date : deux fleches larges encadrant un libelle lisible. */
.datenav {
  display: grid; grid-template-columns: var(--tap) 1fr var(--tap);
  gap: .5rem; align-items: center; margin-bottom: .55rem;
}
.datenav .label {
  text-align: center; font-weight: 700; font-size: 1rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.datenav .label::first-letter { text-transform: uppercase; }
.datenav-tools { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .9rem; }
.datenav-tools input, .datenav-tools select { width: auto; flex: 1 1 140px; min-height: 44px; }

/* Bandeau d'accueil */
.hero { margin-bottom: 1rem; }
.hero h1 { font-size: 1.65rem; margin: 0; }
.hero .date { color: var(--muted); font-size: .95rem; text-transform: capitalize; margin: .15rem 0 0; }

/* ------------------------------------------------------------ formulaires */

label { display: block; font-size: .88rem; font-weight: 650; color: var(--ink-2); margin-bottom: .3rem; }
label .req { color: var(--danger); font-weight: 700; margin-left: .15rem; }
.field { margin-bottom: .95rem; }
.field .help { font-size: .8rem; color: var(--muted); margin-top: .3rem; line-height: 1.4; }
.field.error input, .field.error select, .field.error textarea { border-color: var(--danger); }
.field .error-text { font-size: .8rem; color: var(--danger); margin-top: .25rem; }

input, select, textarea {
  width: 100%; font: inherit; font-size: 16px;   /* 16px : evite le zoom iOS */
  padding: .7rem .8rem; min-height: var(--field-h);
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  appearance: none;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { min-height: 92px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .22);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
button:focus-visible, a:focus-visible, .choice:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
input[type=checkbox], input[type=radio] { width: 24px; height: 24px; min-height: 0; flex: none; accent-color: var(--accent); }
input[type=date], input[type=time] { min-height: var(--field-h); }
/* Sur iOS, les champs date/heure se centrent mal sans hauteur de ligne explicite. */
input[type=date]::-webkit-date-and-time-value,
input[type=time]::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }

select {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%236b7891' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .8rem center; background-size: 13px;
  padding-right: 2.4rem;
}

/* Case a cocher : toute la ligne est cliquable, avec un cadre visible. */
.check {
  display: flex; align-items: center; gap: .7rem;
  padding: .7rem .8rem; min-height: var(--field-h); cursor: pointer;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface);
}
.check:hover { background: var(--surface-2); }
.check.checked { border-color: var(--accent); background: var(--accent-soft); }
.check label, .check span { margin: 0; font-size: .95rem; font-weight: 600; color: var(--ink); cursor: pointer; }

.switch-row { display: flex; align-items: center; gap: .7rem; padding: .7rem 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .txt { flex: 1; }
.switch-row .txt b { display: block; font-size: .95rem; font-weight: 650; }
.switch-row .txt small { color: var(--muted); font-size: .8rem; }

fieldset { border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: .85rem; margin: 0 0 .9rem; }
legend { font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 0 .35rem; }

/* --------------------------------------------------- compteur +/- (stepper)

   Saisie d'un nombre sans clavier : deux grandes touches encadrant la valeur.
   C'est la brique la plus utilisee de l'application.
   ------------------------------------------------------------------------ */

.stepper {
  display: grid; grid-template-columns: var(--tap-lg) 1fr var(--tap-lg);
  align-items: stretch;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); overflow: hidden;
}
.stepper button {
  min-height: var(--tap-lg); border: 0; border-radius: 0;
  background: var(--surface-2); color: var(--accent);
  font-size: 1.6rem; font-weight: 400; line-height: 1; padding: 0;
}
.stepper button:hover { background: var(--surface-3); }
.stepper button:disabled { color: var(--muted); opacity: .4; }
.stepper input {
  border: 0; border-radius: 0; border-left: 1.5px solid var(--line);
  border-right: 1.5px solid var(--line);
  text-align: center; font-size: 1.35rem; font-weight: 750;
  font-variant-numeric: tabular-nums; padding: 0; min-height: var(--tap-lg);
  background: var(--surface);
  /* Les fleches natives feraient doublon avec les deux touches. */
  -moz-appearance: textfield;
}
.stepper input:focus { box-shadow: none; border-color: var(--line); }
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ------------------------------------------------- selecteur segmente ---- */

.segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px;
  padding: 4px; background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
}
.segmented button {
  min-height: 44px; border: 0; border-radius: 7px; padding: .3rem .5rem;
  background: transparent; color: var(--ink-2); font-size: .9rem; font-weight: 650;
  box-shadow: none;
}
.segmented button.active {
  background: var(--surface); color: var(--accent);
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}

/* ------------------------------------------------ liste de choix tactile -- */

.choices { display: flex; flex-direction: column; gap: .5rem; }
.choice {
  display: flex; align-items: center; gap: .75rem; width: 100%;
  min-height: var(--tap-lg); padding: .65rem .8rem; text-align: left;
  border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-weight: 600;
}
.choice .mark {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
}
.choice .mark svg { width: 15px; height: 15px; color: #fff; opacity: 0; }
.choice .body { flex: 1; min-width: 0; }
.choice .title { font-size: .98rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.choice .sub { font-size: .82rem; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.choice .swatch { width: 5px; align-self: stretch; border-radius: 3px; background: var(--accent); flex: none; }
.choice.active { border-color: var(--accent); background: var(--accent-soft); }
.choice.active .mark { border-color: var(--accent); background: var(--accent); }
.choice.active .mark svg { opacity: 1; }

/* --------------------------------------------------------- autocompletion */

.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 40; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 300px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.combo-list[hidden] { display: none; }
.combo-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .75rem .8rem; min-height: var(--tap); cursor: pointer; font-size: .98rem;
  border-bottom: 1px solid var(--line);
}
.combo-item:last-child { border-bottom: 0; }
.combo-item svg { width: 1.15em; height: 1.15em; }
.combo-item small { color: var(--muted); font-size: .82rem; }
.combo-item .spacer { flex: 1; }
.combo-item:hover, .combo-item.active { background: var(--accent-soft); }
.combo-item.create { color: var(--accent); font-weight: 700; }
.combo-item mark { background: transparent; color: var(--accent); font-weight: 750; }

/* --------------------------------------------------------------- listes */

.list { display: flex; flex-direction: column; gap: .5rem; }
.item {
  display: flex; align-items: center; gap: .75rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem .85rem; min-height: 60px;
}
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: var(--accent); background: var(--surface-2); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 650; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: .84rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.item .side { text-align: right; font-size: .84rem; color: var(--muted); flex: none; }
.item .side .tiny { font-size: .74rem; }
.item.done { opacity: .6; }
.item.done .title { text-decoration: line-through; text-decoration-thickness: 1px; }
.item .swatch { width: 5px; align-self: stretch; min-height: 40px; border-radius: 3px; background: var(--accent); flex: none; }
/* Chevron de fin de ligne : un simple repere, jamais l'element dominant. */
.item > svg { width: 1.15em; height: 1.15em; color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .2rem .55rem; border-radius: 999px;
  font-size: .76rem; font-weight: 700; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.empty { text-align: center; color: var(--muted); padding: 2.2rem 1rem; font-size: .95rem; }
.empty svg { width: 2.9rem; height: 2.9rem; opacity: .3; margin-bottom: .6rem; }
.empty p { margin-bottom: .9rem; }

/* -------------------------------------------------------------- tableaux */

.table-wrap {
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .7rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th {
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; background: var(--surface-2);
  position: sticky; top: 0;
}
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
table.wrap td { white-space: normal; }

/* ------------------------------------------------------------ graphiques */

.bars { display: flex; flex-direction: column; gap: .45rem; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: .55rem; align-items: center; font-size: .88rem; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--surface-3); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; min-width: 4px; transition: width .35s ease; }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 700; min-width: 40px; text-align: right; }

/* --------------------------------------------------------------- onglets */

.tabs {
  display: flex; gap: .4rem; overflow-x: auto;
  padding: 0 .1rem .5rem; margin-bottom: .8rem;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  min-height: 44px; padding: .4rem 1rem; font-size: .92rem; white-space: nowrap;
  border-radius: 999px; border: 1.5px solid var(--line-strong);
  background: var(--surface); color: var(--ink-2); scroll-snap-align: start;
}
.tabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 30%, transparent); }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; }
.chip {
  padding: .4rem .85rem; min-height: 40px; border-radius: 999px;
  font-size: .88rem; font-weight: 650;
  border: 1.5px solid var(--line-strong); background: var(--surface); color: var(--ink-2); cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* -------------------------------------------------------------- modales */

.modals:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 15, 25, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(24px); opacity: .4; } }
.modal {
  background: var(--surface); width: 100%; max-width: 620px;
  max-height: 94vh; max-height: 94dvh; overflow: hidden;
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: slideUp .2s ease;
}
/* Poignee : indique clairement une feuille que l'on peut fermer. */
.modal::before {
  content: ''; display: block; flex: none;
  width: 40px; height: 4px; border-radius: 999px;
  background: var(--line-strong); margin: .55rem auto .1rem;
}
.modal-head {
  display: flex; align-items: center; gap: .6rem;
  padding: .7rem .9rem .8rem; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.12rem; flex: 1; }
.modal-body { padding: 1rem .9rem 1.1rem; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal-foot {
  display: flex; gap: .55rem; padding: .8rem .9rem;
  border-top: 1px solid var(--line); background: var(--surface);
  padding-bottom: calc(.8rem + env(safe-area-inset-bottom));
}
.modal-foot .spacer { flex: 1; }
.modal-foot button { flex: 1; min-height: var(--tap-lg); font-size: 1rem; }
/* Sur telephone, l'action secondaire reste presente mais discrete. */
.modal-foot button.btn-ghost { flex: 0 1 auto; }
@media (min-width: 700px) {
  .modal-backdrop { align-items: center; padding: 1.5rem; }
  .modal { border-radius: 18px; max-height: 88vh; }
  .modal::before { display: none; }
  .modal-body { padding: 1.1rem; }
  .modal-foot button { flex: none; min-height: var(--tap); }
  .modal.wide { max-width: 920px; }
}

/* ---------------------------------------------------------------- toasts */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 1rem + env(safe-area-inset-bottom));
  z-index: 80; display: flex; flex-direction: column; gap: .45rem;
  width: min(94vw, 480px); pointer-events: none;
}
@media (min-width: 860px) { .toasts { bottom: 1.4rem; } }
.toast {
  pointer-events: auto;
  background: #1d2431; color: #fff;
  padding: .8rem 1rem; border-radius: var(--radius-sm);
  font-size: .95rem; font-weight: 550; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: .55rem;
  animation: slideUp .18s ease;
}
.toast.ok { background: #106a3d; }
.toast.error { background: #a52630; }
.toast.warn { background: #7f4f00; }
.toast button {
  background: transparent; border: 0; color: inherit;
  min-height: 32px; width: 32px; padding: 0; opacity: .8;
}

/* ------------------------------------------------------------ connexion */

.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; padding: 1.2rem;
  background: radial-gradient(120% 80% at 50% 0%, var(--accent-soft), var(--bg) 60%);
}
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 1.8rem 1.4rem;
  box-shadow: var(--shadow-lg);
}
.auth-card .logo { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1.4rem; text-align: center; }
.auth-card .logo img { width: 68px; height: 68px; border-radius: 18px; object-fit: cover; }
.auth-card .logo .dot { width: 64px; height: 64px; border-radius: 18px; background: linear-gradient(160deg, #4f92ff, #1f4fd8); box-shadow: 0 10px 26px rgba(47, 111, 237, .3); }
.auth-card .logo h1 { margin: 0; font-size: 1.4rem; }
.auth-card .logo p { margin: 0; color: var(--muted); font-size: .9rem; }
.auth-card .btn-primary { min-height: var(--tap-lg); font-size: 1.02rem; margin-top: .3rem; }
.auth-alt { text-align: center; margin-top: 1rem; font-size: .9rem; }
.auth-alt button { background: none; border: 0; color: var(--accent); font-weight: 650; min-height: var(--tap); padding: .2rem .5rem; }

/* ----------------------------------------------------------- utilitaires */

.muted { color: var(--muted); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; }
.bold { font-weight: 700; }
.mono { font-family: var(--mono); font-size: .85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.mt { margin-top: .8rem; }
.mb { margin-bottom: .8rem; }
.mt-lg { margin-top: 1.5rem; }
.hidden, [hidden] { display: none !important; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }
.pre {
  font-family: var(--mono); font-size: .8rem; white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: .7rem; max-height: 320px; overflow: auto;
}
.callout {
  border-left: 4px solid var(--accent); background: var(--accent-soft);
  padding: .75rem .9rem; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: .9rem; margin-bottom: .8rem; line-height: 1.45;
}
.callout.warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.callout.danger { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.callout.ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.callout ul { margin: .35rem 0 0; padding-left: 1.2rem; }

.spinner {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}

.preview-frame {
  width: 100%; min-height: 260px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: #fff;
}

@media print {
  .appbar, .tabbar, .sidebar, .btn-fab, .toasts, .netbar, .tabs { display: none !important; }
  .main { padding: 0; }
  .card { break-inside: avoid; box-shadow: none; }
}
