/* ============================================================
   WebFactory SaaS — Design System v3
   ============================================================ */

:root {
  --bg: #f7f6f3;
  --bg-card: #fffdfa;
  --bg-card-2: #fbfaf7;
  --bg-elevated: #ffffff;
  --text: #1f1f1d;
  --text-2: #6f6b63;
  --text-3: #9a958b;
  --border: #dedbd2;
  --border-soft: #ebe8df;
  --accent: #1f1f1d;
  --accent-text: #fffdfa;
  --shadow-1: 0 1px 2px rgba(31, 31, 29, 0.04), 0 1px 1px rgba(31, 31, 29, 0.03);
  --shadow-2: 0 4px 16px rgba(31, 31, 29, 0.06), 0 2px 4px rgba(31, 31, 29, 0.04);
  --shadow-3: 0 8px 32px rgba(31, 31, 29, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --serif: "Instrument Serif", "Times New Roman", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --doc-serif: "Times New Roman", "Liberation Serif", Times, serif;
  --mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --transition: 200ms cubic-bezier(0.16, 1, 0.3, 1);
  --sidebar-w: 244px;
  --sidebar-w-collapsed: 60px;
}

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

html, body {
  height: 100%;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(31, 31, 29, 0.12); }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; border: none; outline: none; background: transparent; }

/* ============================================================ TYPO */
.serif { font-family: var(--serif); font-weight: 400; letter-spacing: -0.01em; }
h1, h2, h3, h4 { font-weight: 500; letter-spacing: -0.015em; }
.title-xl { font-family: var(--serif); font-weight: 400; font-size: 48px; line-height: 1.1; letter-spacing: -0.02em; }
.title-lg { font-family: var(--serif); font-weight: 400; font-size: 32px; line-height: 1.15; letter-spacing: -0.015em; }
.title-md { font-family: var(--serif); font-weight: 400; font-size: 22px; line-height: 1.25; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-2 { color: var(--text-2); }
.text-3 { color: var(--text-3); }

/* ============================================================ LAYOUT */
.app { display: flex; height: 100vh; overflow: hidden; }

/* SIDEBAR : même couleur que les cartes / input chat — rappel visuel */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 14px 12px;
  transition: width var(--transition);
  position: relative;
}

.sidebar.collapsed { width: var(--sidebar-w-collapsed); padding: 14px 8px; }
.sidebar.collapsed .label,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .who,
.sidebar.collapsed .new-chat-btn-text,
.sidebar.collapsed .sidebar-tree-list,
.sidebar.collapsed .sidebar-brand .name,
.sidebar.collapsed .chevron { display: none; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 7px 8px; }
.sidebar.collapsed .new-chat-btn { justify-content: center; padding: 8px; }
.sidebar.collapsed .sidebar-user { justify-content: center; padding: 8px; }
.sidebar.collapsed .logout-btn { display: none; }

/* === BOUTON COLLAPSE — style "panel left close" type Linear/Cursor === */
.sidebar-toggle {
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-3);
  transition: all var(--transition);
  flex-shrink: 0;
}
.sidebar-toggle:hover {
  color: var(--text);
  background: rgba(31, 31, 29, 0.05);
}
.sidebar-toggle svg { width: 16px; height: 16px; }

.sidebar-brand {
  padding: 4px 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  justify-content: space-between;
}

.sidebar-brand .brand-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 4px 0 16px;
}
.sidebar.collapsed .sidebar-brand .brand-left { display: none; }

.sidebar-brand .logo-img {
  height: 28px;
  width: auto;
  flex-shrink: 0;
  display: block;
  /* Affiche le PNG tel quel — l'utilisateur fournit son propre logo transparent */
}

.sidebar-brand .name {
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  margin: 4px 0 8px;
  white-space: nowrap;
}
.new-chat-btn:hover { border-color: var(--border); background: var(--bg-card-2); }
.new-chat-btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.sidebar-section { margin-top: 16px; display: flex; flex-direction: column; gap: 1px; }

.sidebar-section-title {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  padding: 6px 10px 4px;
  font-weight: 500;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13.5px;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.sidebar-link:hover { background: rgba(31, 31, 29, 0.04); color: var(--text); }
.sidebar-link.active { background: rgba(31, 31, 29, 0.06); color: var(--text); font-weight: 500; }
.sidebar-link svg.icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.sidebar-link .chevron {
  margin-left: auto;
  width: 12px;
  height: 12px;
  transition: transform var(--transition);
  opacity: 0.5;
  flex-shrink: 0;
}
.sidebar-link.expanded .chevron { transform: rotate(90deg); }

.sidebar-tree-list {
  display: none;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 4px;
}
.sidebar-tree-list.expanded { display: flex; }

.sidebar-tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 28px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.sidebar-tree-item .item-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sidebar-tree-item:hover { background: rgba(31, 31, 29, 0.03); color: var(--text); }
.sidebar-tree-item.active { color: var(--text); font-weight: 500; background: rgba(31, 31, 29, 0.04); }
.sidebar-tree-item.empty { color: var(--text-3); font-style: italic; cursor: default; padding-left: 28px; }
.sidebar-tree-item.empty:hover { background: transparent; }

.sidebar-tree-item .item-menu {
  width: 22px; height: 22px;
  display: none;
  place-items: center;
  border-radius: 4px;
  color: var(--text-3);
  flex-shrink: 0;
}
.sidebar-tree-item:hover .item-menu { display: grid; }
.sidebar-tree-item .item-menu:hover { background: rgba(31, 31, 29, 0.08); color: var(--text); }
.sidebar-tree-item .item-menu svg { width: 13px; height: 13px; }

/* Menu contextuel "..." */
.context-menu {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-3);
  min-width: 160px;
  padding: 4px;
  z-index: 1100;
  font-size: 13px;
}
.context-menu .ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 4px;
  cursor: pointer; color: var(--text);
  transition: background var(--transition);
}
.context-menu .ctx-item:hover { background: rgba(31, 31, 29, 0.05); }
.context-menu .ctx-item.danger { color: #8a3a2a; }
.context-menu .ctx-item.danger:hover { background: #f5e0db; }
.context-menu .ctx-item svg { width: 13px; height: 13px; }

.sidebar-footer { margin-top: auto; padding-top: 10px; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.sidebar-user .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 500;
  flex-shrink: 0;
}

.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .who-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who-meta { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-user .logout-btn {
  font-size: 11px;
  color: var(--text-3);
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}
.sidebar-user .logout-btn:hover { color: var(--text); background: rgba(31, 31, 29, 0.04); }

/* ============================================================ MAIN */
.main { flex: 1; display: flex; min-width: 0; overflow: hidden; }
.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.toolbar {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--bg);
  flex-shrink: 0;
  gap: 16px;
}

.toolbar-title {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ============================================================ BTN */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: #2a2a26; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: rgba(31, 31, 29, 0.05); color: var(--text); }
.btn-outline { background: var(--bg-card); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg-card-2); border-color: var(--text-3); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============================================================ CHAT */
.chat-shell {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  position: relative;
}

.chat-shell.with-preview { grid-template-columns: minmax(380px, 1fr) minmax(480px, 1.3fr); }

.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  border-right: 1px solid var(--border-soft);
}

.chat-shell:not(.with-preview) .chat-pane { border-right: none; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 32px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 16px;
}

.chat-empty .greeting {
  font-family: var(--serif);
  font-size: 38px;
  letter-spacing: -0.015em;
  color: var(--text);
}

.chat-empty .sub {
  color: var(--text-2);
  max-width: 460px;
  font-size: 14px;
}

.chat-empty .suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 12px;
  width: 100%;
  max-width: 720px;
}

.chat-empty .suggestion {
  padding: 12px 14px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--bg-card);
  text-align: left;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--transition);
}
.chat-empty .suggestion:hover { border-color: var(--border); background: var(--bg-card-2); color: var(--text); }

.message {
  display: flex;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.message.user { justify-content: flex-end; }

.message.user .message-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  background: #f0f0ee;
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.assistant {
  flex-direction: column;
  align-items: stretch;
}

.message.assistant .assistant-content {
  padding: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-bubble .files-attached {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: rgba(255, 253, 250, 0.15);
  border-radius: 99px;
  font-size: 11.5px;
}
.message.assistant .file-chip {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  color: var(--text-2);
}

/* === BLOC ÉTAPES === */
.agent-thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 13.5px;
  color: var(--text-2);
  margin-bottom: 12px;
  min-height: 22px;
}

.agent-thinking .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text);
  animation: pulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}

.agent-thinking .step-text { transition: opacity 200ms ease; }

.agent-thinking.done .dot {
  background: #4a7c59;
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

.agent-step-fade { animation: stepFade 220ms ease; }
@keyframes stepFade {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === V55 — VRAIE BARRE DE PROGRESSION DESIGN === */
/* Inspirée de la barre Claude lors de la compression de conversation.
   Fine, gradient subtil, animation fluide grâce aux transitions CSS. */

.agent-progress {
  display: none; /* caché par défaut, affiché en JS quand un step a un progress */
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  margin-bottom: 4px;
  width: 100%;
  max-width: 460px;
}

.agent-progress.active {
  display: flex;
  animation: progressFadeIn 240ms ease;
}

@keyframes progressFadeIn {
  from { opacity: 0; transform: translateY(-2px); }
  to { opacity: 1; transform: translateY(0); }
}

.agent-progress-track {
  position: relative;
  width: 100%;
  height: 4px;
  background: var(--border-soft, rgba(0,0,0,0.08));
  border-radius: 999px;
  overflow: hidden;
}

.agent-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg,
    var(--text, #2c2c2c) 0%,
    var(--text, #2c2c2c) 100%);
  border-radius: 999px;
  /* V55 — Transition fluide entre 2 mises à jour serveur */
  transition: width 800ms cubic-bezier(0.4, 0, 0.2, 1);
  /* Effet de scintillement subtil pendant le chargement */
  background-size: 200% 100%;
  animation: progressShimmer 2.4s linear infinite;
}

.agent-progress.done .agent-progress-fill {
  animation: none;
  background: linear-gradient(90deg, #4a7c59 0%, #4a7c59 100%);
}

/* V56.3 — Disparition élégante quand le job est terminé (déclenchée en JS) */
.agent-progress.fading-out {
  animation: progressFadeOut 400ms ease forwards;
}

@keyframes progressFadeOut {
  from { opacity: 1; max-height: 60px; margin-top: 8px; margin-bottom: 4px; }
  to   { opacity: 0; max-height: 0; margin-top: 0; margin-bottom: 0; padding: 0; overflow: hidden; }
}

@keyframes progressShimmer {
  0%   { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

/* V55 — Ligne d'infos sous la barre : pourcentage + ETA */
.agent-progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2, #6e6e6e);
  padding: 0 2px;
  font-variant-numeric: tabular-nums;
}

.agent-progress-pct {
  font-weight: 500;
  color: var(--text, #2c2c2c);
}

.agent-progress-eta {
  font-size: 11.5px;
  opacity: 0.85;
}

/* === CARTE DOCUMENT === */
.doc-action-card {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all var(--transition);
  max-width: 600px;
}
.doc-action-card:hover { border-color: var(--border); }
.doc-action-card .doc-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-card-2);
  border: 1px solid var(--border-soft);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.doc-action-card .doc-icon svg { width: 16px; height: 16px; color: var(--text-2); }
.doc-action-card .doc-info { flex: 1; min-width: 0; }
.doc-action-card .doc-name { font-weight: 500; font-size: 13.5px; margin-bottom: 1px; }
.doc-action-card .doc-meta { font-size: 11.5px; color: var(--text-3); }
.doc-action-card .doc-actions { display: flex; gap: 4px; flex-shrink: 0; }
.doc-action-card .icon-action {
  width: 28px; height: 28px;
  border-radius: 5px;
  display: grid; place-items: center;
  color: var(--text-3);
  cursor: pointer;
  transition: all var(--transition);
}
.doc-action-card .icon-action:hover { background: rgba(31, 31, 29, 0.05); color: var(--text); }
.doc-action-card .icon-action svg { width: 14px; height: 14px; }

/* ============================================================ INPUT CHAT */
.chat-input-wrap { padding: 12px 24px 24px; flex-shrink: 0; }

.chat-input {
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input:focus-within { border-color: var(--text-3); box-shadow: var(--shadow-2); }

.chat-input-files { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-input-files:empty { display: none; }

.attached-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  background: var(--bg-card-2);
  border: 1px solid var(--border-soft);
  border-radius: 99px;
  font-size: 12px;
}

.attached-file .remove {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-3);
  cursor: pointer;
}
.attached-file .remove:hover { background: rgba(31, 31, 29, 0.08); color: var(--text); }

.chat-input textarea { width: 100%; resize: none; min-height: 24px; max-height: 200px; font-size: 14px; line-height: 1.5; }

.chat-input-actions { display: flex; align-items: center; gap: 6px; }
.chat-input-actions .left { display: flex; gap: 2px; }

.icon-btn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-3);
  transition: all var(--transition);
  cursor: pointer;
}
.icon-btn:hover { background: rgba(31, 31, 29, 0.05); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

.send-btn {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  background: #1f1f1d;
  color: #fffdfa;
  border: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: all var(--transition);
}
.send-btn:hover:not(:disabled) { background: #000; }
.send-btn svg { width: 14px; height: 14px; }
.send-btn:disabled { background: var(--text-3); cursor: not-allowed; opacity: 0.5; }

/* ============================================================ PREVIEW PANE */
.preview-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-card-2);
  overflow: hidden;
}

.preview-header {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  gap: 12px;
}

.preview-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  min-width: 0;
}

.preview-title .doc-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  padding: 2px 8px;
  border-radius: 99px;
}

.preview-status { font-size: 11.5px; color: var(--text-3); }
.preview-status.saved { color: #4a7c59; }

.preview-body { flex: 1; overflow-y: auto; }

/* CCTP : reproduction visuelle du PDF */
.cctp-preview {
  padding: 32px 16px 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.cctp-page {
  width: 100%;
  max-width: 720px;
  background: white;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  box-shadow: var(--shadow-1);
  font-family: var(--doc-serif);
  color: #1f1f1d;
  padding: 70px;
  min-height: 920px;
  position: relative;
}

.cctp-cover {
  display: flex;
  flex-direction: column;
  height: 920px;
}

.cctp-cover-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 60px;
}

.cctp-cover-top .cover-logo {
  max-height: 90px;
  max-width: 140px;
  object-fit: contain;
}

.cctp-cover-top .cover-producer {
  font-family: var(--doc-serif);
  font-size: 11px;
  color: var(--text-2);
}

.cctp-cover-middle { margin-top: auto; margin-bottom: auto; }

.cctp-cover-label {
  font-family: var(--doc-serif);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-2);
  margin-bottom: 12px;
}

.cctp-cover-project {
  font-family: var(--doc-serif);
  font-weight: bold;
  font-size: 28px;
  margin-bottom: 8px;
  line-height: 1.2;
}

.cctp-cover-address {
  font-family: var(--doc-serif);
  font-style: italic;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 28px;
}

.cctp-cover-divider { width: 70px; height: 1px; background: var(--text); margin-bottom: 24px; }

.cctp-cover-doctitle { font-family: var(--doc-serif); font-weight: bold; font-size: 19px; line-height: 1.3; }
.cctp-cover-docsubtitle { font-family: var(--doc-serif); font-size: 14px; margin-top: 4px; margin-bottom: 28px; }
.cctp-cover-lotlabel {
  font-family: var(--doc-serif);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-2);
  margin-bottom: 12px;
}
.cctp-cover-lot { font-family: var(--doc-serif); font-weight: bold; font-size: 22px; }

.cctp-cover-bottom {
  display: flex;
  flex-direction: column;
  font-family: var(--doc-serif);
  font-size: 11px;
  color: var(--text-2);
  gap: 4px;
}
.cctp-cover-phase { font-style: italic; }

.cctp-page h1, .cctp-page h2, .cctp-page h3 {
  font-family: var(--doc-serif);
  font-weight: bold;
  outline: none;
}

.cctp-page h1 {
  font-size: 16px;
  margin-top: 28px;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 0.5px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.cctp-page h1:first-child { margin-top: 0; }

.cctp-page h2 { font-size: 13px; margin-top: 20px; margin-bottom: 8px; }
.cctp-page h3 { font-size: 12px; margin-top: 14px; margin-bottom: 6px; }
.cctp-page p { font-size: 12px; line-height: 1.55; margin-bottom: 10px; outline: none; }
.cctp-page ul { padding-left: 22px; margin-bottom: 10px; }
.cctp-page li { font-size: 12px; line-height: 1.55; margin-bottom: 4px; outline: none; }

.cctp-page .page-header {
  position: absolute;
  top: 30px;
  left: 70px;
  right: 70px;
  display: flex;
  justify-content: space-between;
  font-family: var(--doc-serif);
  font-size: 9px;
  color: var(--text-2);
  border-bottom: 0.4px solid var(--border-soft);
  padding-bottom: 6px;
}

/* ============================================================
 * Quantitatif preview V56.5 — Vraie preview Excel scrollable
 * - Header sticky (titre + meta + actions)
 * - Tableau scrollable X et Y dans la zone disponible
 * - En-têtes colonnes sticky
 * - Affichage des colonnes PU/Montant si dispo
 * - Alternance lignes + section rows
 * ============================================================ */
.preview-body.preview-quantitatif {
  background: var(--bg-card);
  margin: 0;                   /* V56.5 — supprime margin pour utiliser toute la place */
  border-radius: 0;
  border: none;
  overflow: hidden;            /* container : pas de scroll lui-même */
  padding: 0;
  display: flex;               /* V56.5 — flex column pour header + scroll body */
  flex-direction: column;
  height: 100%;                /* Prend toute la hauteur disponible */
}

.qt-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-shrink: 0;              /* V56.5 — ne se compresse jamais */
  background: var(--bg-card);
}

.qt-header .qt-title { font-family: var(--serif); font-size: 22px; }
.qt-header .qt-meta { font-size: 12px; color: var(--text-3); }

/* V56.5 — Vrai wrapper scrollable : prend toute la place restante */
.qt-table-wrap {
  flex: 1;                     /* prend l'espace restant */
  overflow: auto;              /* scroll X ET Y */
  background: #fafaf8;         /* fond Excel-like clair */
}

.qt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  min-width: 1100px;           /* V56.5 — force largeur min pour scroll X visible */
  background: white;
}

.qt-table th {
  background: #1f1f1d;
  color: #fffdfa;
  text-align: left;
  padding: 10px 12px;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 2;                  /* V56.5 — au-dessus des lignes */
  white-space: nowrap;
  border-right: 1px solid #2d2d2a;
}

.qt-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  background: white;
  font-size: 12px;
}

/* V56.5 — Alternance lignes (zébré subtil) */
.qt-table tbody tr:nth-child(even) td { background: #fafaf8; }

.qt-table tr:hover td { background: rgba(31, 31, 29, 0.04); }

.qt-table .section-row td {
  background: #ece9e0 !important;     /* Beige WebFactory pour sections */
  font-weight: 600;
  border-top: 2px solid #1f1f1d;
  border-bottom: 1px solid #1f1f1d;
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: #1f1f1d;
  padding: 10px 12px;
}

/* V56.5 — Lignes total : fond doré accentué */
.qt-table .total-row td {
  background: #c9a961 !important;
  color: #fffdfa;
  font-weight: 700;
  font-size: 13px;
  padding: 12px 12px;
  border-top: 2px solid #1f1f1d;
  border-bottom: 2px solid #1f1f1d;
}

/* V56.5 — Cellules numériques alignées droite */
.qt-table td.num,
.qt-table td.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.qt-table td.money {
  font-weight: 500;
  color: #1f1f1d;
}

.qt-table td.money-bold {
  font-weight: 700;
  background: #f5f0e4 !important;  /* Léger fond pour montant total ligne */
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.qt-confiance { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 500; }
.qt-confiance.eleve { background: #e6f0e9; color: #2d5a3a; }
.qt-confiance.moyen { background: #f5ecda; color: #7a5c1f; }
.qt-confiance.faible { background: #f5e0db; color: #8a3a2a; }

.qt-validate { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; }
.qt-validate.oui { background: #f5ecda; color: #7a5c1f; }
.qt-validate.non { color: var(--text-3); }

/* ============================================================ PAGES PROJETS / DOCS */
.page-content { flex: 1; overflow-y: auto; padding: 32px 40px 60px; }

.page-header { display: flex; align-items: baseline; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.page-header h1 { font-family: var(--serif); font-size: 32px; font-weight: 400; letter-spacing: -0.015em; }
.page-header .sub { color: var(--text-2); margin-top: 4px; font-size: 13.5px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: all var(--transition);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card:hover { border-color: var(--border); box-shadow: var(--shadow-2); transform: translateY(-1px); }

.card-title { font-family: var(--serif); font-size: 18px; letter-spacing: -0.01em; }
.card-meta { font-size: 12px; color: var(--text-3); display: flex; flex-wrap: wrap; gap: 8px 14px; }
.card-meta span { display: inline-flex; align-items: center; gap: 4px; }

.card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; padding-top: 8px; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--bg-card-2);
  border: 1px solid var(--border-soft);
  border-radius: 99px;
  font-size: 11px;
  color: var(--text-2);
}

.list-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--bg-card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border-soft); }
.list-table th {
  text-align: left; padding: 12px 16px; background: var(--bg-card-2);
  border-bottom: 1px solid var(--border-soft); font-weight: 500;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2);
}
.list-table td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.list-table tr:last-child td { border-bottom: none; }
.list-table tr:hover td { background: rgba(31, 31, 29, 0.015); }
.list-table .actions { display: flex; gap: 4px; justify-content: flex-end; }

.empty-state { text-align: center; padding: 60px 24px; color: var(--text-2); }
.empty-state .title-md { margin-bottom: 8px; color: var(--text); }

/* ============================================================ MODAL */
.modal-backdrop { position: fixed; inset: 0; background: rgba(31, 31, 29, 0.4); display: grid; place-items: center; z-index: 1000; animation: fadeIn 200ms ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  width: min(440px, 92vw);
  padding: 24px;
  box-shadow: var(--shadow-3);
  animation: modalIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { transform: translateY(8px) scale(0.98); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.modal h3 { font-family: var(--serif); font-size: 20px; margin-bottom: 6px; font-weight: 400; }
.modal .sub { color: var(--text-2); font-size: 13px; margin-bottom: 16px; }

.modal-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; max-height: 280px; overflow-y: auto; }

.modal-option { padding: 10px 14px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); cursor: pointer; transition: all var(--transition); display: flex; align-items: center; gap: 10px; }
.modal-option:hover { border-color: var(--border); background: var(--bg-card-2); }
.modal-option.create { background: var(--bg-card-2); border-style: dashed; color: var(--text-2); }
.modal-option.create:hover { color: var(--text); border-color: var(--text-3); }

.modal-option-icon { width: 28px; height: 28px; border-radius: 6px; background: var(--bg-card-2); border: 1px solid var(--border-soft); display: grid; place-items: center; flex-shrink: 0; }
.modal-option-icon svg { width: 14px; height: 14px; color: var(--text-2); }
.modal-option-info { flex: 1; min-width: 0; }
.modal-option-name { font-size: 13px; font-weight: 500; }
.modal-option-meta { font-size: 11px; color: var(--text-3); margin-top: 1px; }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

.form-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-field label { font-size: 12px; color: var(--text-2); font-weight: 500; }
.form-field input, .form-field textarea, .form-field select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card-2); font-size: 14px; transition: all var(--transition);
}
.form-field input:focus, .form-field textarea:focus { border-color: var(--text); background: var(--bg-card); }

/* ============================================================ ÉDITEUR */
.editor-shell { flex: 1; display: grid; grid-template-columns: 240px 1fr; overflow: hidden; }

.editor-toc { border-right: 1px solid var(--border-soft); padding: 24px 16px; overflow-y: auto; }
.editor-toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 12px; font-weight: 500; }
.editor-toc-list { display: flex; flex-direction: column; gap: 1px; }

.toc-item { padding: 6px 10px; border-radius: var(--radius-sm); font-size: 13px; color: var(--text-2); cursor: pointer; transition: all var(--transition); }
.toc-item:hover { background: rgba(31, 31, 29, 0.04); color: var(--text); }
.toc-item.h2 { padding-left: 22px; font-size: 12.5px; }
.toc-item.h3 { padding-left: 34px; font-size: 12px; color: var(--text-3); }

.editor-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.editor-toolbar-btn {
  width: 30px; height: 30px;
  border-radius: 5px;
  display: grid; place-items: center;
  color: var(--text-2);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: all var(--transition);
}
.editor-toolbar-btn:hover { background: rgba(31, 31, 29, 0.05); color: var(--text); }
.editor-toolbar-btn.active { background: rgba(31, 31, 29, 0.08); color: var(--text); }

.editor-toolbar-sep { width: 1px; height: 16px; background: var(--border-soft); margin: 0 4px; }

.editor-canvas {
  overflow-y: auto;
  padding: 32px 16px 80px;
  background: var(--bg-card-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.editor-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: auto;
  width: 100%;
}

.editor-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }

.editor-table th {
  background: #1f1f1d; color: #fffdfa;
  text-align: left; padding: 10px 12px; font-weight: 500;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
}

.editor-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.editor-table td[contenteditable="true"]:focus {
  background: rgba(31, 31, 29, 0.04);
  outline: 2px solid var(--text-3);
  outline-offset: -2px;
}

/* ============================================================ LOGIN */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-1);
}

.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-brand .logo-img {
  height: 40px;
  width: auto;
  display: block;
  /* Affiche le PNG tel quel */
}

.login-card h1 { font-family: var(--serif); font-size: 26px; font-weight: 400; letter-spacing: -0.015em; margin-bottom: 6px; }
.login-card .lead { color: var(--text-2); font-size: 13.5px; margin-bottom: 28px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 14px; }

.error-banner { background: #f5e0db; color: #8a3a2a; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }

/* ============================================================ UTILS */
.spinner {
  width: 14px; height: 14px;
  border: 1.5px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-sm { gap: 6px; }
.gap-md { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

@media print {
  .sidebar, .toolbar, .preview-header, .chat-input-wrap, .editor-toc { display: none; }
  .preview-body, .editor-canvas { padding: 0; background: white; }
}

/* ProjectFacts — données extraites avant génération */
.project-facts-card {
  margin: 14px 0 10px 0;
  padding: 14px 16px;
  border: 1px solid rgba(0,0,0,.08);
  background: rgba(255,255,255,.55);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.04);
  max-width: 820px;
}
.facts-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
.facts-title { font-weight: 600; font-size: 15px; color:#1f1f1f; }
.facts-subtitle { margin-top:3px; color:#6b6259; font-size: 12px; line-height:1.35; }
.facts-toggle { border:1px solid rgba(0,0,0,.1); background:#f7f6f3; border-radius:10px; padding:7px 10px; font-size:12px; cursor:pointer; }
.facts-warning { margin-top:10px; padding:9px 10px; border-radius:10px; background:#fff7e8; color:#7a4b00; font-size:12px; }
.facts-warning strong { display:block; margin-bottom:4px; }
.qw-item { padding:2px 0; line-height:1.4; }
.qw-hallu { color:#9a2a2a; font-weight:500; }
.facts-list { margin-top:10px; font-size:13px; color:#312d28; line-height:1.5; }
.facts-json { margin-top:12px; width:100%; min-height:260px; border:1px solid rgba(0,0,0,.12); border-radius:12px; padding:12px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size:12px; background:#fbfaf8; color:#24201c; }
