:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --pos: #2a78d6;
  --neg: #e34948;
  --grid: #e8e6e1;
  --good: #008300;
  --warn: #b26b00;
  --danger: #c93636;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  --radius: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;
  --accent-soft: #1b2a3d;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --pos: #3987e5;
  --neg: #e66767;
  --grid: #2b2b29;
  --good: #3fae3f;
  --warn: #e0a030;
  --danger: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  padding: 20px 14px; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column; gap: 4px;
}
.brand { font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.brand span { color: var(--accent); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.badge {
  margin-left: auto; font-size: 12px; background: var(--surface-2); color: var(--text-2);
  padding: 1px 8px; border-radius: 999px;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 6px; }
.stack-tight { display: flex; flex-direction: column; gap: 8px; }
.stack-tight[hidden] { display: none; }
.main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; min-width: 0; }

/* Images de fond, derrière le contenu */
.layout { position: relative; z-index: 1; }
.decor {
  position: fixed; bottom: 0; z-index: 0; pointer-events: none; user-select: none;
  height: 92vh; max-width: 38vw; object-fit: contain; opacity: 0.3;
}
.decor-right { right: 16px; object-position: right bottom; }
.decor-left { left: 236px; object-position: left bottom; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; }

/* ---------- Composants ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--text-2); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.section-title { margin: 30px 0 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); padding: 7px 13px; border-radius: 8px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.input, select.input, textarea.input {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar .input[type="search"] { flex: 1 1 220px; }

.tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 9px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px;
  cursor: pointer; font-size: 13.5px; color: var(--text); text-align: left;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

.banner {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 18px; font-size: 14px;
}
.banner.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.banner code { background: var(--surface); padding: 1px 6px; border-radius: 5px; }

/* ---------- Tableaux et listes ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--text-2); font-size: 12.5px; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.rank li:last-child { border-bottom: 0; }
.rank .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.rank .v { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-2); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.stars { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 360px; }
.chart-box.xl { height: 480px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 13px; color: var(--text-2); }

/* ---------- Wishlist ---------- */
.wish-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.wish {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow);
}
.wish.done { opacity: 0.7; }
.wish-top { display: flex; justify-content: space-between; gap: 8px; align-items: start; }
.wish h3 { font-size: 15.5px; }
.wish .meta { font-size: 13px; color: var(--text-2); }
.wish .why { font-size: 13.5px; color: var(--text-2); margin: 0; }
.wish-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; align-items: center; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.film { background: var(--accent-soft); color: var(--accent); }
.pill.serie { background: color-mix(in srgb, var(--series-3) 16%, transparent); color: var(--series-3); }
.pill.livre { background: color-mix(in srgb, var(--series-2) 16%, transparent); color: var(--series-2); }
.pill.p-note { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pill.p1 { background: color-mix(in srgb, var(--neg) 14%, transparent); color: var(--neg); }
.empty { text-align: center; padding: 40px 20px; color: var(--text-2); border: 1px dashed var(--border); border-radius: var(--radius); }
details.add { margin-bottom: 16px; }
details.add summary { cursor: pointer; font-weight: 500; color: var(--accent); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.form-row .input { flex: 1 1 160px; }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; height: calc(100vh - 140px); min-height: 480px; }
.conv-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--text-2);
}
.conv-item:hover { background: var(--surface-2); color: var(--text); }
.conv-item.active { background: var(--accent-soft); color: var(--accent); }
.conv-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item button { visibility: hidden; border: 0; background: none; cursor: pointer; color: var(--text-3); padding: 0 2px; }
.conv-item:hover button { visibility: visible; }
.chat-panel { display: flex; flex-direction: column; min-height: 0; padding: 0; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 18px; }
.msg { max-width: 760px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 9px 14px; border-radius: 14px 14px 4px 14px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; width: 100%; }
.msg.assistant .md > :first-child { margin-top: 0; }
.msg.assistant .md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md table { margin: 8px 0 12px; font-size: 13.5px; }
.md h1, .md h2, .md h3 { margin: 14px 0 8px; font-size: 16px; }
.md code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.md blockquote { margin: 0 0 10px; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-2); }
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2);
  background: var(--surface-2); border-radius: 999px; padding: 3px 10px; margin: 2px 0 8px;
}
.tool-chip.err { color: var(--danger); }
.tool-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); }
.tool-chip.err .dot { background: var(--danger); }
.status-line { font-size: 13px; color: var(--text-3); display: flex; align-items: center; gap: 8px; }
.spinner { width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer { border-top: 1px solid var(--border); padding: 12px; display: flex; gap: 8px; align-items: end; background: var(--surface); }
.composer textarea { flex: 1; resize: none; max-height: 180px; min-height: 42px; padding: 10px 12px; }
.chat-empty { margin: auto; text-align: center; max-width: 560px; display: flex; flex-direction: column; gap: 14px; align-items: center; }
.chat-empty .chips { justify-content: center; }
.error-box { color: var(--danger); font-size: 14px; }

/* ---------- Tooltip graphique ---------- */
.viz-tip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgb(0 0 0 / 0.12);
  max-width: 280px; opacity: 0; transition: opacity 0.1s;
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 140px; }
  .chat-panel { height: 70vh; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; gap: 2px;
  }
  .brand { padding: 0 8px 0 0; font-size: 16px; white-space: nowrap; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 7px 9px; }
  .nav a .lbl, .sidebar-foot, .badge { display: none; }
  .main { padding: 18px 16px 50px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  h1 { font-size: 22px; }
  .decor { height: 70vh; max-width: 60vw; opacity: 0.12; }
  .decor-left { left: 0; }
}
