/* F-Care — design system (§17). Mobile-first (§13.4.1). */

:root {
  /* Marque (§17.2) */
  --c-primary: #0B6E8F;
  --c-primary-dark: #0A3D52;
  --c-secondary: #2FBFB0;
  --c-secondary-light: #CDF0EC;
  --c-white: #FFFFFF;
  --c-mist: #F5F9FA;
  --c-ink: #12313D;
  --c-ink-soft: #5C7A85;
  --c-border: #DCEAEC;

  /* Couleurs fonctionnelles — statut du jour (§17.2, hors palette de marque) */
  --day-red: #E4574A;
  --day-white: #FFFFFF;
  --day-green: #3F9E6D;
  --day-yellow: #F0A93B;
  --badge-blue: #0B6E8F;

  /* Espacement base 4px (§17.4) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-6: 24px; --sp-8: 32px;
  --radius-field: 8px; --radius-card: 12px; --radius-pill: 999px;
  --shadow-float: 0 2px 8px rgba(11, 61, 82, 0.08);

  --font: "Nunito Sans", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;            /* corps (§17.3) */
  line-height: 1.5;
  color: var(--c-ink);
  background: var(--c-mist);
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 24px; font-weight: 600; margin: 0 0 var(--sp-4); }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 var(--sp-3); }
small, .muted { color: var(--c-ink-soft); font-size: 13px; }
a { color: var(--c-primary); }

/* Layout ------------------------------------------------------------- */
.app-header {
  background: var(--c-white);
  border-bottom: 1px solid var(--c-border);
  padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.app-header .brand { font-weight: 700; color: var(--c-primary); font-size: 18px; }
.app-header nav a { margin-left: var(--sp-4); text-decoration: none; font-weight: 600; }
.app-header nav a.active { color: var(--c-primary-dark); }
.container { max-width: 1100px; margin: 0 auto; padding: var(--sp-6) var(--sp-4); }

/* Boutons (§17.5) ---------------------------------------------------- */
.btn {
  font: inherit; font-weight: 600; border-radius: var(--radius-field);
  padding: 10px var(--sp-4); border: 1px solid transparent; cursor: pointer;
  min-height: 44px;           /* zone tactile (§13.4.1) */
}
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-secondary { background: transparent; border-color: var(--c-primary); color: var(--c-primary); }
.btn-secondary:hover { background: var(--c-secondary-light); }
.btn-sm { min-height: 36px; padding: 6px var(--sp-3); }

/* Cartes (§17.5) ----------------------------------------------------- */
.card {
  background: var(--c-white); border: 1px solid var(--c-border);
  border-radius: var(--radius-card); padding: var(--sp-6);
}
.grid-cards { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }

/* Bandeau "aujourd'hui" (§4.2 / §17.5) */
.today-banner { background: var(--c-secondary-light); color: var(--c-primary-dark); }

/* Onglets bascule vue (§2.1) ----------------------------------------- */
.view-toggle { display: inline-flex; border: 1px solid var(--c-border); border-radius: var(--radius-field); overflow: hidden; }
.view-toggle button { border: 0; background: var(--c-white); padding: 10px var(--sp-4); font: inherit; font-weight: 600; cursor: pointer; color: var(--c-ink-soft); min-height: 44px; }
.view-toggle button.active { background: var(--c-primary); color: #fff; }

/* Pastilles / fonds de statut (§17.2 / §17.5) ------------------------ */
.day-dot { position: relative; }
.bg-RED { background: var(--day-red); color: #fff; }
.bg-WHITE { background: var(--day-white); color: var(--c-ink); border: 1px solid var(--c-border); }
.bg-GREEN { background: var(--day-green); color: #fff; }
.bg-YELLOW { background: var(--day-yellow); color: var(--c-primary-dark); }
.bg-none { background: repeating-linear-gradient(45deg, #fff, #fff 4px, #f0f4f5 4px, #f0f4f5 8px); color: var(--c-ink-soft); border: 1px dashed var(--c-border); }

/* Badge de transition superposé (§2.4) — coin sup. droit */
.badge {
  position: absolute; top: -6px; right: -6px; width: 16px; height: 16px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 10px; line-height: 1; color: #fff; box-shadow: var(--shadow-float);
}
.badge-ETOILE { background: var(--badge-blue); }
.badge-CHEVRON { background: var(--day-green); }
.badge-ECLAIR { background: var(--day-yellow); color: var(--c-primary-dark); }

/* Vue grille (§2.1) -------------------------------------------------- */
/* Pas d'overflow:hidden ici : il casserait le position:sticky de l'en-tête (ANO-003). */
.grid-table { width: 100%; border-collapse: collapse; background: #fff; }
.grid-table th, .grid-table td { padding: var(--sp-2) var(--sp-3); text-align: left; border-bottom: 1px solid var(--c-border); font-size: 14px; }
/* top calé sur la hauteur réelle de l'en-tête d'app (var. posée par pwa.js, ANO-004) :
   un top codé en dur laissait un liseré de ligne passer entre les deux en-têtes.
   box-shadow = bord bas visible malgré border-collapse (les bordures ne « collent » pas). */
.grid-table th {
  background: var(--c-mist); font-weight: 600; color: var(--c-ink-soft);
  position: sticky; top: var(--app-header-h, 52px); z-index: 5;
  box-shadow: inset 0 -1px 0 var(--c-border);
}
.grid-table tr.is-today { outline: 2px solid var(--c-secondary); outline-offset: -2px; }
.grid-table tbody tr { cursor: pointer; }
.grid-table tbody tr:hover { background: var(--c-mist); }
.status-cell { display: inline-flex; align-items: center; gap: var(--sp-2); }
.status-swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; }

/* Vue grille en CARTES sur mobile (§13.4.1) — un tableau à défilement horizontal ne
   peut pas avoir d'en-tête collant fiable (overflow-x casse le sticky, ANO-004). Sous
   640px, chaque ligne devient une carte : libellé (data-label) à gauche, valeur à droite.
   Plus de tableau large, plus de scroll horizontal, plus d'en-tête flottant sur les lignes. */
@media (max-width: 639.98px) {
  .grid-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } /* masqué mais accessible */
  .grid-table, .grid-table tbody, .grid-table tr, .grid-table td { display: block; width: auto; }
  .grid-table tr {
    border: 1px solid var(--c-border); border-radius: var(--radius-card);
    background: #fff; padding: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3);
    box-shadow: var(--shadow-card, 0 1px 2px rgba(0,0,0,.06));
  }
  .grid-table td {
    border-bottom: 1px solid var(--c-border); padding: 6px 0;
    display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4);
    text-align: right;
  }
  .grid-table td::before {
    content: attr(data-label); font-weight: 600; color: var(--c-ink-soft);
    text-align: left; flex: none;
  }
  .grid-table td:empty { display: none; }               /* cache les champs non saisis */
  .grid-table td:last-child { border-bottom: 0; }
  .grid-table td.cell-day { font-size: 16px; font-weight: 700; color: var(--c-primary-dark); }
  .grid-table td.cell-day::before { color: inherit; font-weight: 700; }
}
/* overflow visible sur les deux axes : sinon overflow-x:auto force overflow-y:auto et
   casse le position:sticky de l'en-tête (il se calerait sur ce conteneur au lieu du
   viewport) — ANO-003/ANO-004. Pas de scroll horizontal à gérer : desktop, la table
   tient ; mobile (<640px), la grille bascule en cartes empilées (voir plus bas). */
.table-wrap { overflow: visible; }

/* Vue agenda (§2.1) -------------------------------------------------- */
.agenda-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: var(--sp-2); }
.agenda-grid .dow { text-align: center; font-size: 12px; color: var(--c-ink-soft); font-weight: 600; }
.agenda-tile {
  aspect-ratio: 1; border-radius: var(--radius-field); display: flex; flex-direction: column;
  align-items: center; justify-content: center; cursor: pointer; position: relative; font-size: 13px;
}
.agenda-tile .cd { font-size: 10px; opacity: .8; }
.agenda-tile.is-today { outline: 2px solid var(--c-secondary); outline-offset: 1px; }
.agenda-tile.selected { box-shadow: 0 0 0 3px var(--c-primary); z-index: 1; }
.agenda-tile.empty { background: transparent; cursor: default; }

/* Disposition agenda : détail sous le calendrier (mobile) ou à côté (desktop) */
.agenda-layout { display: grid; gap: var(--sp-4); grid-template-columns: 1fr; }

/* Détail jour sélectionné (agenda, §2.1.1) */
.day-detail dl { display: grid; grid-template-columns: auto 1fr; gap: var(--sp-2) var(--sp-4); margin: 0; }
.day-detail dt { color: var(--c-ink-soft); }

/* Formulaire de saisie partagé (§2.1, bottom sheet mobile / modale desktop).
   IMPORTANT : aucun `transform` sur la feuille — un ancêtre transformé décale le
   popup natif des <select> sur desktop (cf. ANO-002). Centrage via flex du backdrop. */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10,61,82,.35); display: none; z-index: 50; }
.sheet-backdrop.open { display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: #fff; z-index: 60; width: 100%;
  border-radius: var(--radius-card) var(--radius-card) 0 0; box-shadow: var(--shadow-float);
  padding: var(--sp-6); max-height: 90vh; overflow-y: auto;
}
.field { margin-bottom: var(--sp-4); }
.field label { display: block; font-weight: 600; margin-bottom: var(--sp-2); font-size: 14px; }
.field select, .field input[type=number], .field input[type=date],
.field input[type=text], .field input[type=password], .field textarea {
  width: 100%; padding: 10px; border: 1px solid var(--c-border); border-radius: var(--radius-field);
  font: inherit; background: #fff;
}
.field select:focus, .field input:focus, .field textarea:focus { outline: none; border-color: var(--c-secondary); border-width: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.chip {
  border: 1px solid var(--c-border); background: var(--c-secondary-light); color: var(--c-primary-dark);
  border-radius: var(--radius-pill); padding: 6px var(--sp-3); cursor: pointer; font-size: 13px; min-height: 36px;
}
.chip.active { background: var(--c-secondary); color: #fff; border-color: var(--c-secondary); }
.sheet-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; margin-top: var(--sp-4); }
.retro-flag { color: var(--c-ink-soft); font-size: 13px; }

/* Alertes (§4.5) */
.alert { border-left: 3px solid var(--c-secondary); background: var(--c-mist); padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-field); margin-bottom: var(--sp-3); }

.stat { font-size: 28px; font-weight: 700; color: var(--c-primary-dark); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-4); margin-top: var(--sp-4); }
.legend-item { display: flex; align-items: center; gap: var(--sp-2); font-size: 13px; }
.legend-swatch { width: 16px; height: 16px; border-radius: 4px; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }

/* Formulaires d'authentification (allauth) ------------------------- */
.auth-form p { margin: 0 0 14px; }
.auth-form label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 14px; }
.auth-form input { width: 100%; padding: 10px; border: 1px solid var(--c-border); border-radius: var(--radius-field); font: inherit; background: #fff; }
.auth-form input:focus { outline: none; border-color: var(--c-secondary); border-width: 2px; }
.errorlist { list-style: none; margin: 0 0 6px; padding: 8px 12px; background: #FDECEA; border: 1px solid var(--day-red); border-radius: var(--radius-field); color: #9B2C22; font-size: 13px; }
.errorlist li { margin: 0; }
.auth-error { margin-bottom: 12px; }
.helptext { display: block; color: var(--c-ink-soft); font-size: 12px; margin-top: 4px; }
.helptext ul { margin: 4px 0 0; padding-left: 16px; }
.social-block { margin-top: 16px; border-top: 1px solid var(--c-border); padding-top: 16px; }
.social-sep { margin: 0 0 8px; }
.social-btn { display: block; width: 100%; margin-top: 8px; text-align: center; text-decoration: none; }
.social-btn[disabled] { opacity: .6; cursor: not-allowed; }

/* Desktop (§13.4.3) -------------------------------------------------- */
@media (min-width: 640px) {
  .grid-cards { grid-template-columns: repeat(2, 1fr); }
  /* Modale centrée, toujours sans transform (dropdown natif correct) */
  .sheet-backdrop.open { align-items: center; }
  .sheet { width: 520px; max-width: 92vw; border-radius: var(--radius-card); }
}
@media (min-width: 900px) {
  /* Détail du jour à droite du calendrier, collant -> toujours visible sans scroll */
  .agenda-layout { grid-template-columns: 1fr minmax(300px, 360px); align-items: start; }
  .agenda-layout .day-detail { position: sticky; top: calc(var(--app-header-h, 52px) + 20px); }
}
@media (min-width: 1024px) {
  .grid-cards { grid-template-columns: repeat(3, 1fr); }
}
