/* ==========================================================================
   Kènèya Sô — système de design (CDC 7.3 : interface sobre et cohérente).
   Vient par-dessus Bootstrap 5 : tokens de couleur/typo, mise en page en
   barre latérale, et un habillage plus soigné des composants (cartes,
   tableaux, badges, boutons) qu'un thème Bootstrap par défaut.
   ========================================================================== */

:root {
  /* --- Marque --- */
  --ks-primary: #16294f;
  --ks-primary-dark: #0d1a33;
  --ks-primary-light: #22396b;
  --ks-accent: #0d9488;
  --ks-accent-dark: #0b7a70;

  /* --- Neutres --- */
  --ks-bg: #f5f6fa;
  --ks-surface: #ffffff;
  --ks-border: #e4e7ef;
  --ks-text: #1c2233;
  --ks-text-muted: #667085;

  /* --- Sémantique (alignées sur les teintes Bootstrap, affinées) --- */
  --ks-success: #15803d;
  --ks-warning: #b45309;
  --ks-danger: #b91c1c;
  --ks-info: #1d4ed8;

  /* --- Rythme --- */
  --ks-radius-sm: 8px;
  --ks-radius: 12px;
  --ks-radius-lg: 16px;
  --ks-shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --ks-shadow: 0 2px 8px rgba(16, 24, 40, .08);
  --ks-shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --ks-sidebar-w: 17rem;

  /* Palette d'accent par module (fond clair + premier-plan), pour les puces
     d'icône du tableau de bord et de la barre latérale. */
  --ks-a-bleu-bg: #e7f0ff;   --ks-a-bleu-fg: #2563eb;
  --ks-a-indigo-bg: #ece9fe; --ks-a-indigo-fg: #6366f1;
  --ks-a-cyan-bg: #e0f7fa;   --ks-a-cyan-fg: #0891b2;
  --ks-a-rose-bg: #fde9ef;   --ks-a-rose-fg: #e11d48;
  --ks-a-violet-bg: #f3e8ff; --ks-a-violet-fg: #9333ea;
  --ks-a-ambre-bg: #fef3e0;  --ks-a-ambre-fg: #d97706;
  --ks-a-teal-bg: #e6fbf8;   --ks-a-teal-fg: #0d9488;
  --ks-a-vert-bg: #e8f8ee;   --ks-a-vert-fg: #16a34a;
  --ks-a-slate-bg: #eef1f5;  --ks-a-slate-fg: #475569;

  --bs-primary: var(--ks-primary);
  --bs-primary-rgb: 22, 41, 79;
  --bs-body-font-family: "Inter", "Segoe UI", "Noto Sans Arabic", system-ui, sans-serif;
}

html[lang="ar"], [dir="rtl"] {
  --bs-body-font-family: "Cairo", "Inter", "Segoe UI", system-ui, sans-serif;
}

body {
  background:
    radial-gradient(70rem 30rem at 100% -10%, rgba(13, 148, 136, .06), transparent 60%),
    var(--ks-bg);
  color: var(--ks-text);
  font-family: var(--bs-body-font-family);
  font-optical-sizing: auto;
}

/* Défilement plus discret (Chrome/Edge/Safari) ; navigateurs sans support
   ignorent silencieusement ces règles — pas de repli nécessaire. */
* { scrollbar-color: var(--ks-border) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ks-border); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--ks-text-muted); }
.app-sidebar ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .18); }
.app-sidebar ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .3); }

@media (prefers-reduced-motion: no-preference) {
  .app-content { animation: ks-entree .25s ease-out; }
}
@keyframes ks-entree {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

h1, h2, h3, h4, h5, h6, .navbar-brand {
  font-weight: 700;
  letter-spacing: -.01em;
}

a { color: var(--ks-primary); }
code { color: var(--ks-accent-dark); background: var(--ks-a-teal-bg); padding: .1em .4em; border-radius: 6px; }

/* ==========================================================================
   Mise en page : barre latérale + zone de contenu
   ========================================================================== */

.auth-shell { min-height: 100vh; background: var(--ks-surface); }

.auth-grid {
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  min-height: 100vh;
}

.auth-showcase {
  position: relative;
  display: flex;
  align-items: center;
  padding: 3rem;
  color: #fff;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(13, 148, 136, .4), transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(34, 57, 107, .6), transparent 50%),
    var(--ks-primary-dark);
}
.auth-showcase::before {
  /* Grille discrète en fond, pour une texture plus "produit" qu'un aplat uni. */
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 30% 30%, #000 0%, transparent 70%);
}
.auth-showcase-inner { position: relative; max-width: 27rem; margin-inline: auto; }
.auth-showcase .brand-mark { width: 52px; height: 52px; margin-bottom: 1.75rem; }
.auth-showcase-title { font-size: clamp(1.75rem, 2.4vw, 2.15rem); font-weight: 700; margin-bottom: .6rem; letter-spacing: -.02em; }
.auth-showcase-tag { color: rgba(255, 255, 255, .8); font-size: 1.02rem; margin-bottom: 2.75rem; max-width: 24rem; }

.auth-showcase-features { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 1.1rem; }
.auth-showcase-features li { display: flex; align-items: center; gap: .85rem; font-size: .92rem; color: rgba(255, 255, 255, .92); }
.auth-showcase-features i {
  width: 2.3rem; height: 2.3rem; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .14);
  border-radius: var(--ks-radius-sm); font-size: 1.05rem;
}

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 2rem 1.5rem; }

[dir="rtl"] .auth-showcase { order: 2; }
[dir="rtl"] .auth-panel { order: 1; }

@media (max-width: 991.98px) {
  .auth-grid { grid-template-columns: 1fr; }
  .auth-showcase { display: none; }
  [dir="rtl"] .auth-showcase, [dir="rtl"] .auth-panel { order: initial; }
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  position: fixed;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: var(--ks-sidebar-w);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform .2s ease;
  /* Fond « premium » : bleu nuit profond, halo turquoise en haut, lueur indigo en bas. */
  background:
    radial-gradient(120% 55% at 0% 0%, rgba(13, 148, 136, .28) 0%, transparent 60%),
    radial-gradient(90% 45% at 100% 100%, rgba(99, 102, 241, .18) 0%, transparent 65%),
    linear-gradient(185deg, #17305e 0%, #0e1d3c 55%, #0a1429 100%);
  border-inline-end: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 4px 0 24px rgba(10, 20, 41, .18);
}
[dir="rtl"] .app-sidebar { box-shadow: -4px 0 24px rgba(10, 20, 41, .18); }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1rem .85rem .35rem;
  padding: .85rem .9rem;
  border-radius: var(--ks-radius);
  background: linear-gradient(135deg, rgba(255, 255, 255, .10), rgba(255, 255, 255, .03));
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

.sidebar-brand .brand-mark {
  width: 36px; height: 36px; flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(13, 148, 136, .55));
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 1.05rem; color: #fff; line-height: 1.15; letter-spacing: -.01em; }
.sidebar-brand .brand-text { min-width: 0; }
/* Nom de l'hôpital connecté : sur deux lignes au plus, coupé proprement au-delà. */
.sidebar-brand .brand-hopital {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: .95rem;
}
.sidebar-brand .brand-tag { display: block; margin-top: .15rem; font-size: .64rem; font-weight: 600; color: #5eead4; letter-spacing: .09em; text-transform: uppercase; }

.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: .5rem .85rem 1rem;
}

.sidebar-section {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .38);
  padding: 1.15rem .4rem .45rem;
}
.sidebar-section::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, rgba(255, 255, 255, .14), transparent);
}
[dir="rtl"] .sidebar-section::after { background: linear-gradient(270deg, rgba(255, 255, 255, .14), transparent); }

/* Couleur d'accent de chaque module (réutilise la palette du tableau de bord). */
.tone-bleu { --tone: var(--ks-a-bleu-fg); }
.tone-indigo { --tone: var(--ks-a-indigo-fg); }
.tone-cyan { --tone: var(--ks-a-cyan-fg); }
.tone-rose { --tone: var(--ks-a-rose-fg); }
.tone-violet { --tone: var(--ks-a-violet-fg); }
.tone-ambre { --tone: var(--ks-a-ambre-fg); }
.tone-teal { --tone: #2dd4bf; }
.tone-vert { --tone: var(--ks-a-vert-fg); }
.tone-slate { --tone: #94a3b8; }

.sidebar-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .42rem .55rem;
  margin-block-end: .2rem;
  border-radius: 10px;
  color: rgba(255, 255, 255, .78);
  text-decoration: none;
  font-size: .88rem;
  font-weight: 500;
  transition: background-color .15s ease, color .15s ease, transform .15s ease;
}

.nav-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex-shrink: 0;
  border-radius: 9px;
  font-size: 1rem;
  background: color-mix(in srgb, var(--tone, #94a3b8) 20%, transparent);
  color: color-mix(in srgb, var(--tone, #94a3b8) 55%, #fff);
  transition: background-color .15s ease, color .15s ease, box-shadow .15s ease;
}

.sidebar-link:hover {
  background: rgba(255, 255, 255, .07);
  color: #fff;
}
.sidebar-link:hover .nav-chip {
  background: color-mix(in srgb, var(--tone, #94a3b8) 32%, transparent);
}
@media (prefers-reduced-motion: no-preference) {
  .sidebar-link:hover { transform: translateX(2px); }
  [dir="rtl"] .sidebar-link:hover { transform: translateX(-2px); }
}

.sidebar-link.active {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(90deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .04));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
}
[dir="rtl"] .sidebar-link.active { background: linear-gradient(270deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .04)); }
.sidebar-link.active::before {
  content: "";
  position: absolute;
  inset-inline-start: -.85rem;
  top: 22%;
  bottom: 22%;
  width: 4px;
  border-radius: 0 4px 4px 0;
  background: var(--tone, #2dd4bf);
  box-shadow: 0 0 12px var(--tone, #2dd4bf);
}
[dir="rtl"] .sidebar-link.active::before { border-radius: 4px 0 0 4px; }
.sidebar-link.active .nav-chip {
  background: var(--tone, #2dd4bf);
  color: #0a1429;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--tone, #2dd4bf) 55%, transparent);
}
.sidebar-link:focus-visible { outline: 2px solid #5eead4; outline-offset: 2px; }

.sidebar-footer {
  padding: .85rem .85rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .6rem .7rem;
  border-radius: var(--ks-radius);
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
}
.sidebar-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  flex-shrink: 0;
  border-radius: 50%;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(135deg, #0d9488, #6366f1);
  box-shadow: 0 4px 12px rgba(13, 148, 136, .35);
}
.sidebar-user-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.sidebar-user-name { font-size: .84rem; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: .7rem; color: rgba(255, 255, 255, .55); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-copy { margin-top: .7rem; text-align: center; font-size: .66rem; letter-spacing: .04em; color: rgba(255, 255, 255, .32); }

.app-main {
  flex: 1 1 auto;
  margin-inline-start: var(--ks-sidebar-w);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .65rem 1.5rem;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--ks-border);
  box-shadow: 0 1px 0 rgba(16, 24, 40, .02), 0 6px 20px rgba(16, 24, 40, .04);
}

.app-content {
  flex: 1 1 auto;
  padding: 1.75rem;
  max-width: 1600px;
  width: 100%;
}

.app-footer {
  padding: 1.25rem 1.75rem;
  color: var(--ks-text-muted);
  font-size: .8rem;
  text-align: center;
}

.sidebar-toggle {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  color: var(--ks-text);
  line-height: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 1025;
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-105%); }
  [dir="rtl"] .app-sidebar { transform: translateX(105%); }
  .app-shell.sidebar-open .app-sidebar { transform: translateX(0); }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  .app-main { margin-inline-start: 0; }
  .app-content { padding: 1.15rem; }
}

@media (min-width: 992px) {
  .sidebar-toggle { display: none; }
}

/* ==========================================================================
   Composants
   ========================================================================== */

.card {
  border: 1px solid var(--ks-border);
  border-radius: var(--ks-radius);
  box-shadow: var(--ks-shadow-sm);
  transition: box-shadow .15s ease;
}

.card-header {
  font-weight: 600;
  background: var(--ks-surface);
  border-bottom: 1px solid var(--ks-border);
}

.shadow-sm { box-shadow: var(--ks-shadow-sm) !important; }

.btn {
  border-radius: var(--ks-radius-sm);
  font-weight: 500;
  transition: transform .1s ease, box-shadow .15s ease, background-color .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--ks-primary);
  border-color: var(--ks-primary);
  box-shadow: 0 1px 2px rgba(22, 41, 79, .15);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--ks-primary-dark);
  border-color: var(--ks-primary-dark);
  box-shadow: 0 4px 12px rgba(22, 41, 79, .25);
}
.btn-outline-primary { color: var(--ks-primary); border-color: var(--ks-primary); }
.btn-outline-primary:hover { background: var(--ks-primary); border-color: var(--ks-primary); }

.form-control, .form-select {
  border-radius: var(--ks-radius-sm);
  border-color: var(--ks-border);
}
.form-control:focus, .form-select:focus {
  border-color: var(--ks-accent);
  box-shadow: 0 0 0 .2rem rgba(13, 148, 136, .15);
}

.table { --bs-table-bg: transparent; }
.table > thead {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ks-text-muted);
  border-bottom-width: 1px;
}
.table > :not(caption) > * > * { padding: .7rem .9rem; }
.table-hover > tbody > tr { transition: background-color .1s ease; }
.table-hover > tbody > tr:hover > * { --bs-table-accent-bg: var(--ks-a-teal-bg); }

.pagination .page-link {
  border-radius: 999px;
  margin-inline: .15rem;
  border-color: var(--ks-border);
  color: var(--ks-text);
}
.pagination .page-item.active .page-link {
  background: var(--ks-primary);
  border-color: var(--ks-primary);
}
.pagination .page-item.disabled .page-link { border-color: transparent; }

.badge { font-weight: 600; letter-spacing: .01em; border-radius: 999px; padding-inline: .7em; padding-block: .38em; }

/* Badges en "pastille douce" (fond clair + texte teinté) plutôt qu'en aplat
   saturé — plus proche d'un design system SaaS moderne, tout en gardant les
   classes Bootstrap déjà utilisées partout dans les gabarits (aucun gabarit
   à modifier). */
.badge.text-bg-success { background: var(--ks-a-vert-bg) !important;  color: var(--ks-success) !important; }
.badge.text-bg-warning { background: var(--ks-a-ambre-bg) !important; color: var(--ks-warning) !important; }
.badge.text-bg-danger  { background: var(--ks-a-rose-bg) !important;  color: var(--ks-danger) !important; }
.badge.text-bg-info    { background: var(--ks-a-bleu-bg) !important;  color: var(--ks-info) !important; }
.badge.text-bg-secondary { background: var(--ks-a-slate-bg) !important; color: var(--ks-text-muted) !important; }
.badge.text-bg-light   { background: var(--ks-bg) !important; color: var(--ks-text-muted) !important; border-color: var(--ks-border) !important; }

.breadcrumb { font-size: .82rem; }

/* Fiches détail : libellé au-dessus de la valeur plutôt que côte à côte —
   beaucoup plus lisible que le grid Bootstrap par défaut dans une carte
   étroite (deux cartes par ligne à côté de la barre latérale). S'applique à
   tout `<dl class="row">…<dt class="col-*">…<dd class="col-*">` existant,
   sans toucher aux gabarits. */
dl.row { row-gap: .1rem; }
dl.row dt {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  margin-top: .6rem;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--ks-text-muted);
}
dl.row dd {
  flex: 0 0 100% !important;
  max-width: 100% !important;
  margin-bottom: 0;
  margin-inline-start: 0; /* RTL : la marge par défaut du navigateur est logique, celle de Bootstrap physique */
}
dl.row dt:first-child { margin-top: 0; }

/* Puce d'icône colorée (cartes du tableau de bord, en-têtes de section). */
.icon-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: var(--ks-radius-sm);
  font-size: 1.25rem;
  flex-shrink: 0;
}
.icon-chip-sm { width: 2.1rem; height: 2.1rem; font-size: 1rem; }

.icon-chip-bleu   { background: var(--ks-a-bleu-bg);   color: var(--ks-a-bleu-fg); }
.icon-chip-indigo { background: var(--ks-a-indigo-bg); color: var(--ks-a-indigo-fg); }
.icon-chip-cyan   { background: var(--ks-a-cyan-bg);   color: var(--ks-a-cyan-fg); }
.icon-chip-rose   { background: var(--ks-a-rose-bg);   color: var(--ks-a-rose-fg); }
.icon-chip-violet { background: var(--ks-a-violet-bg); color: var(--ks-a-violet-fg); }
.icon-chip-ambre  { background: var(--ks-a-ambre-bg);  color: var(--ks-a-ambre-fg); }
.icon-chip-teal   { background: var(--ks-a-teal-bg);   color: var(--ks-a-teal-fg); }
.icon-chip-vert   { background: var(--ks-a-vert-bg);   color: var(--ks-a-vert-fg); }
.icon-chip-slate  { background: var(--ks-a-slate-bg);  color: var(--ks-a-slate-fg); }

/* Tableau de bord : bandeau d'accueil */
.dash-hero {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1.75rem 2rem;
  border-radius: var(--ks-radius-lg);
  color: #fff;
  background:
    radial-gradient(circle at 88% 15%, rgba(13, 148, 136, .55), transparent 55%),
    linear-gradient(120deg, var(--ks-primary) 0%, var(--ks-primary-dark) 100%);
}
.dash-hero-eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: rgba(255, 255, 255, .65); margin-bottom: .35rem; }
.dash-hero-title { font-size: 1.6rem; margin-bottom: .3rem; }
.dash-hero-sub { color: rgba(255, 255, 255, .82); margin-bottom: 0; }
.dash-hero-role {
  flex-shrink: 0;
  padding: .5rem 1.1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .2);
  font-weight: 600;
  font-size: .85rem;
  white-space: nowrap;
}
@media (max-width: 575.98px) { .dash-hero { flex-direction: column; align-items: flex-start; } }

/* Carte de module du tableau de bord */
.module-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  text-decoration: none;
  color: inherit;
  padding: 1.15rem 1.15rem 1.15rem 1.35rem;
  height: 100%;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.module-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px;
  background: var(--chip-fg, var(--ks-accent));
  opacity: 0; transition: opacity .12s ease;
}
.module-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--ks-shadow);
  border-color: var(--ks-accent);
}
.module-card:hover::before { opacity: 1; }
.module-card:hover .bi-chevron-right { transform: translateX(3px); }
[dir="rtl"] .module-card:hover .bi-chevron-right { transform: translateX(-3px) scaleX(-1); }
.module-card .module-title { font-weight: 600; color: var(--ks-text); margin-bottom: .15rem; }
.module-card .module-sub { color: var(--ks-text-muted); font-size: .82rem; }
.module-card .bi-chevron-right { color: var(--ks-text-muted); margin-inline-start: auto; align-self: center; transition: transform .12s ease; }

.module-card-bleu   { --chip-fg: var(--ks-a-bleu-fg); }
.module-card-indigo { --chip-fg: var(--ks-a-indigo-fg); }
.module-card-cyan   { --chip-fg: var(--ks-a-cyan-fg); }
.module-card-rose   { --chip-fg: var(--ks-a-rose-fg); }
.module-card-violet { --chip-fg: var(--ks-a-violet-fg); }
.module-card-ambre  { --chip-fg: var(--ks-a-ambre-fg); }
.module-card-teal   { --chip-fg: var(--ks-a-teal-fg); }
.module-card-vert   { --chip-fg: var(--ks-a-vert-fg); }
.module-card-slate  { --chip-fg: var(--ks-a-slate-fg); }

/* Cartes indicateur (statistiques / KPI) */
.stat-card { padding: 1.15rem 1.3rem; position: relative; overflow: hidden; }
.stat-card::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px;
  background: var(--ks-accent);
}
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; color: var(--ks-primary); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-card .stat-label { color: var(--ks-text-muted); font-size: .8rem; }

/* Notifications */
.bell-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  color: var(--ks-text);
  font-size: 1.15rem;
  text-decoration: none;
}
.bell-btn:hover { background: var(--ks-border); }

/* Panneau de formulaire (connexion, configuration initiale) — le panneau
   `.auth-panel` fournit déjà le fond ; la carte ne fait que borner la largeur. */
.auth-card { width: 100%; max-width: 24rem; }
.auth-card .brand-mark { width: 40px; height: 40px; margin-bottom: 1.1rem; }
.auth-card h1 { font-size: 1.6rem; }

[dir="rtl"] .module-card .bi-chevron-right { transform: scaleX(-1); display: inline-block; }

/* RTL : Bootstrap standard (non-rtl.css) code .text-end/.text-start en valeurs
   physiques (right/left) ; on les repasse en logique pour un vrai miroir RTL
   (.text-end = bord de fin de ligne = gauche en arabe, pas toujours la droite). */
[dir="rtl"] .text-end { text-align: end !important; }
[dir="rtl"] .text-start { text-align: start !important; }

/* Bascule afficher/masquer un mot de passe (comportement : static/js/app.js,
   appliqué automatiquement à tout input[type=password] de la page). */
.password-field { position: relative; }
.password-field input { padding-inline-end: 2.75rem; }
.password-toggle {
  position: absolute;
  top: 50%;
  inset-inline-end: .35rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 0;
  background: transparent;
  color: var(--ks-text-muted);
  border-radius: 999px;
  line-height: 1;
}
.password-toggle:hover { background: var(--ks-border); color: var(--ks-text); }
.password-toggle:focus-visible { outline: 2px solid var(--ks-accent); outline-offset: 1px; }


/* ==========================================================================
   Adaptation à tous les appareils (téléphone étroit → très grand écran)
   ========================================================================== */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img, svg, video, canvas { max-width: 100%; }
input[type="file"] { max-width: 100%; }
.form-control, .form-select { min-width: 0; }

/* Très grands écrans : le contenu reste centré et de largeur lisible. */
.app-content { margin-inline: auto; }

/* Encoches (iPhone, Android) : ne rien coller sous la barre système. */
.app-topbar { padding-top: max(.65rem, env(safe-area-inset-top)); }
.app-sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

/* En-têtes de page (titre + actions) et barres d'outils : passent à la ligne
   au lieu de déborder de l'écran. S'applique à tous les gabarits existants. */
.app-content .d-flex.justify-content-between { flex-wrap: wrap; gap: .75rem; }
.app-content .d-flex.gap-2, .app-content .d-flex.gap-3 { flex-wrap: wrap; }
.app-content h1, .app-content h2, .app-content h3 { overflow-wrap: anywhere; }
.app-content .card-body, .app-content dd { overflow-wrap: anywhere; }
.table-responsive .table td, .table-responsive .table th { min-width: 4.5rem; }

/* Menu latéral en tiroir : largeur bornée, défilement interne, verrou du fond. */
.app-sidebar { max-width: 85vw; overscroll-behavior: contain; }
body.sidebar-locked { overflow: hidden; }

/* Filtres en ligne (ex. select .w-auto) : pleine largeur sur téléphone. */
@media (max-width: 575.98px) {
  .app-topbar { padding-inline: .75rem; gap: .5rem; }
  .app-topbar .form-select { max-width: 6.5rem; padding-inline-end: 1.5rem; font-size: .8rem; }
  .app-topbar .border-start { padding-inline-start: 0 !important; border: 0 !important; }
  .app-content { padding: .9rem .75rem; }
  .app-footer { padding: 1rem .75rem; }
  .app-content h1, .app-content .h3 { font-size: 1.3rem; }
  .app-content .form-select.w-auto, .app-content .form-control.w-auto { width: 100% !important; }
  /* En-tête de page : le titre prend toute la largeur, les actions passent dessous. */
  .app-content > .d-flex.justify-content-between { flex-direction: column; align-items: stretch !important; }
  .app-content .d-flex.justify-content-between > .d-flex { width: 100%; }
  .app-content .d-flex.justify-content-between > .d-flex > .btn { flex: 1 1 auto; }
  .stat-card .stat-value { font-size: 1.4rem; }
  .dash-hero { padding: 1.25rem; }
  .dash-hero-title { font-size: 1.3rem; }
  .modal-dialog { margin: .5rem; }
}

/* Tablettes : deux colonnes de cartes restent lisibles, marges réduites. */
@media (min-width: 576px) and (max-width: 991.98px) {
  .app-content { padding: 1.25rem; }
}

/* Écrans tactiles : cibles d'au moins 44 px et champs sans zoom automatique iOS. */
@media (pointer: coarse) {
  .btn, .form-control, .form-select { min-height: 2.75rem; }
  .btn-sm { min-height: 2.5rem; padding-inline: .8rem; }
  input, select, textarea { font-size: 1rem !important; }
  .sidebar-link { padding-block: .72rem; }
  .password-toggle { width: 2.6rem; height: 2.6rem; }
  .pagination .page-link { min-width: 2.5rem; min-height: 2.5rem; display: inline-flex; align-items: center; justify-content: center; }
  .bell-btn, .sidebar-toggle { min-width: 2.75rem; min-height: 2.75rem; display: inline-flex; align-items: center; justify-content: center; }
}

/* Paysage sur téléphone (peu de hauteur) : en-tête de menu compact. */
@media (max-height: 480px) and (orientation: landscape) {
  .sidebar-brand { padding: .6rem 1rem; }
  .sidebar-link { padding-block: .4rem; }
  .auth-panel { align-items: flex-start; padding-block: 1.25rem; }
}

/* Impression (dossiers, factures) : pas de menu ni de barre. */
@media print {
  .app-sidebar, .app-topbar, .app-footer, .sidebar-backdrop, .btn, .pagination { display: none !important; }
  .app-main { margin: 0 !important; }
  .app-content { padding: 0; max-width: none; animation: none; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

/* Mouvement réduit : pas d'animations superflues. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Tableaux → cartes sur téléphone (static/js/app.js pose data-label sur chaque cellule) :
   chaque ligne devient une carte « libellé : valeur », lisible sans défilement latéral. */
@media (max-width: 575.98px) {
  .table-cards thead { display: none; }
  .table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards { border: 0; }
  .table-cards tbody tr {
    background: var(--ks-surface);
    border: 1px solid var(--ks-border);
    border-radius: var(--ks-radius);
    padding: .4rem .9rem;
    margin-bottom: .75rem;
    box-shadow: var(--ks-shadow-sm);
  }
  .table-cards td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
    padding: .4rem 0 !important; border: 0 !important; text-align: end; min-width: 0;
    overflow-wrap: anywhere; background: transparent !important;
  }
  .table-cards td + td { border-top: 1px dashed var(--ks-border) !important; }
  .table-cards td::before {
    content: attr(data-label);
    flex-shrink: 0; max-width: 45%; text-align: start;
    font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
    color: var(--ks-text-muted);
  }
  .table-cards td[data-label=""]::before, .table-cards td:not([data-label])::before { display: none; }
  .table-cards td[data-label=""] { justify-content: flex-end; }
  .table-cards td[colspan] { justify-content: center; text-align: center; }
  .card > .table-responsive { border-radius: var(--ks-radius); }
  .card:has(> .table-responsive > .table-cards) { background: transparent; border: 0; box-shadow: none; }
}


/* Champ piège à robots : invisible mais en place (un décalage hors écran, lui,
   rendrait la page défilable de ~10 000 px en lecture droite-à-gauche). */
.champ-piege {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap; opacity: 0; pointer-events: none;
}


/* ==========================================================================
   Console propriétaire — écran du super-administrateur de la plateforme.
   Sans barre latérale : en-tête sombre premium (même habillage que le menu
   de l'application) et navigation en pastilles : établissements, utilisateurs, plans, journal.
   ========================================================================== */
.owner-content { max-width: 68rem; margin-inline: auto; }
.owner-shell {
  min-height: 100vh;
  background:
    radial-gradient(70rem 30rem at 100% -10%, rgba(13, 148, 136, .06), transparent 60%),
    var(--ks-bg);
}

/* En-tête sombre (même fond que la barre latérale de l'application) */
.owner-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  padding: .85rem 1.5rem 0;
  color: #fff;
  background:
    radial-gradient(60% 140% at 0% 0%, rgba(13, 148, 136, .30) 0%, transparent 62%),
    radial-gradient(50% 120% at 100% 100%, rgba(99, 102, 241, .20) 0%, transparent 65%),
    linear-gradient(100deg, #17305e 0%, #0e1d3c 60%, #0a1429 100%);
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  box-shadow: 0 8px 28px rgba(10, 20, 41, .22);
}
.owner-topbar-row {
  display: flex;
  align-items: center;
  gap: .85rem;
  flex-wrap: wrap;
  max-width: 62rem;
  margin-inline: auto;
}
.owner-topbar .brand-mark {
  width: 34px; height: 34px; flex-shrink: 0;
  filter: drop-shadow(0 4px 12px rgba(13, 148, 136, .55));
}
.owner-topbar-brand { display: flex; align-items: center; gap: .7rem; text-decoration: none; color: inherit; margin-inline-end: auto; }
.owner-topbar-brand:hover { color: inherit; }
.owner-topbar-brand strong { display: block; font-weight: 700; color: #fff; line-height: 1.15; letter-spacing: -.01em; }
.owner-topbar-brand span span { display: block; margin-top: .1rem; font-size: .64rem; font-weight: 600; color: #5eead4; letter-spacing: .09em; text-transform: uppercase; }

.owner-lang {
  color: #fff;
  background-color: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .14);
}
.owner-lang option { color: var(--ks-text); }
.owner-lang:focus { border-color: #5eead4; box-shadow: 0 0 0 .2rem rgba(94, 234, 212, .2); }

.owner-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .3rem .4rem .3rem .35rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .10);
}
.owner-user-name { font-size: .82rem; font-weight: 600; color: #fff; padding-inline-end: .15rem; }
.owner-logout {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem;
  border: 0; border-radius: 50%;
  color: rgba(255, 255, 255, .8);
  background: rgba(255, 255, 255, .08);
  transition: background-color .15s ease, color .15s ease;
}
.owner-logout:hover { background: rgba(244, 63, 94, .85); color: #fff; }
.owner-logout:focus-visible { outline: 2px solid #5eead4; outline-offset: 2px; }

/* Navigation en pastilles (remplace la barre latérale) */
.owner-nav {
  display: flex;
  gap: .35rem;
  max-width: 62rem;
  margin: .85rem auto 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.owner-nav::-webkit-scrollbar { display: none; }
.owner-nav-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  flex-shrink: 0;
  padding: .5rem .8rem .55rem .5rem;
  border-radius: 10px 10px 0 0;
  color: rgba(255, 255, 255, .72);
  text-decoration: none;
  font-size: .86rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}
.owner-nav-link .nav-chip { width: 1.7rem; height: 1.7rem; font-size: .9rem; border-radius: 8px; }
.owner-nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.owner-nav-link:hover .nav-chip { background: color-mix(in srgb, var(--tone, #94a3b8) 32%, transparent); }
.owner-nav-link.active {
  color: #fff;
  font-weight: 600;
  background: linear-gradient(180deg, rgba(255, 255, 255, .13), rgba(255, 255, 255, .04));
}
.owner-nav-link.active::after {
  content: "";
  position: absolute;
  inset-inline: .5rem;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--tone, #2dd4bf);
  box-shadow: 0 0 12px var(--tone, #2dd4bf);
}
.owner-nav-link.active .nav-chip {
  background: var(--tone, #2dd4bf);
  color: #0a1429;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--tone, #2dd4bf) 55%, transparent);
}
.owner-nav-link:focus-visible { outline: 2px solid #5eead4; outline-offset: -2px; }

.owner-main { max-width: 62rem; margin-inline: auto; padding: 2rem 1.5rem 3rem; }
@media (max-width: 575.98px) { .owner-topbar { padding: .75rem 1rem 0; } .owner-main { padding: 1.5rem 1rem 2.5rem; } }
