/* ============================================================
   MyAcademia — Design tokens & base
   Light theme · Indigo accent · Rubik (Latin + Arabic)
   ============================================================ */

:root {
  /* Accent (tweakable) */
  --accent: #4F46E5;
  --accent-600: #4338CA;
  --accent-700: #3730A3;
  --accent-soft: #EEF0FF;
  --accent-softer: #F5F6FF;

  /* Neutrals — cool slate, very light (entre blanc et l'ancien #E9ECF2) */
  --bg: #F0F2F7;
  --surface: #FFFFFF;
  --surface-2: #F5F7FB;
  --ink: #1A1D28;        /* near-black, slightly cool */
  --ink-2: #545A6B;      /* secondary text */
  --ink-3: #878FA3;      /* muted */
  --line: #ECEEF3;       /* hairline */
  --line-2: #E1E4EC;

  /* Status */
  --ok: #0E9F6E;        --ok-soft: #E4F6EF;
  --warn: #C2780B;      --warn-soft: #FBF1DC;
  --bad: #E02424;       --bad-soft: #FCE8E8;
  --info: #2563EB;      --info-soft: #E6EEFE;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 10px;
  --r-xl: 12px;
  --r-pill: 999px;

  /* Shadows — froides, douces et fondues (multicouche, faible opacité) */
  --sh-1: 0 1px 1px rgba(28,38,66,.03), 0 1px 3px rgba(28,38,66,.04);
  --sh-2: 0 1px 2px rgba(28,38,66,.03), 0 4px 10px rgba(28,38,66,.05), 0 10px 22px rgba(28,38,66,.05);
  --sh-3: 0 6px 16px rgba(28,38,66,.07), 0 16px 38px rgba(28,38,66,.10);
  --sh-pop: 0 8px 24px rgba(28,38,66,.10), 0 22px 54px rgba(28,38,66,.15);

  --font: 'Rubik', system-ui, -apple-system, sans-serif;
  --mono: 'Rubik', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100vw; overflow-x: clip; }
body {
  font-family: var(--font);
  color: var(--ink);
  background-color: #F0F2F7;
  /* Gris-bleu très clair « cassé » par des couches froides discrètes : une pointe d'indigo
     en haut, un bleu doux de l'autre côté, et une lumière blanche diffuse — tout en légèreté. */
  background-image:
    radial-gradient(1100px 560px at 100% -10%, rgba(79,70,229,.045), transparent 60%),
    radial-gradient(860px 520px at -8% 108%, rgba(46,92,170,.035), transparent 60%),
    radial-gradient(150% 125% at 50% -20%, rgba(255,255,255,.55), transparent 52%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  width: 100%;
}
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; max-width: 100%; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #D7DBE4; border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #C3C8D4; }

/* Custom scrollbar for weekly schedule */
.ma-schedule-scroll::-webkit-scrollbar {
  height: 10px;
}
.ma-schedule-scroll::-webkit-scrollbar-track {
  background: #F8FAFC;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}
.ma-schedule-scroll::-webkit-scrollbar-thumb {
  background: #CBD5E1;
  border-radius: 99px;
  border: 2px solid #F8FAFC;
}
.ma-schedule-scroll::-webkit-scrollbar-thumb:hover {
  background: #94A3B8;
}

/* Hide scrollbars on mobile for a native feel */
@media (max-width: 768px) {
  ::-webkit-scrollbar { display: none; }
  * { -ms-overflow-style: none; scrollbar-width: none; }
  
  /* Keep scrollbar visible for schedule to guide the user */
  .ma-schedule-scroll::-webkit-scrollbar {
    display: block !important;
    height: 8px;
  }
  .ma-schedule-scroll {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin !important;
    scrollbar-color: #CBD5E1 #F8FAFC !important;
  }
}

/* RTL helpers */
[dir="rtl"] { font-family: var(--font); }

/* Reusable atoms ------------------------------------------------ */
.card {
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid rgba(28,38,66,.05);
  box-shadow: 0 1px 1px rgba(28,38,66,.03), 0 2px 6px rgba(28,38,66,.04), 0 8px 18px rgba(28,38,66,.04);
}
/* cartes cliquables : relief au survol au lieu d'une teinte pleine */
.card.ma-rowlink:hover { background: var(--surface) !important; box-shadow: 0 2px 6px rgba(28,38,66,.05), 0 8px 18px rgba(28,38,66,.07), 0 18px 36px rgba(28,38,66,.08); transform: translateY(-2px); }
.card.ma-rowlink { transition: box-shadow .18s ease, transform .18s ease; }

/* Page de connexion */
.ma-login-card { background: var(--surface); border-radius: 20px; padding: 34px 32px; box-shadow: var(--sh-2); border: 1px solid var(--line); }
@media (max-width: 860px) {
  .ma-login-grid { grid-template-columns: 1fr !important; }
  .ma-login-hero { display: none !important; }
  .ma-login-brand-sm { display: flex !important; }
  .ma-login-card { box-shadow: none; border: none; padding: 6px 2px; }
}

.ma-email-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  min-height: 380px;
}
@media (max-width: 800px) {
  .ma-email-grid {
    grid-template-columns: 1fr;
  }
}
.muted { color: var(--ink-3); }
.subtle { color: var(--ink-2); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-pill);
  font-size: 12.5px; font-weight: 500; line-height: 1; white-space: nowrap;
}
.pill .dot { width: 7px; height: 7px; border-radius: 99px; }
.pill-ok   { background: var(--ok-soft);   color: #0a7a55; }
.pill-bad  { background: var(--bad-soft);  color: #c01c1c; }
.pill-warn { background: var(--warn-soft); color: #9a5e08; }
.pill-info { background: var(--info-soft); color: var(--accent-700); }
.pill-neutral { background: #F0F2F6; color: var(--ink-2); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 10px 16px; font-size: 14px; font-weight: 500;
  transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--sh-1); }
.btn-primary:hover { background: var(--accent-600); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface-2); border-color: #D2D6E0; }
.btn-soft { background: var(--accent-soft); color: var(--accent-700); }
.btn-soft:hover { background: #E4E7FF; }
.btn-danger { background: var(--bad); color:#fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-sm { padding: 7px 12px; font-size: 13px; border-radius: var(--r-xs); }
.btn-icon { padding: 9px; border-radius: var(--r-sm); }

input.field, textarea.field, select.field {
  width: 100%; background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 10px 12px; font-size: 14px; color: var(--ink);
  outline: none; transition: border .15s, box-shadow .15s;
}
input.field:focus, textarea.field:focus, select.field:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}

/* fade/scale entrance */
@keyframes maPop { from { opacity:0; transform: translateY(8px) scale(.98);} to {opacity:1; transform:none;} }
@keyframes maFade { from { opacity:0;} to {opacity:1;} }
@keyframes maSlideIn { from { opacity:0; transform: translateX(12px);} to {opacity:1; transform:none;} }
@keyframes maScan { 0% { top: 30px; } 50% { top: calc(100% - 32px); } 100% { top: 30px; } }
.ma-pop { animation: maPop .28s cubic-bezier(.2,.7,.3,1) both; }
.ma-fade { animation: maFade .3s ease both; }

/* table */
.ma-table { width: 100%; border-collapse: collapse; }
.ma-table th {
  text-align: start; font-size: 11.5px; font-weight: 500; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-3); padding: 0 16px 12px; white-space: nowrap;
}
.ma-table td { padding: 14px 16px; border-top: 1px solid var(--line); vertical-align: middle; }
.ma-table tbody tr { transition: background .12s; }
.ma-table tbody tr:hover { background: var(--surface-2); }

/* number / fee */
.tnum { font-variant-numeric: tabular-nums; }

/* row link hover (clic = redirection profil) */
.ma-rowlink { transition: background .12s; }
.ma-rowlink:hover { background: var(--accent-softer) !important; }
.ma-notify:hover { filter: brightness(.97); }

/* responsive helpers */
.ma-only-mobile { display: none !important; }
@media (max-width: 860px) {
  .ma-sidebar { display: none !important; }
  .ma-only-mobile { display: inline-flex !important; }
  .ma-content { padding: 16px 14px 80px !important; }
  .ma-hide-sm { display: none !important; }
  .ma-search { display: none !important; }
  .ma-kpis { grid-template-columns: repeat(2, 1fr) !important; }
  .ma-2col, .ma-3col, .ma-scan-grid, .ma-course-body, .ma-req-grid { grid-template-columns: 1fr !important; }
  .ma-course-body > div { border-inline-end: none !important; border-top: 1px solid var(--line); }
  .ma-scan-modes { grid-template-columns: 1fr !important; }
  .ma-week { grid-template-columns: 1fr !important; grid-auto-flow: row; }
}

@media (max-width: 600px) {
  .ma-topbar { padding: 10px 14px !important; flex-wrap: wrap; }
  input, select, textarea, input.field, select.field, textarea.field { font-size: 16px !important; }
  .card { border-radius: var(--r-md); }
  .ma-3col, .ma-2col, .ma-kpis { gap: 8px !important; }
  h1, h2 { font-size: 18px !important; }

  /* Stat cards — compact on mobile */
  .ma-stat-card { padding: 12px !important; gap: 8px !important; }
  .ma-stat-icon { width: 30px !important; height: 30px !important; border-radius: 8px !important; }
  .ma-stat-icon svg { width: 15px; height: 15px; }
  .ma-stat-value { font-size: 18px !important; }
  .ma-stat-label { font-size: 11px !important; }
  .ma-stat-sub { font-size: 11px !important; }

  /* Avatars — smaller on mobile */
  .ma-table .ma-avatar,
  .ma-table .ma-kid-avatar { width: 28px !important; height: 28px !important; }
  .ma-table .ma-kid-avatar img { width: 28px !important; height: 28px !important; }

  /* Timeline cells — smaller on mobile */
  .ma-cell-dot { width: 9px !important; height: 9px !important; border-radius: 2px !important; }
  .ma-justified-dot { width: 9px !important; height: 2px !important; }

  /* Buttons — slightly smaller */
  .btn { padding: 8px 12px; font-size: 13px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }

  /* Pills — slightly smaller */
  .pill { padding: 3px 6px; font-size: 10.5px; gap: 4px; }
}

@media (max-width: 520px) {
  .ma-kpis { grid-template-columns: 1fr 1fr !important; }
  .ma-scan-people { grid-template-columns: 1fr 1fr !important; }
  .ma-userchip { display: none !important; }
  .ma-content { padding: 14px 8px 72px !important; }
}

@media (max-width: 400px) {
  .ma-topbar { padding: 8px 10px !important; }
  .ma-stat-card { padding: 10px !important; }
  .ma-stat-value { font-size: 16px !important; }
  .ma-stat-label { font-size: 10px !important; }
  .ma-kpis { grid-template-columns: 1fr !important; }
}

/* density */
body[data-density="compact"] .ma-table td { padding: 9px 14px; }
body[data-density="compact"] .card { border-radius: var(--r-md); }
body[data-density="compact"] main > div:last-child { padding-top: 18px !important; }

/* print — only the QR card */
.ma-print-only { display: none !important; }

@media print {
  body * { visibility: hidden !important; }
  .ma-print-only { display: block !important; }
  #ma-print-card, #ma-print-card * { visibility: visible !important; }
  #ma-print-card { position: fixed; inset: 0; margin: auto; box-shadow: none !important; }
  @page { margin: 18mm; }
}

/* ============================================================
   NATIVE MOBILE UI OVERHAUL
   ============================================================ */

/* Bottom Sheet Animation & Layout */
@keyframes slideUpSheet {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes fadeInOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ============================================================
   Animations & Alertes Agence
   ============================================================ */
@keyframes blink-danger-anim {
  0%, 100% {
    background-color: var(--card-bg);
    box-shadow: 0 4px 15px var(--shadow-color);
  }
  50% {
    background-color: #ffebee;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.4);
    border-color: #ef4444;
  }
}

/* Variante sombre — @keyframes ne peut PAS être imbriqué sous un sélecteur : on le nomme
   séparément et on le branche via une règle [data-theme="dark"] .blink-danger. */
@keyframes blink-danger-anim-dark {
  0%, 100% {
    background-color: var(--surface);
    box-shadow: 0 4px 15px rgba(0,0,0,.3);
  }
  50% {
    background-color: rgba(239, 68, 68, 0.15);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
    border-color: #ef4444;
  }
}

.blink-danger {
  animation: blink-danger-anim 1.5s infinite;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}
[data-theme="dark"] .blink-danger { animation-name: blink-danger-anim-dark; }

/* ── Garde-fou mobile : empêche un enfant flex trop large de décaler/tronquer le contenu
   (dashboards admin/prof « décalés vers la droite »). Pas de scroll horizontal de page. ── */
@media (max-width: 860px) {
  html, body { overflow-x: hidden; }
  main { min-width: 0 !important; }
  .ma-content { max-width: 100% !important; }
}

/* ── Mobile : barres de filtres empilées + selects pleine largeur (élèves, planning…) ── */
@media (max-width: 640px) {
  .ma-toolbar { gap: 8px !important; }
  .ma-toolbar .field,
  .ma-toolbar select.field { width: 100% !important; min-width: 0 !important; flex: 1 1 100% !important; }
  /* Panneau latéral fixe (ex. 320 px) → pleine largeur une fois la grille repliée */
  .ma-2col > .card, .ma-3col > .card { min-width: 0 !important; }

  /* Centre e-mails / notifications : mêmes blocs, tailles réduites, sans troncature */
  .ma-ec > div:nth-child(1), .ma-ec > div:nth-child(2) { padding: 12px 14px !important; }
  .ma-ec .ma-email-grid button { padding: 12px 14px !important; }
  .ma-ec .ma-email-grid > div:last-child { padding: 14px !important; }
}

/* ── Mobile : en-têtes de page compacts, actions sur toute la largeur (même design, réduit) ── */
@media (max-width: 600px) {
  .ma-page-head { margin-bottom: 14px !important; gap: 10px !important; align-items: flex-start !important; }
  .ma-page-head h1 { font-size: 19px !important; }
  .ma-page-head p { font-size: 12.5px !important; margin-top: 4px !important; }
  .ma-page-actions { width: 100%; flex-wrap: wrap; gap: 8px !important; }
  .ma-page-actions .btn { flex: 1 1 auto; justify-content: center; }
  /* Boutons longs : jamais de débordement, le texte peut passer à la ligne */
  .btn { white-space: normal; text-align: center; }
}

/* ── Mobile : AUCUNE table tronquée. Le parent direct d'une table devient scrollable
   (indispensable car html/body est en overflow-x:hidden pour éviter le décalage de page). ── */
@media (max-width: 860px) {
  div:has(> .ma-table) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  /* Une carte qui contient une table ne doit pas clipper son contenu */
  .card:has(.ma-table) { overflow: hidden; }
  /* Tables : cellules resserrées (même design, plus compact) */
  .ma-table th { padding: 0 10px 9px !important; font-size: 10.5px !important; }
  .ma-table td { padding: 10px !important; font-size: 13px; }
}

