@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #12141a;
  --panel: #191c24;
  --panel-raised: #20242f;
  --border: #2a2f3d;
  --text: #edeef2;
  --muted: #8b93a6;
  --muted-dim: #5b6274;

  --local: #e8a33d;
  --local-dim: #4a3a22;
  --cloud: #56b9d6;
  --cloud-dim: #1f3a42;

  --danger: #e2596b;
  --success: #52c48a;

  --radius: 10px;
  --radius-sm: 6px;
  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  font-family: var(--font-body);
  background: var(--ink);
  color: var(--text);
  display: flex;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--cloud); outline-offset: 2px; }

/* ---------- Rail de navigation ---------- */

#nav-root { flex-shrink: 0; }

.rail {
  width: 220px;
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
}

.rail-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
  padding: 4px 8px 20px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.rail-brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--local); display: inline-block; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; }

.rail-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background 0.12s, color 0.12s;
}

.rail-nav a:hover { color: var(--text); background: var(--panel-raised); }
.rail-nav a.active { color: var(--text); background: var(--panel-raised); }
.rail-nav a.active::before {
  content: "";
  width: 3px;
  height: 14px;
  background: var(--cloud);
  border-radius: 2px;
  margin-left: -13px;
  margin-right: 7px;
}

.rail-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-dim);
}

.rail-status { display: flex; align-items: center; gap: 6px; padding: 4px 8px; }
.rail-status .led { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-dim); flex-shrink: 0; }
.rail-status.ok .led { background: var(--success); box-shadow: 0 0 6px var(--success); }
.rail-status.down .led { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

/* ---------- Contenu principal ---------- */

.app-main { flex: 1; min-width: 0; max-width: 920px; margin: 0 auto; padding: 32px 28px 60px; }

.page-head { margin-bottom: 24px; }
.page-head h1 { font-family: var(--font-display); font-size: 24px; margin: 0 0 4px; }
.page-head p { color: var(--muted); font-size: 14px; margin: 0; }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }

.card h2 {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin: 0 0 14px;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.stat { background: var(--panel-raised); border-radius: var(--radius-sm); padding: 14px; }
.stat .value { font-family: var(--font-mono); font-size: 24px; font-weight: 500; }
.stat .label { font-size: 12px; color: var(--muted); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
td { font-family: var(--font-mono); font-size: 13px; }
td:first-child, th:first-child { font-family: var(--font-body); }

.provider-badge { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 12px; padding: 2px 0; }
.provider-badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.provider-badge.local .dot { background: var(--local); }
.provider-badge.cloud .dot { background: var(--cloud); }

button, select, input[type="text"] {
  font-family: var(--font-body); background: var(--panel-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 13px; font-size: 14px;
}

button { cursor: pointer; font-weight: 500; transition: background 0.12s; }
button.primary { background: var(--cloud); border: none; color: #0b1418; }
button.primary:hover { background: #6cc6e0; }
button.danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); }
button.danger:hover { background: rgba(226, 89, 107, 0.1); }
button:not(.primary):not(.danger):hover { background: #262b38; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }

.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }
.success { color: var(--success); }

.empty-state { text-align: center; padding: 30px 20px; color: var(--muted); font-size: 14px; }

/* ---------- Chat ---------- */

.chat-shell { display: flex; flex-direction: column; height: calc(100vh - 64px); }

#chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 4px 2px 16px; }

.msg-row { display: flex; flex-direction: column; max-width: 72%; animation: rise 0.18s ease-out; }
.msg-row.user { align-self: flex-end; align-items: flex-end; }
.msg-row.assistant { align-self: flex-start; align-items: flex-start; }

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

.bubble { padding: 11px 15px; border-radius: 14px; font-size: 14.5px; line-height: 1.5; white-space: pre-wrap; }
.msg-row.user .bubble { background: var(--cloud); color: #0b1418; border-bottom-right-radius: 4px; }
.msg-row.assistant .bubble { background: var(--panel-raised); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

.route-chip {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  margin-top: 5px; padding-left: 3px; display: flex; align-items: center; gap: 5px;
}
.route-chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.route-chip.local .dot { background: var(--local); }
.route-chip.local { color: var(--local); }
.route-chip.cloud .dot { background: var(--cloud); }
.route-chip.cloud { color: var(--cloud); }

.thinking { display: flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 13px; color: var(--muted); padding: 4px 2px; }
.cursor-blink { animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.chat-input-row { display: flex; gap: 8px; padding-top: 14px; border-top: 1px solid var(--border); }
.chat-input-row input { flex: 1; font-size: 14.5px; padding: 12px 14px; }

.suggestions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.suggestion {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--muted); background: var(--panel-raised);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 13px; cursor: pointer;
}
.suggestion:hover { color: var(--text); border-color: var(--muted-dim); }

/* ---------- Documents ---------- */

.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius); padding: 36px 20px;
  text-align: center; color: var(--muted); cursor: pointer;
  transition: border-color 0.12s, background 0.12s; font-size: 14px;
}
.dropzone:hover { border-color: var(--muted-dim); }
.dropzone.dragover { border-color: var(--cloud); background: var(--cloud-dim); color: var(--text); }

.tag {
  display: inline-block; font-family: var(--font-mono); background: var(--panel-raised);
  border-radius: 4px; padding: 2px 7px; font-size: 11px; margin: 2px 3px 2px 0; color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .msg-row, .cursor-blink { animation: none !important; }
}

@media (max-width: 760px) {
  body { flex-direction: column; }
  .rail { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 14px; }
  .rail-brand { padding: 0; }
  .rail-nav { flex-direction: row; margin-left: auto; }
  .rail-footer { display: none; }
  .app-main { padding: 20px 16px 40px; }
}

/* ---------- Liste des conversations (chat.html) ---------- */

.chat-layout { display: flex; gap: 18px; height: calc(100vh - 64px); }

.conv-panel {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding-right: 14px;
}

.conv-new-btn {
  width: 100%;
  margin-bottom: 10px;
  padding: 9px;
  font-size: 13px;
}

.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.conv-item:hover { background: var(--panel-raised); color: var(--text); }
.conv-item.active { background: var(--panel-raised); color: var(--text); border-left: 2px solid var(--cloud); padding-left: 7px; }

.conv-item .conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.conv-item .conv-actions { display: none; gap: 4px; flex-shrink: 0; }
.conv-item:hover .conv-actions { display: flex; }
.conv-item .conv-actions button {
  padding: 2px 6px;
  font-size: 11px;
  background: transparent;
  border: none;
  color: var(--muted-dim);
}
.conv-item .conv-actions button:hover { color: var(--text); }

.conv-empty { color: var(--muted-dim); font-size: 12px; padding: 8px; text-align: center; }

.chat-shell { flex: 1; min-width: 0; }

/* ---------- Confidentialité (Documents) ---------- */

.conf-badge {
  display: inline-block; font-family: var(--font-mono); font-size: 11px;
  padding: 2px 8px; border-radius: 999px; background: var(--panel-raised); color: var(--muted);
}
.conf-badge.public { color: var(--success); border: 1px solid var(--success); }
.conf-badge.internal { color: var(--cloud); border: 1px solid var(--cloud); }
.conf-badge.sensitive { color: var(--local); border: 1px solid var(--local); }
.conf-badge.confidential { color: var(--danger); border: 1px solid var(--danger); }
.conf-badge.secret { color: var(--danger); border: 1px solid var(--danger); background: rgba(226,89,107,0.12); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; width: 100%; max-width: 460px; max-height: 85vh; overflow-y: auto;
}
.modal-panel h2 { margin-top: 0; }
.group-checkbox-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; }
.exception-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12px; font-family: var(--font-mono); }
.exception-row .exc-grant { color: var(--success); }
.exception-row .exc-deny { color: var(--danger); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.doc-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.doc-actions button { padding: 5px 9px; font-size: 12px; }
