:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --navy: #1b2a63;
  --navy-2: #22336f;
  --blue: #2f6bff;
  --line: #eceef5;
  --text: #1b2559;
  --muted: #8a93b2;
  --green-bg: #e7f8ef; --green: #12a05f;
  --red-bg: #fdeaef;  --red: #e5484d;
  --gray-bg: #eef1f7; --gray: #8a93b2;
  --chat-w: 320px;
  /* Right column width, shared by the score card and the recommendations so the
     two stay aligned on the same right edge. */
  --rail-w: 330px;
  --radius: 16px;
  --shadow: 0 6px 22px rgba(27, 42, 99, .07);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
}
.muted { color: var(--muted); }
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Chatbot fixe gauche ---------- */
#chatbot {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--chat-w);
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px; gap: 14px; z-index: 30;
}
.chat-header { display: flex; align-items: center; gap: 10px; }
.chat-avatar {
  width: 40px; height: 40px; border-radius: 12px; background: var(--navy); color: #fff;
  display: grid; place-items: center; font-weight: 800; font-size: .72rem; letter-spacing: .5px;
}
.chat-title { font-weight: 700; color: var(--navy); }
.chat-sub { font-size: .68rem; color: var(--muted); }
.chat-online { width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-left: auto; box-shadow: 0 0 0 3px var(--green-bg); }
#agent-select, #client-select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--text); font-size: .85rem; font-family: inherit;
}
#chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 3px; }
.msg { padding: 10px 13px; border-radius: 13px; font-size: .84rem; line-height: 1.45; white-space: pre-wrap; }
.msg.user { background: var(--blue); color: #fff; align-self: flex-end; max-width: 92%; border-bottom-right-radius: 4px; }
.msg.bot { background: var(--bg); color: var(--text); align-self: flex-start; max-width: 96%; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg-p { margin: 4px 0; }
.msg-p:first-child { margin-top: 0; }
.msg-h { font-weight: 700; color: var(--navy); margin: 9px 0 3px; font-size: .82rem; }
.msg.bot ul { margin: 5px 0; padding-left: 18px; }
.msg.bot li { margin: 2px 0; }
.msg-chart { margin-top: 10px; height: 170px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.msg-table { overflow-x: auto; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; }
.msg.bot table { width: 100%; border-collapse: collapse; font-size: .7rem; }
.msg.bot th, .msg.bot td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 5px 8px; text-align: right; white-space: nowrap; }
.msg.bot th { background: var(--bg); color: var(--navy); text-align: right; font-weight: 700; }
.msg.bot th:first-child, .msg.bot td:first-child { text-align: left; }
.msg.bot tr:last-child td { border-bottom: 0; }
.msg.typing { color: var(--muted); font-style: italic; }
.msg-agent { margin-top: 7px; font-size: .66rem; color: var(--muted); font-weight: 600; opacity: .85; }
#chat-form { display: flex; gap: 7px; }
#chat-input { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px; font-size: .84rem; font-family: inherit; }
#chat-send { width: 44px; border: 0; border-radius: 10px; background: var(--blue); color: #fff; font-size: 1rem; }
#chat-send:disabled { opacity: .5; }

/* ---------- Layout principal ---------- */
#content { margin-left: var(--chat-w); }
.navbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  background: #fff; border-bottom: 1px solid var(--line); padding: 12px 30px;
}
.brand { font-weight: 800; font-size: 1.05rem; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 16px; height: 16px; border-radius: 5px; background: linear-gradient(135deg, var(--blue), #7c5cfc); }
.nav-center { flex: 1; display: flex; justify-content: center; }
.client-picker { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px 8px 4px 12px; min-width: 320px; }
.picker-icon { font-size: .9rem; }
.client-picker select { border: 0; background: transparent; min-width: 260px; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.period-picker { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; font-size: .8rem; }
.period-picker select { border: 0; background: transparent; font-size: .8rem; color: var(--text); }
.btn-primary { background: var(--blue); color: #fff; border: 0; padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: .82rem; }
.btn-ghost { background: var(--bg); border: 1px solid var(--line); color: var(--muted); width: 36px; height: 36px; border-radius: 10px; font-size: 1rem; }
.btn-ghost:hover { color: var(--blue); border-color: var(--blue); }
.user-chip { display: flex; align-items: center; gap: 9px; }
.user-avatar { width: 38px; height: 38px; border-radius: 11px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .72rem; }
.user-name { font-weight: 700; font-size: .82rem; }
.user-role { font-size: .64rem; color: var(--muted); letter-spacing: .5px; }

#main { padding: 26px 34px 60px; }

/* ---------- Écran d'accueil ---------- */
.welcome { display: grid; place-items: center; padding-top: 6vh; }
.welcome-card { background: var(--card); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 42px; max-width: 640px; text-align: center; }
.welcome-emoji { font-size: 2.6rem; }
.welcome-card h2 { margin: 10px 0 6px; color: var(--navy); }
.client-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }
.client-chip { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 7px 14px; font-size: .8rem; color: var(--navy); cursor: pointer; transition: .12s; }
.client-chip:hover { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---------- Hero ---------- */
/* `center`, not `stretch`: the greeting block is shorter than the score card,
   and stretching it left all the slack as blank space under the title. */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 22px; margin-bottom: 8px; }
.hero-greeting h1 { margin: 0 0 6px; font-size: 2rem; color: var(--navy); }
.hero-sub { font-size: .82rem; color: var(--muted); letter-spacing: .8px; display: flex; align-items: center; gap: 6px; }
.score-card { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; border-radius: var(--radius); padding: 18px 24px; flex: 0 0 var(--rail-w); box-shadow: var(--shadow); }
.score-label { font-size: .68rem; letter-spacing: .6px; opacity: .82; }
.info { cursor: help; opacity: .7; }
.score-row { display: flex; align-items: center; gap: 12px; margin: 6px 0 4px; }
.score-value { font-size: 2.4rem; font-weight: 800; line-height: 1; }
.score-delta { font-size: .78rem; font-weight: 700; background: rgba(255,255,255,.16); padding: 4px 9px; border-radius: 20px; }
.score-delta.up { color: #7ef0b0; } .score-delta.down { color: #ff9aa5; }
.score-perf { font-size: .68rem; letter-spacing: .6px; opacity: .82; }

/* ---------- Corps 2 colonnes ---------- */
.dash-body { display: grid; grid-template-columns: minmax(0, 1fr) var(--rail-w); gap: 26px; align-items: start; }
.dash-main { min-width: 0; }
.dash-right { position: sticky; top: 84px; }
@media (max-width: 1100px) { .dash-body { grid-template-columns: 1fr; } .dash-right { position: static; } }

/* ---------- Colonne recommandations ---------- */
.reco-head { margin-bottom: 14px; }
.reco-title { font-weight: 800; color: var(--navy); }
.reco-sub { font-size: .74rem; color: var(--muted); }
.reco-list { display: flex; flex-direction: column; gap: 12px; }
.reco-card { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); }
.reco-badge { font-size: .62rem; font-weight: 800; letter-spacing: .5px; padding: 3px 8px; border-radius: 6px; color: #fff; }
.reco-name { font-weight: 700; color: var(--navy); margin: 9px 0 5px; font-size: .9rem; }
.reco-desc { font-size: .78rem; color: var(--muted); line-height: 1.45; }
.reco-action { margin-top: 10px; font-size: .76rem; font-weight: 600; color: var(--blue); background: #eef3ff; border: 0; padding: 6px 12px; border-radius: 8px; }
.reco-empty { color: var(--muted); font-size: .84rem; padding: 16px; text-align: center; background: var(--card); border: 1px dashed var(--line); border-radius: 12px; }

/* ---------- Panneau détail (dans la page) ---------- */
.detail-panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 22px; animation: slidein .25s ease; }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; }
.detail-title { font-weight: 800; color: var(--navy); font-size: 1.05rem; }
.detail-value { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 2px; }
.dv-num { font-size: 1.6rem; font-weight: 800; color: var(--navy); }
.dv-unit { font-size: .9rem; color: var(--muted); font-weight: 700; margin-left: 2px; }
.dv-period { font-size: .72rem; color: var(--muted); }
.detail-cache { font-size: .7rem; color: var(--muted); margin-top: 2px; }
.detail-actions { display: flex; gap: 8px; }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 12px 0 4px; }
.progress.hidden { display: none; }
.progress-bar { height: 100%; width: 40%; background: linear-gradient(90deg, var(--blue), #7c5cfc); border-radius: 4px; animation: indet 1.1s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.detail-body { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 14px; }
.detail-body h3 { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 0 0 10px; }
.detail-synthesis { line-height: 1.6; white-space: pre-wrap; }
.detail-synthesis b { color: var(--navy); }
.detail-agent { margin-top: 12px; font-size: .72rem; color: var(--muted); }
.detail-chart canvas { max-height: 240px; }
@media (max-width: 760px) { .detail-body { grid-template-columns: 1fr; } }

/* ---------- Sections ---------- */
.section-title { font-weight: 800; color: var(--navy); font-size: 1.02rem; margin: 22px 0 12px; }
/* The first title of a column already sits below the hero: its top margin would
   stack with the hero's and misalign the two columns. */
.dash-main > .section-title:first-child { margin-top: 0; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; }
.synth-card { background: linear-gradient(180deg, #eef3ff, #f7f9ff); border: 1px solid #e0e8ff; border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.synth-head { font-size: .68rem; font-weight: 800; letter-spacing: .8px; color: var(--blue); margin-bottom: 8px; }
.synth-text { line-height: 1.6; color: var(--text); }
.synth-text b, .synth-text strong { color: var(--navy); }

/* ---------- Grille KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.kpi-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); cursor: pointer; transition: transform .12s, box-shadow .12s; position: relative; }
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(27,42,99,.13); }
.kpi-card.selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(47,107,255,.28), 0 12px 30px rgba(27,42,99,.13); transform: translateY(-2px); }
.kpi-card.selected::after { content: "● affiché ci-dessus"; position: absolute; bottom: 12px; right: 16px; font-size: .64rem; font-weight: 700; color: var(--blue); }
.kpi-grid.has-selection .kpi-card:not(.selected) { opacity: .5; }
.kpi-grid.has-selection .kpi-card:not(.selected):hover { opacity: 1; }
.kpi-top { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.kpi-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.1rem; }
.kpi-cat { font-weight: 700; color: var(--navy); font-size: .95rem; }
.kpi-name { font-size: .74rem; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 5px; }
.kpi-valrow { display: flex; align-items: baseline; gap: 10px; }
.kpi-value { font-size: 1.9rem; font-weight: 800; color: var(--navy); }
.kpi-value .unit { font-size: .95rem; color: var(--muted); font-weight: 700; margin-left: 2px; }
.kpi-value.na { font-size: 1rem; color: var(--muted); font-weight: 600; }
.badge { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; display: inline-flex; align-items: center; gap: 3px; }
.badge.up { background: var(--green-bg); color: var(--green); }
.badge.down { background: var(--red-bg); color: var(--red); }
.badge.flat { background: var(--gray-bg); color: var(--gray); }
.kpi-caption { font-size: .72rem; color: var(--muted); margin-top: 12px; }
.kpi-detail-hint { position: absolute; top: 16px; right: 18px; font-size: .68rem; color: var(--blue); opacity: 0; transition: .12s; }
.kpi-card:hover .kpi-detail-hint { opacity: 1; }

/* ---------- Modal ---------- */
#modal-overlay { position: fixed; inset: 0; background: rgba(20,28,60,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; backdrop-filter: blur(2px); }
#modal { background: var(--card); border-radius: 20px; width: min(880px, 94vw); max-height: 88vh; overflow-y: auto; padding: 28px; position: relative; box-shadow: 0 30px 60px rgba(20,28,60,.25); }
#modal-close { position: absolute; top: 18px; right: 20px; background: var(--bg); border: 0; width: 32px; height: 32px; border-radius: 9px; color: var(--muted); font-size: 1rem; }
#modal h2 { margin: 0 0 20px; color: var(--navy); }
.modal-body { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.modal-body h3 { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 0 0 12px; }
.synthesis-text { line-height: 1.6; color: var(--text); white-space: pre-wrap; }
.synthesis-agent { margin-top: 14px; font-size: .72rem; color: var(--muted); }
.chart-wrap canvas { max-height: 280px; }
@media (max-width: 760px) { .modal-body { grid-template-columns: 1fr; } .hero { flex-direction: column; }
  /* Stacked hero: the card spans the full width instead of the rail. */
  .score-card { flex: 1 1 auto; } }
