/* ═══════════════════════════════════════════════════════════
   DOMAINE MANAGER PRO — Design System
   Palette : terre, paille, feuille (cohérent Domaine + Finance)
   ═══════════════════════════════════════════════════════════ */

:root {
  /* Couleurs de base */
  --ink: #1c1712;
  --soil: #3d2b1f;
  --clay: #8a7060;
  --straw: #c9a84c;
  --hay: #e8d5a3;
  --cream: #f7f3ec;
  --white: #fdfbf8;
  --leaf: #4a7a4a;
  --leaf-light: #6fa66f;
  --fire: #e74c3c;
  --water: #2980b9;
  --frost: #e8f0fa;

  /* Couleurs sémantiques (overridables par site_settings) */
  --primary: var(--straw);
  --primary-dark: #a8861a;
  --accent: var(--leaf);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #e74c3c;

  /* Surfaces */
  --bg: var(--cream);
  --surface: var(--white);
  --surface-2: #fbf7ef;
  --border: rgba(138, 112, 96, 0.18);
  --border-strong: rgba(138, 112, 96, 0.35);

  /* Typo */
  --font-display: 'Playfair Display', Georgia, serif;
  --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, monospace;

  /* Spacing & radius */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 3px rgba(28, 23, 18, 0.08);
  --shadow: 0 4px 16px rgba(28, 23, 18, 0.10);
  --shadow-lg: 0 20px 50px rgba(28, 23, 18, 0.18);

  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button { background: none; border: none; cursor: pointer; font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--water); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }
ol, ul { list-style: none; }

/* ─── Typo ─── */
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.01em; line-height: 1.2; color: var(--soil); font-weight: 600; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; font-family: var(--font-sans); font-weight: 600; }
h4 { font-size: 1rem; font-family: var(--font-sans); font-weight: 600; }
.muted { color: var(--clay); }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.text-mono { font-family: var(--font-mono); }

/* ─── Layout ─── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: block; position: fixed; inset: 60px 0 0 0; z-index: 100; background: var(--surface); }
}

.sidebar {
  background: var(--soil);
  color: var(--hay);
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 20px;
  border-bottom: 1px solid rgba(232, 213, 163, 0.2);
  margin-bottom: 16px;
}
.brand-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--straw), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 4px 12px rgba(201, 168, 76, 0.3);
  flex-shrink: 0;
}
.sidebar-brand h1 {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--hay);
  margin: 0;
}
.sidebar-brand p { font-size: 10px; color: var(--clay); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-section { padding: 12px 8px 4px; font-size: 10px; color: var(--clay); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--hay);
  transition: all var(--transition);
  font-weight: 500;
}
.nav-item:hover { background: rgba(232, 213, 163, 0.08); color: var(--white); }
.nav-item.active { background: rgba(201, 168, 76, 0.15); color: var(--straw); }
.nav-item .icon { font-size: 18px; width: 22px; text-align: center; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(232, 213, 163, 0.15);
  font-size: 12px;
}
.user-block {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--straw);
  color: var(--soil);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: 13px;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name { color: var(--hay); font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info .role { color: var(--clay); font-size: 11px; }

/* ─── Main content ─── */
.main { padding: 32px; max-width: 1400px; margin: 0 auto; width: 100%; }
@media (max-width: 640px) { .main { padding: 20px 16px; } }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.75rem; }
.page-header .subtitle { color: var(--clay); margin-top: 4px; }

/* ─── Topbar mobile ─── */
.topbar-mobile {
  display: none;
  background: var(--soil);
  color: var(--hay);
  padding: 12px 16px;
  align-items: center;
  gap: 12px;
  position: sticky; top: 0; z-index: 99;
}
@media (max-width: 900px) {
  .topbar-mobile { display: flex; }
  .main { padding-top: 16px; }
}
.btn-menu { color: var(--hay); font-size: 22px; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-compact { padding: 16px; }
.card-elevated { box-shadow: var(--shadow); }
.card-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--clay);
  margin-bottom: 8px;
  font-weight: 600;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9375rem;
  transition: all var(--transition);
  white-space: nowrap;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  min-height: 40px;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--soil);
  box-shadow: 0 4px 12px rgba(201, 168, 76, 0.25);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(201, 168, 76, 0.35); }
.btn-secondary { background: var(--surface-2); color: var(--soil); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--hay); border-color: var(--primary); }
.btn-ghost { color: var(--clay); padding: 8px 12px; }
.btn-ghost:hover:not(:disabled) { background: rgba(138, 112, 96, 0.1); color: var(--soil); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8125rem; min-height: 32px; }
.btn-lg { padding: 14px 24px; font-size: 1rem; min-height: 48px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; min-height: 36px; min-width: 36px; }

/* ─── Inputs ─── */
.input, .textarea, .select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.9375rem;
  color: var(--ink);
  transition: all var(--transition);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}
.textarea { min-height: 100px; resize: vertical; font-family: inherit; }
.input-lg { padding: 14px 18px; font-size: 1.0625rem; }

.form-group { margin-bottom: 16px; }
.label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--clay);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.help { font-size: 0.8125rem; color: var(--clay); margin-top: 4px; }

/* ─── Tables ─── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table th {
  background: var(--surface-2);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--clay);
  white-space: nowrap;
  position: sticky; top: 0;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 4px; }

/* ─── Badges ─── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.badge-success { background: rgba(16, 185, 129, 0.15); color: #047857; }
.badge-danger { background: rgba(231, 76, 60, 0.15); color: #b1271a; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #92590a; }
.badge-info { background: var(--frost); color: var(--water); }
.badge-muted { background: var(--hay); color: var(--soil); }

/* ─── Statistic cards ─── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--primary);
}
.stat-card.success::before { background: var(--success); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.warning::before { background: var(--warning); }
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--clay);
  margin-bottom: 6px;
  font-weight: 600;
}
.stat-value {
  font-size: 1.875rem;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  color: var(--soil);
}
.stat-trend { font-size: 0.8125rem; margin-top: 4px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
  flex-wrap: nowrap;
}
.tab {
  padding: 12px 18px;
  color: var(--clay);
  font-weight: 600;
  font-size: 0.9375rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all var(--transition);
}
.tab:hover { color: var(--soil); }
.tab.active { color: var(--primary-dark); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 200ms ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Toasts ─── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 380px;
}
.toast {
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9375rem;
  animation: slideIn 200ms ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--water); }
.toast.removing { animation: slideOut 200ms ease-in forwards; }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes slideOut { to { transform: translateX(120%); opacity: 0; } }

/* ─── Modal ─── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(28, 23, 18, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 150ms ease-out;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 500px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ─── Spinner ─── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cursor-blink::after {
  content: '▌'; color: var(--primary);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ─── Loading dots ─── */
.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots span {
  width: 6px; height: 6px;
  background: var(--clay);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* ─── Module switcher (page home) ─── */
.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
  margin-top: 32px;
}
.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  transition: all var(--transition);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 260px;
}
.module-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}
.module-card .module-icon {
  width: 64px; height: 64px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin-bottom: 20px;
  box-shadow: 0 8px 20px rgba(201, 168, 76, 0.3);
}
.module-card.module-domaine .module-icon {
  background: linear-gradient(135deg, var(--leaf), var(--leaf-light));
  box-shadow: 0 8px 20px rgba(74, 122, 74, 0.3);
}
.module-card h3 { font-family: var(--font-display); font-size: 1.5rem; margin-bottom: 8px; }
.module-card p { color: var(--clay); margin-bottom: 20px; }
.module-card .module-features {
  font-size: 0.875rem;
  color: var(--clay);
  margin-bottom: 20px;
}
.module-card .module-features li { padding: 4px 0; }
.module-card .module-features li::before { content: '✓ '; color: var(--success); font-weight: bold; }
.module-card .btn { margin-top: auto; align-self: flex-start; }

/* ─── Chat ─── */
.chat-wrapper {
  display: flex; flex-direction: column;
  height: calc(100vh - 200px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
}
.chat-msg {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-msg.user {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--soil);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
  background: var(--surface-2);
  color: var(--ink);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-input-row {
  display: flex; gap: 8px;
  padding: 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.chat-input-row .textarea { min-height: 44px; max-height: 200px; }

/* ─── Result block (analyse) ─── */
.result-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 24px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-block.verdict-investir { border-left-color: var(--success); }
.result-block.verdict-ne-pas-investir { border-left-color: var(--danger); }
.result-block.verdict-attendre { border-left-color: var(--warning); }

/* ─── Utility ─── */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--clay);
}
.empty-state .empty-icon { font-size: 3.5rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { color: var(--soil); margin-bottom: 8px; }

/* ─── Print ─── */
@media print {
  .sidebar, .topbar-mobile, .btn, .actions, .chat-input-row { display: none !important; }
  .app-shell { grid-template-columns: 1fr; }
  body { background: white; color: black; }
  .card, .result-block { border: 1px solid #ccc; box-shadow: none; }
}
