:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --border: #e3e6ee;
  --text: #1f2333;
  --text-muted: #6b7080;
  --primary: #4f5df3;
  --primary-dark: #3b47d1;
  --danger: #e05264;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(30, 34, 60, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: filter 0.15s ease;
}
button:hover { filter: brightness(0.95); }
button:active { filter: brightness(0.9); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #eef0fb; color: var(--primary-dark); }
.btn-danger { background: #fdeaec; color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-icon { padding: 6px 10px; }

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
}
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 12px;
}
label:first-child { margin-top: 0; }

.hidden { display: none !important; }

/* ---------- AUTH ---------- */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  width: 100%;
  max-width: 380px;
}
.auth-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
}
.auth-logo {
  height: 42px;
  display: block;
  margin: 0 0 10px;
}
.auth-card p.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0 0 20px;
}
.auth-card .actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.auth-card .actions button { flex: 1; }
.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-switch a { color: var(--primary); cursor: pointer; font-weight: 600; }
.auth-error {
  background: #fdeaec;
  color: var(--danger);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin-top: 12px;
}

/* ---------- APP LAYOUT ---------- */
#app-screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.topbar-left h1 {
  font-size: 17px;
  margin: 0;
}
.topbar-logo {
  height: 28px;
  display: block;
}
.calendar-select {
  max-width: 220px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-badge {
  font-size: 13px;
  color: var(--text-muted);
}

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.side-nav {
  width: 84px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav-item {
  background: transparent;
  border-radius: 10px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-weight: 600;
}
.nav-item .nav-icon { font-size: 19px; }
.nav-item .nav-label { font-size: 10.5px; }
.nav-item:hover { background: #f0f1fa; }
.nav-item.active {
  background: #eef0fb;
  color: var(--primary-dark);
}

.app-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}

/* ---------- TÂCHES ---------- */
.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-top: 1px solid var(--border);
}
.task-row:first-of-type { border-top: none; }
.task-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.task-row-title {
  flex: 1;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.task-row.done .task-row-title {
  text-decoration: line-through;
  color: var(--text-muted);
}
.task-row-author {
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.task-delete-btn {
  background: transparent;
  color: var(--danger);
  padding: 2px 6px;
  font-size: 16px;
  line-height: 1;
  flex-shrink: 0;
}

.main-layout {
  display: flex;
  flex: 1;
  gap: 16px;
  padding: 16px 20px 32px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
  flex-wrap: wrap;
}

.calendar-panel {
  flex: 1 1 640px;
  min-width: 300px;
}
.side-panel {
  flex: 0 1 260px;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.month-nav h2 {
  font-size: 18px;
  margin: 0;
  text-transform: capitalize;
}
.month-nav-btns { display: flex; gap: 6px; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.weekday-label {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  padding-bottom: 4px;
  text-transform: uppercase;
}
.day-cell {
  background: #fbfbfd;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 88px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: pointer;
  overflow: hidden;
}
.day-cell:hover { background: #f0f1fa; }
.day-cell.other-month { opacity: 0.35; }
.day-cell.today { border-color: var(--primary); border-width: 2px; }
.day-number {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}
.event-chip {
  font-size: 10.5px;
  padding: 2px 5px;
  border-radius: 5px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
}
.event-chip.more {
  background: #e3e6ee !important;
  color: var(--text-muted) !important;
}

/* Bandeau "travail" : distinct des rendez-vous pour ne pas les masquer */
.work-strip {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 9.5px;
  font-weight: 700;
  color: #fff;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background-image: repeating-linear-gradient(
    135deg,
    rgba(255,255,255,0.22) 0px,
    rgba(255,255,255,0.22) 4px,
    transparent 4px,
    transparent 8px
  );
}
.work-strip-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 1px;
}

.legend-title, .side-panel h3 {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
  letter-spacing: 0.4px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}
.member-row:hover { background: #f3f4fa; }
.member-row.muted { opacity: 0.4; }
.color-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

.invite-box {
  display: flex;
  gap: 6px;
}
.invite-box input { font-weight: 700; letter-spacing: 1px; text-align: center; }

/* ---------- SÉLECTEUR DE COULEUR PERSO ---------- */
.color-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px #fff inset;
}
.color-swatch-custom {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  padding: 0;
  border: 1px dashed var(--border);
  cursor: pointer;
  overflow: hidden;
}
.color-swatch-custom input[type="color"] {
  width: 34px;
  height: 34px;
  border: none;
  padding: 0;
  margin: -5px;
  cursor: pointer;
}

/* ---------- RÉCAPITULATIF PAR PERSONNE ---------- */
.recap-panel { max-height: 420px; overflow-y: auto; }
.recap-member-group { margin-bottom: 14px; }
.recap-member-group:last-child { margin-bottom: 0; }
.recap-member-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 700;
  margin-bottom: 6px;
}
.recap-item {
  display: flex;
  gap: 8px;
  padding: 5px 0;
  font-size: 12.5px;
  border-top: 1px solid var(--border);
}
.recap-item:first-of-type { border-top: none; }
.recap-date {
  color: var(--text-muted);
  min-width: 56px;
  flex-shrink: 0;
  font-weight: 600;
}
.recap-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recap-empty {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 4px 0 10px;
}

/* ---------- MODAL ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
.modal-close {
  float: right;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  padding: 0 4px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions button { flex: 1; }
.field-row {
  display: flex;
  gap: 10px;
}
.field-row > div { flex: 1; }
.weekday-picker {
  display: flex;
  gap: 5px;
  margin-top: 6px;
  flex-wrap: wrap;
}
.weekday-toggle {
  flex: 1;
  min-width: 36px;
  text-align: center;
  padding: 7px 4px;
  border-radius: 6px;
  background: #eef0fb;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.weekday-toggle.active {
  background: var(--primary);
  color: #fff;
}
.category-picker {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.category-toggle {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 8px;
  background: #eef0fb;
  color: var(--primary-dark);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.category-toggle.active {
  background: var(--primary);
  color: #fff;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

.field-with-btn {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.field-with-btn > div { flex: 1; }
.field-with-btn button {
  padding: 9px 12px;
  white-space: nowrap;
}

.preset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.preset-row:first-of-type { border-top: none; }
.preset-row-name { font-weight: 600; }
.preset-row-time { color: var(--text-muted); font-size: 12px; }
.preset-delete-btn {
  background: transparent;
  color: var(--danger);
  padding: 2px 6px;
  font-size: 16px;
  line-height: 1;
}

.day-cell.holiday { border-bottom: 3px solid #2bb673; }

.dependent-row, .holiday-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.dependent-row:first-of-type, .holiday-row:first-of-type { border-top: none; }
.dependent-row-left, .holiday-row-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
}
.dependent-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.row-icon-btn {
  background: transparent;
  color: var(--text-muted);
  padding: 3px 6px;
  font-size: 13px;
}
.row-icon-btn.danger { color: var(--danger); }
.holiday-row-dates { color: var(--text-muted); font-size: 11.5px; }

.delegate-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 13.5px;
}
.delegate-check-row:first-of-type { border-top: none; }
.delegate-check-row input { width: auto; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 20px;
}

@media (max-width: 720px) {
  .main-layout { flex-direction: column; padding: 12px 12px 24px; gap: 12px; }
  .day-cell { min-height: 60px; padding: 4px; }
  .app-body { flex-direction: column; }
  .side-nav {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    padding: 6px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 4px;
  }
  .nav-item { flex-direction: row; padding: 8px 14px; flex: 1; justify-content: center; }
  .topbar { padding: 10px 12px; }
  .topbar-logo { height: 24px; }
  .calendar-select { max-width: 140px; }
  .field-row { flex-direction: column; gap: 0; }
  .modal { padding: 18px; }
}

@media (max-width: 480px) {
  .day-cell { min-height: 48px; border-radius: 6px; }
  .day-number { font-size: 10.5px; }
  .event-chip, .work-strip { font-size: 9px; padding: 1px 3px; }
  .calendar-grid { gap: 3px; }
  .weekday-label { font-size: 10px; }
  .month-nav { flex-wrap: wrap; gap: 8px; }
  .month-nav h2 { width: 100%; text-align: center; order: -1; font-size: 16px; }
  .topbar-right { justify-content: center; width: 100%; }
  .topbar-right button, .topbar-right .user-badge { font-size: 12.5px; }
  .auth-card { padding: 22px; }
  .card { padding: 13px; }
}

/* Empêche tout débordement horizontal sur mobile */
html, body { overflow-x: hidden; }
input, select, textarea, button { max-width: 100%; }
