/* NurunAI BI — feuille de style unique, sans dependance externe.
   Palette alignee sur Odoo 19 : #714B67 (primaire), #017E84 (accent). */

:root {
  --primary: #714b67;
  --primary-dark: #5a3c53;
  --primary-light: #f3eef2;
  --accent: #017e84;
  --accent-light: #e6f2f2;
  --ink: #1f2429;
  --ink-soft: #5a6672;
  --ink-faint: #8f8f8f;
  --line: #dee2e6;
  --line-soft: #eef0f2;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --danger: #c0392b;
  --warning: #b9770e;
  --ok: #1e8449;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(31, 36, 41, .08), 0 1px 2px rgba(31, 36, 41, .06);
  --series-1: #714b67;
  --series-2: #017e84;
  --series-3: #b9770e;
  --series-4: #2874a6;
  --series-5: #7d3c98;
  --series-6: #1e8449;
  --series-7: #c0392b;
  --series-8: #5d6d7e;
}

* { box-sizing: border-box; }

/* L'attribut `hidden` doit l'emporter : sans cette regle, toute classe qui
   pose un `display` (flex, grid) le neutralise et l'ecran de connexion reste
   affiche derriere l'application. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------ Boutons ------------------------------ */
.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--line-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #e8c4bf; }
.btn-danger:hover { background: #fdf2f1; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(255, 255, 255, .15); }
.btn-small { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; padding: 9px; margin-top: 14px; }

.select, .input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px;
  background: var(--surface);
}
.select:focus, .input:focus, textarea:focus {
  outline: 2px solid var(--primary-light); border-color: var(--primary);
}

/* ----------------------------- Connexion ----------------------------- */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
  background: linear-gradient(140deg, #714b67 0%, #4a3144 60%, #017e84 100%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 10px; padding: 26px; box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
}
.login-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 20px; }
.login-brand h1 { font-size: 19px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-faint); }
.login-card label {
  display: block; margin: 12px 0 4px; font-size: 12px;
  font-weight: 600; color: var(--ink-soft);
}
.login-card input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-error {
  margin: 12px 0 0; padding: 8px 10px; border-radius: var(--radius);
  background: #fdf2f1; color: var(--danger); font-size: 13px;
}
.login-note {
  margin: 16px 0 0; font-size: 11.5px; color: var(--ink-faint); line-height: 1.5;
}

/* -------------------------- Mise en service -------------------------- */
/* Meme fond que l'ecran de connexion : c'est la meme porte d'entree, avant
   qu'il existe un compte pour la franchir. Plus large, parce qu'on y lit un
   rapport, pas seulement deux champs. */
.setup-card {
  width: 100%; max-width: 600px; background: var(--surface);
  border-radius: 10px; padding: 26px; box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
  display: flex; flex-direction: column; gap: 14px;
}
.setup-card .login-brand { margin-bottom: 0; }
.setup-card label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.setup-card input[type=text], .setup-card input[type=password],
.setup-card input[type=number], .setup-card select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius); margin-top: 4px; font: inherit;
  background: var(--surface);
}
.setup-card p { margin: 0; line-height: 1.5; font-size: 13px; }

.setup-steps {
  display: flex; gap: 6px; list-style: none; margin: 0; padding: 0;
  counter-reset: step;
}
.setup-steps li {
  flex: 1; font-size: 11.5px; color: var(--ink-faint); padding-top: 6px;
  border-top: 3px solid var(--line-soft); counter-increment: step;
}
.setup-steps li::before { content: counter(step) ". "; }
.setup-steps li.is-done { border-top-color: var(--accent); color: var(--ink-soft); }
.setup-steps li.is-current {
  border-top-color: var(--primary); color: var(--primary); font-weight: 600;
}
.setup-panel { display: flex; flex-direction: column; gap: 10px; }
/* Les blocs internes respirent comme le panneau ; l'attribut ``hidden``
   l'emporte de toute facon (regle ``[hidden]`` en tete de feuille). */
#setup-analysis, #setup-done, #setup-failed {
  display: flex; flex-direction: column; gap: 12px;
}
.setup-command {
  margin: 0; padding: 8px 10px; background: #1f2429; color: #e8f0f2;
  border-radius: var(--radius); font-size: 12px; overflow-x: auto;
  white-space: pre;
}

.setup-choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.setup-option {
  display: flex; flex-direction: column; gap: 4px; text-align: left;
  padding: 11px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer; font: inherit;
}
.setup-option span { font-size: 12px; color: var(--ink-soft); line-height: 1.4; }
.setup-option.is-active {
  border-color: var(--primary); background: var(--primary-light);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.setup-subpanel { display: flex; flex-direction: column; gap: 8px; }
.setup-drop {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 26px 14px; border: 2px dashed var(--line); border-radius: 8px;
  text-align: center; cursor: pointer; color: var(--ink-soft);
}
.setup-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.setup-drop strong { color: var(--ink); font-size: 14px; }
.setup-drop:hover, .setup-drop.is-over {
  border-color: var(--primary); background: var(--primary-light);
}
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.setup-grid .span-2 { grid-column: span 2; }
.setup-result {
  padding: 8px 10px; border-radius: var(--radius); font-size: 12.5px;
}
.setup-result.is-ok { background: var(--accent-light); color: var(--accent); }
.setup-result.is-error { background: #fdf2f1; color: var(--danger); }

.setup-file-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.progress {
  height: 8px; background: var(--line-soft); border-radius: 4px; overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0; background: var(--primary); border-radius: 4px;
  transition: width .3s ease;
}
/* Etape dont on ne connait pas la duree : une bande qui circule plutot
   qu'une barre figee, qui laisserait croire a un blocage. */
.progress-bar.is-indeterminate {
  width: 35%; animation: setup-slide 1.4s ease-in-out infinite;
}
@keyframes setup-slide {
  0% { margin-left: -35%; }
  100% { margin-left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .progress-bar.is-indeterminate { animation: none; width: 100%; opacity: .45; }
}

.setup-facts {
  display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px;
  margin: 0; font-size: 13px;
}
.setup-facts dt { color: var(--ink-soft); }
.setup-facts dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.setup-warnings {
  margin: 0; padding-left: 18px; font-size: 12px; color: var(--warning);
  line-height: 1.5;
}
.setup-warnings:empty { display: none; }
.setup-card details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-soft); }
.setup-card details ul { margin-top: 6px; color: var(--ink-soft); }
.setup-job { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.setup-job li { font-size: 13px; padding-left: 22px; position: relative; }
.setup-job li::before {
  position: absolute; left: 0; width: 16px; text-align: center; font-weight: 700;
}
.setup-job li.is-done::before { content: "\2713"; color: var(--ok); }
.setup-job li.is-running::before { content: "\2022"; color: var(--primary); }
.setup-job li.is-running { font-weight: 600; }
.setup-job li.is-failed::before { content: "\2715"; color: var(--danger); }
.setup-confirm { align-items: flex-start; font-weight: 400; }
.setup-path-row { display: flex; gap: 8px; align-items: stretch; }
.setup-path-row input[type=text] { margin-top: 0; flex: 1; min-width: 0;
  font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 12.5px; }
.setup-list-title { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.setup-files {
  list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.setup-files:empty { display: none; }
.setup-files li + li { border-top: 1px solid var(--line-soft); }
.setup-files button {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%;
  padding: 8px 10px; background: none; border: 0; text-align: left;
  font: inherit; cursor: pointer; color: var(--ink);
}
.setup-files button:hover, .setup-files button:focus-visible {
  background: var(--primary-light); outline: none;
}
.setup-files button:disabled { cursor: not-allowed; opacity: .55; }
.setup-files .file-name { font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.setup-files .file-meta {
  font-size: 12px; color: var(--ink-soft); text-align: right; white-space: nowrap;
}
.setup-files .file-folder {
  grid-column: 1 / -1; font-size: 11.5px; color: var(--ink-faint);
  overflow-wrap: anywhere;
}
.setup-job-status { align-items: center; gap: 10px; }
.setup-job-status p { flex: 1; min-width: 0; }
.setup-cancel { align-self: center; color: var(--ink-soft); }
.setup-cancel:hover { background: var(--line-soft); }
#replace-box {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 11px;
  display: flex; flex-direction: column; gap: 8px;
}
@media (max-width: 560px) {
  .setup-choice, .setup-grid { grid-template-columns: 1fr; }
  .setup-grid .span-2 { grid-column: span 1; }
  .setup-card { padding: 18px; }
}

/* ------------------------------ Ossature ----------------------------- */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px; height: 48px; flex: 0 0 48px;
  background: var(--primary); color: #fff;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.topbar-brand strong { font-weight: 700; }
.topbar-tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab {
  border: 0; background: transparent; color: rgba(255, 255, 255, .78);
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
}
.tab:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.tab.is-active { background: rgba(255, 255, 255, .2); color: #fff; font-weight: 600; }
.topbar-right {
  margin-left: auto; display: flex; align-items: center; gap: 12px;
  font-size: 13px;
}
.company-name { opacity: .85; }
.user-chip { display: flex; align-items: center; gap: 6px; }

.layout { display: flex; flex: 1; min-height: 0; }

/* -------------------------------- Rail ------------------------------- */
.rail {
  flex: 0 0 258px; display: flex; flex-direction: column; gap: 14px;
  padding: 14px; background: var(--surface); border-right: 1px solid var(--line);
  overflow: hidden;
}
.rail-section { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.rail-grow { flex: 1 1 0; }
.rail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rail-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--ink-faint);
}
.rail-hint { margin: 0; font-size: 11.5px; color: var(--ink-faint); line-height: 1.45; }
.mini-search {
  width: 92px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 6px; font-size: 12px;
}
.field-list {
  list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1;
  border: 1px solid var(--line-soft); border-radius: var(--radius);
}
.field-list li {
  display: flex; align-items: center; gap: 6px; padding: 5px 8px;
  cursor: pointer; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.field-list li:last-child { border-bottom: 0; }
.field-list li:hover { background: var(--primary-light); }
.field-list li.is-used { background: var(--accent-light); }
.field-kind {
  flex: 0 0 auto; width: 16px; height: 16px; border-radius: 3px;
  font-size: 10px; line-height: 16px; text-align: center; color: #fff;
  background: var(--ink-faint);
}
.field-kind.dim { background: var(--accent); }
.field-kind.mes { background: var(--primary); }
.field-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------- Centre ------------------------------ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; padding: 14px; gap: 12px; }

.builder { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.shelf { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; }
.shelf-label {
  display: block; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--ink-faint); margin-bottom: 6px;
}
.shelf-drop { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; align-items: flex-start; }
.shelf-empty { font-size: 12px; color: var(--ink-faint); font-style: italic; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--primary-light); border: 1px solid #e0d4dd;
  border-radius: 14px; padding: 3px 6px 3px 10px; font-size: 12.5px;
}
.pill.measure { background: var(--accent-light); border-color: #cfe4e4; }
.pill select {
  border: 1px solid var(--line); border-radius: 10px; font-size: 11.5px;
  padding: 1px 3px; background: #fff;
}
.pill .pill-x {
  border: 0; background: transparent; cursor: pointer; color: var(--ink-faint);
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.pill .pill-x:hover { color: var(--danger); }
.pill-filter { background: #fdf6e8; border-color: #ecd9ae; }
.pill-filter input, .pill-filter select { max-width: 150px; }

.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px;
}
.toolbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chart-picker { display: flex; gap: 4px; flex-wrap: wrap; }
.chart-btn {
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
  border-radius: var(--radius); padding: 5px 9px; font-size: 12.5px;
}
.chart-btn.is-active { background: var(--primary); border-color: var(--primary); color: #fff; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-soft); }
.limit { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--ink-soft); }
.limit input { width: 64px; border: 1px solid var(--line); border-radius: var(--radius); padding: 3px 5px; }

.message {
  padding: 9px 12px; border-radius: var(--radius); font-size: 13px;
  border-left: 3px solid var(--warning); background: #fdf6e8; color: #7a5600;
}
.message.is-error { border-left-color: var(--danger); background: #fdf2f1; color: #8c2a1e; }
.message.is-ok { border-left-color: var(--ok); background: #eefaf2; color: #15623a; }

.result { display: flex; flex-direction: column; gap: 10px; }
.chart-area {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; min-height: 260px;
}
.table-area {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: auto; max-height: 420px;
}
.notes, .sql-block {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; font-size: 12.5px;
}
.notes ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-soft); }
.sql-block pre {
  margin: 8px 0 0; padding: 10px; background: #1f2429; color: #e8e8e8;
  border-radius: var(--radius); overflow-x: auto; font-size: 11.5px; line-height: 1.5;
}
summary { cursor: pointer; font-weight: 600; color: var(--ink-soft); }

/* ------------------------------ Tableaux ----------------------------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  padding: 6px 10px; border-bottom: 1px solid var(--line-soft); text-align: left;
  white-space: nowrap;
}
table.data thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--ink-faint); border-bottom: 2px solid var(--line);
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: var(--primary-light); }
table.data tfoot td { font-weight: 700; border-top: 2px solid var(--line); background: #fbfbfc; }
.table-empty { padding: 28px; text-align: center; color: var(--ink-faint); }

/* ---------------------------- Table croisee -------------------------- */
.pivot-wrap { overflow: auto; max-height: 520px; }
table.data.pivot th.pivot-col {
  text-align: center; background: var(--primary-light); color: var(--ink);
  border-left: 2px solid var(--line);
}
table.data.pivot td.pivot-total, table.data.pivot th.pivot-total {
  background: #fbfbfc; font-weight: 600; border-left: 2px solid var(--line);
}
table.data.pivot tbody td:first-child { font-weight: 500; }
table.data.pivot thead tr:nth-child(2) th {
  font-size: 10.5px; background: var(--primary-light); color: var(--ink-soft);
}

.mini-select {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 4px; font-size: 12px; background: var(--surface);
}
.limit input, .check input[type=number] {
  width: 56px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 4px;
}
.pill.column { background: #eaf3fb; border-color: #c9ddf0; }
.pill .pill-axis {
  border: 0; background: transparent; cursor: pointer; color: var(--accent);
  font-size: 12px; padding: 0 2px;
}
.pill .pill-axis:hover { color: var(--primary); }

/* --------------------------- Graphiques SVG -------------------------- */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-axis text { font-size: 10.5px; fill: var(--ink-faint); }
.chart-axis line { stroke: var(--line); }
.chart-grid line { stroke: var(--line-soft); }
.chart-bar { transition: opacity .12s; }
.chart-bar:hover { opacity: .78; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--ink-soft); }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-empty { padding: 42px; text-align: center; color: var(--ink-faint); }

.kpi-grid { display: flex; flex-wrap: wrap; gap: 14px; }
.kpi {
  flex: 1 1 170px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--primary-light); border: 1px solid #e4d8e0;
}
.kpi-label { font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--primary); font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; color: var(--ink-faint); margin-top: 3px; }

/* ------------------------- Tableaux de bord -------------------------- */
.dashboard-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px;
}
.dashboard-bar .select { width: 220px; }
.dashboard-bar .input { width: 240px; }
.dashboard-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
  gap: 12px; align-items: start;
}
.widget {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.widget.span-2 { grid-column: span 2; }
.widget-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.widget-title { font-weight: 600; font-size: 13.5px; flex: 1; }
.widget-body { padding: 10px; min-height: 180px; }
.widget-comment { padding: 0 10px 10px; font-size: 12px; color: var(--ink-faint); }
.widget-empty { padding: 36px; text-align: center; color: var(--ink-faint); }

/* ----------------------------- Assistante ---------------------------- */
.assistant {
  flex: 0 0 390px; display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line);
  min-height: 0;
  /* Sans min-width: 0, un tableau large affiche dans la conversation
     elargit le panneau et ecrase l'exploration : la taille minimale d'un
     element flex est celle de son contenu. */
  min-width: 0;
}
.assistant-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-weight: 600; font-size: 13.5px;
}
.assistant-status {
  padding: 6px 12px; font-size: 12px; color: var(--accent);
  min-height: 26px; border-bottom: 1px solid var(--line-soft);
}
.assistant-bar {
  display: flex; gap: 6px; align-items: center; padding: 7px 12px;
  border-bottom: 1px solid var(--line-soft); background: #fbfbfc;
}
.assistant-bar .mini-select { flex: 1; min-width: 0; }
.assistant-bar .mini-select:first-child { flex: 1.1; }
.chat-sessions {
  max-height: 190px; overflow-y: auto; border-bottom: 1px solid var(--line);
  background: #fbfbfc;
}
.chat-sessions button {
  display: block; width: 100%; text-align: left; border: 0;
  background: transparent; padding: 7px 12px; cursor: pointer;
  font-size: 12.5px; border-bottom: 1px solid var(--line-soft);
}
.chat-sessions button:hover { background: var(--primary-light); }
.chat-sessions .meta { display: block; font-size: 11px; color: var(--ink-faint); }
.chat-sessions .empty { padding: 10px 12px; font-size: 12px; color: var(--ink-faint); }
.chat-file {
  align-self: stretch; display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--accent); border-radius: 8px; padding: 9px 11px;
  background: var(--accent-light);
}
.chat-file-name { flex: 1; font-size: 12.8px; font-weight: 600; }
.chat-file-size { font-size: 11px; color: var(--ink-faint); }
.integration-chip {
  align-self: flex-start; font-size: 11px; color: var(--ink-faint);
  padding: 1px 0;
}
.integration-chip b { color: var(--accent); }

.chat-log { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
/* Aucun element du fil ne doit etre comprime : un graphique SVG a une hauteur
   intrinseque nulle, il se reduirait a un trait des que le fil deborde. */
.chat-log > * { flex: 0 0 auto; }
.bubble { padding: 9px 12px; border-radius: 10px; font-size: 13.2px; line-height: 1.55; max-width: 94%; white-space: pre-wrap; word-break: break-word; }
/* Modificateurs prefixes : une classe « assistant » nue entrerait en conflit
   avec le panneau .assistant et imposerait sa hauteur fixe aux bulles. */
.bubble.from-user { align-self: flex-end; background: var(--primary); color: #fff; }
.bubble.from-assistant { align-self: flex-start; background: var(--line-soft); }
.bubble.from-error { align-self: stretch; background: #fdf2f1; color: #8c2a1e; }
.trace {
  align-self: flex-start; font-size: 11.5px; color: var(--ink-faint);
  background: #fafbfc; border: 1px solid var(--line-soft);
  border-radius: 8px; padding: 6px 9px; max-width: 94%;
}
.trace b { color: var(--accent); font-weight: 600; }
.chat-card {
  align-self: stretch; border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; max-width: 100%; min-width: 0;
}
.chat-card-head {
  padding: 6px 9px; background: #fafbfc; border-bottom: 1px solid var(--line-soft);
  font-size: 12px; font-weight: 600; display: flex; gap: 6px; align-items: center;
}
.chat-card-head button { margin-left: auto; }
.chat-card-body { padding: 8px; overflow-x: auto; }
.chat-card-body table.data { font-size: 11.5px; }
.chat-card-body table.data th, .chat-card-body table.data td {
  padding: 3px 6px;
}
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); }
.chat-form textarea {
  flex: 1; resize: vertical; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 7px 9px; min-height: 42px;
}
.assistant-note {
  margin: 0; padding: 0 12px 10px; font-size: 11px; color: var(--ink-faint);
  line-height: 1.45;
}

/* ------------------------------- Toast ------------------------------- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, .22); z-index: 50;
}
.toast.is-error { background: var(--danger); }

.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(1, 126, 132, .25); border-top-color: var(--accent);
  animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------- Adaptatif ----------------------------- */
/* ------------------------------------------------- fraicheur et synchro

   Le panneau s'ouvre par-dessus, a droite, et ne deplace rien : on y vient
   pour verifier une date, pas pour reorganiser son ecran.
*/
.freshness {
  border: 1px solid rgba(255, 255, 255, .28); background: transparent;
  color: inherit; font: inherit; opacity: .88; cursor: pointer;
  padding: 3px 8px; border-radius: var(--radius); white-space: nowrap;
}
.freshness:hover { background: rgba(255, 255, 255, .12); opacity: 1; }
.freshness.is-stale {
  color: #f8d7a0; border-color: rgba(248, 215, 160, .55);
}

.side-panel {
  position: fixed; top: 48px; right: 0; bottom: 0; width: 460px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -2px 0 12px rgba(31, 36, 41, .12);
  display: flex; flex-direction: column; z-index: 40;
}
.side-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--primary-light);
}
.side-panel-body {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: 14px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.side-panel-body > * { flex: 0 0 auto; }

.muted { color: var(--ink-soft); }
.small { font-size: 11.5px; }
.row-between {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.notice {
  padding: 9px 11px; border-radius: var(--radius); font-size: 12px;
  line-height: 1.5; background: #fdf6e3; border: 1px solid #e8d9a8;
  color: var(--warning);
}

#sync-box {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 11px;
  display: flex; flex-direction: column; gap: 8px;
}
.sync-result {
  border-top: 1px solid var(--line-soft); padding-top: 8px;
  display: flex; flex-direction: column; gap: 2px;
  max-height: 180px; overflow-y: auto;
}

/* `table-layout: fixed` est indispensable ici : avec quatre colonnes en
   `nowrap` dans un panneau de 460 px, la mise en page automatique elargit la
   table au-dela du panneau et la derniere colonne sort de l'ecran. */
.freshness-table {
  width: 100%; border-collapse: collapse; font-size: 11.5px;
  table-layout: fixed;
}
.freshness-table th, .freshness-table td {
  padding: 4px 6px; border-bottom: 1px solid var(--line-soft);
  text-align: left; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.freshness-table th:nth-child(1), .freshness-table td:nth-child(1) { width: 44%; }
.freshness-table th:nth-child(2), .freshness-table td:nth-child(2) { width: 26%; }
.freshness-table th:nth-child(3), .freshness-table td:nth-child(3) { width: 16%; }
.freshness-table th:nth-child(4), .freshness-table td:nth-child(4) { width: 14%; }
.freshness-table th { color: var(--ink-faint); font-weight: 600; }
.freshness-table td.num, .freshness-table th.num { text-align: right; }
.freshness-table tr.is-watched td { font-weight: 600; }

/* Le mode direct interroge la production : l'interrupteur doit se voir. */
.live-check {
  border: 1px solid var(--warning); border-radius: var(--radius);
  padding: 2px 7px; color: var(--warning); font-weight: 600;
}

@media (max-width: 1180px) {
  .assistant { flex-basis: 330px; }
  .builder { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .layout { flex-direction: column; overflow-y: auto; }
  /* En colonne, un rail en `overflow: hidden` avec des listes en `flex: 1`
     ecrase ces listes a zero : on leur rend une hauteur propre et leur propre
     defilement. */
  .rail {
    flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--line);
    overflow: visible;
  }
  .rail-grow { flex: 0 0 auto; }
  .field-list { max-height: 230px; }
  .main { overflow: visible; }
  .view { overflow: visible; }
  .assistant { flex: 0 0 auto; height: 60vh; border-left: 0; border-top: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 10px; }
  .widget.span-2 { grid-column: span 1; }
  .side-panel { top: 0; width: 100vw; max-width: 100vw; }
  /* La zone de droite reunit societe, fraicheur, assistante et compte : sur
     un telephone elle depasse forcement la largeur de l'ecran. On la laisse
     passer a la ligne plutot que de la laisser deborder — un defilement
     horizontal sur toute la page rend l'outil penible a tenir en main. */
  .topbar-right {
    flex-wrap: wrap; justify-content: flex-end; max-width: 100%;
    row-gap: 6px;
  }
  .freshness { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
