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

/* ────────────────────────────────────────────────────────────────────────
   THÈMES — design system TimeSheet v2
   Par défaut : Sky Medical (clair). Variantes : indigo, stone, dark.
   Toutes les variantes light partagent les mêmes neutres (bg/surface/text)
   et ne diffèrent que par l'accent. Le thème sombre garde l'ambiance v1.
   ──────────────────────────────────────────────────────────────────────── */

/* ── Thème par défaut : Sky Medical (clair) ─────────── */
:root {
  /* Neutres communs aux 3 thèmes light */
  --bg:        #f1f5f9;      /* slate-100 — fond général */
  --surface:   #ffffff;      /* cards & panneaux */
  --card:      #f8fafc;      /* slate-50 — surface secondaire */
  --card2:     #f1f5f9;      /* slate-100 — surface tertiaire */
  --weekend-bg: #e0f2fe;     /* sky-100 — fond samedi/dimanche, harmonise avec accent */
  --weekend-text: #475569;   /* slate-600 — texte weekend, plus discret */
  --border:    #e2e8f0;      /* slate-200 — bordures fines */
  --border2:   #cbd5e1;      /* slate-300 — bordures emphase */
  --text:      #0f172a;      /* slate-900 — texte principal */
  --text2:     #334155;      /* slate-700 — texte secondaire */
  --muted:     #64748b;      /* slate-500 — labels & meta */
  --muted2:    #94a3b8;      /* slate-400 — hints très discrets */
  --input-bg:  #ffffff;

  /* Accent — Sky Medical */
  --accent:    #0284c7;      /* sky-600 */
  --accent2:   #0369a1;      /* sky-700 — hover */
  --accent-dim:#e0f2fe;      /* sky-100 — fond pill/badge */
  --on-accent: #ffffff;      /* texte sur fond accent */

  /* Couleurs sémantiques */
  --green:     #059669;      /* validation, jour rempli */
  --green-dim: #d1fae5;
  --red:       #dc2626;      /* erreur, supprimer */
  --red-dim:   #fee2e2;
  --amber:     #d97706;      /* warning, attention */
  --amber-dim: #fef3c7;
  --blue:      #2563eb;
  --blue-dim:  #dbeafe;

  /* Layout / typo */
  --sidebar-w: 260px;
  --radius:    10px;
  --radius-lg: 14px;
  --font-head: 'Syne', sans-serif;
  --font-body: 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
  --ring:      0 0 0 3px rgba(2, 132, 199, 0.18);

  /* Aliases legacy (v1 → v2) : permettent au CSS existant de continuer
     à utiliser --amber* sans tout réécrire. Pointent vers --accent. */
  --amber:     var(--accent);
  --amber2:    var(--accent2);
  --amber-dim: var(--accent-dim);
}

/* ── Thème Indigo Clinique (clair alt) ───────────────── */
[data-theme="indigo"] {
  --accent:     #4f46e5;     /* indigo-600 */
  --accent2:    #4338ca;     /* indigo-700 */
  --accent-dim: #eef2ff;     /* indigo-50 */
  --ring:       0 0 0 3px rgba(79, 70, 229, 0.20);
  --weekend-bg: #e0e7ff;     /* indigo-100 — harmonise avec accent */
}

/* ── Thème Stone Editorial (clair alt) ───────────────── */
[data-theme="stone"] {
  --bg:        #fafaf9;      /* stone-50 */
  --surface:   #ffffff;
  --card:      #f5f5f4;      /* stone-100 */
  --card2:     #e7e5e4;      /* stone-200 */
  --border:    #e7e5e4;      /* stone-200 */
  --border2:   #d6d3d1;      /* stone-300 */
  --text:      #1c1917;      /* stone-900 */
  --text2:     #44403c;      /* stone-700 */
  --muted:     #78716c;      /* stone-500 */
  --muted2:    #a8a29e;      /* stone-400 */
  --accent:    #18181b;      /* zinc-900 — accent noir */
  --accent2:   #27272a;      /* zinc-800 */
  --accent-dim:#fff7ed;      /* orange-50 — touche chaleur */
  --on-accent: #ffffff;
  --ring:      0 0 0 3px rgba(234, 88, 12, 0.18);
  --weekend-bg: #e7e5e4;     /* stone-200 — contraste warm */
  --weekend-text: #57534e;   /* stone-600 */
}

/* ── Thème Sombre (legacy v1) ────────────────────────── */
[data-theme="dark"] {
  --bg:        #0b0d12;
  --surface:   #12151f;
  --card:      #181b26;
  --card2:     #1e2130;
  --border:    #242838;
  --border2:   #2e3347;
  --text:      #e2e8f0;
  --text2:     #cbd5e1;
  --muted:     #64748b;
  --muted2:    #475569;
  --input-bg:  #12151f;
  --accent:    #f59e0b;
  --accent2:   #fbbf24;
  --accent-dim:#451a03;
  --on-accent: #000000;
  --weekend-bg: #1e2130;     /* slate-tinted, légèrement plus sombre que --card */
  --weekend-text: #94a3b8;
  --green:     #34d399;
  --green-dim: #064e3b;
  --red:       #f87171;
  --red-dim:   #7f1d1d;
  --amber:     #fbbf24;
  --amber-dim: #422006;
  --blue:      #60a5fa;
  --blue-dim:  #1e3a8a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:    0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  --ring:      0 0 0 3px rgba(245, 158, 11, 0.25);
}

html, body {
  height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body);
  transition: background 0.3s, color 0.3s;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: var(--font-body); }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ═══════════════════════════════════════════════════════ THEME SWITCHER */
.theme-row {
  padding: 10px 12px 6px;
  border-top: 1px solid var(--border);
}
.theme-label {
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase; margin-bottom: 7px;
}
.theme-pills { display: flex; gap: 5px; }
.theme-pill {
  flex: 1; padding: 5px 0; border-radius: 6px;
  font-size: 10px; font-family: var(--font-mono);
  border: 1px solid var(--border2); color: var(--muted);
  text-align: center; transition: all 0.15s; cursor: pointer;
  line-height: 1;
}
.theme-pill:hover { border-color: var(--accent); color: var(--accent); }
.theme-pill.active {
  background: var(--accent); color: var(--on-accent);
  border-color: var(--accent); font-weight: 600;
}
.theme-pill .pill-icon { display: block; font-size: 13px; margin-bottom: 2px; }

/* ═══════════════════════════════════════════════════════ LAYOUT */
#app { display: flex; height: 100vh; }

/* ═══════════════════════════════════════════════════════ SIDEBAR */
#sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.sidebar-logo {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--amber); display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.sidebar-logo .logo-mark span {
  font-family: var(--font-head); font-weight: 700; font-size: 14px; color: var(--on-accent);
}
.sidebar-logo .logo-text { font-family: var(--font-head); font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.sidebar-logo .logo-text small { display: block; font-family: var(--font-mono); font-size: 9px; color: var(--muted); font-weight: 400; letter-spacing: 0.08em; }

.sidebar-section-label {
  padding: 14px 18px 6px;
  font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
}
.client-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.client-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
  transition: background 0.15s; position: relative;
  margin-bottom: 2px;
}
.client-item:hover { background: var(--card); }
.client-item.active { background: var(--card2); }
.client-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 60%; border-radius: 2px;
  background: var(--client-color, var(--amber));
}
.client-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  background: var(--client-color, var(--amber));
}
.client-name { font-size: 13px; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-edit-btn {
  opacity: 0; width: 22px; height: 22px; border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); transition: all 0.15s; flex-shrink: 0;
}
.client-edit-btn:hover { background: var(--border2); color: var(--text); }
.client-item:hover .client-edit-btn { opacity: 1; }

.sidebar-add-btn {
  margin: 8px 8px; padding: 8px 12px; border-radius: 7px;
  border: 1px dashed var(--border2); color: var(--muted);
  font-size: 12px; font-family: var(--font-body);
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s; width: calc(100% - 16px);
}
.sidebar-add-btn:hover { border-color: var(--amber); color: var(--amber); background: var(--amber-dim); }

.sidebar-bottom {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}
.settings-btn {
  width: 100%; padding: 8px 10px; border-radius: 7px;
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px;
  transition: all 0.15s;
}
.settings-btn:hover { background: var(--card); color: var(--text); }
.settings-btn svg { flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════ MAIN */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── Top bar */
#topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  flex-shrink: 0;
}
.month-nav { display: flex; align-items: center; gap: 12px; }
.month-nav button {
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--border2); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.month-nav button:hover { border-color: var(--accent); color: var(--accent); }
#month-label {
  font-family: var(--font-body); font-size: 18px; font-weight: 600;
  min-width: 180px; text-align: center;
  letter-spacing: -0.01em;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.export-btn {
  padding: 8px 14px; border-radius: 7px;
  background: var(--accent); color: var(--on-accent);
  font-size: 12px; font-weight: 500; font-family: var(--font-body);
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s; letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
}
.export-btn:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: var(--shadow); }
.import-btn {
  padding: 7px 12px; border-radius: 7px;
  border: 1px solid var(--border2); color: var(--muted);
  font-size: 12px; font-family: var(--font-body);
  display: flex; align-items: center; gap: 6px;
  transition: all 0.15s;
}
.import-btn:hover { border-color: var(--border); color: var(--text); }
.today-btn {
  padding: 7px 10px; border-radius: 7px;
  border: 1px solid var(--border2); color: var(--muted);
  font-size: 11px; font-family: var(--font-mono);
  transition: all 0.15s;
}
.today-btn:hover { border-color: var(--blue); color: var(--blue); }

/* ── Calendar */
#calendar-wrap { flex: 1; overflow-y: auto; padding: 20px 24px; }
.no-client {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: 12px;
  color: var(--muted); text-align: center;
}
.no-client .icon { font-size: 48px; opacity: 0.3; }
.no-client p { font-size: 14px; }
.no-client strong { color: var(--amber); }

.cal-grid-header {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 8px; margin-bottom: 8px;
}
.cal-day-header {
  text-align: center; padding: 8px 6px;
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em;
  color: var(--muted); text-transform: uppercase;
  font-weight: 500;
}
.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}
.cal-day {
  border-radius: var(--radius);
  border: 1px solid var(--border2);
  background: var(--surface);
  min-height: 100px; padding: 10px;
  cursor: pointer; position: relative;
  transition: all 0.15s;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.cal-day:hover {
  border-color: var(--accent);
  background: var(--card);
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.cal-day.empty { background: transparent; border-color: transparent; box-shadow: none; cursor: default; pointer-events: none; }
.cal-day.today { border-color: var(--accent) !important; border-width: 2px; padding: 9px; }
.cal-day.today .cal-day-num { color: var(--accent); font-weight: 600; }
.cal-day.has-data { border-color: var(--accent); }
.cal-day.has-data::after {
  content: ''; position: absolute;
  top: 0; left: 0; right: 0; height: 3px;
  background: var(--client-color, var(--accent));
  border-radius: var(--radius) var(--radius) 0 0;
}
.cal-day.weekend { background: var(--weekend-bg); }
.cal-day.weekend .cal-day-num { color: var(--weekend-text, var(--muted2)); }
.cal-day-num {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  color: var(--text2); margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.task-count {
  font-size: 10px; padding: 2px 7px; border-radius: 20px;
  background: var(--client-color, var(--accent)); color: #fff;
  font-weight: 500; font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.cal-task-preview {
  font-size: 10px; color: var(--muted); line-height: 1.4;
  overflow: hidden;
}
.cal-task-preview .task-line {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 1px 0;
}
.cal-task-preview .task-line:first-child { color: var(--text); font-size: 10.5px; }
.cal-task-preview .more { color: var(--muted2); font-size: 9px; margin-top: 2px; }

/* ═══════════════════════════════════════════════════════ MODALS */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: 14px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.6);
  transform: translateY(12px) scale(0.98);
  transition: transform 0.2s;
  overflow: hidden;
}
.modal-overlay.show .modal { transform: none; }

/* Day edit modal */
#day-modal .modal { width: 520px; max-height: 80vh; display: flex; flex-direction: column; }
.modal-head {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-head .date-label { flex: 1; }
.modal-head .date-label .day-name {
  font-family: var(--font-mono); font-size: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 2px;
}
.modal-head .date-label .day-date {
  font-family: var(--font-body); font-size: 18px; font-weight: 600;
  letter-spacing: -0.01em;
}
.modal-head .client-chip {
  padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--client-color, var(--amber)); color: #000;
}
.modal-close {
  width: 28px; height: 28px; border-radius: 6px;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--border); color: var(--text); }
.modal-body { padding: 16px 20px; flex: 1; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* Task list in modal */
.task-input-list { display: flex; flex-direction: column; gap: 6px; }
.task-input-row {
  display: flex; align-items: flex-start; gap: 8px;
}
.task-drag-handle {
  color: var(--muted); padding-top: 9px; cursor: grab; flex-shrink: 0;
  opacity: 0.4; transition: opacity 0.15s;
}
.task-input-row:hover .task-drag-handle { opacity: 1; }
.task-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 7px 10px; color: var(--text); font-size: 13px;
  resize: none; min-height: 36px; line-height: 1.5;
  transition: border-color 0.15s;
  overflow: hidden;
}
.task-input:focus { outline: none; border-color: var(--amber); }
.task-del-btn {
  width: 28px; height: 28px; border-radius: 6px; margin-top: 4px;
  color: var(--muted); display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.task-del-btn:hover { background: rgba(248,113,113,0.15); color: var(--red); }
.add-task-btn {
  margin-top: 8px; padding: 7px 12px; border-radius: 7px;
  border: 1px dashed var(--border2); color: var(--muted);
  font-size: 12px; display: flex; align-items: center; gap: 6px;
  width: 100%; transition: all 0.15s;
}
.add-task-btn:hover { border-color: var(--amber); color: var(--amber); background: var(--amber-dim); }

.import-section {
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border);
}
.import-section label {
  font-size: 11px; color: var(--muted); font-family: var(--font-mono); letter-spacing: 0.08em;
  display: block; margin-bottom: 6px;
}
.import-textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 10px; color: var(--muted); font-size: 12px;
  font-family: var(--font-mono); resize: vertical; min-height: 70px;
  line-height: 1.5; transition: border-color 0.15s;
}
.import-textarea:focus { outline: none; border-color: var(--blue); color: var(--text); }
.parse-btn {
  margin-top: 6px; padding: 6px 12px; border-radius: 6px;
  background: var(--blue-dim); color: var(--blue);
  font-size: 11px; border: 1px solid var(--blue); font-family: var(--font-body);
  transition: all 0.15s;
}
.parse-btn:hover { background: var(--blue); color: #000; }

/* Buttons */
.btn-primary {
  padding: 9px 16px; border-radius: 7px;
  background: var(--accent); color: var(--on-accent);
  font-size: 13px; font-weight: 500; font-family: var(--font-body);
  transition: all 0.15s;
}
.btn-primary:hover { background: var(--amber2); }
.btn-ghost {
  padding: 8px 14px; border-radius: 7px;
  border: 1px solid var(--border2); color: var(--muted);
  font-size: 13px; font-family: var(--font-body);
  transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--border); color: var(--text); }
.btn-danger {
  padding: 8px 14px; border-radius: 7px;
  border: 1px solid rgba(248,113,113,0.3); color: var(--red);
  font-size: 13px; font-family: var(--font-body);
  transition: all 0.15s;
}
.btn-danger:hover { background: rgba(248,113,113,0.1); }

/* Client modal */
#client-modal .modal { width: 380px; }
.field-group { margin-bottom: 14px; }
.field-label {
  font-size: 11px; color: var(--muted); font-family: var(--font-mono);
  letter-spacing: 0.08em; margin-bottom: 6px; display: block;
}
.field-input {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 7px; padding: 8px 12px; color: var(--text); font-size: 14px;
  transition: border-color 0.15s;
}
.field-input:focus { outline: none; border-color: var(--amber); }
.color-picker-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: all 0.15s;
}
.color-swatch.selected { border-color: var(--text); transform: scale(1.15); }
.color-custom { display: flex; align-items: center; gap: 6px; }
.color-custom input[type=color] {
  width: 28px; height: 28px; border: none; background: none; cursor: pointer;
  border-radius: 50%; padding: 0;
}

/* Export modal */
#export-modal .modal { width: 440px; }
.export-period { display: flex; gap: 10px; }
.export-period .field-group { flex: 1; }
.export-mode-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab-btn {
  flex: 1; padding: 7px; border-radius: 6px; font-size: 12px;
  font-family: var(--font-body); color: var(--muted);
  border: 1px solid var(--border); transition: all 0.15s;
}
.tab-btn.active { background: var(--card2); color: var(--text); border-color: var(--border2); }

/* Settings modal */
#settings-modal .modal { width: 500px; max-height: 85vh; display: flex; flex-direction: column; }
.settings-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.settings-section-title {
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em;
  color: var(--muted); text-transform: uppercase; margin-bottom: 12px; margin-top: 16px;
}
.settings-section-title:first-child { margin-top: 0; }
.settings-row { display: flex; gap: 10px; }
.settings-row .field-group { flex: 1; }
.logo-area {
  display: flex; align-items: center; gap: 14px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
  margin-bottom: 14px;
}
.logo-preview {
  width: 56px; height: 56px; border-radius: 8px;
  border: 1px solid var(--border); overflow: hidden;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 10px; flex-shrink: 0;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }
.logo-area-text { flex: 1; }
.logo-area-text p { font-size: 12px; color: var(--text); margin-bottom: 4px; }
.logo-area-text small { font-size: 11px; color: var(--muted); }
.logo-btns { display: flex; gap: 6px; margin-top: 8px; }
.btn-sm {
  padding: 5px 10px; border-radius: 6px; font-size: 11px;
  font-family: var(--font-body); transition: all 0.15s;
}

/* Toast */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  background: var(--card2); border: 1px solid var(--border2);
  border-radius: 10px; padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  transform: translateY(80px); opacity: 0;
  transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  font-size: 13px; pointer-events: none; max-width: 300px;
}
#toast.show { transform: none; opacity: 1; }
#toast.success { border-color: var(--green); }
#toast.error { border-color: var(--red); }
.toast-icon { font-size: 16px; flex-shrink: 0; }

/* Spinner */
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid rgba(0,0,0,0.2); border-top-color: #000;
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Pulse dot for today */
.today-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--amber);
  animation: pulse-dot 2s ease infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 var(--amber); }
  50% { opacity: 0.8; box-shadow: 0 0 0 4px transparent; }
}

.fade-in { animation: fadeUp 0.3s ease both; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ═══════════════════════════════════════════════════════ MENU TOGGLE (mobile) */
.menu-toggle {
  display: none;
  width: 38px; height: 38px; border-radius: 8px;
  align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border2);
  color: var(--text); margin-right: 10px;
  transition: background 0.15s, border-color 0.15s;
}
.menu-toggle:hover { background: var(--card); border-color: var(--accent); color: var(--accent); }

#sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 99;
  -webkit-tap-highlight-color: transparent;
}
#sidebar-backdrop.open { display: block; }

/* ═══════════════════════════════════════════════════════ RESPONSIVE */
@media (max-width: 900px) {
  /* Tablette : sidebar plus étroite */
  :root { --sidebar-w: 220px; }
  .cal-day { min-height: 80px; padding: 8px; }
  .cal-day-num { font-size: 12px; margin-bottom: 4px; }
  .cal-task-preview { font-size: 9px; }
  #topbar { padding: 12px 16px; }
}

@media (max-width: 700px) {
  /* Mobile : sidebar passe en drawer overlay */
  .menu-toggle { display: inline-flex; }

  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }

  #main { width: 100%; }

  /* Topbar plus compact */
  #topbar {
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  #month-label { font-size: 16px; min-width: 0; }
  .today-btn { padding: 6px 10px; font-size: 11px; }
  .export-btn span, .import-btn span { display: none; }
  .topbar-right { gap: 6px; }

  /* Calendrier mobile : cellules très compactes mais lisibles */
  .cal-grid-header { gap: 4px; margin-bottom: 4px; }
  .cal-day-header { padding: 4px 2px; font-size: 9px; letter-spacing: 0.06em; }
  .cal-grid { gap: 4px; padding: 0 6px 6px; }
  .cal-day {
    min-height: 56px; padding: 6px 4px;
    border-radius: 8px;
  }
  .cal-day.today { padding: 5px 3px; }
  .cal-day-num { font-size: 11px; margin-bottom: 2px; }
  .cal-task-preview { display: none; }  /* trop petit pour être lisible, on garde juste le point de couleur */
  .task-count { font-size: 8px; padding: 1px 4px; }

  /* Modales en plein écran sur mobile */
  .modal {
    width: 100% !important; max-width: 100% !important;
    height: 100vh; max-height: 100vh;
    border-radius: 0;
  }
  .modal-body { padding: 16px; }
}

@media (max-width: 380px) {
  /* Très petit écran : cacher quelques éléments non essentiels */
  .today-btn { display: none; }
  .cal-day-header { font-size: 8px; }
}

/* ═══════════════════════════════════════════════════════ USER MENU (sidebar bottom) */
.user-row {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}
.user-info {
  flex: 1; display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 8px;
  text-decoration: none; color: var(--text);
  transition: background 0.15s;
  min-width: 0;  /* permet à user-detail de truncate */
}
.user-info:hover { background: var(--card); }
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
  font-family: var(--font-body);
}
.user-detail { flex: 1; min-width: 0; }
.user-name {
  font-size: 12px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-email {
  font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-family: var(--font-mono);
}
.user-logout {
  width: 32px; height: 32px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.15s;
  flex-shrink: 0;
}
.user-logout:hover {
  color: var(--red); border-color: var(--red);
  background: var(--red-dim);
}

/* ═══════════════════════════════════════════════════════ SIDEBAR — refonte v2 */

/* Ligne header Clients + bouton "+" en haut */
.sidebar-action-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 6px;
}
.sidebar-action-row .sidebar-section-label {
  padding: 0;  /* override le padding global */
}
.sidebar-add-icon {
  width: 26px; height: 26px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
  border: none; cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.sidebar-add-icon:hover { background: var(--accent2); }
.sidebar-add-icon:active { transform: scale(0.95); }

/* Bouton Paramètres : sobre, full width au-dessus du user */
.settings-btn {
  width: calc(100% - 16px); margin: 8px;
  padding: 9px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px;
  background: transparent; color: var(--text2);
  font-family: var(--font-body); font-size: 13px;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  cursor: pointer;
}
.settings-btn:hover {
  background: var(--card);
  color: var(--accent);
  border-color: var(--border);
}
.settings-btn svg { flex-shrink: 0; }

/* Bloc thèmes dans la modale Paramètres */
.settings-theme-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 8px; margin-bottom: 18px;
}
.settings-theme-row .theme-pill {
  padding: 10px 0; font-size: 11px;
  font-family: var(--font-body); letter-spacing: 0.02em;
}
.settings-theme-row .theme-pill .pill-icon {
  font-size: 14px; margin-bottom: 4px;
}

/* Override des styles legacy .sidebar-add-btn pour le rendre invisible si jamais
   du HTML l'utilise encore (au cas où) */
.sidebar-add-btn { display: none; }

/* ═══════════════════════════════════════════════════════ EXPORT FORMATS PICKER */
.export-formats {
  display: flex; flex-direction: column; gap: 6px;
}
.export-format {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.export-format:hover { border-color: var(--border2); background: var(--card); }
.export-format.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.export-format input[type="radio"] {
  margin-top: 3px; accent-color: var(--accent);
}
.export-format-text { flex: 1; min-width: 0; }
.export-format-label {
  font-size: 13px; font-weight: 500; color: var(--text);
  margin-bottom: 2px;
}
.export-format-desc {
  font-size: 11px; color: var(--muted);
  line-height: 1.4;
}

/* ═══════════════════════════════════════════════════════ PHASE 7B — Vue matricielle */

/* ── Toggle Calendrier / Matriciel dans le topbar ── */
.view-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
  margin-left: 8px;
}
.view-toggle-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 12px; font-weight: 500;
  border: none; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.view-toggle-btn:hover { color: var(--text); background: var(--surface); }
.view-toggle-btn.active {
  background: var(--accent);
  color: var(--on-accent);
}
.view-toggle-btn svg { flex-shrink: 0; }

/* ── Matrice : table scrollable horizontalement ── */
.matrix-scroll {
  width: 100%;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.matrix-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-family: var(--font-body);
  font-size: 12px;
}
.matrix-grid thead th {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase;
  padding: 8px 4px;
  text-align: center;
  position: sticky; top: 0;
  z-index: 2;
}
.matrix-grid .matrix-col-code,
.matrix-grid .matrix-col-label {
  position: sticky; left: 0;
  background: var(--surface);
  z-index: 3;
  text-align: left;
  border-right: 1px solid var(--border);
}
.matrix-grid thead .matrix-col-code,
.matrix-grid thead .matrix-col-label {
  z-index: 4; background: var(--card);
}
.matrix-grid .matrix-col-code  { left: 0;     min-width: 72px;  padding-left: 12px; }
.matrix-grid .matrix-col-label { left: 72px;  min-width: 180px; padding-right: 8px; }
.matrix-grid .matrix-col-total {
  text-align: center; font-weight: 700; color: var(--text);
  border-left: 1px solid var(--border);
  background: var(--card);
  min-width: 60px;
}

.matrix-day-h {
  min-width: 34px;
}
.matrix-day-h .dow {
  font-size: 9px; color: var(--muted2); margin-bottom: 1px;
}
.matrix-day-h .dnum {
  font-size: 12px; font-weight: 700; color: var(--text);
  font-family: var(--font-body); letter-spacing: 0;
}
.matrix-day-h.weekend { background: var(--weekend-bg); opacity: 0.9; }
.matrix-day-h.weekend .dow,
.matrix-day-h.weekend .dnum { color: var(--weekend-text, var(--muted)); }
.matrix-day-h.today .dnum { color: var(--accent); }

/* Bouton "Notes du jour" dans l'en-tête de colonne (matriciel) — toujours visible */
.matrix-day-h { position: relative; padding-bottom: 22px !important; }
.day-notes-btn {
  position: absolute;
  bottom: 3px; left: 50%;
  transform: translateX(-50%);
  width: 18px; height: 18px;
  border-radius: 5px;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 1;
  transition: all 0.15s;
}
.day-notes-btn:hover {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  transform: translateX(-50%) scale(1.1);
}
.day-notes-btn:active { transform: translateX(-50%) scale(0.95); }
/* Jour avec notes : badge accent permanent (le user voit immédiatement où il y a du contenu) */
.matrix-day-h.has-notes .day-notes-btn {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
/* Jour sans notes : "+" plus discret mais visible */
.day-notes-btn-empty { opacity: 0.5; }
.matrix-day-h:hover .day-notes-btn-empty { opacity: 1; }

.matrix-grid tbody tr { transition: background 0.1s; }
.matrix-grid tbody tr:hover .matrix-cell:not(.filled) { background: var(--card); }

.matrix-row .matrix-col-code {
  font-family: var(--font-mono); font-size: 11px;
  font-weight: 700; color: var(--text);
  letter-spacing: 0.04em;
  border-top: 1px solid var(--border);
  padding: 8px 0 8px 12px;
}
.code-dot {
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle;
}
.matrix-row .matrix-col-label {
  color: var(--text2); font-size: 12px;
  border-top: 1px solid var(--border);
  padding: 8px;
}

.matrix-cell {
  text-align: center;
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border3, var(--border));
  padding: 6px 2px;
  cursor: pointer;
  color: var(--text);
  font-weight: 600;
  font-size: 11px;
  transition: background 0.1s, transform 0.05s;
  white-space: nowrap;
}
.matrix-cell:hover { background: var(--accent-dim, var(--card)); }
.matrix-cell.weekend { background: var(--weekend-bg); }
.matrix-cell.today {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}
.matrix-cell.filled { font-weight: 700; }
.matrix-cell.filled.weekend { background: var(--accent-dim); }
.matrix-cell .matrix-col-total { background: var(--card); }

.matrix-row .matrix-col-total {
  border-top: 1px solid var(--border);
  padding: 8px 4px;
  font-size: 12px;
}

.matrix-total-row td {
  background: var(--card) !important;
  border-top: 2px solid var(--accent);
  font-weight: 700;
  padding: 10px 4px;
  text-align: center;
  color: var(--text);
}
.matrix-total-row .matrix-col-code,
.matrix-total-row .matrix-col-label {
  text-align: left;
  font-family: var(--font-mono); font-size: 10px;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--muted);
}
/* Spécificité augmentée pour battre ``.matrix-total-row td`` qui set background:--card */
.matrix-total-row td.matrix-grand-total {
  background: var(--accent) !important;
  color: var(--on-accent) !important;
  font-size: 13px !important;
  border-left: 1px solid var(--accent) !important;
}
.matrix-total-cell.weekend { background: var(--weekend-bg) !important; opacity: 0.7; }

.matrix-empty {
  padding: 60px 24px;
  text-align: center;
  color: var(--muted);
}
.matrix-empty .icon {
  font-size: 40px; margin-bottom: 14px;
  color: var(--muted2);
}
.matrix-empty p { font-size: 14px; line-height: 1.6; }
.matrix-empty p.hint { font-size: 12px; margin-top: 8px; color: var(--muted2); }
.matrix-empty strong { color: var(--text); }

/* ── Popover saisie rapide ── */
.cell-popover {
  display: none;
  position: fixed;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 10px;
  min-width: 200px;
  animation: cpFadeIn 0.12s ease-out;
}
@keyframes cpFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cell-popover-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.cell-popover-label {
  font-size: 11px; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.cp-code-chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 4px;
  color: #fff; font-family: var(--font-mono);
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.05em;
}
.cp-date { font-size: 11px; color: var(--muted); }
.cell-popover-close {
  background: none; border: none; cursor: pointer;
  color: var(--muted); padding: 2px;
  border-radius: 4px;
}
.cell-popover-close:hover { background: var(--card); color: var(--text); }

.cell-popover-body {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.cp-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 8px 0;
  font-family: var(--font-body);
  font-size: 13px; font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.12s;
  display: flex; align-items: center; justify-content: center;
}
.cp-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim, var(--card));
}
.cp-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.cp-btn-clear { color: var(--red); }
.cp-btn-clear:hover { border-color: var(--red); background: var(--red-dim); }

/* Bouton "Notes du jour" dans la popover : pleine largeur sous les boutons valeurs */
.cell-popover-body .cp-btn-notes {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--text2);
  font-size: 11px;
  gap: 6px;
  position: relative;
}
.cell-popover-body .cp-btn-notes:hover {
  background: var(--card);
  color: var(--accent);
  border-color: var(--accent);
}
.cp-notes-count {
  display: inline-block;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 9px; font-weight: 700;
  line-height: 16px;
  text-align: center;
  margin-left: 4px;
}

/* Lien Administration dans la sidebar (visible uniquement pour les admins) */
.settings-btn.admin-link {
  color: var(--accent);
  text-decoration: none;
}
.settings-btn.admin-link:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* ─── Bandeau "Impersonate" — admin connecté en tant qu'un autre user ──── */
.impersonate-banner {
  position: sticky;
  top: 0;
  z-index: 9999;
  background: linear-gradient(90deg, #f59e0b 0%, #ef4444 100%);
  color: #fff;
  padding: 8px 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  font-family: var(--font-body);
  font-size: 0.88rem;
}
.impersonate-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
}
.impersonate-icon { flex-shrink: 0; }
.impersonate-text { flex: 1; min-width: 200px; line-height: 1.4; }
.impersonate-text strong { font-weight: 700; }
.impersonate-form { margin: 0; flex-shrink: 0; }
.impersonate-back-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.45);
  color: #fff;
  font-family: var(--font-body); font-size: 0.85rem; font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.impersonate-back-btn:hover {
  background: rgba(255,255,255,0.28);
  border-color: rgba(255,255,255,0.7);
  transform: translateY(-1px);
}
@media (max-width: 700px) {
  .impersonate-banner { padding: 8px 12px; font-size: 0.82rem; }
  .impersonate-banner-content { gap: 8px; }
}

/* ── Sections CRUD codes dans les modals ── */
.codes-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.codes-section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.codes-section-hint {
  font-size: 10px; color: var(--muted2);
  font-style: italic;
}
.codes-list {
  display: flex; flex-direction: column; gap: 6px;
  margin-bottom: 8px;
}
.codes-empty {
  font-size: 12px; color: var(--muted);
  padding: 12px; text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--card);
}
.codes-empty code {
  background: var(--surface); padding: 1px 5px;
  border-radius: 3px; font-size: 11px;
}
.codes-error {
  padding: 8px 12px;
  border-radius: 7px;
  background: var(--red-dim);
  color: var(--red);
  font-size: 12px;
}
.code-row {
  display: grid;
  grid-template-columns: 32px 70px 1fr 28px;
  gap: 6px;
  align-items: center;
  padding: 4px;
  border-radius: 7px;
  background: var(--card);
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.2s;
}
.code-row.invalid { border-color: var(--red); }
.code-row.saved { background: var(--green-dim, var(--card)); }
.code-color {
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0; cursor: pointer;
  background: var(--surface);
}
.code-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px; color: var(--text);
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.12s;
}
.code-input:focus { border-color: var(--accent); }
.code-code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.code-del-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 24px; height: 24px;
  border-radius: 5px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
}
.code-del-btn:hover { color: var(--red); border-color: var(--red); background: var(--red-dim); }
.codes-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 12px; color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-body);
}
.codes-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim, transparent);
}

/* ── Mobile responsive ── */
@media (max-width: 700px) {
  .matrix-grid .matrix-col-code  { min-width: 56px; padding-left: 8px; }
  .matrix-grid .matrix-col-label { left: 56px; min-width: 110px; }
  .view-toggle-btn { padding: 6px 8px; font-size: 11px; }
  .view-toggle-btn svg { width: 11px; height: 11px; }
  .code-row { grid-template-columns: 28px 60px 1fr 26px; }
}
