*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-a:      #4f7df3;
  --color-b:      #e8724a;
  --color-bg:     #f4f6fb;
  --color-card:   #ffffff;
  --color-border: #e0e4ed;
  --color-text:   #222;
  --color-muted:  #888;
  --radius:       12px;
  --shadow:       0 2px 8px rgba(0,0,0,.07);
}

/* ── Dark mode ───────────────────────────────────────── */
[data-theme="dark"] {
  --color-bg:     #1a1d23;
  --color-card:   #252830;
  --color-border: #363a45;
  --color-text:   #e8eaf0;
  --color-muted:  #7a7f8e;
  --shadow:       0 2px 8px rgba(0,0,0,.35);
}
[data-theme="dark"] header               { background: #252830; border-color: #363a45; }
[data-theme="dark"] .overlay-box         { background: #252830; }
[data-theme="dark"] input[type="text"],
[data-theme="dark"] select               { background: #1a1d23; color: var(--color-text); }
[data-theme="dark"] .cal-today .cal-col-header { background: #1e3060; }
[data-theme="dark"] .btn-identity        { background: #1a1d23; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────── */
header {
  background: #fff;
  border-bottom: 1px solid var(--color-border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

header h1 { font-size: 1.05rem; font-weight: 700; }

.view-tabs { display: flex; gap: 4px; }

.tab-btn {
  font-size: .8rem;
  font-weight: 600;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-muted);
  cursor: pointer;
  transition: all .15s;
}
.tab-btn.active          { background: var(--color-a); color: #fff; border-color: var(--color-a); }
.tab-btn:not(.active):hover { border-color: var(--color-a); color: var(--color-a); }

.user-chip {
  font-size: .82rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  cursor: pointer;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  transition: opacity .15s;
}

/* ── Print button ────────────────────────────────────── */
.btn-print {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--color-text);
  transition: background .15s;
}
.btn-print:hover { background: var(--color-bg); }
body[data-view="calendar"] .btn-print { display: none; }

/* ── Theme toggle button ─────────────────────────────── */
.btn-theme {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-theme:hover { background: var(--color-bg); }
.user-chip:hover { opacity: .75; }
.user-chip[data-person="A"] { color: var(--color-a); border-color: var(--color-a); }
.user-chip[data-person="B"] { color: var(--color-b); border-color: var(--color-b); }

/* ── Main ────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 12px 8px 20px;
  overflow-x: auto;
}

/* ── Calendar navigation ─────────────────────────────── */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem 0 0.75rem;
}
.cal-nav-btn {
  background: none;
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  padding: 0.25rem 0.75rem;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--color-text);
  transition: background .15s;
}
.cal-nav-btn:hover { background: var(--color-bg); }
.cal-nav-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-muted);
  min-width: 180px;
  text-align: center;
}

/* ── Calendar grid ───────────────────────────────────── */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(148px, 1fr));
  gap: 8px;
  min-width: 780px;
}

.cal-col {
  background: var(--color-card);
  border-radius: var(--radius);
  border: 1.5px solid var(--color-border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.cal-col.cal-today {
  border-color: var(--color-a);
  border-width: 2px;
}

.cal-col-header {
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-bg);
}
.cal-today .cal-col-header { background: #ddeaff; }

.cal-day-name {
  font-size: .65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
}
.cal-today .cal-day-name { color: var(--color-a); }

.cal2w-date {
  font-size: .78rem;
  font-weight: 600;
  color: var(--color-text);
  margin-top: 2px;
}
.cal-today .cal2w-date { color: var(--color-a); }


.cal-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cal-empty {
  text-align: center;
  color: var(--color-muted);
  font-size: .8rem;
  padding: 10px 0;
}

/* ── Time labels ─────────────────────────────────────── */
.cal-time-label {
  font-size: .6rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
  padding: 0 2px;
  border-top: 1px solid var(--color-border);
  padding-top: 5px;
  margin-top: 2px;
}
.cal-body > .cal-time-label:first-child { border-top: none; margin-top: 0; padding-top: 0; }

/* ── Task cards ──────────────────────────────────────── */
.cal-task {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 7px 8px;
  position: relative;
}

.cal-task-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}

.cal-task-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.cal-task-name {
  font-size: .82rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
}

/* Task action buttons (edit + delete) */
.cal-task-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
}
.cal-task:hover .cal-task-actions { opacity: 1; }

.cal-btn-edit,
.cal-btn-duplicate,
.cal-btn-delete {
  background: none;
  border: none;
  font-size: .72rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--color-muted);
  line-height: 1;
  transition: color .12s, background .12s;
}
.cal-btn-edit:hover      { color: var(--color-a); background: #ddeaff; }
.cal-btn-duplicate:hover { color: #0d7a65;        background: #d1faf0; }
.cal-btn-delete:hover    { color: #c0392b;         background: #fde8e0; }

/* Drag & drop (Sortable.js) */
.cal-task[data-recurrence="weekly"],
.cal-task[data-recurrence="monthly"],
.cal-task[data-recurrence="yearly"]         { cursor: grab; }
.cal-task[data-recurrence="weekly"]:active,
.cal-task[data-recurrence="monthly"]:active,
.cal-task[data-recurrence="yearly"]:active  { cursor: grabbing; }
.sortable-ghost  { opacity: .3; }
.sortable-chosen { box-shadow: 0 4px 16px rgba(79,125,243,.3); }

/* ── Assignee circles ────────────────────────────────── */
.assignee-circles {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}

.initials-circle {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: #fff;
  font-size: .67rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: .03em;
}
.circle-a { background: var(--color-a); }
.circle-b { background: var(--color-b); }

/* ── Room badges ─────────────────────────────────────── */
.room-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: .95rem;
  flex-shrink: 0;
  line-height: 1;
}
.room-cuisine    { background: #fde8c8; color: #b75500; }
.room-salon      { background: #ddeaff; color: #1d4ed8; }
.room-chambre    { background: #ede8f7; color: #6d28d9; }
.room-sdb        { background: #d1faf0; color: #0d7a65; }
.room-wc         { background: #ececec; color: #555;    }
.room-bureau     { background: #d1fae5; color: #065f46; }
.room-exterieur  { background: #dcfce7; color: #166534; }
.room-general    { background: #f0f0f0; color: #666;    }

/* ── Monthly grid ────────────────────────────────────── */
.monthly-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px;
  min-width: 600px;
}

.month-col {
  background: var(--color-card);
  border-radius: var(--radius);
  border: 1.5px solid var(--color-border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.month-col-header {
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--color-bg);
}

.month-week-name {
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
}

.month-week-dates {
  font-size: .65rem;
  color: var(--color-muted);
  margin-top: 1px;
}

/* ── Yearly grid ─────────────────────────────────────── */
.yearly-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px;
  min-width: 600px;
}

.year-col {
  background: var(--color-card);
  border-radius: var(--radius);
  border: 1.5px solid var(--color-border);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.year-col-header {
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}

.year-month-name {
  font-size: .7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-muted);
}

/* ── Empty message ───────────────────────────────────── */
.empty-msg { text-align: center; color: var(--color-muted); margin-top: 40px; font-size: .95rem; }

/* ── Add-day button ──────────────────────────────────── */
.cal-btn-add-day {
  width: 100%;
  padding: 6px 0;
  background: none;
  border: 1.5px dashed var(--color-border);
  border-radius: 8px;
  color: var(--color-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
  margin-top: 2px;
}
.cal-btn-add-day:hover {
  color: var(--color-a);
  border-color: var(--color-a);
  background: #f0f4ff;
}

/* ── Overlays ────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px 22px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.overlay-box h2 { font-size: 1.1rem; margin-bottom: 18px; text-align: center; }

/* Identity buttons */
.btn-identity {
  display: block;
  width: 100%;
  padding: 16px;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-bg);
  cursor: pointer;
  margin-bottom: 12px;
  transition: border-color .15s, background .15s;
}
.btn-identity[data-person="A"]:hover { border-color: var(--color-a); background: #ddeaff; }
.btn-identity[data-person="B"]:hover { border-color: var(--color-b); background: #fde8e0; }

/* Form */
label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: .83rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
}

input[type="text"], select {
  padding: 8px 11px;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  font-size: .92rem;
  width: 100%;
  font-family: inherit;
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color .15s;
}
input[type="text"]:focus, select:focus { outline: none; border-color: var(--color-a); }

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 6px;
}

.btn-primary {
  background: var(--color-a);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 20px;
  font-size: .88rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover { opacity: .85; }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  padding: 9px 15px;
  font-size: .88rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: var(--color-border); }

.error-msg { color: #c0392b; font-size: .8rem; font-weight: 500; }
.hidden { display: none !important; }

/* ── Responsive mobile ───────────────────────────────── */
@media (max-width: 767px) {

  header { padding: 8px 10px; gap: 4px; }
  header h1 { font-size: .85rem; }
  .tab-btn { padding: 4px 8px; font-size: .72rem; }

  main { padding: 8px 6px 20px; }

  .calendar-grid {
    grid-template-columns: 1fr;
    min-width: 0;
    gap: 6px;
  }

  .monthly-grid,
  .yearly-grid {
    grid-template-columns: repeat(2, 1fr);
    min-width: 0;
  }

  .cal-btn-edit,
  .cal-btn-duplicate,
  .cal-btn-delete {
    padding: 6px 10px;
    font-size: .85rem;
    opacity: 1;
  }

  .cal-day-name   { font-size: .75rem; }
  .cal2w-date     { font-size: .85rem; }
  .cal-time-label { font-size: .7rem; }

  .form-actions { flex-direction: column; }
  .form-actions .btn-primary,
  .form-actions .btn-secondary { width: 100%; text-align: center; }
}

/* ── Toasts ──────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .88rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 1;
  transition: opacity .35s;
}
.toast.toast-success { background: #0d7a65; }
.toast.toast-error   { background: #c0392b; }
.toast.fade-out      { opacity: 0; }

/* ── Print / PDF ─────────────────────────────────────── */
@media print {
  @page { size: A4 landscape; margin: 12mm; }

  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  header, .cal-nav, .cal-btn-add-day,
  .cal-task-actions, #empty-msg { display: none !important; }

  body, main { background: white; }
  main { padding: 0; }

  .calendar-grid {
    grid-template-columns: repeat(4, 1fr);
    min-width: 0;
    gap: 4px;
  }

  .monthly-grid {
    grid-template-columns: repeat(4, 1fr);
    min-width: 0;
    gap: 4px;
  }

  .yearly-grid {
    grid-template-columns: repeat(3, 1fr);
    min-width: 0;
    gap: 4px;
  }

  .cal-task              { break-inside: avoid; }
  .cal-col, .month-col, .year-col { break-inside: avoid; }

  .cal-task-name { font-size: .78rem; }
}
