:root {
  --bg: #f5f6f8;
  --fg: #1c2330;
  --accent: #2a5bd7;
  --user: #2a5bd7;
  --bot: #ffffff;
  --muted: #6b7280;
  --border: #e1e4ea;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Zone défilante (header + saisie + footer restent fixes). */
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

header {
  flex: 0 0 auto;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-nav {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.kb-link {
  flex-shrink: 0;
  color: var(--accent);
  text-decoration: none;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.45rem 0.7rem;
  border: 1px solid #d6e0f7;
  border-radius: 8px;
  background: #eef2fb;
  white-space: nowrap;
  cursor: pointer;
}

.kb-link:hover {
  background: #e2e9fa;
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--accent);
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

main#thread {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.25rem;
}

.msg {
  max-width: 85%;
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  margin-bottom: 0.6rem;
  white-space: pre-wrap;
  line-height: 1.45;
}

.msg-user {
  background: var(--user);
  color: #fff;
  margin-left: auto;
  border-bottom-right-radius: 3px;
}

.msg-bot {
  background: var(--bot);
  border: 1px solid var(--border);
  border-bottom-left-radius: 3px;
}

.sources {
  max-width: 85%;
  margin: -0.2rem 0 0.8rem;
  padding: 0.55rem 0.8rem;
  background: #eef2fb;
  border: 1px solid #d6e0f7;
  border-radius: 10px;
  font-size: 0.82rem;
}

.sources-title {
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--accent);
}

.source-item {
  color: #33415c;
  padding: 0.1rem 0;
}

form#chat-form {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
  border-top: 1px solid var(--border);
  background: #fff;
}

#question {
  flex: 1;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

#send {
  padding: 0.65rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

#send:disabled {
  opacity: 0.5;
  cursor: default;
}

footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.6rem;
}

/* --- Page base de connaissances --- */
.kb-main {
  flex: 1;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 1.25rem;
}

.kb-count {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.kb-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.2rem;
  margin-bottom: 1.1rem;
}

.kb-card-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.kb-id {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  color: var(--accent);
  background: #eef2fb;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
}

.kb-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.kb-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 0.55rem 0 0.2rem;
}

.kb-badge {
  font-size: 0.72rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: #eceff4;
  color: #33415c;
}

.kb-badge-ok {
  background: #e3f4e8;
  color: #1d6b39;
}

.kb-badge-warn {
  background: #fdf0d8;
  color: #8a5a00;
}

.kb-refs {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, monospace;
}

.kb-section-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin: 0.9rem 0 0.35rem;
}

.kb-resume {
  margin: 0;
  line-height: 1.5;
}

.kb-contenu {
  margin: 0;
  white-space: pre-wrap;
  font-family: inherit;
  line-height: 1.5;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}

.kb-qr {
  margin: 0;
}

.kb-qr dt {
  font-weight: 600;
  margin-top: 0.5rem;
}

.kb-qr dd {
  margin: 0.15rem 0 0;
  color: #33415c;
  line-height: 1.45;
}

.kb-page main {
  overflow-y: auto;
}

/* --- Bloc d'accueil + questions suggérées --- */
.welcome {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0;
}

.welcome-intro {
  color: var(--muted);
  margin: 0 0 1.1rem;
}

.suggest-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  text-align: left;
  background: #fff;
  border: 1px solid #d6e0f7;
  color: #24324d;
  border-radius: 10px;
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.35;
}

.chip:hover {
  background: #eef2fb;
  border-color: var(--accent);
}

/* --- Page logs Q/R (#19) --- */
.logs-main {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.25rem;
  overflow-y: auto;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.logs-table th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}

.logs-dt-col {
  width: 11.5rem;
}

.logs-dt {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.logs-total-col {
  width: 7.5rem;
  text-align: right;
}

.logs-row {
  cursor: pointer;
}

.logs-row:hover {
  background: #eef2fb;
}

.logs-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.logs-row td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: top;
}

.logs-q,
.logs-r {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logs-total {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.logs-row-oos {
  background: #fff8ec;
}

.logs-row-oos:hover {
  background: #fdf0d8;
}

.logs-badge-oos {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.05rem 0.4rem;
  margin-right: 0.4rem;
  border-radius: 999px;
  background: #fdf0d8;
  color: #8a5a00;
  white-space: nowrap;
}

.logs-more {
  display: block;
  margin: 1rem auto 0;
  padding: 0.55rem 1.1rem;
  border: 1px solid #d6e0f7;
  border-radius: 8px;
  background: #eef2fb;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.logs-more:hover {
  background: #e2e9fa;
}

.logs-more:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- Drawer détail (panneau latéral droit, style Notion) --- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 48, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 50;
}

.drawer-overlay[hidden] {
  display: none;
}

.drawer {
  width: min(520px, 94vw);
  height: 100%;
  background: #fff;
  box-shadow: -8px 0 28px rgba(28, 35, 48, 0.18);
  display: flex;
  flex-direction: column;
  animation: drawer-in 0.16s ease-out;
}

@keyframes drawer-in {
  from {
    transform: translateX(24px);
    opacity: 0.4;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.drawer-topbar {
  position: sticky;
  top: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.drawer-nav {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.drawer-navbtn,
.drawer-close {
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}

.drawer-navbtn:hover,
.drawer-close:hover {
  background: #eef2fb;
}

.drawer-navbtn:disabled {
  opacity: 0.4;
  cursor: default;
}

.drawer-pos {
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-left: 0.3rem;
}

.drawer-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem 1.1rem 1.5rem;
}

.drawer-scope {
  margin-bottom: 0.8rem;
}

.logs-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
}

.logs-badge-in {
  background: #e3f4e8;
  color: #1d6b39;
}

.logs-badge.logs-badge-oos {
  background: #fdf0d8;
  color: #8a5a00;
}

.drawer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 0.4rem;
}

.drawer-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.drawer-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 600;
}

.drawer-value {
  font-size: 0.9rem;
  word-break: break-word;
}

.drawer-block {
  margin-top: 1rem;
}

.drawer-pre {
  margin: 0.3rem 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.5;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.85rem;
}

.drawer-pre-scroll {
  max-height: 42vh;
  overflow-y: auto;
}

.drawer-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.35rem;
}

.drawer-chip {
  font-family: ui-monospace, monospace;
  font-size: 0.76rem;
  color: var(--accent);
  background: #eef2fb;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  word-break: break-all;
}

/* --- Rendu markdown des réponses (partagé : bulles chat .msg.md + drawer /logs .drawer-pre.md) --- */
.md {
  white-space: normal;
}

.md > *:first-child {
  margin-top: 0;
}

.md > *:last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 0.6rem;
}

.md ul,
.md ol {
  margin: 0 0 0.6rem;
  padding-left: 1.3rem;
}

.md li {
  margin: 0.2rem 0;
}

.md h1,
.md h2,
.md h3 {
  font-size: 1rem;
  margin: 0.8rem 0 0.4rem;
}

.md blockquote {
  margin: 0 0 0.6rem;
  padding-left: 0.8rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.md code {
  background: #eef2fb;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.md pre {
  background: #f3f5f9;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  overflow-x: auto;
}

.md a {
  color: var(--accent);
}

.md table {
  border-collapse: collapse;
  margin: 0 0 0.6rem;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 0.3rem 0.5rem;
  text-align: left;
}

/* --- Page déclaration des activités (#45) --- */
.act-intro {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.act-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.act-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
}

.act-item:hover {
  border-color: var(--accent);
}

.act-label {
  font-size: 0.95rem;
}

.act-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.act-save {
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 0.55rem 1rem;
  cursor: pointer;
}

.act-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Modale « Mes activités » (#54) --- */
dialog#activites-modal {
  width: min(92vw, 520px);
  max-height: 85vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.5rem;
  background: #fff;
  color: var(--fg);
  box-shadow: 0 12px 40px rgba(20, 28, 45, 0.2);
}

dialog#activites-modal::backdrop {
  background: rgba(20, 28, 45, 0.45);
}

dialog#activites-modal h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

dialog#activites-modal #status {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1rem;
}

.act-close {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--fg);
  font-family: inherit;
  font-weight: 600;
  padding: 0.55rem 1rem;
  cursor: pointer;
}

.act-close:hover {
  background: var(--bg);
}
