:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e6e8ef;
  --accent: #5b6bff;
  --accent-soft: #eef1ff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-lg: 0 18px 50px rgba(16, 24, 40, .16);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background:
    radial-gradient(1100px 550px at 100% -10%, #e9edff 0%, transparent 55%),
    radial-gradient(900px 500px at -10% 110%, #fdeaf4 0%, transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- Barre du haut ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, .78);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-icon {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  font-size: 21px;
  border-radius: 13px;
  background: linear-gradient(145deg, #eef1ff, #ffe9f3);
  border: 1px solid #e7e9f7;
  box-shadow: 0 2px 6px rgba(91, 107, 255, .1);
  flex: none;
}

.brand-text { min-width: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.015em;
  line-height: 1.2;
}

.child-line {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 1px;
}

#childName {
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px dashed transparent;
  padding: 0 1px;
  width: 150px;
  border-radius: 0;
}
#childName:hover { border-bottom-color: #cfd4e6; }
#childName:focus { outline: none; border-bottom-color: var(--accent); }
#childName::placeholder { font-weight: 500; color: #a2a8ba; }

.pencil { font-size: 10px; opacity: .55; }

.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }

/* ---------- Mode lecture seule / édition ---------- */

.mode-box { display: flex; align-items: center; gap: 6px; }

.mode-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  padding: 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.mode-badge.locked { background: #eef1f7; color: #5b6478; }
.mode-badge.editing { background: #e7f8ef; color: #0a7a4a; }

#modeBtn { white-space: nowrap; }

.readonly-hint {
  margin: 0 0 10px;
  padding: 8px 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: #5b6478;
  background: #f6f7fb;
  border: 1px dashed #dde1ec;
  border-radius: 9px;
}
.readonly-hint b { color: var(--text); }

.dialog-hint {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--muted);
}

.form-error {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: #c92f3c;
}

#childName:disabled {
  color: var(--text);
  opacity: 1;
  border-bottom-color: transparent;
  cursor: default;
}

.type-item.locked { cursor: default; }
.type-item.locked:hover { background: transparent; }
.chip.locked { cursor: pointer; }
.chip.locked:hover { filter: none; }


/* ---------- Boutons ---------- */

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, opacity .15s;
}
.btn:hover { background: #f2f4fa; border-color: #d7dbe9; }
.btn:active { transform: translateY(.5px); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: #f0f2f9; }
.btn.icon { width: 36px; height: 36px; padding: 0; justify-content: center; font-size: 18px; }
.btn.tiny { font-size: 12px; padding: 5px 9px; border-radius: 8px; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 5px 14px rgba(91, 107, 255, .28);
}
.btn.primary:hover { background: #4a5af0; border-color: #4a5af0; }
.btn.danger { color: #c92f3c; }
.btn.danger:hover { background: #fff0f1; }
.btn:disabled { opacity: .35; cursor: default; }
.btn:disabled:hover { background: var(--panel); border-color: var(--line); }

/* ---------- Menu déroulant ---------- */

.menu { position: relative; }
.menu > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}
.menu > summary::-webkit-details-marker { display: none; }
.menu[open] > summary { background: #eef1ff; color: var(--accent); }

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 242px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
}
.menu-panel button {
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 9px 11px;
  cursor: pointer;
}
.menu-panel button:hover { background: #f3f5fb; }
.menu-panel button.danger { color: #c92f3c; }
.menu-panel hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: 5px 0; }

/* ---------- Mise en page ---------- */

.layout {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  max-width: 1520px;
  margin: 0 auto;
  padding: 18px 22px 44px;
}

.sidebar { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.panel-head h2 { margin: 0; }

.hint {
  margin: 0 0 10px;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

.tip {
  margin: 0 2px;
  font-size: 11px;
  line-height: 1.55;
  color: #8b93a7;
}

/* ---------- Palette de types ---------- */

.palette { display: flex; flex-direction: column; gap: 3px; }

.type-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 7px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: grab;
  user-select: none;
  min-width: 0;
  transition: background .14s, border-color .14s, box-shadow .14s;
}
.type-item:hover { background: #f6f7fb; }
.type-item:focus-visible { outline: 2px solid rgba(91, 107, 255, .45); outline-offset: 1px; }
.type-item.active {
  background: var(--accent-soft);
  border-color: rgba(91, 107, 255, .45);
  box-shadow: 0 0 0 3px rgba(91, 107, 255, .1);
}
.type-item.dragging-item { opacity: .45; }

.type-dot {
  width: 27px; height: 27px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 9px;
  font-size: 14px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}

.type-label {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.type-edit {
  flex: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  padding: 3px 4px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .14s, background .14s;
}
.type-item:hover .type-edit,
.type-item:focus-within .type-edit { opacity: 1; }
.type-edit:hover { background: #e6e9f5; }

.eraser {
  width: 100%;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: #fafbfe;
  border: 1px dashed #dfe3ef;
  border-radius: 10px;
  padding: 8px 11px;
  cursor: pointer;
  transition: background .14s, border-color .14s;
}
.eraser span { font-size: 10.5px; font-weight: 400; color: var(--muted); }
.eraser:hover { background: #f4f6fc; }
.eraser.active {
  background: #fff1f1;
  border-style: solid;
  border-color: #e88a92;
  box-shadow: 0 0 0 3px rgba(225, 75, 75, .1);
}

/* ---------- Statistiques ---------- */

.stats-meta {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  margin-bottom: 10px;
  font-size: 12px;
}
.stat-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.stat-count { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.stat-bar {
  grid-column: 1 / -1;
  height: 5px;
  border-radius: 99px;
  background: #eef0f7;
  overflow: hidden;
}
.stat-bar i { display: block; height: 100%; border-radius: 99px; }

.stats-empty { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }

/* ---------- Calendrier ---------- */

.calendar-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.month-nav { display: flex; align-items: center; gap: 4px; min-width: 0; }

.month-title {
  margin: 0;
  min-width: 200px;
  text-align: center;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.015em;
  white-space: nowrap;
}

.brush-banner {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 8px 11px;
  font-size: 12.5px;
  color: #3d469c;
  background: #f0f2ff;
  border: 1px solid #d9deff;
  border-radius: 10px;
}
.brush-banner .brush-dot {
  width: 22px; height: 22px;
  flex: none;
  display: grid; place-items: center;
  border-radius: 7px;
  font-size: 12px;
}
.brush-banner kbd {
  font: inherit;
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid #c9cfff;
  background: #fff;
}
.brush-banner .btn { margin-left: auto; color: #3d469c; }
.brush-banner .btn:hover { background: #e2e7ff; }

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 6px;
}
.weekdays div {
  padding: 2px 0;
  text-align: center;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.weekdays div.weekend { color: #c25a86; }

.grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.day {
  position: relative;
  min-width: 0;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: #fff;
  border: 1px solid #eceef5;
  border-radius: 12px;
  transition: border-color .12s, box-shadow .12s;
}
.day::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--tint, transparent);
  pointer-events: none;
}
.day.weekend { background: #fcfcfe; }
.day.other { background: #fafbfd; }
.day.other .daynum,
.day.other .chips { opacity: .5; }
.day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.day.drop {
  border-color: var(--accent);
  background: #f2f4ff;
  box-shadow: 0 0 0 3px rgba(91, 107, 255, .16);
}
.day:focus-visible { outline: 2px solid rgba(91, 107, 255, .5); outline-offset: 1px; }

body.painting, body.painting * { user-select: none; cursor: crosshair !important; }

.day-head {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: 21px;
}

.daynum {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-size: 11.5px;
  font-weight: 700;
  color: #7a8194;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
}
.day.weekend .daynum { color: #a4738c; }
.day.today .daynum { background: var(--accent); color: #fff; }

.day-add {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: #5b6478;
  background: #eef0f8;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  opacity: .4;
  transition: opacity .12s, background .12s, color .12s;
}
.day:hover .day-add { opacity: 1; }
.day-add:hover { background: var(--accent); color: #fff; }

.chips {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.chip {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  padding: 2.5px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--tc, #fff);
  background: var(--c, #64748b);
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .1);
  cursor: grab;
  user-select: none;
  transition: filter .12s, opacity .12s;
}
.chip:hover { filter: brightness(1.07); }
.chip.dragging { opacity: .35; }
.chip:active { cursor: grabbing; }

.chip-emoji { flex: none; font-size: 10.5px; }
.chip-text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chip-time {
  margin-right: 4px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: .92;
}

/* ---------- Dialogues ---------- */

.dialog {
  width: min(545px, calc(100vw - 28px));
  padding: 0;
  color: var(--text);
  background: #fff;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 26px 70px rgba(16, 24, 40, .28);
}
.dialog-sm { width: min(470px, calc(100vw - 28px)); }
.dialog::backdrop {
  background: rgba(20, 24, 40, .42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.dialog-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: #525a6b;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  transition: border-color .14s, box-shadow .14s, background .14s;
}
.field textarea { resize: vertical; min-height: 54px; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 107, 255, .16);
}
.field input[type="color"] {
  width: 100%;
  height: 39px;
  padding: 3px;
  cursor: pointer;
  background: #fff;
}
.field.emoji { width: 74px; flex: none; }
.field.date { width: 152px; flex: none; }
.field.color { width: 64px; flex: none; }

.form-row { display: flex; gap: 10px; }
.form-row .grow { flex: 1; }

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.switch input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 24px; height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--sw);
  box-shadow: 0 0 0 1px #dfe3ef;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--sw); }

.dialog-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.spacer { flex: 1; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 100;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: #20242f;
  border-radius: 12px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .26);
  opacity: 0;
  transform: translate(-50%, 18px);
  pointer-events: none;
  transition: opacity .22s, transform .22s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsive ---------- */

@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .sidebar { gap: 12px; }
  .palette {
    flex-direction: row;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .type-item {
    flex: none;
    background: #f7f8fc;
    border-color: var(--line);
    padding: 5px 8px;
  }
  .type-label { max-width: 140px; }
  .type-edit { opacity: .55; }
  .eraser { flex-direction: row; align-items: center; gap: 8px; }
  .eraser span { font-size: 10.5px; }
  .tip { display: none; }
}

@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  .brand-icon { width: 36px; height: 36px; font-size: 18px; }
  .mode-badge { display: none; }
  .day { min-height: 82px; border-radius: 10px; padding: 4px; gap: 3px; }
  .chip { font-size: 10px; padding: 2px 4px; border-radius: 6px; }
  .daynum { width: 19px; height: 19px; font-size: 10.5px; }
  .calendar-panel { padding: 10px; }
  .month-title { min-width: 0; font-size: 15.5px; }
}

@media (max-width: 560px) {
  .brand-text h1 { font-size: 15px; }
  .brand-icon { display: none; }
  .top-actions { gap: 2px; }
  #modeBtn { padding: 5px 7px; font-size: 11px; }
  .child-line > span:first-child { display: none; }
  #childName { width: 120px; }
  .weekdays { gap: 3px; }
  .weekdays div { font-size: 9px; letter-spacing: .02em; }
  .grid { gap: 3px; }
  .day { min-height: 68px; padding: 3px; border-radius: 8px; }
  .chips { gap: 2px; }
  .chip { font-size: 9.5px; padding: 2px 3px; }
  .chip-emoji { display: none; }
  .chip-time { display: none; }
  .day-add { display: none; }
  .month-nav { gap: 0; }
  .month-title { font-size: 14.5px; padding: 0 2px; }
  .cal-toolbar .btn { padding: 7px 10px; font-size: 12px; }
  .dialog form { padding: 16px; }
  .form-row { flex-wrap: wrap; }
  .field.date { width: 100%; flex: 1; }
}

/* ---------- Impression ---------- */

@media print {
  @page { margin: 12mm; }
  body { background: #fff; }
  .topbar, .sidebar, .day-add, .toast, .brush-banner, .cal-toolbar .btn, .mode-box, .readonly-hint { display: none !important; }
  .layout { display: block; max-width: none; padding: 0; }
  .calendar-panel { border: 0; box-shadow: none; padding: 0; }
  .month-title { text-align: left; min-width: 0; font-size: 18px; }
  .cal-toolbar { margin-bottom: 10px; }
  .day { min-height: 92px; break-inside: avoid; }
  .chip { box-shadow: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
