/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --c-orange: #FF7043;
  --c-orange-light: #FFF3EE;
  --c-orange-dark: #BF360C;
  --c-blue: #42A5F5;
  --c-blue-light: #E3F2FD;
  --c-green: #66BB6A;
  --c-green-light: #E8F5E9;
  --c-purple: #AB47BC;
  --c-purple-light: #F3E5F5;
  --c-yellow: #FFCA28;
  --c-yellow-light: #FFFDE7;
  --c-bg: #FFF8F5;
  --c-surface: #FFFFFF;
  --c-text: #2D1B0E;
  --c-text-muted: #8D6E63;
  --c-border: #F0D9D0;
  --c-today: #FF7043;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --shadow-card: 0 2px 12px rgba(255,112,67,0.10);
  --shadow-modal: 0 -4px 32px rgba(45,27,14,0.15);
  --font-main: 'Nunito', 'Baloo 2', sans-serif;
  --font-display: 'Baloo 2', 'Nunito', sans-serif;
  --header-h: 64px;
  --bottom-h: 64px;
  --monthbar-h: 52px;
  --legend-h: 48px;
}

html, body { height: 100%; overflow: hidden; background: var(--c-bg); }
body { font-family: var(--font-main); color: var(--c-text); -webkit-tap-highlight-color: transparent; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  overflow: hidden;
}

/* ===== HEADER ===== */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--c-surface);
  border-bottom: 1.5px solid var(--c-border);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.app-logo { font-size: 28px; }
.app-title { font-family: var(--font-display); font-size: 20px; font-weight: 800; color: var(--c-orange); line-height: 1.1; }
.app-subtitle { font-size: 12px; color: var(--c-text-muted); font-weight: 600; }
.header-right { display: flex; gap: 8px; }
.icon-btn { background: none; border: none; font-size: 22px; cursor: pointer; padding: 6px; border-radius: 50%; transition: background 0.15s; }
.icon-btn:hover { background: var(--c-orange-light); }

/* ===== MONTH NAV ===== */
#month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: var(--monthbar-h);
  background: var(--c-surface);
  flex-shrink: 0;
}
#month-label { font-family: var(--font-display); font-size: 18px; font-weight: 800; color: var(--c-text); text-align: center; flex: 1; text-transform: capitalize; }
.nav-btn { background: none; border: none; font-size: 28px; cursor: pointer; color: var(--c-orange); padding: 4px 12px; border-radius: var(--radius-sm); transition: background 0.15s; line-height: 1; }
.nav-btn:hover { background: var(--c-orange-light); }

/* ===== LÉGENDE ===== */
#legend {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: var(--legend-h);
  background: var(--c-surface);
  border-bottom: 1.5px solid var(--c-border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
}
#legend::-webkit-scrollbar { display: none; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  background: var(--c-bg);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 700;
}
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== CALENDRIER ===== */
#calendar-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--c-bg);
  scrollbar-width: thin;
}

.cal-header-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  position: sticky;
  top: 0;
  background: var(--c-surface);
  border-bottom: 1.5px solid var(--c-border);
  z-index: 2;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  color: var(--c-text-muted);
  padding: 6px 0;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

#cal-body {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  padding: 4px 2px;
}

.cal-day {
  background: var(--c-surface);
  border-radius: var(--radius-sm);
  min-height: 72px;
  padding: 4px 3px 3px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: border-color 0.15s, transform 0.1s;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  overflow: hidden;
}
.cal-day:active { transform: scale(0.96); }
.cal-day.other-month { opacity: 0.35; }
.cal-day.today { border-color: var(--c-orange); }
.cal-day.today .day-num { background: var(--c-orange); color: #fff; }
.cal-day.weekend { background: #FFF8F5; }

.day-num {
  font-size: 12px;
  font-weight: 800;
  color: var(--c-text);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1px;
  flex-shrink: 0;
}

.day-tasks {
  display: flex;
  flex-direction: column;
  gap: 1.5px;
  flex: 1;
}

.day-task-dot {
  height: 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 3px;
  font-size: 8px;
  font-weight: 700;
  color: #fff;
  gap: 2px;
  white-space: nowrap;
  overflow: hidden;
}
.day-task-dot .task-icon { font-size: 9px; flex-shrink: 0; }
.day-task-dot .task-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ===== BOTTOM BAR ===== */
#bottom-bar {
  display: flex;
  height: var(--bottom-h);
  background: var(--c-surface);
  border-top: 1.5px solid var(--c-border);
  flex-shrink: 0;
  padding: 6px 12px;
  gap: 8px;
}
.bottom-btn {
  flex: 1;
  border: 1.5px solid var(--c-border);
  background: transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.bottom-btn.active {
  background: var(--c-orange);
  border-color: var(--c-orange);
  color: #fff;
}

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(45,27,14,0.45);
  backdrop-filter: blur(2px);
}

.modal-sheet {
  position: relative;
  background: var(--c-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  animation: slide-up 0.3s cubic-bezier(.32,1.25,.6,1);
}
.modal-sheet-full { max-height: 95vh; }

@keyframes slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--c-border);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 12px;
  flex-shrink: 0;
}
.modal-title, #modal-day-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  color: var(--c-text);
}

.modal-close {
  background: var(--c-bg);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  color: var(--c-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 16px 20px;
  border-top: 1.5px solid var(--c-border);
  flex-shrink: 0;
}

/* ===== TÂCHES DANS MODAL JOUR ===== */
.task-group {
  background: var(--c-bg);
  border-radius: var(--radius-md);
  padding: 12px;
}
.task-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.task-group-icon { font-size: 20px; }
.task-group-label {
  font-size: 14px;
  font-weight: 800;
  color: var(--c-text);
}
.task-group-sub {
  font-size: 11px;
  color: var(--c-text-muted);
  font-weight: 600;
  margin-left: auto;
}
.hidden-task { display: none; }

.guardian-choice-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.guardian-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 2px solid transparent;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--c-surface);
  color: var(--c-text);
}
.guardian-chip.selected {
  border-color: currentColor;
  opacity: 1;
}
.guardian-chip:not(.selected) { opacity: 0.5; }
.guardian-chip .g-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
}
.nobody-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border-radius: 99px;
  border: 2px solid var(--c-border);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--c-surface);
  color: var(--c-text-muted);
}
.nobody-chip.selected {
  border-color: var(--c-text-muted);
  background: var(--c-bg);
}

/* ===== BOUTONS ===== */
.btn-primary {
  flex: 1;
  background: var(--c-orange);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--c-orange-dark); }
.btn-primary.full-width { width: 100%; }
.btn-secondary {
  flex: 1;
  background: var(--c-bg);
  color: var(--c-text-muted);
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

/* ===== PARAMÈTRES ===== */
.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.settings-h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  color: var(--c-orange);
  padding-bottom: 6px;
  border-bottom: 1.5px solid var(--c-border);
}
.settings-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--c-text-muted);
}
.settings-hint {
  font-size: 12px;
  color: var(--c-text-muted);
}
.settings-input {
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-text);
  background: var(--c-bg);
  width: 100%;
}
.settings-input:focus { outline: 2px solid var(--c-orange); border-color: transparent; }

.guardian-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-bg);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.guardian-color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid #fff;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.15);
}
.guardian-name-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  color: var(--c-text);
}
.guardian-name-input:focus { outline: none; }
.guardian-emoji-input {
  width: 36px;
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 18px;
  padding: 2px;
}
.guardian-del-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--c-text-muted);
  padding: 2px;
  flex-shrink: 0;
}
.btn-add-guardian {
  background: var(--c-orange-light);
  color: var(--c-orange-dark);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

/* Jours école */
.school-days-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.school-day-btn {
  flex: 1;
  min-width: 36px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--c-border);
  background: var(--c-surface);
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 700;
  color: var(--c-text-muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.school-day-btn.active {
  background: var(--c-orange);
  border-color: var(--c-orange);
  color: #fff;
}

/* ===== SEMAINE TYPE ===== */
.wt-day {
  background: var(--c-bg);
  border-radius: var(--radius-md);
  padding: 12px;
}
.wt-day-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 800;
  color: var(--c-text);
  margin-bottom: 10px;
  text-transform: capitalize;
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 700;
  z-index: 200;
  white-space: nowrap;
  animation: fade-in-up 0.3s ease;
}
.toast.hidden { display: none; }
@keyframes fade-in-up {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 2px; }

/* ===== COLOR PICKER PALETTE ===== */
.color-palette {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  background: var(--c-surface);
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--c-border);
}
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s;
}
.color-swatch:hover { transform: scale(1.2); }
.color-swatch.selected { border-color: var(--c-text); }

/* Onboarding */
.onboarding-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 20px;
  text-align: center;
}
.onboarding-emoji { font-size: 64px; }
.onboarding-title { font-family: var(--font-display); font-size: 24px; font-weight: 800; color: var(--c-orange); }
.onboarding-text { font-size: 15px; color: var(--c-text-muted); line-height: 1.6; }
