/* VARIABLES */
:root {
  /* Identite « petrole » : un bleu-vert remplace le noir, coherent avec le
     degrade mint -> teal du logo. Deux tons volontairement distincts :
     --deep-* pour le decor (peut etre clair, c'est de l'apparence), et
     --ink-* pour ce qui porte du texte blanc (reste fonce, sinon la
     lisibilite s'effondre quand l'image est claire). */
  --deep-1: #13505f;
  --deep-2: #1c6b7d;
  --deep-1-rgb: 19,80,95;
  --ink-1: #0b3340;
  --ink-1-rgb: 11,51,64;
  --ink-glass: rgba(11,51,64,.72);
  --ink-glass-fort: rgba(11,51,64,.86);

  --bg: rgba(242,246,249,.92); --bg-card: rgba(228,234,240,.90); --bg-hover: rgba(208,218,227,.95);
  --text: #222222; --text-secondary: #555555; --text-muted: #777777;
  --border: rgba(108,122,136,.42); --border-light: rgba(255,255,255,.20);
    --primary: #6f9eb5; --primary-hover: #5e8ba3; --primary-light: #eaf3f7;
    /* Accent a deux etats. --primary (pastel) habille les surfaces : fond de
       pastille, bordure, aplat de graphique. Il est trop clair pour PORTER du
       texte, et trop clair pour receive du blanc : d'ou --primary-ink pour
       l'encre et --primary-btn pour les fonds de bouton (blanc dessus). */
    --primary-ink: #2f5b73; --primary-btn: #45768d; --primary-btn-hover: #3a657a;
  --danger: #ef4444; --success: #22c55e; --warning: #f59e0b;
  --shadow: 0 2px 8px rgba(0,0,0,.05);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.15);
  --sidebar-bg: rgba(11,47,58,.84); --sidebar-text: #cfe3e8;
  --sidebar-active: #6f9eb5; --sidebar-hover: rgba(30,74,88,.72);
}
body.dark {
  --bg: rgba(16,44,53,.92); --bg-card: rgba(23,57,68,.94); --bg-hover: rgba(32,72,85,.95);
  --text: #f2f4fa; --text-secondary: #e2e6f0; --text-muted: #d2d8e2;
  --border: rgba(160,200,215,.22); --border-light: rgba(220,240,250,.14);
  /* le formulaire, seul cadre clair conserve en mode sombre */
  --form-bg: rgba(226,233,240,.94); --form-field: #ffffff;
  --form-text: #1e262e; --form-muted: #6b7885; --form-border: rgba(96,112,128,.38);
  --form-checked: #d3e4ee; --form-checked-texte: #1d4a63;
    --primary: #8fb7cc; --primary-hover: #7ba6bc; --primary-light: #24404a;
    /* Sur la page sombre, l'encre d'accent doit etre CLAIRE ; le fond de bouton
       doit rester assez sombre pour porter du blanc. */
    --primary-ink: #a8cfe2; --primary-btn: #2f5b73; --primary-btn-hover: #24485c;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.5);
  --sidebar-bg: rgba(9,34,42,.86); --sidebar-text: #e2f0f4;
  --sidebar-active: #8fb7cc; --sidebar-hover: rgba(28,68,82,.72);
}

/* Verre dépoli sur les cadres des pages : laisser transparaître la photo de fond */
.latest-item, .topbar, .kpi-card, .dashboard-card, .stat-card, .status-bars, .tags-stats,
.chart-container, .calendar-header, .calendar-grid, .day-events, .reminder-card,
.report-preview, .modal-content, form, table {
  -webkit-backdrop-filter: blur(12px) saturate(1.15);
  backdrop-filter: blur(12px) saturate(1.15);
}

/* Fond flou global des pages d'app */
.app-bg {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: url("./assets/photo1.jpg") center / cover no-repeat;
  filter: blur(8px) brightness(1.35) saturate(1.05);
  transform: scale(1.05);
  z-index: 0;
  pointer-events: none;
}
body.dark .app-bg { filter: blur(6px) brightness(.42) saturate(1.15); }

* { box-sizing: border-box; margin: 0; padding: 0; font-family: system-ui, -apple-system, "Segoe UI", "Tahoma", sans-serif; }
body { background: transparent; color: var(--text); min-height: 100vh; transition: background .25s ease, color .25s ease; -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }

/* MESURES MULTI-TYPES : dernières valeurs par type */
.latest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.latest-item { background: var(--bg-card); padding: 14px; border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.latest-item .latest-title { font-size: .82rem; font-weight: 700; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.latest-item .latest-value { font-size: 1.25rem; font-weight: 700; color: var(--primary-ink); }
.latest-item .latest-sub { font-size: .72rem; color: var(--text-muted); }
.type-pill { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: .78rem; font-weight: 600; background: var(--primary-light); color: var(--primary-ink); margin: 1px; }
/* ---- IMC : categorie OMS + poids ideal + saisie de la taille ---- */
.imc-item { position: relative; }
.imc-item #dbImc { font-size: 1.6rem; font-weight: 700; color: var(--primary-ink); }
.bmi-cat { align-self: flex-start; margin-top: 2px; padding: 3px 10px; border-radius: 12px; font-size: .74rem; font-weight: 700; }
.bmi-cat.is-hidden { display: none; }
.bmi-cat.is-under  { background: #dbeafe; color: #1d4ed8; }
.bmi-cat.is-normal { background: #dcfce7; color: #15803d; }
.bmi-cat.is-over   { background: #fef3c7; color: #b45309; }
.bmi-cat.is-obese  { background: #fee2e2; color: #b91c1c; }
.imc-detail { flex-direction: row; align-items: center; justify-content: space-between; padding: 10px 14px; }
.imc-detail .type-pill { margin: 0; }
.imc-detail b { font-size: .95rem; color: var(--text); }
.imc-height-input { width: 92px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font-size: .95rem; text-align: center; }
.imc-height-input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.imc-hint { margin: 8px 0 0; font-size: .78rem; color: var(--text-secondary); background: var(--primary-light); padding: 8px 10px; border-radius: 8px; }
.imc-note { margin: 6px 0 0; font-size: .7rem; color: var(--text-muted); }
.unit-inline { color: var(--text-muted); font-size: .8em; font-weight: 500; }
.badge-dash { font-size: .7rem; padding: 2px 7px; }

/* Saisie : ligne valeur + second champ inline */
.value2-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }


/* RTL support */
html[dir="rtl"] .sidebar-nav, html[dir="rtl"] .sidebar-footer { text-align: right; }
html[dir="rtl"] .nav-item { text-align: right; }
html[dir="rtl"] th, html[dir="rtl"] td { text-align: right; }
html[dir="rtl"] .report-preview table { direction: rtl; }
html[dir="rtl"] .login-box small, html[dir="rtl"] .login-box .download-link, html[dir="rtl"] .dashboard-sub { text-align: right; }

/* LOGIN */
.login-screen {
  position: fixed; inset: 0;
  background: var(--deep-1);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; overflow: hidden;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* Vidéo de fond médicale en boucle */
.login-video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; object-position: center; z-index: -1;
  opacity: 1;
}
@media (prefers-reduced-data: reduce) {
  .login-video { display: none; }
}

.login-top-actions, .login-box, .login-features { position: relative; z-index: 1; }

.login-top-actions {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: 20px;
  display: flex; gap: 10px; align-items: center;
}
html[dir="rtl"] .login-top-actions { right: auto; left: 20px; }

.lang-select {
  padding: 8px 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(255,255,255,.18);
  color: white; font-size: .9rem; cursor: pointer;
  backdrop-filter: blur(6px);
}
.lang-select option { color: #222; background: #fff; }

/* Cadre de connexion : AUCUN voile global sur la video (l'image est
  .visible telle quelle) et AUCUN flou — le verre est net, on voit la
   video a travers. Le fond est donc tres ouvert (.04).
   Seule la lisibilite est assuree localement, dans le bas du cadre, par
   .login-box::before : sans ce renfort, le texte blanc sur une image
   claire tombait a 1.6:1. La bordure reste marquee pour que le cadre
   ne se fonde pas dans l'image. */
.login-box {
  position: relative;
  background: rgba(255,255,255,.04);
  padding: 22px 18px; border-radius: 18px;
  width: 290px; max-width: 100%; text-align: center;
  border: 1px solid rgba(255,255,255,.46);
  box-shadow:
    0 18px 50px rgba(0,0,0,.22),
    inset 0 1px 0 rgba(255,255,255,.32),
    inset 0 0 0 1px rgba(255,255,255,.06),
    0 0 0 1px rgba(0,0,0,.16);
}
/* Assombrissement LOCAL, dans le bas du cadre uniquement (la ou sont les
   champs et les textes). La video n'est assombrie que derriere le texte
   a lire, jamais autour du cadre ni derriere le logo. */
.login-box::before {
  content: "";
  position: absolute;
  left: 1px; right: 1px; top: 30%; bottom: 1px;
  z-index: -1;                 /* entre le fond du cadre et son contenu */
  pointer-events: none;
  border-radius: 0 0 17px 17px;
  background: linear-gradient(180deg,
    rgba(var(--ink-1-rgb),0) 0%, rgba(var(--ink-1-rgb),.50) 16%, rgba(var(--ink-1-rgb),.72) 100%);
}

/* Logo : goutte de sante teintee, deux halos qui respirent, un tracé
   cardiaque qui se dessine et un point qui le parcourt. */
.login-logo {
  width: 74px; height: 74px; margin-bottom: 6px; display: block;
  margin-left: auto; margin-right: auto;
  overflow: visible;
  filter: drop-shadow(0 6px 16px rgba(0,0,0,.42));
}
.cura-halo { transform-origin: 32px 32px; animation: curaHalo 3.4s ease-out infinite; }
.cura-halo-2 { animation-delay: 1.7s; }
@keyframes curaHalo {
  0%   { transform: scale(.72); opacity: .70; }
  70%  { transform: scale(1.22); opacity: 0; }
  100% { transform: scale(1.22); opacity: 0; }
}
.cura-drop { transform-origin: 32px 34px; animation: curaDrop 3.4s ease-in-out infinite; }
@keyframes curaDrop {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.055); }
}
.cura-ecg {
  stroke-dasharray: 42; stroke-dashoffset: 42;
  animation: curaDraw 3.4s ease-in-out infinite;
}
@keyframes curaDraw {
  0%        { stroke-dashoffset: 42; opacity: 1; }
  45%, 60%  { stroke-dashoffset: 0;  opacity: 1; }
  95%, 100% { stroke-dashoffset: -42; opacity: 0; }
}
.cura-dot {
  offset-path: path("M19.5 35.5h7l3.5-7.5 5 14 4-9h4.5");
  offset-distance: 0%;
  animation: curaRun 3.4s linear infinite;
  filter: drop-shadow(0 0 3px rgba(255,255,255,.9));
}
@keyframes curaRun {
  0%        { offset-distance: 0%;   opacity: 0; }
  8%        { opacity: 1; }
  52%, 100% { offset-distance: 100%; opacity: 0; }
}

/* Le mot CURA : capitales espacees, degrade clair-mint, et un reflet qui
   glisse de gauche a droite. Le degrade est sur le texte lui-meme, donc
   pas de text-shadow (il serait invisible) : la profondeur vient d'un
   filtre. */
.login-box h1 {
  margin-bottom: 6px; font-size: 1.6rem; font-weight: 800;
  letter-spacing: .22em; text-indent: .22em;
  text-transform: uppercase;
  background: linear-gradient(100deg, #ffffff 0%, #ffffff 38%, #a9f2e2 50%, #ffffff 62%, #ffffff 100%);
  background-size: 260% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: curaSheen 6s ease-in-out infinite;
  filter: drop-shadow(0 2px 10px rgba(0,0,0,.45));
}
@keyframes curaSheen {
  0%, 100% { background-position: 130% 0; }
  50%      { background-position: -30% 0; }
}
.login-box p { color: rgba(255,255,255,.92); margin-bottom: 14px; font-size: .8rem; }

/* Champs de saisie : verre sombre, donc bien plus transparents que
   l'ancien blanc quasi opaque (0.85 -> 0.24). Le texte est blanc sur ce
   fond sombre : c'est le seul choix lisible PARTOUT, car la video
   defilee et sa luminosite varie (avec un texte sombre sur du verre
   clair, le contraste tombait a 2:1 sur les zones sombres).
   La garantie de lisibilite repose sur le champ LUI-MEME et sur le voile
   local du cadre, pas sur l'esperance que l'image soit sombre a cet
   instant : mesure sur 6 images variables, 0.20 tenait 5.4:1 au pire
   moment, 0.26 tient au-dessus de 6:1. L'ombre portee du texte est un
   supplement de securite au niveau du glyphe. */
.login-box input {
  width: 100%; padding: 10px; margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,.32); border-radius: 10px; font-size: .88rem;
  background: rgba(var(--ink-1-rgb),.28); color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  backdrop-filter: blur(12px) saturate(1.2);
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.login-box input::placeholder { color: rgba(255,255,255,.72); text-shadow: none; }
.login-box input:focus {
  outline: none; border-color: rgba(255,255,255,.9);
  background: rgba(var(--ink-1-rgb),.48);
  box-shadow: 0 0 0 3px rgba(143,240,220,.22);
}
.login-box > button:not(.theme-toggle) {
  width: 100%; padding: 9px; color: white;
  border: none; border-radius: 9px; font-size: .9rem; cursor: pointer; font-weight: 600;
  background: #2e7d8a;
}
.login-box > button:not(.theme-toggle):hover { filter: brightness(1.1); }
.login-box > button:not(.theme-toggle):active { transform: scale(.97); }
.login-box .login-pwd-wrap.hidden { display: none; }
.login-box .login-generate {
  width: 100%; padding: 7px 10px; margin-bottom: 8px; color: #143a44;
  border: 1px solid rgba(255,255,255,.5); border-radius: 9px; font-size: .78rem;
  cursor: pointer; font-weight: 600; background: rgba(255,255,255,.9);
}
.login-box .login-generate:hover { filter: brightness(1.05); }
.login-box small { display: block; margin-top: 9px; color: rgba(255,255,255,.85); font-size: .74rem; }
.login-box .download-link { display: block; margin-top: 8px; color: rgba(255,255,255,.95); font-size: .74rem; text-decoration: underline; }
#installAppBtn { margin-top: 12px; }
.login-box .ios-hint {
  display: flex; flex-direction: column; gap: 3px; text-align: right;
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: rgba(var(--ink-1-rgb),.42); border: 1px solid rgba(255,255,255,.34);
}
.login-box .ios-hint strong { font-size: .82rem; color: #fff; margin-bottom: 2px; }
.login-box .ios-hint span { font-size: .74rem; color: rgba(255,255,255,.92); }
html[dir="ltr"] .login-box .ios-hint { text-align: left; }
.reset-link { color: #fff; font-weight: 600; cursor: pointer; text-decoration: underline; }

/* Si l'utilisateur demande moins d'animations, on fige le logo et le
   reflet du mot CURA a leur etat final (et non a leur etat initial,
   qui laissait le trace cardiaque invisible). */
@media (prefers-reduced-motion: reduce) {
  .cura-halo, .cura-drop, .cura-ecg, .cura-dot, .login-box h1 { animation: none; }
  .cura-halo { opacity: .32; }
  .cura-halo-2 { opacity: .22; }
  .cura-ecg { stroke-dashoffset: 0; }
  .cura-dot { opacity: 0; }
  .login-box h1 { background-position: 50% 0; }
}
/* Mentions sous le cadre. Elles etaient en blanc sur fond blanc : avec la
   video entiere ment visible, le contraste tombait a 1.0:1, elles
   disparaissaient. Chacune recoit donc son propre verre petrole, fonce et
   opaque, qui guarantees la lisibilite SANS assombrir la video. */
.login-features { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; justify-content: center; max-width: 560px; }
.login-features .feat {
  background: var(--ink-glass); color: #f4fbfd; padding: 7px 14px; border-radius: 18px;
  font-size: .8rem; font-weight: 500; letter-spacing: .01em;
  text-shadow: 0 1px 2px rgba(0,0,0,.55);
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  backdrop-filter: blur(8px) saturate(1.2);
  border: 1px solid rgba(255,255,255,.26);
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
}
/* Mention de credit, en bas a droite : meme principe, un verre petrole
   discret pour qu'on la lise sur n'importe quel instant de la video. */
.login-credit {
  position: absolute; right: 20px; left: auto;
  bottom: max(14px, env(safe-area-inset-bottom));
  font-size: .72rem; color: #e8f5f8;
  text-shadow: 0 1px 2px rgba(0,0,0,.55);
  text-align: right; z-index: 1; pointer-events: none;
  background: var(--ink-glass);
  border: 1px solid rgba(255,255,255,.20);
  border-radius: 999px; padding: 5px 13px;
  -webkit-backdrop-filter: blur(8px) saturate(1.2);
  backdrop-filter: blur(8px) saturate(1.2);
}
html[dir="rtl"] .login-credit { direction: ltr; }

/* LAYOUT */
.app-layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; position: relative; z-index: 1; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 20px 0; padding-top: max(20px, env(safe-area-inset-top)); position: sticky; top: 0; height: 100vh; z-index: 100; transition: transform .25s ease; }
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 0 22px 20px; border-bottom: 1px solid rgba(255,255,255,.06); margin-bottom: 16px; }
.sidebar-logo { font-size: 1.6rem; }
.sidebar-title { font-size: 1.15rem; font-weight: 700; color: #ffffff; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding: 0 12px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; background: transparent; border: none; color: var(--sidebar-text); font-size: .92rem; border-radius: 10px; cursor: pointer; text-align: left; width: 100%; transition: background .15s, color .15s; }
.nav-item:hover { background: var(--sidebar-hover); color: #ffffff; }
.nav-item.active { background: var(--sidebar-active); color: #ffffff; font-weight: 600; box-shadow: 0 4px 14px rgba(102,126,234,.35); }
.nav-item.danger:hover { background: rgba(239,68,68,.15); color: #f87171; }
.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.06); display: flex; flex-direction: column; gap: 2px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }

.main-content { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; background: var(--bg-card); padding: 16px 28px; padding-top: max(16px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.topbar h1 { font-size: 1.3rem; flex: 1; color: var(--text); }
.menu-toggle { display: none; background: transparent; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text); padding: 4px 8px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

.topbar .lang-select {
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: .9rem; cursor: pointer;
}

.login-top-actions .theme-toggle { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.3); }
.theme-toggle { background: var(--bg); border: 1px solid var(--border); width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 1.1rem; display: inline-flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: var(--bg-hover); transform: scale(1.08); }

.content-area { padding: 24px 28px; padding-bottom: max(24px, env(safe-area-inset-bottom)); max-width: 1300px; width: 100%; margin: 0 auto; flex: 1; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.tab-content h2 { margin-bottom: 8px; font-size: 1.35rem; color: var(--text); }
.tab-content h3 { margin-bottom: 12px; font-size: 1.05rem; color: var(--text); }
.dashboard-sub { color: var(--text-secondary); margin-bottom: 24px; font-size: .95rem; }
body.dark .dashboard-sub { color: #f4f6fb; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
body.dark .kpi-label { color: #f4f6fb; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
body.dark .kpi-sub { color: #dde3ee; text-shadow: 0 1px 2px rgba(0,0,0,.55); }
body.dark .dashboard-card h3 { color: #f4f6fb; text-shadow: 0 1px 3px rgba(0,0,0,.55); }
body.dark .mini-bar-row { color: #f4f6fb; text-shadow: 0 1px 3px rgba(0,0,0,.55); }
body.dark .legend { color: #f4f6fb; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
body.dark .reminder-card p { color: #f4f6fb; }
body.dark .reminder-card small { color: #dde3ee; }

/* DASHBOARD */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: var(--bg-card); padding: 20px; border-radius: 14px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; transition: transform .15s; }
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card.highlight { background: linear-gradient(135deg, var(--primary-btn), #764ba2); color: white; }
.kpi-card.highlight .kpi-label, .kpi-card.highlight .kpi-sub { color: rgba(255,255,255,.85); }
.kpi-card.highlight .kpi-value { color: white; }
.kpi-icon { font-size: 2rem; width: 52px; height: 52px; display: flex; align-items: center; justify-content: center; background: var(--primary-light); border-radius: 12px; flex-shrink: 0; }
.kpi-card.highlight .kpi-icon { background: rgba(255,255,255,.2); }
.kpi-info { flex: 1; min-width: 0; }
.kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--primary-ink); line-height: 1.1; }
.kpi-label { font-size: .85rem; color: var(--text-secondary); margin-top: 2px; }
.kpi-sub { font-size: .75rem; color: var(--text-muted); margin-top: 2px; }
.dashboard-row { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; }
.dashboard-card { background: var(--bg-card); padding: 20px; border-radius: 14px; box-shadow: var(--shadow); }
.dashboard-card h3 { font-size: 1rem; margin-bottom: 14px; color: var(--text-secondary); font-weight: 600; }
.mini-chart-container { height: 220px; position: relative; }
.mini-bars { display: grid; gap: 12px; }
.mini-bar-row { display: grid; grid-template-columns: 100px 1fr 55px; gap: 12px; align-items: center; font-size: .88rem; color: var(--text-secondary); }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-btn { padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; font-size: .88rem; color: var(--text); text-align: left; }
html[dir="rtl"] .quick-btn { text-align: right; }
.quick-btn:hover { background: var(--primary-light); border-color: var(--primary-ink); color: var(--primary-ink); }

/* FORMS */
form { background: var(--bg-card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); margin-bottom: 24px; display: grid; gap: 14px; }
form label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--text-secondary); }
form input, form select { padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; background: var(--bg); color: var(--text); -webkit-appearance: none; }
form input:focus, form select:focus { outline: none; border-color: var(--primary-ink); }
form button { padding: 12px; background: var(--primary-btn); color: white; border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; font-weight: 600; }
form button:hover { background: var(--primary-btn-hover); }
/* Le fond venait de var(--border) : tres clair en mode sombre, il laissait un
   texte clair dessus (bouton "Effacer" illisible hors cadre). --bg-hover est
   le bon neutre dans les trois contextes : page sombre, carte claire, clair. */
.btn-secondary { padding: 10px 16px; background: var(--bg-hover); color: var(--text); border: none; border-radius: 8px; cursor: pointer; }
.btn-danger { background: var(--danger) !important; color: white; }
.btn-primary { padding: 10px 16px; background: var(--primary-btn); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; }

/* MODE SOMBRE - surfaces de travail claires.
   Tous les cadres (formulaires, tableaux, graphiques, cartes, calendrier, modales)
   gardent une apparence CLAIRE et dense, meme en mode sombre.
   Point cle : on redefinit les jetons de texte/fond SUR le cadre lui-meme.
   Tout ce qui est a l'interieur herite automatiquement des couleurs fondees,
   donc aucun texte clair ne peut subsister sur un fond clair.
   La barre laterale et la page de connexion restent sombres : elles ne sont pas des cadres de travail. */
body.dark :is(form, table, .chart-container, .kpi-card, .dashboard-card, .stat-card,
              .status-bars, .tags-stats, .stats-table-wrap, .calendar-header, .calendar-grid,
              .day-events, .reminder-card, .report-preview, .modal-content, .latest-item,
              .topbar, .tab-content > h2) {
  --text: #1e262e;
  --text-secondary: #3d4854;
  --text-muted: #6b7885;
  --border: rgba(96,112,128,.30);
  --border-light: rgba(96,112,128,.20);
  --bg: #ffffff;
  --bg-hover: #e4ebf1;
  /* L'accent clair du theme sombre (bleu pastel) devenait illisible pose
     sur une carte claire : valeurs, pilules, badges, degrade "highlight".
     On le remplace par un accent fonce de meme teinte, et on re-pointe
     aussi la teinte claire utilisee en fond (pastille IMC, filet de titre). */
  --primary: #3f6d85;
  --primary-light: #e2eef4;
  /* Carte claire en mode sombre : l'encre et le fond de bouton retombent sur
     les valeurs du theme clair, sinon pastel sur blanc. */
  --primary-ink: #2f5b73;
  --primary-btn: #45768d;
  --primary-btn-hover: #3a657a;
  background: var(--form-bg);
  border-color: var(--form-border);
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
  /* Sans cela, un texte sans classe (ex. un <b> nu) herite de la couleur
     CLAIRE de la page : redefinir --text ne suffit pas, il faut l'appliquer. */
  color: var(--text);
}
/* Le degrade "highlight" est un accent de couleur, pas une surface de travail :
   il doit rester colore meme en mode sombre, sinon le texte blanc passe sur
   un fond clair. (La regle ci-dessus est plus specifique, on la reapplique.) */
body.dark :is(.stat-card.highlight, .kpi-card.highlight) {
  background: linear-gradient(135deg, var(--primary-btn), #764ba2);
  color: #ffffff;
}
body.dark :is(.stat-card.highlight, .kpi-card.highlight)
  :is(.stat-value, .stat-label, .kpi-label, .kpi-sub) { color: #ffffff; }
/* Les textes qui etaient forces en clair pour lisibilite sur la video
   doivent repartir sur les jetons, sinon ils deviennent blancs sur blanc. */
body.dark :is(.kpi-card, .dashboard-card, .reminder-card, .status-bars, .topbar)
  :is(.kpi-label, .kpi-sub, .dashboard-sub, .mini-bar-row, .legend) {
  color: var(--text-secondary);
  text-shadow: none;
}
body.dark :is(.kpi-card, .dashboard-card, .reminder-card) :is(h3, p) { color: var(--text); }
body.dark .reminder-card small { color: var(--text-muted); }
body.dark .kpi-card.highlight .kpi-label, body.dark .kpi-card.highlight .kpi-sub {
  color: rgba(30,38,46,.85);
}
/* Champs de formulaire sur fond clair */
body.dark form label { color: var(--form-text); }
body.dark form input,
body.dark form select,
body.dark form textarea {
  background: var(--form-field);
  color: var(--form-text);
  border-color: var(--form-border);
}
body.dark form input::placeholder,
body.dark form textarea::placeholder { color: var(--form-muted); }
body.dark form .btn-secondary { background: var(--form-field); color: var(--form-text); }

/* Les puces de tags (A jeun, Coucher, ...) : leur fond suivait le mode sombre
   alors que leur texte devenait sombre avec le formulaire -> invisible.
   On repasse leur fond en clair, et la case cochee garde une teinte lisible. */
body.dark form .tag-check {
  background: var(--form-field);
  border-color: var(--form-border);
  color: var(--form-text);
}
body.dark form .tag-check:has(input:checked) {
  background: var(--form-checked);
  border-color: var(--primary-ink);
  color: var(--form-checked-texte);
}
body.dark form .tags-label { color: var(--form-text); }

/* Titre de section (Nouvelle mesure, ...) : hors cadre, il montrait le gris de la video.
   Le fond vient du bloc generique ; ici on ajoute la mise en page. */
body.dark .tab-content > h2 {
  background: var(--form-bg);
  color: var(--form-text);
  border: 1px solid var(--form-border);
  padding: 14px 18px;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.45);
  margin-bottom: 16px;
}

/* Petit texte d'aide sous un champ : plage de reference, precision du type.
   Herite des jetons du cadre, donc lisible en mode sombre comme en mode clair. */
.field-hint {
  display: block;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
  line-height: 1.35;
}
body.dark form .field-hint { color: var(--form-muted); }

/* Selecteur de la mesure suivie, en tete du tableau de bord.
   Inline et compact : c'est un reglage, pas un titre. */
.dash-focus {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  font-size: .88rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.dash-focus select {
  min-width: 220px;
  max-width: 100%;
  padding: 8px 10px;
  font-size: .9rem;
}

/* ---- Reglages : editeur des plages de reference ----
   Un tableau par categorie : les colonnes restent courtes,
   on ne demande que la borne basse et la borne haute. */
.refs-block { margin: 18px 0; border-top: 1px solid var(--border); padding-top: 14px; }
.refs-block > summary {
  cursor: pointer;
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  padding: 6px 0;
  list-style: revert;
}
/* Les 15 types repartis en 6 tableaux de categorie : empiles, ils ne
   tenaient pas a l'ecran et la modale scrollait dans tous les sens.
   Sur une modale large on les dispose en colonnes, tout tient sans
   defilement ; en dessous, on retombe sur une seule colonne. */
.modal-wide #refsEditor {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 2px 18px;
  align-items: start;
}
.modal-wide .refs-group { min-width: 0; }
.modal-wide .refs-group:first-child .refs-group-title { margin-top: 0; }
/* Champs resserres : chaque rangee gagne de la hauteur, et c'est la
   hauteur qui manquait. */
.modal-wide .refs-input { padding: 5px 4px; font-size: .84rem; }
.modal-wide .refs-table th, .modal-wide .refs-table td { padding: 4px 5px; }
/* Le nom du type peut etre long ("Hemoglobine g/dL") : on lui laisse la
   part qui lui revient, les colonnes de saisie prennent le reste. */
.modal-wide .refs-table th:first-child, .modal-wide .refs-table td:first-child { width: 40%; }
.refs-intro {
  font-size: .82rem;
  color: var(--text-secondary);
  margin: 8px 0 14px;
  line-height: 1.45;
}
.refs-group-title {
  font-size: .82rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin: 16px 0 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.refs-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; table-layout: fixed; }
.refs-table th {
  font-size: .74rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: left;
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
}
.refs-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-light);
  font-size: .85rem;
  color: var(--text);
  vertical-align: middle;
}
.refs-table td.refs-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Les cellules de saisie : memes couleurs que les autres champs,
   mais resserrees pour tenir sur petits ecrans. */
.refs-input {
  width: 100%;
  min-width: 0;
  max-width: 92px;
  padding: 6px 8px;
  border: 1px solid var(--form-border);
  border-radius: 8px;
  background: var(--form-field);
  color: var(--form-text);
  font-size: .85rem;
  font-family: inherit;
}
.refs-input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary-ink);
}
.refs-sexe-tag {
  font-size: .7rem;
  color: var(--form-muted);
  white-space: nowrap;
}
.refs-row-active { background: color-mix(in srgb, var(--primary) 8%, transparent); }

/* TABLES */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.toolbar .search-bar { flex: 1; min-width: 200px; margin-bottom: 0; }
.toolbar-filter { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--text-secondary); font-weight: 600; }
.chart-toolbar { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.chart-toolbar label { display: inline-flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text-secondary); font-weight: 600; }
.table-wrapper { overflow-x: auto; border-radius: 12px; }
/* min-width 600px : impose aux tableaux de donnees larges (historique,
   statistiques) de defiler plutot que de se tasser. Les tableaux de
   plages, eux, vivent dans une grille multi-colonnes et doivent pouvoir
   se retrecir a la largeur de leur colonne. */
table { width: 100%; background: var(--bg-card); border-radius: 12px; overflow: hidden; border-collapse: collapse; box-shadow: var(--shadow); min-width: 600px; }
table.refs-table { min-width: 0; background: transparent; box-shadow: none; border-radius: 0; }
th, td { padding: 12px 14px; text-align: left; font-size: .9rem; vertical-align: top; color: var(--text); }
th { background: var(--bg-hover); color: var(--text-secondary); font-weight: 600; }
tr { border-bottom: 1px solid var(--border-light); }
tr:last-child { border-bottom: none; }
tr:hover { background: var(--bg-hover); }
.badge { padding: 4px 10px; border-radius: 12px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.badge.hypo { background: #fee2e2; color: #b91c1c; }
.badge.normal { background: #d1fae5; color: #047857; }
.badge.hyper { background: #fef3c7; color: #b45309; }
body.dark .badge.hypo { background: #4a1f1f; color: #fca5a5; }
body.dark .badge.normal { background: #14532d; color: #86efac; }
body.dark .badge.hyper { background: #4a2f0f; color: #fcd34d; }
.actions button { padding: 6px 10px; margin-right: 4px; border: none; border-radius: 6px; cursor: pointer; font-size: .85rem; }
.actions .edit { background: #dbeafe; color: #1d4ed8; }
.actions .del { background: #fee2e2; color: #b91c1c; }
body.dark .actions .edit { background: #1e3a8a; color: #93c5fd; }
body.dark .actions .del { background: #4a1f1f; color: #fca5a5; }

/* TAGS */
.tags-section { display: flex; flex-direction: column; gap: 8px; }
.tags-label { font-size: .9rem; color: var(--text-secondary); font-weight: 600; }
.tags-checkboxes { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-check { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; background: var(--bg); border-radius: 20px; font-size: .85rem; cursor: pointer; border: 1px solid var(--border); color: var(--text); }
.tag-check input { margin: 0; }
.tag-check:has(input:checked) { background: var(--primary-light); border-color: var(--primary-ink); color: var(--primary-ink); font-weight: 600; }
.tag-pill { display: inline-block; padding: 2px 8px; background: var(--primary-light); color: var(--primary-ink); border-radius: 12px; font-size: .75rem; margin: 2px; }
textarea { padding: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: .95rem; font-family: inherit; resize: vertical; background: var(--bg); color: var(--text); }

/* CHART */
.chart-container { background: var(--bg-card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); height: 450px; position: relative; }
.legend { margin-top: 16px; display: flex; gap: 20px; font-size: .9rem; align-items: center; color: var(--text-secondary); flex-wrap: wrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; }
.dot.hypo { background: rgba(239,68,68,.5); }
.dot.normal { background: rgba(34,197,94,.5); }
.dot.hyper { background: rgba(245,158,11,.5); }

/* STATS */
.stats-filters { margin-bottom: 20px; }
.stats-filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat-card { background: var(--bg-card); padding: 18px; border-radius: 12px; box-shadow: var(--shadow); text-align: center; }
.stat-card.highlight { background: linear-gradient(135deg, var(--primary-btn), #764ba2); color: white; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary-ink); margin-bottom: 6px; }
.stat-card.highlight .stat-value { color: white; }
.stat-label { font-size: .85rem; color: var(--text-secondary); }
.stat-card.highlight .stat-label { color: rgba(255,255,255,.85); }
.status-bars { background: var(--bg-card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.status-bar-row { display: grid; grid-template-columns: 110px 1fr 60px; gap: 12px; align-items: center; color: var(--text-secondary); }
.status-name { font-size: .9rem; font-weight: 600; }
.bar-track { height: 24px; background: var(--bg); border-radius: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 12px; transition: width .4s ease; width: 0%; }
.bar-fill.hypo { background: linear-gradient(90deg, #ef4444, #f87171); }
.bar-fill.normal { background: linear-gradient(90deg, #22c55e, #4ade80); }
.bar-fill.hyper { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.bar-pct { text-align: right; font-weight: 600; font-size: .9rem; color: var(--text); }
html[dir="rtl"] .bar-pct { text-align: left; }
.tags-stats { display: flex; flex-wrap: wrap; gap: 10px; background: var(--bg-card); padding: 20px; border-radius: 12px; box-shadow: var(--shadow); }
.tags-stats p { width: 100%; }
.tag-stat-item { padding: 10px 16px; background: var(--primary-light); border-radius: 10px; display: flex; flex-direction: column; align-items: center; min-width: 110px; }
.tag-stat-item .tname { font-size: .85rem; color: var(--primary-ink); font-weight: 600; }
.tag-stat-item .tcount { font-size: 1.3rem; font-weight: 700; color: var(--text); }
.tag-stat-item .tavg { font-size: .75rem; color: var(--text-secondary); margin-top: 2px; }
/* ---- Statistiques multi-types : une section par type de mesure ---- */
.stats-body { display: flex; flex-direction: column; gap: 30px; }
.stats-section { display: flex; flex-direction: column; gap: 14px; }
.stats-type { display: flex; align-items: baseline; gap: 10px; font-size: 1.05rem; font-weight: 700; color: var(--text); margin: 0; padding-bottom: 10px; border-bottom: 2px solid var(--primary-light); }
.stats-type-unit { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.stats-sub { font-size: .9rem; font-weight: 600; color: var(--text-secondary); margin: 8px 0 0; }
.stats-empty { color: var(--text-muted); font-size: .88rem; margin: 0; }
.stats-grid-2 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat-card.good .stat-value { color: #16a34a; }
.stat-card.warn .stat-value { color: #d97706; }
.stats-table-wrap { overflow-x: auto; background: var(--bg-card); padding: 16px 20px; border-radius: 12px; box-shadow: var(--shadow); }
.stats-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.stats-table th, .stats-table td { padding: 9px 10px; text-align: center; border-bottom: 1px solid var(--border); }
.stats-table thead th { font-size: .76rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .4px; }
.stats-table tbody th { text-align: start; font-weight: 600; color: var(--text); }
.stats-table tbody tr:last-child th, .stats-table tbody tr:last-child td { border-bottom: none; }
.stats-table td { color: var(--text); font-weight: 600; }

/* CALENDRIER */
.calendar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; background: var(--bg-card); padding: 12px; border-radius: 12px; box-shadow: var(--shadow); }
.calendar-header button { padding: 8px 14px; background: var(--primary-btn); color: white; border: none; border-radius: 6px; cursor: pointer; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; background: var(--bg-card); padding: 12px; border-radius: 12px; box-shadow: var(--shadow); }
.cal-day { aspect-ratio: 1; padding: 6px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; cursor: pointer; font-size: .85rem; border: 1px solid transparent; color: var(--text); }
.cal-day:hover { background: var(--bg-hover); }
.cal-day.empty { cursor: default; }
.cal-day.today { border-color: var(--primary-ink); font-weight: 700; }
.cal-day.has-event { background: var(--primary-light); }
.cal-day .event-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); margin-top: 4px; }
.cal-header { font-weight: 600; text-align: center; padding: 6px; color: var(--text-secondary); }
.day-events { margin-top: 16px; background: var(--bg-card); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); }
.day-events:empty { display: none; }
.event-item { padding: 10px; border-left: 4px solid var(--primary); background: var(--bg-hover); border-radius: 6px; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; color: var(--text); }
html[dir="rtl"] .event-item { border-left: none; border-right: 4px solid var(--primary); }
.event-item button { background: #fee2e2; color: #b91c1c; border: none; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: .8rem; }

/* RAPPELS */
.reminder-card { background: var(--bg-card); padding: 14px 18px; border-radius: 10px; box-shadow: var(--shadow); margin-bottom: 10px; border-left: 5px solid var(--primary); color: var(--text); }
html[dir="rtl"] .reminder-card { border-left: none; border-right: 5px solid var(--primary); }
.reminder-card.overdue { border-left-color: var(--danger); background: rgba(239,68,68,.08); }
.reminder-card.today { border-left-color: var(--warning); background: rgba(245,158,11,.08); }
html[dir="rtl"] .reminder-card.overdue { border-right-color: var(--danger); }
html[dir="rtl"] .reminder-card.today { border-right-color: var(--warning); }
.reminder-card h4 { font-size: 1rem; margin-bottom: 4px; }
.reminder-card p { font-size: .9rem; color: var(--text-secondary); }
.reminder-card small { color: var(--text-muted); font-size: .8rem; }
.reminder-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-mini { padding: 6px 12px; font-size: .82rem; background: var(--bg-hover); color: var(--text); border: none; border-radius: 6px; cursor: pointer; }
.btn-mini:hover { filter: brightness(.96); }
.btn-mini.danger { background: var(--danger); color: white; }
#activeReminders:empty::after { content: attr(data-empty); color: var(--text-muted); font-style: italic; }
#upcomingReminders:empty::after { content: attr(data-empty); color: var(--text-muted); font-style: italic; }
#dbUpcomingEvents:empty::after { content: attr(data-empty); color: var(--text-muted); font-style: italic; }
#dbUpcomingEvents .reminder-card { padding: 10px 14px; margin-bottom: 8px; }
#dbUpcomingEvents .reminder-card h4 { font-size: .92rem; }

/* REPORT */
.report-controls { display: flex; gap: 12px; align-items: end; margin-bottom: 20px; flex-wrap: wrap; }
.report-controls label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--text-secondary); }
.report-controls input[type=month], .report-controls select { padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.report-preview { background: var(--bg-card); padding: 30px; border-radius: 12px; box-shadow: var(--shadow); min-height: 300px; color: var(--text); overflow-x: auto; }
.report-preview h1 { font-size: 1.5rem; margin-bottom: 8px; }
.report-preview h2 { font-size: 1.1rem; margin-top: 20px; margin-bottom: 10px; border-bottom: 2px solid var(--primary); padding-bottom: 6px; }
.report-preview .report-meta { color: var(--text-secondary); font-size: .9rem; margin-bottom: 20px; }
.report-preview table { width: 100%; margin-top: 10px; min-width: 400px; }
.report-preview .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 16px 0; }
.report-preview .kpi { padding: 12px; background: var(--bg); border-radius: 8px; text-align: center; }
.report-preview .kpi .v { font-size: 1.4rem; font-weight: 700; color: var(--primary-ink); }
.report-preview .kpi .l { font-size: .8rem; color: var(--text-secondary); }
.report-preview .report-section { margin-bottom: 28px; page-break-inside: avoid; }
.report-preview .report-chart { position: relative; height: 220px; margin: 14px 0 6px; }
.report-preview .report-chart canvas { width: 100% !important; height: 100% !important; }
@media print {
  .report-preview { box-shadow: none; padding: 20px 0; }
  .report-preview .report-chart { height: 190px; }
}

/* NOTIF BANNER */
.notif-banner { background: rgba(245,158,11,.15); border-left: 4px solid var(--warning); padding: 12px 20px; margin: 0; font-size: .9rem; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--text); }
html[dir="rtl"] .notif-banner { border-left: none; border-right: 4px solid var(--warning); }
.notif-banner button { padding: 6px 12px; border: none; border-radius: 6px; cursor: pointer; font-size: .85rem; }
.notif-banner #enableNotif { background: var(--warning); color: white; }

/* MODAL */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 999; padding: 20px; }
.modal-content { background: var(--bg-card); padding: 24px; border-radius: 12px; width: 420px; max-width: 100%; display: grid; gap: 12px; max-height: 90vh; overflow-y: auto; color: var(--text); position: relative; }
/* La modale de personnalisation contient les plages des 10 types reglables :
   en 420px elle scrollait dans tous les sens. On l'elargit, et les trois
   champs courts (sexe, cible, taille) passent sur une seule ligne. Les
   colonnes de la grille restent fluides pour que le bloc des plages, qui
   s'etale sur toute la largeur, conserve sa place ; c'est le contenu des
   trois champs qui est borne, sinon ils s'etirent sur 340px chacun. */
.modal-wide { width: min(1080px, 100%); grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
.modal-wide > .field-narrow { max-width: 250px; }
.modal-wide > h3, .modal-wide > .refs-block, .modal-wide > .modal-actions { grid-column: 1 / -1; }
.modal-wide .modal-actions { justify-content: flex-end; }
.modal-wide .modal-actions button { flex: 0 0 auto; min-width: 150px; }
/* Croix de fermeture, en haut a droite, toujours visible. */
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { background: var(--bg-hover); }
.modal-close:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.modal-wide h3, .modal-content h3 { padding-right: 44px; }
/* En arabe, la croix revient a gauche et le titre degage de ce cote. */
html[dir="rtl"] .modal-close { right: auto; left: 10px; }
html[dir="rtl"] .modal-wide h3,
html[dir="rtl"] .modal-content h3 { padding-right: 0; padding-left: 44px; }
.modal-content label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; color: var(--text-secondary); }
.modal-content input, .modal-content textarea { padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.modal-actions { display: flex; gap: 8px; margin-top: 8px; }
.modal-actions button { flex: 1; padding: 10px; border: none; border-radius: 8px; cursor: pointer; }
#saveEdit, #savePwd { background: var(--primary-btn); color: white; }
#saisieFeedback { margin-top: 10px; font-weight: 600; text-align: center; }
.pwd-feedback { min-height: 20px; font-size: .85rem; text-align: center; }
.modal-credit { margin-top: 14px; font-size: .72rem; color: var(--text-muted); text-align: center; }
.pwd-feedback.error { color: var(--danger); font-weight: 600; }
.pwd-feedback.success { color: var(--success); font-weight: 600; }

/* SELECTEUR D'HEURE (maison) */
.time-field {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 1rem; text-align: left; cursor: pointer;
}
.time-field:hover { background: var(--bg-hover); }
.time-field:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.time-field-value { font-variant-numeric: tabular-nums; }
.time-field-value.empty { color: var(--text-muted); }
.tp-modal { width: min(320px, 100%); }
.tp-columns { display: flex; align-items: center; justify-content: center; gap: 10px; }
.tp-col { flex: 1; }
.tp-list {
  position: relative; height: 210px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  scroll-snap-type: y proximity; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
.tp-item {
  scroll-snap-align: center; flex: 0 0 auto; padding: 9px 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--text); font-size: 1rem; font-variant-numeric: tabular-nums; cursor: pointer;
}
.tp-item:hover { background: var(--bg-hover); }
.tp-item.active { background: var(--primary-btn); color: #fff; }
.tp-sep { font-size: 1.5rem; font-weight: 700; color: var(--text-secondary); }
#tpClear { background: transparent; border: none; color: var(--text-muted); text-decoration: underline; cursor: pointer; font-size: .85rem; padding: 4px; }
#tpClear:hover { color: var(--text); }

/* SIDEBAR OVERLAY */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
.sidebar-overlay.active { display: block; }

.legend-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend-range { font-variant-numeric: tabular-nums; opacity: .85; }

/* RESPONSIVE */
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 0; left: 0; width: 260px; transform: translateX(-100%); box-shadow: 4px 0 24px rgba(0,0,0,.2); }
  html[dir="rtl"] .sidebar { left: auto; right: 0; transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .dashboard-row { grid-template-columns: 1fr; }
  .content-area { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 1.05rem; }
  .chart-container { height: 320px; }
  /* La modale large redevient une colonne : sur telephone, deux colonnes
     de tableaux de plages forceraient un defilement horizontal. */
  .modal-wide { grid-template-columns: 1fr; }
  .modal-wide .modal-actions { flex-direction: column; }
  .modal-wide .modal-actions button { width: 100%; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .login-box { padding: 18px 16px; }
  /* Les mentions ne sont plus masquees sur telephone : elles etaient
     simplement disparues. On les garde, plus compactes, et la mention de
     credit se centre pour ne pas deborder. */
  .login-features { gap: 7px; margin-top: 16px; }
  .login-features .feat { font-size: .72rem; padding: 5px 10px; }
  .login-credit {
    right: 50%; transform: translateX(50%); white-space: nowrap;
    font-size: .64rem; padding: 4px 10px; bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* ACCESSIBILITÉ : désactive les animations si demandé */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .001s !important; }
  .login-video { display: none; }
}

/* ---- BILANS : archivage des documents de laboratoire ---- */
.bilans-warning {
  margin-bottom: 12px; padding: 10px 12px; font-size: .82rem; line-height: 1.45;
  color: var(--text-secondary);
  background: var(--bg-hover); border: 1px solid var(--border);
  border-left: 3px solid var(--primary); border-radius: 8px;
}
.bilans-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.bilans-stats { font-size: .82rem; color: var(--text-muted); }
.bilans-space {
  margin-bottom: 12px; padding: 10px 12px; font-size: .84rem; color: var(--text);
  background: rgba(255,193,7,.14); border: 1px solid rgba(255,193,7,.5); border-radius: 8px;
}
.bilans-list { display: grid; gap: 14px; }
.bilans-empty { padding: 24px 12px; text-align: center; color: var(--text-muted); font-size: .88rem; }
.bilan-card { padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-card); color: var(--text); }
.bilan-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.bilan-card-title { margin: 0; font-size: 1rem; font-weight: 600; }
.bilan-card-meta { margin: 2px 0 0; font-size: .8rem; color: var(--text-muted); }
.bilan-doc-count { font-size: .76rem; color: var(--text-muted); white-space: nowrap; }
.bilan-card-note { margin: 8px 0; padding: 8px 10px; font-size: .84rem; color: var(--text-secondary); background: var(--bg-hover); border-radius: 8px; }
.bilan-card-values { margin: 8px 0; font-size: .84rem; color: var(--text-secondary); line-height: 1.6; }
.bilan-valeurs-vides { color: var(--text-muted); font-style: italic; }
.bilan-docs { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 0; }
.bilan-docs-vides { margin: 0; font-size: .82rem; color: var(--text-muted); font-style: italic; }
.bilan-doc { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 96px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-hover); }
.bilan-thumb { width: 100%; height: 74px; padding: 0; border: none; border-radius: 6px; background: var(--bg-card); cursor: pointer; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.bilan-thumb:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.bilan-thumb-img { width: 100%; height: 100%; object-fit: cover; }
.bilan-thumb-pdf { font-size: 1.7rem; }
.bilan-doc-name { font-size: .68rem; color: var(--text-secondary); text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bilan-doc-size { font-size: .64rem; color: var(--text-muted); }
.bilan-doc-flag { font-size: .7rem; }
.bilan-doc-actions { display: flex; flex-direction: column; gap: 4px; width: 100%; margin-top: 4px; }
.bilan-doc-actions button { font-size: .68rem; padding: 5px 4px; width: 100%; }
.bilan-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.bilan-actions button { font-size: .78rem; padding: 7px 10px; }
.bilan-actions button:disabled { opacity: .45; cursor: not-allowed; }
.bilan-banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 9px 12px;
  font-size: .84rem; color: var(--text);
  background: var(--bg-hover); border: 1px solid var(--primary); border-radius: 8px;
}
.bilan-link-list { display: grid; gap: 2px; max-height: 46vh; overflow-y: auto; }
.bilan-link-item { display: flex; align-items: center; gap: 10px; padding: 7px 9px; font-size: .86rem; cursor: pointer; border-radius: 6px; }
.bilan-link-item:hover { background: var(--bg-hover); }
.bilan-link-item time { margin-left: auto; font-size: .78rem; color: var(--text-muted); }
.modal-hint { margin: 0 0 10px; font-size: .82rem; color: var(--text-muted); }

.report-bilans { margin: 10px 0; padding: 10px 12px; border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: 8px; background: var(--bg-hover); }
.report-bilans p { margin: 2px 0; font-size: .85rem; color: var(--text-secondary); }
.photo-viewer { position: fixed; inset: 0; z-index: 1200; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.88); }
.photo-viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.photo-viewer-close { position: absolute; top: 14px; right: 16px; width: 38px; height: 38px; font-size: 1.15rem; color: #fff; background: rgba(255,255,255,.14); border: none; border-radius: 50%; cursor: pointer; }


/* PRINT : rapport opaque et lisible à l'impression / PDF */
@media print {
  body * { visibility: hidden; }
  #reportPreview, #reportPreview * { visibility: visible; }
  #reportPreview { position: absolute; left: 0; top: 0; width: 100%; box-shadow: none; padding: 0; background: #fff !important; -webkit-backdrop-filter: none; backdrop-filter: none; }
  #reportPreview table, #reportPreview .kpi { background: #fff !important; }
  .sidebar, .topbar, .notif-banner, .report-controls { display: none !important; }
}