:root {
  --violet-900: #2a1559;
  --violet-700: #4b2a9b;
  --violet-600: #5b34c4;
  --violet-500: #7048e8;
  --violet-100: #ece6fd;
  --violet-50: #f6f3fe;
  --ink: #1d1830;
  --ink-soft: #5d577a;
  --line: #e4dff2;
  --bg: #fbfaff;
  --panel: #ffffff;
  --danger: #c2334d;
  --ok: #1f8f5f;
  --radius: 14px;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ece8fb;
    --ink-soft: #a59fc4;
    --line: #2f2850;
    --bg: #14111f;
    --panel: #1c1830;
    --violet-50: #221c3d;
    --violet-100: #2c2450;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- Logo ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.02em; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--violet-500), var(--violet-900));
  color: #fff; display: grid; place-items: center; font-size: 15px; font-weight: 800;
}
.brand-name { font-size: 20px; }
.brand-name span { color: var(--violet-500); }

/* ---------- Ecran de connexion ---------- */
.login {
  min-height: 100%; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(circle at 20% 10%, var(--violet-100), transparent 50%), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px; box-shadow: 0 20px 50px -30px rgba(75, 42, 155, .5);
}
.login-card h1 { font-size: 22px; margin: 20px 0 6px; }
.login-card p { color: var(--ink-soft); margin: 0 0 20px; font-size: 14px; line-height: 1.5; }
.field {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 16px; outline: none;
}
.field:focus { border-color: var(--violet-500); box-shadow: 0 0 0 3px var(--violet-100); }
.code-field { text-transform: uppercase; letter-spacing: .12em; text-align: center; font-weight: 600; }
.btn {
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600;
  background: var(--violet-600); color: #fff;
}
.btn:hover { background: var(--violet-700); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-block { width: 100%; margin-top: 12px; }
.btn-ghost { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--violet-50); color: var(--ink); }
.error { color: var(--danger); font-size: 14px; margin-top: 10px; min-height: 20px; }

/* ---------- Mise en page du chat ---------- */
.app { display: grid; grid-template-columns: 270px 1fr; height: 100%; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { padding: 18px 16px 12px; display: flex; flex-direction: column; gap: 14px; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; width: 100%; text-align: left;
  padding: 9px 10px; border-radius: 9px; border: 0; background: transparent; font-size: 14px;
}
.conv-item:hover { background: var(--violet-50); }
.conv-item.active { background: var(--violet-100); font-weight: 600; }
.conv-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-del { opacity: 0; border: 0; background: none; color: var(--ink-soft); padding: 2px 6px; border-radius: 6px; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger); }
.sidebar-foot {
  border-top: 1px solid var(--line); padding: 12px 16px; font-size: 13px; color: var(--ink-soft);
  display: flex; flex-direction: column; gap: 8px;
}
.usage-line { display: flex; justify-content: space-between; }
.foot-row { display: flex; justify-content: space-between; align-items: center; }
.link-btn { border: 0; background: none; color: var(--violet-500); padding: 0; font-size: 13px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.menu-btn { display: none; border: 0; background: none; font-size: 20px; padding: 4px 8px; }
.model-chip {
  display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px; background: var(--violet-50); border: 1px solid var(--line);
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #aaa; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(31, 143, 95, .18); }
.dot.off { background: var(--danger); }

.thread { flex: 1; overflow-y: auto; padding: 28px 20px 12px; }
.thread-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }
.empty { text-align: center; color: var(--ink-soft); margin-top: 12vh; }
.empty .brand-mark { width: 54px; height: 54px; font-size: 24px; border-radius: 16px; margin: 0 auto 16px; }
.empty h2 { color: var(--ink); margin: 0 0 6px; }

.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-end; }
.bubble { max-width: 100%; line-height: 1.6; font-size: 15.5px; overflow-wrap: anywhere; }
.msg.user .bubble {
  background: var(--violet-600); color: #fff; padding: 10px 15px; border-radius: 16px 16px 4px 16px;
  white-space: pre-wrap; max-width: 85%;
}
.msg.assistant .bubble { padding: 2px 0; }
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 1em 0 .4em; }
.bubble ul, .bubble ol { padding-left: 1.4em; margin: 0 0 .7em; }
.bubble code { background: var(--violet-50); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.bubble pre { background: var(--violet-50); border: 1px solid var(--line); padding: 12px; border-radius: 10px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: .5em 0; font-size: .93em; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 9px; }
.cursor::after { content: "▍"; color: var(--violet-500); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.reasoning { font-size: 13px; color: var(--ink-soft); border-left: 2px solid var(--line); padding-left: 10px; }
.reasoning summary { cursor: pointer; }
.reasoning div { white-space: pre-wrap; margin-top: 6px; max-height: 240px; overflow-y: auto; }

.meta { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-soft); }
.rate { border: 1px solid transparent; background: none; border-radius: 7px; padding: 2px 6px; font-size: 14px; filter: grayscale(1); opacity: .6; }
.rate:hover { background: var(--violet-50); opacity: 1; }
.rate.active { filter: none; opacity: 1; border-color: var(--line); background: var(--violet-50); }
.msg-error { color: var(--danger); font-size: 14px; }

.composer-wrap { padding: 10px 20px 18px; }
.composer {
  max-width: 780px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 10px 10px 8px 14px; box-shadow: 0 10px 30px -24px rgba(75, 42, 155, .6);
}
.composer:focus-within { border-color: var(--violet-500); }
.composer textarea {
  width: 100%; border: 0; outline: none; resize: none; background: transparent;
  font-size: 15.5px; line-height: 1.5; max-height: 220px; min-height: 26px;
}
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.toggle { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--violet-600); }
.send { border-radius: 12px; padding: 8px 16px; }
.hint { max-width: 780px; margin: 8px auto 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* ---------- Administration ---------- */
.admin { max-width: 1060px; margin: 0 auto; padding: 28px 20px 60px; }
.admin-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 26px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 26px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card .k { font-size: 12.5px; color: var(--ink-soft); }
.card .v { font-size: 24px; font-weight: 700; margin-top: 4px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel h2 { font-size: 16px; margin: 0 0 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 200px; }
.new-code {
  margin-top: 14px; padding: 14px; border-radius: 10px; background: var(--violet-50);
  border: 1px dashed var(--violet-500); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.new-code strong { font-size: 20px; letter-spacing: .1em; font-family: ui-monospace, Consolas, monospace; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; color: var(--ink-soft); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--violet-100); }
.badge.revoked { background: #fbe3e8; color: var(--danger); }
.btn-small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .menu-btn { display: block; }
  .thread { padding: 18px 16px 8px; }
  .composer-wrap { padding: 8px 16px 14px; }
}
