/* VARIABLES */
:root {
  --bg: rgba(255,255,255,.50); --bg-card: rgba(255,255,255,.55); --bg-hover: rgba(255,255,255,.72);
  --text: #222222; --text-secondary: #555555; --text-muted: #777777;
  --border: rgba(136,146,156,.30); --border-light: rgba(255,255,255,.20);
  --primary: #6f9eb5; --primary-hover: #5e8ba3; --primary-light: #eaf3f7;
  --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(15,22,28,.82); --sidebar-text: #c8d2da;
  --sidebar-active: #6f9eb5; --sidebar-hover: rgba(40,53,63,.7);
}
body.dark {
  --bg: rgba(38,50,62,.50); --bg-card: rgba(30,42,54,.55); --bg-hover: rgba(46,60,74,.65);
  --text: #f2f4fa; --text-secondary: #e2e6f0; --text-muted: #d2d8e2;
  --border: rgba(190,205,220,.22); --border-light: rgba(220,235,250,.12);
  --primary: #8fb7cc; --primary-hover: #7ba6bc; --primary-light: #2a3942;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --shadow-lg: 0 20px 40px rgba(0,0,0,.5);
  --sidebar-bg: rgba(12,17,22,.82); --sidebar-text: #e2e6f0;
  --sidebar-active: #8fb7cc; --sidebar-hover: rgba(38,54,64,.7);
}

/* 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); }
.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); 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); }
.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: #16262e;
  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; }

.login-box {
  background: rgba(255,255,255,.12);
  padding: 20px 18px; border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  width: 290px; max-width: 100%; text-align: center;
  border: 1px solid rgba(255,255,255,.25);
  backdrop-filter: blur(4px);
}
.login-logo {
  font-size: 1.9rem; margin-bottom: 4px; display: inline-block;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.3));
}
.login-box h1 {
  margin-bottom: 4px; font-size: 1.1rem; color: #ffffff;
  text-shadow: 0 2px 10px rgba(0,0,0,.4);
}
.login-box p { color: rgba(255,255,255,.92); margin-bottom: 14px; font-size: .8rem; }
.login-box input {
  width: 100%; padding: 8px; margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,.3); border-radius: 9px; font-size: .88rem;
  background: rgba(255,255,255,.85); color: #222;
}
.login-box input:focus {
  outline: none; border-color: #fff;
  background: #fff;
}
.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; }
.reset-link { color: #fff; font-weight: 600; cursor: pointer; text-decoration: underline; }
.login-features { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; justify-content: center; }
.login-features .feat {
  background: rgba(255,255,255,.12); color: white; padding: 6px 12px; border-radius: 18px;
  font-size: .8rem; backdrop-filter: blur(6px); border: 1px solid rgba(255,255,255,.18);
}
.login-credit {
  position: absolute; right: 20px; left: auto;
  bottom: max(14px, env(safe-area-inset-bottom));
  font-size: .72rem; color: rgba(255,255,255,.78);
  text-align: right; z-index: 1; pointer-events: none;
}
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), #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); 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); color: var(--primary); }

/* 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); }
form button { padding: 12px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 1rem; cursor: pointer; font-weight: 600; }
form button:hover { background: var(--primary-hover); }
.btn-secondary { padding: 10px 16px; background: var(--border); 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); color: white; border: none; border-radius: 8px; cursor: pointer; font-weight: 600; }

/* 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; }
table { width: 100%; background: var(--bg-card); border-radius: 12px; overflow: hidden; border-collapse: collapse; box-shadow: var(--shadow); min-width: 600px; }
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); color: var(--primary); font-weight: 600; }
.tag-pill { display: inline-block; padding: 2px 8px; background: var(--primary-light); color: var(--primary); 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), #764ba2); color: white; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); 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); 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); 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); 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; }
#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] { 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); }
.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); }
.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); 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; }

/* SIDEBAR OVERLAY */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }
.sidebar-overlay.active { display: block; }

/* 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; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .login-features { display: none; }
  .login-box { padding: 18px 16px; }
}

/* 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; }
}

/* 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; }
}