:root {
  color-scheme: light;
  --bg-color: #f2f2f7;
  --card-bg: #ffffff;
  --text-main: #1c1c1e;
  --text-muted: #8e8e93;
  --accent-blue: #00bcd4; 
  --accent-gray: #636366;
  --border-color: #e5e5ea;
  --badge-cyan-bg: rgba(0, 188, 212, 0.15); 
  --badge-cyan-text: #008ba3; 
  --badge-purple-bg: rgba(175, 82, 222, 0.15);
  --badge-purple-text: #8c28cb;
  --badge-yellow-bg: rgba(255, 204, 0, 0.2); 
  --badge-yellow-text: #8a6c00; 
  --badge-red-bg: rgba(255, 59, 48, 0.18);
  --badge-red-text: #d70015;
}

/* ========================================================
   MODE NUIT AUTOMATIQUE (Lever/Coucher du soleil)
   ======================================================== */
html.dark {
  color-scheme: dark;
  --bg-color: #000000;
  --card-bg: #1c1c1e;
  --text-main: #f2f2f7;
  --text-muted: #8e8e93;
  --accent-blue: #00bcd4;
  --accent-gray: #aeaeb2;
  --border-color: #2c2c2e;
  --badge-cyan-bg: rgba(0, 188, 212, 0.22);
  --badge-cyan-text: #4dd0e1;
  --badge-purple-bg: rgba(175, 82, 222, 0.25);
  --badge-purple-text: #d084f7;
  --badge-yellow-bg: rgba(255, 204, 0, 0.25);
  --badge-yellow-text: #ffd54f;
  --badge-red-bg: rgba(255, 69, 58, 0.25);
  --badge-red-text: #ff453a;
}

html.dark .bottom-bar {
  background: rgba(28, 28, 30, 0.95);
  border-top: 1px solid #2c2c2e;
}

html.dark .bottom-bar input[type="date"] {
  background: #2c2c2e;
  color: #f2f2f7;
  border-color: #3a3a3c;
  color-scheme: dark;
}

html.dark .week-alert-banner {
  background: rgba(215, 0, 21, 0.2);
  color: #ff453a;
  border-bottom: 1px solid rgba(215, 0, 21, 0.3);
}

html.dark .empty-state {
  color: #8e8e93;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; 
  -webkit-tap-highlight-color: transparent;
}

body { 
  background-color: var(--bg-color); 
  color: var(--text-main); 
  -webkit-font-smoothing: antialiased; 
  -moz-osx-font-smoothing: grayscale;
  -webkit-overflow-scrolling: touch; 
  transition: background-color 0.4s ease, color 0.4s ease; 
}

/* ========================================================
   CONTAINER & WEEKS
   ======================================================== */
.container { 
  /* Dégagement net sous l'encoche et la barre d'état iOS */
  padding-top: calc(env(safe-area-inset-top) + 42px);
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(115px + env(safe-area-inset-bottom)); 
  max-width: 600px; 
  margin: 0 auto; 
}

/* Espacement entre les semaines */
.week-header { 
  font-size: 0.75rem; 
  font-weight: 600; 
  color: var(--text-muted); 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  margin: 36px 0 10px 8px; 
}

.week-header:first-child { 
  margin-top: 4px; 
}

.week-card { 
  background: var(--card-bg); 
  border-radius: 16px; 
  box-shadow: 0 2px 8px rgba(0,0,0,0.06); 
  overflow: hidden; 
  transition: all 0.3s ease; 
}

.week-card.highlight { 
  box-shadow: 0 0 0 2px var(--accent-blue), 0 4px 12px rgba(0, 188, 212, 0.3); 
  transform: scale(1.01); 
}

.week-alert-banner {
  background: rgba(215, 0, 21, 0.1); 
  color: #d70015;
  padding: 12px 16px; 
  font-size: 0.85rem; 
  font-weight: 700;
  border-bottom: 1px solid rgba(215, 0, 21, 0.15);
  display: flex; 
  align-items: center;
}

.week-alert-icon { 
  font-size: 1.1rem; 
  margin-right: 8px; 
}

/* ========================================================
   EVENT ROWS
   ======================================================== */
.event-row { 
  display: flex; 
  align-items: center; 
  padding: 16px; 
  border-bottom: 1px solid var(--border-color); 
}

.event-row:last-child { 
  border-bottom: none; 
}

/* Deux événements le même jour : suppression du trait de séparation */
.event-row.no-divider {
  border-bottom: none !important;
  padding-bottom: 8px;
}

.event-row.is-same-day-follow {
  padding-top: 8px;
}

.date-block { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
  width: 45px; 
  margin-right: 16px; 
  flex-shrink: 0; 
}

.date-short { 
  font-size: 0.7rem; 
  font-weight: 700; 
  color: var(--text-muted); 
  text-transform: uppercase; 
}

.date-num { 
  font-size: 1.4rem; 
  font-weight: 400; 
  color: var(--text-main); 
  margin-top: -2px; 
}

.event-content { 
  flex: 1; 
  padding: 12px 14px; 
  border-radius: 12px; 
  display: flex; 
  flex-direction: row; 
  align-items: center; 
  min-width: 0; 
}

.event-text-container { 
  display: flex; 
  flex-direction: column; 
  justify-content: center; 
  flex: 1; 
  min-width: 0; 
}

.event-emoji { 
  font-size: 1.7rem; 
  margin-right: 12px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  flex-shrink: 0; 
  line-height: 1; 
}

.event-title { 
  font-size: 0.95rem; 
  font-weight: 600; 
  line-height: 1.25; 
  word-break: break-word; 
}

.event-time { 
  font-size: 0.8rem; 
  font-weight: 500; 
  opacity: 0.9; 
  margin-top: 3px; 
}

.event-desc { 
  font-size: 0.8rem; 
  font-style: italic; 
  color: var(--text-muted); 
  margin-top: 4px; 
  line-height: 1.3; 
  word-break: break-word; 
}

/* Types d'événements */
.type-confirmed { 
  background: var(--badge-cyan-bg); 
  color: var(--badge-cyan-text); 
}

.type-rdv { 
  background: var(--badge-yellow-bg); 
  color: var(--badge-yellow-text); 
}

.type-holiday { 
  background: var(--badge-purple-bg); 
  color: var(--badge-purple-text); 
}

.type-theory { 
  background: rgba(99, 99, 102, 0.1); 
  color: var(--accent-gray); 
}

.type-theory .event-title {
  font-weight: 500;
}

.type-theory .event-time {
  font-size: 0.78rem;
  opacity: 0.85;
  font-style: italic;
}

/* Jours de repos personnels (Fond Rouge) */
.type-repos-perso {
  background: var(--badge-red-bg);
  color: var(--badge-red-text);
  font-weight: 700;
}

.empty-state { 
  padding: 24px 16px; 
  text-align: center; 
  color: var(--text-muted); 
  font-size: 0.9rem; 
  font-style: italic; 
}

/* ========================================================
   BOTTOM BAR (Rythme vertical harmonisé)
   ======================================================== */
.bottom-bar { 
  position: fixed; 
  bottom: 0; 
  left: 0; 
  right: 0; 
  background: var(--card-bg); 
  border-top: 1px solid var(--border-color); 
  padding-top: 10px;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: max(20px, calc(env(safe-area-inset-bottom) * 0.6)); 
  z-index: 100; 
  backdrop-filter: blur(20px); 
  -webkit-backdrop-filter: blur(20px); 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  gap: 10px; 
  transition: background-color 0.4s ease, border-color 0.4s ease; 
}

.bottom-bar-inner { 
  max-width: 600px; 
  width: 100%; 
  margin: 0 auto; 
  display: flex; 
  gap: 8px; 
  align-items: center; 
}

/* Hauteur uniforme à 46px */
.bottom-bar input[type="date"],
.bottom-bar button#searchBtn,
.bottom-bar .shield-btn,
.bottom-bar .today-btn {
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  box-sizing: border-box;
}

.bottom-bar input[type="date"] { 
  flex: 1; 
  min-width: 0; 
  padding: 0 12px; 
  border: 1px solid var(--border-color); 
  border-radius: 12px; 
  font-size: 0.95rem; 
  background: var(--bg-color); 
  outline: none; 
  color: var(--text-main); 
  cursor: pointer; 
  transition: border-color 0.2s; 
}

.bottom-bar input[type="date"]:focus { 
  border-color: var(--accent-blue); 
}

.bottom-bar button#searchBtn { 
  background: var(--badge-cyan-bg); 
  color: var(--badge-cyan-text); 
  border: none; 
  padding: 0 16px; 
  border-radius: 12px; 
  font-size: 0.95rem; 
  font-weight: 700; 
  cursor: pointer; 
  transition: opacity 0.2s, transform 0.1s; 
  flex-shrink: 0; 
}

/* Bouton Bouclier Sécurisé */
.bottom-bar .shield-btn {
  width: 46px;
  min-width: 46px;
  background: var(--badge-cyan-bg);
  color: var(--badge-cyan-text);
  border: 1.5px solid transparent;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.shield-icon {
  width: 20px;
  height: 20px;
  transition: transform 0.2s ease;
}

/* État actif du bouclier (mode repos perso déverrouillé) */
.bottom-bar .shield-btn.active {
  background: var(--badge-red-bg);
  color: var(--badge-red-text);
  border-color: var(--badge-red-text);
  box-shadow: 0 0 12px rgba(255, 59, 48, 0.35);
}

.bottom-bar .shield-btn.active .shield-icon {
  fill: currentColor;
  transform: scale(1.08);
}

.bottom-bar .today-btn { 
  background: var(--badge-cyan-bg); 
  color: var(--badge-cyan-text); 
  border: none; 
  padding: 0 14px; 
  border-radius: 12px; 
  font-size: 0.92rem; 
  font-weight: 700; 
  cursor: pointer; 
  transition: opacity 0.2s, transform 0.1s; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  text-align: center;
  position: relative;
  white-space: nowrap; 
  flex-shrink: 0; 
}

.bottom-bar .today-btn #todayText {
  display: inline-block;
  text-align: center;
}

.bottom-bar .today-btn .sync-dot { 
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px; 
  height: 5px; 
  border-radius: 50%; 
  background-color: var(--badge-cyan-text); 
  opacity: 0; 
  transition: opacity 0.3s; 
}

.bottom-bar .today-btn .sync-dot.active { 
  opacity: 1; 
  animation: pulse 1s infinite alternate; 
}

.bottom-bar button:hover,
.bottom-bar .today-btn:hover { 
  opacity: 0.85; 
}

.bottom-bar button:active,
.bottom-bar .today-btn:active,
.bottom-bar .shield-btn:active { 
  opacity: 0.6; 
  transform: scale(0.97); 
}

@keyframes pulse { 
  from { opacity: 0.3; transform: scale(0.8); } 
  to { opacity: 1; transform: scale(1.2); } 
}

.footer-credit { 
  font-size: 0.74rem; 
  color: var(--text-muted); 
  text-align: center; 
  line-height: 1.1; 
  user-select: none; 
  font-weight: 500; 
  margin: 0;
  padding: 0;
}

/* ========================================================
   MODALE CODE PIN (BOUCLIER SÉCURISÉ)
   ======================================================== */
.pin-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: calc(env(safe-area-inset-top) + 70px);
  padding-left: 20px;
  padding-right: 20px;
}

.pin-modal-card {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 310px;
  text-align: center;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.35);
  animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.pin-modal-card.shake {
  animation: pinShake 0.4s ease-in-out;
}

@keyframes pinShake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}

.pin-modal-icon {
  font-size: 2.2rem;
  margin-bottom: 8px;
}

.pin-modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 6px;
}

.pin-modal-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.3;
  margin-bottom: 18px;
}

.pin-input-container {
  margin-bottom: 10px;
}

.pin-input-container input {
  width: 160px;
  height: 48px;
  font-size: 1.6rem;
  letter-spacing: 8px;
  text-align: center;
  background: var(--bg-color);
  color: var(--text-main);
  border: 2px solid var(--border-color);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.pin-input-container input:focus {
  border-color: var(--accent-blue);
}

.pin-error {
  color: #ff3b30;
  font-size: 0.8rem;
  font-weight: 600;
  min-height: 18px;
  margin-bottom: 14px;
}

.pin-modal-buttons {
  display: flex;
  gap: 10px;
}

.pin-btn-cancel,
.pin-btn-confirm {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
}

.pin-btn-cancel {
  background: rgba(142, 142, 147, 0.15);
  color: var(--text-muted);
}

.pin-btn-confirm {
  background: var(--accent-blue);
  color: #ffffff;
}

.pin-btn-cancel:active,
.pin-btn-confirm:active {
  opacity: 0.6;
}

/* ========================================================
   LOADER
   ======================================================== */
.loader-container { 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center; 
  margin-top: 60px; 
  color: var(--text-muted); 
}

.spinner { 
  width: 32px; 
  height: 32px; 
  border: 3px solid rgba(0, 188, 212, 0.2); 
  border-top-color: var(--accent-blue); 
  border-radius: 50%; 
  animation: spin 0.8s linear infinite; 
  margin-bottom: 14px; 
}

@keyframes spin { 
  to { transform: rotate(360deg); } 
}
