/* ═══════════════════════════════════════════════════════════════
   Calendrier — papier crème, encre, typographie éditoriale
   ═══════════════════════════════════════════════════════════════ */

:root,
:root.theme-papier {
  /* Palette par défaut : papier crème + encre brune */
  --paper:        #f5f0e8;
  --paper-soft:   #ebe4d6;
  --paper-deep:   #ddd3c0;
  --ink:          #2a2520;
  --ink-soft:     #5a4f44;
  --ink-mute:     #8a7e70;
  --rule:         #cfc4b0;
  --hairline:     #e4dccb;
  --surface:      #ffffff;
  --surface-2:    #faf6ee;
  --accent-1:     #b04e2a;
  --accent-2:     #2e5d52;
  --accent-warm:  #c69c5e;

  /* Typo */
  --serif:  'Fraunces', Georgia, 'Times New Roman', serif;
  --sans:   'Geist', system-ui, -apple-system, sans-serif;

  /* Métriques */
  --radius:    6px;
  --radius-lg: 14px;
  --shadow:    0 1px 2px rgba(42,37,32,0.04), 0 8px 24px rgba(42,37,32,0.06);
  --shadow-lg: 0 4px 12px rgba(42,37,32,0.08), 0 24px 60px rgba(42,37,32,0.16);
}

:root.theme-nuit {
  /* Nuit : fonds sombres, accents chauds */
  --paper:        #1a1612;
  --paper-soft:   #2a2520;
  --paper-deep:   #3a3530;
  --ink:          #f0e8d8;
  --ink-soft:     #c4b8a5;
  --ink-mute:     #8a7e70;
  --rule:         #4a4540;
  --hairline:     #2f2a25;
  --surface:      #2a2520;
  --surface-2:    #1f1b16;
  --accent-1:     #d4724a;
  --accent-2:     #5a9b8c;
  --accent-warm:  #d8b078;
  --shadow:    0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.5), 0 24px 60px rgba(0,0,0,0.7);
}

:root.theme-foret {
  /* Forêt : crème froide, vert sapin, brique chaude */
  --paper:        #f0ede4;
  --paper-soft:   #e2dccc;
  --paper-deep:   #d0cbbb;
  --ink:          #1f2e1f;
  --ink-soft:     #3d5c3e;
  --ink-mute:     #7a8f7b;
  --rule:         #b8c0a8;
  --hairline:     #d8dfc8;
  --surface:      #ffffff;
  --surface-2:    #f5f3ec;
  --accent-1:     #6b8e4e;
  --accent-2:     #b54e2a;
  --accent-warm:  #a78844;
}

:root.theme-ocean {
  /* Océan : bleu-gris, marine profond, contraste cuivre */
  --paper:        #eef2f5;
  --paper-soft:   #d8e1e8;
  --paper-deep:   #c0ccd5;
  --ink:          #1a2a35;
  --ink-soft:     #3a5060;
  --ink-mute:     #7a8a98;
  --rule:         #a8b8c4;
  --hairline:     #d0d8e0;
  --surface:      #ffffff;
  --surface-2:    #f4f7f9;
  --accent-1:     #2a6b8b;
  --accent-2:     #c25c3a;
  --accent-warm:  #6a90a8;
}

:root.theme-sepia {
  /* Sépia : papier ancien, encre café, ocres */
  --paper:        #f0e4ce;
  --paper-soft:   #e4d4b8;
  --paper-deep:   #d4c19a;
  --ink:          #3a2a18;
  --ink-soft:     #6a5238;
  --ink-mute:     #9a8568;
  --rule:         #c4b090;
  --hairline:     #ddc8a6;
  --surface:      #faf2e0;
  --surface-2:    #f5e9d0;
  --accent-1:     #a4502a;
  --accent-2:     #5a7048;
  --accent-warm:  #c4985a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  /* Grain papier subtil */
  background-image:
    radial-gradient(rgba(42,37,32,0.018) 1px, transparent 1px);
  background-size: 3px 3px;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 400;
  font-variation-settings: "opsz" 144, "SOFT" 30;
  letter-spacing: -0.01em;
  margin: 0;
}

button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.view { min-height: 100dvh; }
.view[hidden] { display: none; }

/* ═══════════════════════════════════════════════════════════════
   LOGIN
   ═══════════════════════════════════════════════════════════════ */

.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 10%, rgba(176,78,42,0.06), transparent 40%),
    radial-gradient(circle at 80% 90%, rgba(46,93,82,0.05), transparent 50%),
    var(--paper);
}

.login-card {
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-mark {
  color: var(--ink-soft);
  margin-bottom: 24px;
  display: flex;
  justify-content: center;
}

.login-title {
  font-size: clamp(44px, 9vw, 64px);
  font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1;
  font-weight: 350;
  letter-spacing: -0.025em;
  margin-bottom: 4px;
}

.login-sub {
  font-family: var(--serif);
  font-style: italic;
  font-variation-settings: "opsz" 14;
  color: var(--ink-soft);
  margin: 0 0 36px;
  font-size: 17px;
}

.login-form { display: flex; flex-direction: column; gap: 16px; text-align: left; }

.login-error {
  color: var(--accent-1);
  font-size: 13px;
  text-align: center;
  margin: 0;
  min-height: 1em;
}

/* ═══════════════════════════════════════════════════════════════
   FORMULAIRES (champs)
   ═══════════════════════════════════════════════════════════════ */

.field { display: flex; flex-direction: column; gap: 6px; }

.field > span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  font-weight: 500;
}

.field input,
.field textarea,
.field select {
  padding: 10px 12px;
  border: 1px solid var(--rule);
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 15px;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--ink);
  background: var(--surface);
}

.field textarea { resize: vertical; min-height: 80px; font-family: var(--sans); }

.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--ink-soft);
  padding: 4px 0;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }

/* ═══════════════════════════════════════════════════════════════
   BOUTONS
   ═══════════════════════════════════════════════════════════════ */

.btn-primary,
.btn-ghost,
.btn-danger {
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
}
.btn-primary:hover { background: #1a1612; }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule);
}
.btn-ghost:hover { background: var(--paper-soft); border-color: var(--ink-mute); }

.btn-danger {
  background: transparent;
  color: var(--accent-1);
  border-color: rgba(176,78,42,0.3);
}
.btn-danger:hover { background: rgba(176,78,42,0.08); }

.btn-block { display: block; width: 100%; text-align: center; text-decoration: none; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--paper-soft); color: var(--ink); }

.text-btn {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.text-btn:hover { background: var(--paper-soft); }

/* ═══════════════════════════════════════════════════════════════
   APP TOPBAR
   ═══════════════════════════════════════════════════════════════ */

.app-view { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}

.topbar-left { display: flex; flex-direction: column; gap: 6px; }

.period-title {
  font-family: var(--sans);
  font-size: clamp(22px, 3.8vw, 28px);
  font-weight: 600;
  letter-spacing: -0.025em;
  line-height: 1.1;
  text-transform: capitalize;
  color: var(--ink);
}

.period-nav { display: flex; align-items: center; gap: 4px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

.view-switch {
  display: inline-flex;
  background: var(--paper-soft);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  background: transparent;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink-soft);
  transition: all 0.15s;
}
.view-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(42,37,32,0.08);
}

@media (max-width: 640px) {
  .topbar { padding: 12px 16px 8px; }
  .view-switch { font-size: 12px; }
  .view-btn { padding: 5px 8px; font-size: 12px; }
}

/* ═══════════════════════════════════════════════════════════════
   LÉGENDE UTILISATEURS
   ═══════════════════════════════════════════════════════════════ */

.user-legend {
  display: flex;
  gap: 16px;
  padding: 8px 24px 12px;
  font-size: 12px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--hairline);
}
.user-legend .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.user-legend .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

/* ═══════════════════════════════════════════════════════════════
   CALENDRIER (FullCalendar overrides)
   ═══════════════════════════════════════════════════════════════ */

.calendar-host { flex: 1; padding: 8px 16px 24px; overflow: auto; }

#calendar {
  --fc-border-color: var(--hairline);
  --fc-today-bg-color: rgba(198,156,94,0.08);
  --fc-neutral-bg-color: var(--paper-soft);
  --fc-page-bg-color: transparent;
  --fc-event-text-color: #fff;
  font-family: var(--sans);
}

#calendar .fc {
  background: transparent;
}

/* On masque la toolbar FC : on a la nôtre */
#calendar .fc-toolbar { display: none; }

#calendar .fc-col-header-cell {
  background: transparent;
  border-color: var(--hairline);
  padding: 8px 0;
}
#calendar .fc-col-header-cell-cushion {
  font-family: var(--serif);
  font-variation-settings: "opsz" 14;
  font-weight: 400;
  font-style: italic;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14px;
  text-transform: lowercase;
}

#calendar .fc-daygrid-day-number {
  font-family: var(--serif);
  font-variation-settings: "opsz" 24;
  font-weight: 300;
  color: var(--ink);
  text-decoration: none;
  padding: 6px 8px;
  font-size: 16px;
}

#calendar .fc-day-today .fc-daygrid-day-number {
  color: #fff;
  background: var(--accent-1);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px;
  padding: 0;
  font-weight: 600;
  font-size: 14px;
  line-height: 1;
  font-family: var(--sans);   /* la pastille en sans, plus net que la serif */
}

#calendar .fc-daygrid-day { background: transparent; }
#calendar .fc-day-other .fc-daygrid-day-number { color: var(--ink-mute); opacity: 0.5; }

#calendar .fc-event {
  border: none;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12px;
  font-weight: 400;
  cursor: pointer;
}

#calendar .fc-event-title,
#calendar .fc-event-time {
  font-weight: 400;
}

#calendar .fc-event:hover { filter: brightness(1.05); }

#calendar .fc-timegrid-slot-label,
#calendar .fc-list-day-cushion {
  font-size: 12px;
  color: var(--ink-mute);
}

#calendar .fc-list-event-title a,
#calendar .fc-list-event-time {
  color: var(--ink);
  text-decoration: none;
}

#calendar .fc-list-day-cushion {
  background: var(--surface-2);
}

/* ═══════════════════════════════════════════════════════════════
   FAB (bouton flottant nouveau)
   ═══════════════════════════════════════════════════════════════ */

.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--paper);
  font-size: 28px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: transform 0.2s, background 0.15s;
  z-index: 10;
  /* Safe area iOS */
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
}
.fab:hover { transform: scale(1.05); background: #1a1612; }
.fab:active { transform: scale(0.95); }

/* ═══════════════════════════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════════════════════════ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(42,37,32,0.4);
  backdrop-filter: blur(2px);
}

.modal-panel,
.side-panel {
  position: relative;
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}

.side-panel {
  max-width: 360px;
  margin-left: auto;
  margin-right: 0;
  height: 92dvh;
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--hairline);
}
.modal-head h2 {
  font-size: 22px;
  font-variation-settings: "opsz" 36;
  font-weight: 400;
}

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--hairline);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.modal-foot-right { display: flex; gap: 8px; }

/* ═══════════════════════════════════════════════════════════════
   MENU LATERAL
   ═══════════════════════════════════════════════════════════════ */

.menu-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.menu-section h3 {
  font-size: 11px;
  font-family: var(--sans);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-mute);
  margin-bottom: 4px;
}

.menu-hint {
  font-size: 12px;
  color: var(--ink-mute);
  font-style: italic;
  font-family: var(--serif);
  font-variation-settings: "opsz" 12;
  margin: 4px 0 0;
  line-height: 1.5;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.filter-toggle:hover { background: var(--paper-soft); }
.filter-toggle .dot {
  width: 12px; height: 12px; border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════
   SÉLECTEUR DE THÈME
   ═══════════════════════════════════════════════════════════════ */

.theme-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.theme-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}
.theme-chip:hover { background: var(--paper-soft); }
.theme-chip.active {
  border-color: var(--ink);
  border-width: 2px;
  padding: 7px 9px;  /* compense le border 2px */
}

.theme-preview {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hairline);
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}
.theme-preview::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--preview-paper);
}
.theme-preview::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--preview-accent);
  border: 1.5px solid var(--preview-ink);
}

.theme-name {
  font-size: 13px;
  color: var(--ink);
}

/* ═══════════════════════════════════════════════════════════════
   SÉLECTEUR DE COULEUR PERSONNELLE
   ═══════════════════════════════════════════════════════════════ */

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0;
  cursor: pointer;
}

.color-picker-row input[type="color"] {
  width: 52px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
  background: var(--surface);
}

.color-picker-row span {
  font-size: 13px;
  color: var(--ink-soft);
}

/* ═══════════════════════════════════════════════════════════════
   FullCalendar : neutralisation du point coloré
   pour les événements avec heure de début (rendu uniforme via JS)
   ═══════════════════════════════════════════════════════════════ */
#calendar .fc-daygrid-event-dot {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; gap: 6px; }
  .topbar-left, .topbar-right { width: 100%; justify-content: space-between; }
  .user-legend { padding: 4px 12px 6px; font-size: 11px; gap: 12px; }
  .calendar-host { padding: 2px 4px 24px; }

  .modal-panel { max-height: 96dvh; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot-right { width: 100%; justify-content: flex-end; }

  /* ─── Densification de la vue mois sur petit écran ─── */
  #calendar .fc-event {
    font-size: 10px;
    padding: 0 3px;
    line-height: 1.2;
    border-radius: 3px;
  }
  #calendar .fc-daygrid-event {
    margin-top: 0;
    margin-bottom: 1px;
  }
  #calendar .fc-daygrid-day-events { margin-top: 1px; }
  #calendar .fc-daygrid-day-number {
    font-size: 12px;
    padding: 2px 5px;
  }
  #calendar .fc-day-today .fc-daygrid-day-number {
    width: 24px;
    height: 24px;
    font-size: 12px;
    margin: 3px;
  }
  #calendar .fc-col-header-cell {
    padding: 5px 0;
  }
  #calendar .fc-col-header-cell-cushion {
    font-size: 11px;
  }
  #calendar .fc-daygrid-more-link {
    font-size: 10px;
    padding: 0 2px;
    line-height: 1.15;
  }
  #calendar .fc-event-title {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* On masque l'heure de début dans la vue mois — la lisibilité prime */
  #calendar .fc-daygrid-event .fc-event-time {
    display: none;
  }
}

/* Encore plus compact sur très petits écrans (< 380px) */
@media (max-width: 380px) {
  #calendar .fc-event { font-size: 9px; padding: 0 2px; line-height: 1.1; }
  #calendar .fc-daygrid-day-number { font-size: 11px; padding: 1px 4px; }
  #calendar .fc-day-today .fc-daygrid-day-number {
    width: 22px; height: 22px; font-size: 11px; margin: 2px;
  }
  #calendar .fc-col-header-cell-cushion { font-size: 10px; }
  #calendar .fc-daygrid-more-link { font-size: 9px; }
  .user-legend { font-size: 10px; gap: 10px; }
}
