/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2d3150;
  --accent: #4f7cff;
  --accent2: #7c5cff;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e8eaf6;
  --muted: #8890b5;
  --radius: 10px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html { font-size: 14px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: 54px;
  max-width: 1400px;
  margin: 0 auto;
  flex-wrap: wrap;
}

/* Hamburger button — hidden on desktop */
.hamburger-btn {
  display: none;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 44px;
  margin-left: auto;
}

.hamburger-icon { font-size: 1.1rem; }
.hamburger-tab-label { font-size: 0.82rem; color: var(--muted); max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.03em;
}

#main-nav {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

.nav-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--accent); color: #fff; }

/* ── Main ─────────────────────────────────────────────────── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ── Tabs ─────────────────────────────────────────────────── */
.tab { display: none; }
.tab.active { display: block; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  margin-bottom: 1.2rem;
}

.card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.9rem;
}

/* ── Section header ───────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.meta-info {
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Summary bar ──────────────────────────────────────────── */
.summary-bar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
}

.stat-sub {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 1px;
}

.kpi-bar .stat {
  border-left: 3px solid var(--accent, #6366f1);
}

/* ── Dashboard ────────────────────────────────────────────── */
.dash-summary { display: flex; flex-direction: column; gap: 1.2rem; }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.summary-card.primary {
  border-color: var(--accent);
  background: linear-gradient(135deg, #1a1d27 0%, #1a2040 100%);
}

.summary-card .big-value {
  font-size: 2.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.summary-card .card-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.summary-card .meta-row {
  display: flex;
  gap: 1.5rem;
  margin-top: 0.7rem;
  flex-wrap: wrap;
}

.summary-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}

.cat-card .cat-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.cat-card .cat-value { font-size: 1.4rem; font-weight: 700; }
.cat-card .cat-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.3rem; }

/* ── Colours ──────────────────────────────────────────────── */
.pos { color: var(--green); }
.neg { color: var(--red); }
tbody tr.row-muted td { opacity: 0.5; }
tbody tr.row-warning { background: rgba(255, 180, 0, 0.08); }
tbody tr.row-warning td { color: var(--orange, #f59e0b); }
tbody tr.row-warning td.neg { color: var(--red); }
.neutral { color: var(--muted); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead tr { background: var(--surface2); }

th, td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

th:first-child, td:first-child { text-align: left; }

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }

/* ── Progress bar ─────────────────────────────────────────── */
.progress-bar {
  background: var(--surface2);
  border-radius: 99px;
  height: 6px;
  width: 100px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
  margin-right: 4px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 99px;
  transition: width 0.4s;
}

.progress-fill.complete { background: var(--green); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: transparent; color: var(--red); border: none; font-size: 0.75rem; padding: 4px 8px; }
.btn-edit { background: transparent; color: var(--muted); border: none; font-size: 0.75rem; padding: 4px 8px; }

/* ── Forms ────────────────────────────────────────────────── */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 0.8rem;
}

.inline-form.vertical {
  flex-direction: column;
}

.inline-form input,
.inline-form select,
.inline-form textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}

.inline-form input:focus,
.inline-form select:focus,
.inline-form textarea:focus { border-color: var(--accent); }

.inline-form input { width: 150px; }
.inline-form input[type="date"] { width: 140px; }
.inline-form textarea { width: 100%; min-height: 60px; resize: vertical; }
.inline-form select { width: 120px; }
.inline-form label { display: flex; flex-direction: column; gap: 3px; font-size: 0.78rem; color: var(--muted); }
.inline-form label input { width: 160px; }

.form-details summary {
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--accent);
  padding: 4px 0;
  user-select: none;
}

.form-details[open] summary { margin-bottom: 0.5rem; }

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.8rem;
  line-height: 1.5;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: min(480px, 95vw);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 0.8rem;
  right: 0.8rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
}

#modal-title { margin-bottom: 1rem; font-size: 1rem; }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.2rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 300;
  transition: opacity 0.3s;
}

/* ── Charts ─────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.2rem;
  margin-top: 1.2rem;
}

.chart-card { padding: 1.2rem; }
.chart-card h3 { margin-bottom: 1rem; }

.chart-container {
  position: relative;
  height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .charts-row { grid-template-columns: 1fr; }

  /* Header responsive */
  header { padding: 0 1rem; }

  .header-inner {
    flex-wrap: nowrap;
    gap: 0.75rem;
    min-height: 54px;
    align-items: center;
  }

  header h1 { font-size: 0.95rem; flex: 1; }

  /* Show hamburger, hide nav by default */
  .hamburger-btn { display: flex; }

  #main-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 2px solid var(--accent);
    flex-direction: column;
    gap: 0;
    padding: 0.5rem 0;
    z-index: 99;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  }

  #main-nav.open { display: flex; }

  .nav-btn {
    width: 100%;
    text-align: left;
    padding: 14px 1.2rem;
    border-radius: 0;
    font-size: 0.9rem;
    min-height: 44px;
    border-bottom: 1px solid var(--border);
  }

  .nav-btn:last-child { border-bottom: none; }

  /* Forms — inputs full width on mobile */
  .inline-form input,
  .inline-form input[type="date"],
  .inline-form select,
  .inline-form label input {
    width: 100%;
  }

  /* Section actions wrap */
  .section-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Summary cards always single column */
  .summary-cards-row {
    grid-template-columns: 1fr;
  }
}

.toast.hidden { display: none; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error { border-color: var(--red); color: var(--red); }

/* ── Prévisions ──────────────────────────────────────────── */
.prev-params-card { margin-bottom: 1rem; }

.prev-params-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem 1.4rem;
  margin-top: .5rem;
}

.prev-params-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.param-input {
  width: 90px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .9rem;
  padding: .3rem .5rem;
}

.prev-detail {
  margin-bottom: .8rem;
  padding: 1rem 1.2rem;
}

.prev-detail > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: -.2rem 0 .5rem;
}

.prev-detail > summary::before {
  content: '▶';
  font-size: .65rem;
  color: var(--muted);
  transition: transform .2s;
}

.prev-detail[open] > summary::before { transform: rotate(90deg); }
.prev-detail > summary h3 { margin: 0; }

.prev-sub-table { margin-bottom: 1.2rem; }
.prev-sub-table h4 { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }

td.highlight { font-weight: 700; color: var(--accent, #6366f1); }
tbody tr.row-highlight { background: rgba(99,102,241,.07); }
tbody tr.row-highlight td { font-weight: 600; }
.muted { color: var(--muted); }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── IA Conseiller ────────────────────────────────────────── */
.ai-chat-card {
  border: 1px solid rgba(99, 102, 241, 0.35);
  background: linear-gradient(135deg, rgba(99,102,241,.06) 0%, rgba(124,92,255,.04) 100%);
  margin-top: 1.2rem;
}

.ai-chat-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.ai-chat-header h3 { margin: 0; flex: 1; font-size: 1rem; }

.ai-badge {
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: .04em;
  white-space: nowrap;
}

.ai-clear-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: .3rem;
}
.ai-clear-btn:hover { border-color: var(--red); color: var(--red); }

.ai-chat-messages {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  margin-bottom: .75rem;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  animation: msgIn .2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ai-msg-user {
  flex-direction: row-reverse;
}

.ai-msg-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.ai-msg-content {
  max-width: 88%;
  padding: .65rem .9rem;
  border-radius: 12px;
  line-height: 1.6;
  font-size: .85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-msg-user .ai-msg-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-msg-assistant .ai-msg-content {
  background: var(--surface2);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.ai-msg-assistant .ai-msg-content h3,
.ai-msg-assistant .ai-msg-content h4 {
  color: var(--accent);
  margin: .6rem 0 .3rem;
  font-size: .9rem;
}

.ai-msg-assistant .ai-msg-content ul {
  margin: .3rem 0 .3rem 1.2rem;
  font-size: inherit;
}

.ai-msg-assistant .ai-msg-content li {
  margin-bottom: .2rem;
}

/* Typing indicator */
.ai-msg-loading .ai-msg-content {
  background: var(--surface2);
  border: 1px solid var(--border);
  padding: .75rem 1rem;
}

.ai-dots { display: inline-flex; gap: 4px; align-items: center; height: 16px; }
.ai-dots span {
  width: 6px; height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: dot-bounce .9s infinite;
}
.ai-dots span:nth-child(2) { animation-delay: .15s; }
.ai-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .5; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.ai-chat-actions {
  margin-bottom: .75rem;
}

.btn-ai {
  width: 100%;
  background: linear-gradient(90deg, rgba(99,102,241,.15), rgba(139,92,246,.15));
  border: 1px dashed rgba(99,102,241,.5);
  color: var(--text);
  font-size: .82rem;
  padding: .7rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all .2s;
  line-height: 1.4;
}

.btn-ai:hover {
  background: linear-gradient(90deg, rgba(99,102,241,.3), rgba(139,92,246,.25));
  border-style: solid;
  border-color: var(--accent);
}

.ai-chat-input {
  display: none;
  gap: .5rem;
  align-items: flex-end;
  margin-top: .5rem;
}

.ai-chat-input textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: .85rem;
  padding: .6rem .75rem;
  resize: none;
  min-height: 60px;
  max-height: 160px;
  overflow-y: auto;
  transition: border-color .15s;
}

.ai-chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
}
