:root {
  --navy: #0f2a44;
  --navy-2: #1d3f63;
  --accent: #2e733a;
  --accent-hover: #245c2e;
  --accent-soft: #eaf4ec;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --line: #e2e6eb;
  --text: #1b2430;
  --muted: #647183;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --bad: #c0392b;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.55; }
h1, h2, h3, h4, h5 { line-height: 1.25; margin: 0.9em 0 0.4em; }
a { color: var(--navy-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.fine { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.center { text-align: center; }
.error { color: var(--bad); margin: 0; }
[hidden] { display: none !important; }

/* Buttons */
.btn { font: inherit; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-light:hover { border-color: var(--navy-2); }
.btn-danger { background: var(--surface); color: var(--bad); border-color: #efc4bf; }
.btn-danger:hover { background: #fdf0ee; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; letter-spacing: 0.2px; }
.brand-tile { display: flex; align-items: center; flex: none; }
.brand-tile img { height: 1.6em; width: auto; display: block; }  /* slightly taller than the text */
.brand-lg { font-size: 22px; color: var(--navy); }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%); padding: 16px; }
.login-card { background: var(--surface); border-radius: 16px; padding: 32px; width: min(400px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25); }
.login-form { display: grid; gap: 14px; margin-top: 20px; }
.setup-title { font-size: 18px; margin: 16px 0 8px; color: var(--navy); }
.setup-steps { padding-left: 20px; margin: 0; font-size: 14px; }
.setup-steps li { margin: 6px 0; }
.qr { display: block; width: 200px; height: 200px; margin: 12px auto; background: #fff; image-rendering: pixelated; }
.secret { word-break: break-all; }
.backup-codes { list-style: none; padding: 0; margin: 12px 0 20px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: ui-monospace, monospace; font-size: 15px; }
.backup-codes li { background: var(--accent-soft); border-radius: 6px; padding: 6px 10px; text-align: center; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, textarea, select { font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--surface); width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(46, 115, 58, 0.35); border-color: var(--accent); }

/* App shell */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 20px; gap: 12px; flex-wrap: wrap; }
.topnav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topnav form { margin: 0; }
.layout { flex: 1; display: flex; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; padding: 0 16px 12px; }
.messages { flex: 1; overflow-y: auto; padding: 24px 0; width: 100%; max-width: 860px; margin: 0 auto; }

.welcome { text-align: center; padding-top: 6vh; }
.welcome h1 { color: var(--navy); font-size: 26px; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 24px; text-align: left; }
.suggestion { font: inherit; font-size: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; color: var(--text); }
.suggestion:hover { border-color: var(--accent); background: var(--accent-soft); }

.msg { display: flex; flex-direction: column; margin: 14px 0; }
.msg-user { align-items: flex-end; }
.msg-body { max-width: 100%; overflow-wrap: anywhere; }
.msg-user .msg-body { background: var(--navy); color: #fff; padding: 10px 14px; border-radius: 14px 14px 4px 14px; max-width: 80%; white-space: pre-wrap; }
.msg-assistant .msg-body { background: var(--surface); border: 1px solid var(--line); padding: 4px 18px; border-radius: 14px 14px 14px 4px; }
.msg-body p { margin: 0.6em 0; }
.msg-body pre { background: #0f1b2a; color: #e6edf3; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg-body code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg-body pre code { background: none; padding: 0; }
.msg-body blockquote { border-left: 3px solid var(--accent); margin: 0.6em 0; padding: 2px 12px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.msg-body table, .data-table { border-collapse: collapse; margin: 0.6em 0; font-size: 14px; }
.msg-body th, .msg-body td, .data-table th, .data-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.msg-body th, .data-table th { background: #f0f3f6; }
.typing::after { content: "L'assistant réfléchit…"; display: block; padding: 10px 0; color: var(--muted); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }
.copy { align-self: flex-start; margin-top: 4px; font: inherit; font-size: 12px; background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.copy:hover { color: var(--navy); }

.composer { display: flex; gap: 10px; align-items: flex-end; width: 100%; max-width: 860px; margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px; box-shadow: 0 4px 14px rgba(15, 42, 68, 0.06); }
.composer textarea { border: none; resize: none; padding: 8px; max-height: 220px; }
.composer textarea:focus { outline: none; }
.attach { font-size: 18px; padding: 6px 10px; color: var(--muted); }
.attach:hover { color: var(--accent); }
.chat.drop-active .composer { border-color: var(--accent); background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; max-width: 860px; margin: 0 auto 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 10px; max-width: 100%; }
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.chip-state { color: var(--muted); font-size: 12px; }
.chip-busy .chip-state { animation: pulse 1.2s infinite; }
.chip-ready { border-color: var(--accent); }
.chip-ready .chip-state { color: var(--accent); }
.chip-error { border-color: #efc4bf; }
.chip-error .chip-state { color: var(--bad); white-space: normal; }
.chip-x { font: inherit; background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 4px; font-size: 12px; color: var(--muted); max-width: 80%; }

/* Side panel */
.panel { width: 340px; max-width: 100%; background: var(--surface); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; }
.panel-head h2 { margin: 0; font-size: 18px; }
.panel .btn-ghost { color: var(--text); border-color: var(--line); }
.requests { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 10px; }
.req { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.req-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.req-answer { margin-top: 6px; background: var(--bg); border-radius: 8px; padding: 2px 10px; font-size: 14px; }
.status { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.status-pending { background: #fdf4e3; color: var(--warn); }
.status-answered, .status-approved, .status-ok { background: #e6f5ec; color: var(--ok); }
.status-refused, .status-bad { background: #fbeaea; color: var(--bad); }

/* Admin */
.admin-main { flex: 1; overflow-y: auto; padding: 20px; }
.admin-wrap { max-width: 1100px; margin: 0 auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab { font: inherit; background: none; border: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--navy); border-bottom-color: var(--accent); font-weight: 600; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card h2 { margin-top: 0; font-size: 18px; color: var(--navy); }
.card h3 { font-size: 15px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > label { flex: 1; min-width: 160px; }
.stack { display: grid; gap: 12px; }
.data-table { width: 100%; }
.data-table td .btn { padding: 4px 10px; font-size: 13px; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.checks label { display: flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--text); }
.checks input { width: auto; }
.prompt-editor { min-height: 360px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); z-index: 10; }
.log-msg { border-top: 1px solid var(--line); padding: 8px 0; white-space: pre-wrap; font-size: 14px; }
.log-role { font-weight: 700; font-size: 12px; text-transform: uppercase; color: var(--muted); }
.log-tool { color: var(--muted); font-size: 13px; }
.conn-state { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }

@media (max-width: 720px) {
  .panel { position: fixed; inset: 0; width: auto; z-index: 5; }
  .msg-user .msg-body { max-width: 92%; }
  .topbar { padding: 8px 12px; }
}
