@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600;700&family=DM+Sans:wght@400;500;600;700&display=swap');

/* ══════════════════════════════════════════════════════════════
   THEME: DARK (default)
   ══════════════════════════════════════════════════════════════ */
:root, [data-theme="dark"] {
  --bg: #0f1117;
  --bg-surface: #181a24;
  --bg-hover: #1e2130;
  --border: #2a2d3e;
  --text: #e2e4ed;
  --text-dim: #7a7f96;
  --text-muted: #4a4e64;
  --accent: #6c8cff;

  --cat-fiscal: #ef4444;
  --cat-fiscal-bg: rgba(239,68,68,0.18);
  --cat-fiscal-border: rgba(239,68,68,0.4);
  --cat-fiscal-text: #fca5a5;
  --cat-business: #22c55e;
  --cat-business-bg: rgba(34,197,94,0.18);
  --cat-business-border: rgba(34,197,94,0.4);
  --cat-business-text: #86efac;
  --cat-contenu: #f59e0b;
  --cat-contenu-bg: rgba(245,158,11,0.18);
  --cat-contenu-border: rgba(245,158,11,0.4);
  --cat-contenu-text: #fcd34d;
  --cat-perso: #3b82f6;
  --cat-perso-bg: rgba(59,130,246,0.18);
  --cat-perso-border: rgba(59,130,246,0.4);
  --cat-perso-text: #93c5fd;

  --label-w: 220px;
  --row-h: 44px;
  --header-h: 60px;
  --day-w: 4px;
  --toolbar-h: 52px;
}

/* ══════════════════════════════════════════════════════════════
   THEME: LIGHT
   ══════════════════════════════════════════════════════════════ */
[data-theme="light"] {
  --bg: #f0f1f5;
  --bg-surface: #ffffff;
  --bg-hover: #f5f6fa;
  --border: #dcdee6;
  --text: #1e2130;
  --text-dim: #5a5e72;
  --text-muted: #9a9db0;
  --accent: #4a6cdf;

  --cat-fiscal: #dc2626;
  --cat-fiscal-bg: rgba(220,38,38,0.10);
  --cat-fiscal-border: rgba(220,38,38,0.35);
  --cat-fiscal-text: #991b1b;
  --cat-business: #16a34a;
  --cat-business-bg: rgba(22,163,74,0.10);
  --cat-business-border: rgba(22,163,74,0.35);
  --cat-business-text: #166534;
  --cat-contenu: #d97706;
  --cat-contenu-bg: rgba(217,119,6,0.10);
  --cat-contenu-border: rgba(217,119,6,0.35);
  --cat-contenu-text: #92400e;
  --cat-perso: #2563eb;
  --cat-perso-bg: rgba(37,99,235,0.10);
  --cat-perso-border: rgba(37,99,235,0.35);
  --cat-perso-text: #1e3a8a;
}

/* ══════════════════════════════════════════════════════════════
   RESET & BASE
   ══════════════════════════════════════════════════════════════ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

/* ══════════════════════════════════════════════════════════════
   TOOLBAR
   ══════════════════════════════════════════════════════════════ */
.toolbar {
  height: var(--toolbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  z-index: 100;
  position: relative;
  flex-shrink: 0;
}
.toolbar-title {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-right: 16px;
}
.toolbar-sep {
  width: 1px;
  height: 28px;
  background: var(--border);
  margin: 0 8px;
  flex-shrink: 0;
}
.btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  white-space: nowrap;
}
.btn:hover { background: #282b3e; border-color: var(--text-muted); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: #5a7cf0; }
.btn svg { width: 14px; height: 14px; }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.zoom-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-dim);
  min-width: 40px;
  text-align: center;
}

/* Sync indicator — SVG icon */
.sync-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--cat-business);
  transition: color 0.3s;
}
.sync-indicator svg { width: 18px; height: 18px; }
.sync-indicator.saving { color: var(--cat-contenu); }
.sync-indicator.error { color: var(--cat-fiscal); }

/* ══════════════════════════════════════════════════════════════
   MAIN LAYOUT
   ══════════════════════════════════════════════════════════════ */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ══════════════════════════════════════════════════════════════
   LEFT: LABELS PANEL
   ══════════════════════════════════════════════════════════════ */
.labels-panel {
  width: var(--label-w);
  min-width: var(--label-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.labels-header {
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 12px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}
.labels-header .theme-toggle {
  width: 26px;
  height: 26px;
  font-size: 13px;
  margin-bottom: -2px;
}
.labels-body {
  flex: 1;
  overflow-y: hidden;
}
.labels-body::after {
  content: '';
  display: block;
  height: 120px;
}

.label-row {
  height: var(--row-h);
  display: flex;
  align-items: center;
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  gap: 4px;
  position: relative;
}
.label-row:hover { background: var(--bg-hover); }
.label-text {
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  cursor: default;
}
.label-text[contenteditable="true"] {
  cursor: text;
  outline: 1px solid var(--accent);
  border-radius: 3px;
  padding: 2px 4px;
  -webkit-line-clamp: unset;
  background: var(--bg);
}
.label-row .move-btns {
  display: none;
  flex-direction: column;
  gap: 1px;
}
.label-row:hover .move-btns { display: flex; }
.move-btn {
  width: 18px;
  height: 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 10px;
}
.move-btn:hover { background: var(--bg); color: var(--text); }
.delete-btn {
  width: 18px;
  height: 18px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  font-size: 12px;
}
.label-row:hover .delete-btn { display: flex; }
.delete-btn:hover { color: var(--cat-fiscal); background: var(--cat-fiscal-bg); }

/* Category separator */
.cat-separator {
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  cursor: default;
}
.cat-separator-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.cat-separator-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.cat-add-btn {
  margin-left: auto;
  font-size: 16px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cat-add-btn:hover { background: var(--bg-hover); }

/* ══════════════════════════════════════════════════════════════
   RIGHT: TIMELINE PANEL
   ══════════════════════════════════════════════════════════════ */
.timeline-panel {
  flex: 1;
  overflow: auto;
  position: relative;
}

/* Time header */
.time-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  max-height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  width: fit-content;
  min-width: 100%;
}
.time-header-months {
  height: 36px;
  max-height: 36px;
  display: flex;
  position: relative;
}
.month-block {
  height: 100%;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.time-header-days {
  height: 24px;
  max-height: 24px;
  display: flex;
  position: relative;
  overflow: hidden;
}
.week-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 100%;
  background: var(--border);
}
.week-label {
  position: absolute;
  top: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--text-muted);
  transform: translateX(3px);
}

/* Timeline body */
.timeline-body {
  position: relative;
}

/* Grid lines */
.grid-line-month {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  z-index: 1;
  pointer-events: none;
}
.grid-line-week {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(42,45,62,0.5);
  z-index: 1;
  pointer-events: none;
}

/* Today marker */
.today-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--cat-fiscal);
  z-index: 5;
  pointer-events: none;
}

/* Today marker in header — must be above month blocks */
.today-header-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--cat-fiscal);
  z-index: 10;
  pointer-events: none;
}

/* Timeline rows */
.timeline-row {
  height: var(--row-h);
  position: relative;
  border-bottom: 1px solid var(--border);
}
.timeline-cat-separator {
  height: 32px;
  border-bottom: 1px solid var(--border);
}

/* ══════════════════════════════════════════════════════════════
   BARS
   ══════════════════════════════════════════════════════════════ */
.bar {
  position: absolute;
  height: 28px;
  top: 8px;
  border-radius: 6px;
  cursor: grab;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: 10px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  z-index: 10;
  transition: box-shadow 0.15s;
  min-width: 20px;
}
.bar:hover { box-shadow: 0 0 0 1px rgba(255,255,255,0.2); z-index: 15; }
.bar.dragging { cursor: grabbing; opacity: 0.85; z-index: 20; box-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.bar .bar-label {
  pointer-events: none;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Resize handles */
.bar .handle {
  position: absolute;
  top: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
  z-index: 11;
}
.bar .handle-left { left: 0; border-radius: 6px 0 0 6px; }
.bar .handle-right { right: 0; border-radius: 0 6px 6px 0; }
.bar .handle:hover { background: rgba(255,255,255,0.1); }

/* Category colors */
.bar-fiscal { background: var(--cat-fiscal-bg); border: 1px solid var(--cat-fiscal-border); color: var(--cat-fiscal-text); }
.bar-business { background: var(--cat-business-bg); border: 1px solid var(--cat-business-border); color: var(--cat-business-text); }
.bar-contenu { background: var(--cat-contenu-bg); border: 1px solid var(--cat-contenu-border); color: var(--cat-contenu-text); }
.bar-perso { background: var(--cat-perso-bg); border: 1px solid var(--cat-perso-border); color: var(--cat-perso-text); }

/* ══════════════════════════════════════════════════════════════
   TOOLTIP
   ══════════════════════════════════════════════════════════════ */
.tooltip {
  position: fixed;
  z-index: 1000;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  max-width: 300px;
  pointer-events: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: none;
}
.tooltip-title { font-weight: 700; margin-bottom: 4px; }
.tooltip-dates { color: var(--text-dim); font-family: 'JetBrains Mono', monospace; font-size: 11px; }

/* ══════════════════════════════════════════════════════════════
   MODAL
   ══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 420px;
  max-width: 90vw;
}
.modal h3 {
  font-size: 16px;
  margin-bottom: 16px;
  font-weight: 700;
}
.modal label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 12px;
}
.modal input, .modal select, .modal textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 13px;
}
.modal textarea { resize: vertical; min-height: 60px; }
.modal input:focus, .modal select:focus, .modal textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ══════════════════════════════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════
   LIGHT MODE OVERRIDES
   ══════════════════════════════════════════════════════════════ */
[data-theme="light"] .grid-line-week { background: rgba(200,203,218,0.4); }
[data-theme="light"] .grid-line-month { background: var(--border); }
[data-theme="light"] .bar:hover { box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }
[data-theme="light"] .bar.dragging { box-shadow: 0 4px 20px rgba(0,0,0,0.15); }
[data-theme="light"] .tooltip { box-shadow: 0 8px 32px rgba(0,0,0,0.12); }
[data-theme="light"] .modal-overlay { background: rgba(0,0,0,0.3); }
[data-theme="light"] .btn:hover { background: #e8e9f0; }

/* Theme toggle button */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-size: 16px;
}
.theme-toggle:hover { background: var(--bg); color: var(--text); border-color: var(--text-muted); }

/* ══════════════════════════════════════════════════════════════
   FOOTER (scrolls with content, not fixed)
   ══════════════════════════════════════════════════════════════ */
.app-footer {
  height: 44px;
  min-height: 44px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}

/* ══════════════════════════════════════════════════════════════
   TIMELINE BOTTOM PADDING (scroll past end)
   ══════════════════════════════════════════════════════════════ */
.timeline-body::after {
  content: '';
  display: block;
  height: 120px;
  width: 100%;
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root, [data-theme="dark"], [data-theme="light"] {
    --label-w: 120px;
    --day-w: 3px;
  }
  .label-text { font-size: 10px; }
  .toolbar { padding: 0 8px; gap: 4px; }
  .toolbar-sep { margin: 0 4px; }
  .btn { padding: 6px 10px; }
  .zoom-label { min-width: 32px; }
}
