: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;
  --estime: #7a3e9d;  /* a value the chat estimated from a web page, until the owner confirms it */
  --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%; }

/* History column */
.history { width: 280px; flex: none; display: flex; flex-direction: column; background: var(--surface); border-right: 1px solid var(--line); min-height: 0; }
.history-head { display: flex; gap: 8px; align-items: center; padding: 12px; }
.history .btn-ghost { color: var(--text); border-color: var(--line); }
.history-list { list-style: none; margin: 0; padding: 0 8px 12px; overflow-y: auto; flex: 1; }
.history-list .muted { padding: 10px 8px; font-size: 14px; }
.history-item { position: relative; border-radius: 8px; }
.history-item:hover { background: var(--bg); }
.history-item.active { background: var(--accent-soft); }
.history-item .history-open { display: grid; gap: 2px; width: 100%; text-align: left; font: inherit; background: none; border: none; color: var(--text); cursor: pointer; padding: 8px 32px 8px 8px; }
.history-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-snippet, .history-date { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.history-snippet { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.history-x { position: absolute; top: 6px; right: 4px; font: inherit; font-size: 13px; background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 6px; opacity: 0; }
.history-item:hover .history-x, .history-x:focus { opacity: 1; }
.history-x:hover { color: var(--bad); }
@media (hover: none) { .history-x { opacity: 1; } }
#toggle-history, #close-history { display: none; }

/* 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; }

/* Navigation (Common.renderNav) */
.topnav a { color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 8px; border: 1px solid transparent; }
.topnav a:hover { background: rgba(255, 255, 255, 0.1); }
.topnav a.active { border-color: rgba(255, 255, 255, 0.35); }
.topnav form button { font: inherit; background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.25); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.topnav form button:hover { background: rgba(255, 255, 255, 0.1); }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-light:disabled { opacity: 0.5; cursor: not-allowed; }

/* Worksheet */
.ws-page { min-height: 100vh; padding-bottom: 110px; }  /* room for the results bar */
.ws { max-width: 1480px; margin: 0 auto; padding: 16px 20px; }
.banner { background: #fbeaea; color: var(--bad); border-bottom: 1px solid #efc4bf; padding: 10px 20px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.note { background: #fdf4e3; border: 1px solid #f0d9a8; color: #7a5212; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.ws-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.currency { display: flex; gap: 6px; }
.currency input { width: 5.5em; flex: none; text-transform: uppercase; }
.ws-table .currency input.code { min-width: 0; }
.other-rates { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.other-rates h3 { margin: 0 0 8px; }
.other-rate { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.other-rate label { min-width: 200px; }
.ws-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.ws-table { font-size: 14px; }
.ws-table th { white-space: nowrap; font-size: 13px; }
.ws-table td { padding: 4px 6px; vertical-align: middle; }
.ws-table input, .ws-table select { padding: 5px 7px; font-size: 14px; }
.ws-table input.wide { min-width: 200px; }
.ws-table input.code { min-width: 100px; }
.ws-table td.check { text-align: center; }
.ws-table td.actions { white-space: nowrap; }
.ws-table td.actions .btn { margin-right: 4px; }
.ws-table td.amount { white-space: nowrap; }
.ws-table td.amount .badge { margin: 0 6px; }
.ws-table td.amount .btn { margin-top: 4px; }
input[type="checkbox"] { width: auto; }
input.num { text-align: right; min-width: 100px; font-variant-numeric: tabular-nums; }
.fig { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cat-rates { display: flex; gap: 4px; }
.cat-rate { gap: 2px; font-size: 11px; }
.cat-rate input.num { min-width: 0; width: 58px; }
input.invalid, select.invalid { border-color: var(--bad); background: #fdf0ee; }
.flagged { outline: 3px solid var(--warn) !important; outline-offset: 1px; }
.missing { border-color: #f0d9a8; background: #fffaf0; }
.q-list, .issue-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.question, .issue { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.question select, .question input { width: auto; min-width: 200px; }
.question .answer { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.q-text, .issue-go { font: inherit; background: none; border: none; padding: 0; text-align: left; cursor: pointer; color: var(--text); flex: 1 1 280px; text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.issue-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.issue.seen { opacity: 0.55; }
.suggest { margin-top: 12px; }
.sale-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.sale-line input { width: auto; }
.sale-line input.wide { min-width: 240px; }
.sale-line select { width: auto; }
.sale-name { min-width: 240px; font-weight: 600; }
.unit { color: var(--muted); }
.sale-note { color: var(--muted); font-size: 0.9em; }
.margin-figures { margin: 0 0 10px; color: var(--muted); }
.tax-figures { margin: 0 0 12px; padding: 6px 10px; border-left: 3px solid var(--line); }
.tax-figure { line-height: 1.6; }
.results-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 20px; padding: 10px 20px; flex-wrap: wrap; box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.15); }
.res { display: grid; line-height: 1.25; }
.res-label { font-size: 12px; color: rgba(255, 255, 255, 0.72); }
.res strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.res-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.results-bar .error { color: #ffb4a8; }
.save-status { font-size: 13px; color: rgba(255, 255, 255, 0.8); }
.compute-state { margin: 0; font-size: 13px; color: #ffd98a; }
.compute-state:empty { display: none; }
.results-bar.stale .res strong { opacity: 0.45; }
.card.stale { opacity: 0.6; }

@media (max-width: 720px) {
  #toggle-history, #close-history { display: inline-block; }
  .history { display: none; }
  .history.is-open { display: flex; position: fixed; inset: 0; width: auto; z-index: 5; border-right: none; background: var(--surface); }
  .history-x { opacity: 1; }
  .panel { position: fixed; inset: 0; width: auto; z-index: 5; }
  .msg-user .msg-body { max-width: 92%; }
  .topbar { padding: 8px 12px; }
}

.quick-rates { display: flex; gap: 4px; align-items: center; }
.quick-rates .quick-rate { padding: 2px 8px; white-space: nowrap; }

/* Cells the chat filled or changed, by origin: read from a document, inferred, asked for (until the owner edits them) */
.chat-lu { border-left: 3px solid var(--navy-2); background: color-mix(in srgb, var(--navy-2) 8%, var(--surface)); }
.chat-deduit { border-left: 3px solid var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--surface)); }
.chat-demande { border-left: 3px solid var(--accent); background: var(--accent-soft); }
/* A value the chat read on a web page (an estimate): its own colour, the page's site and « Confirmer », until the
   owner confirms or edits it */
.chat-estime { border-left: 3px dashed var(--estime); background: color-mix(in srgb, var(--estime) 9%, var(--surface)); }
.estimate-mark { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin-top: 3px; font-size: 12px; font-weight: 400; color: var(--estime); }
.estimate-mark .estimate-source { color: var(--estime); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.estimate-mark .estimate-confirm { padding: 0 8px; font-size: 12px; }
.hs-chips .hs-source { font-size: 11px; align-self: center; color: var(--muted); }
/* The chat's HS code guesses, under the line's HS code cell */
.hs-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.hs-chips .hs-chip { padding: 1px 8px; font-size: 12px; border-radius: 999px; white-space: nowrap; }

.ws-title-fields { display: grid; gap: 12px; }
.ws-title-fields input.ws-title { font-size: 20px; font-weight: 600; }
.ws-title-fields textarea { min-height: 64px; resize: vertical; font: inherit; }
.calc-description { font-size: 13px; font-weight: 400; margin-top: 2px; }

/* Quick estimate: the switches under the description, the order's cells they show, the badge in the results bar */
.estimate { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0; display: grid; gap: 8px; }
.estimate legend { font-weight: 600; padding: 0 4px; }
.estimate .switch { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.estimate-fields { display: flex; gap: 12px; flex-wrap: wrap; margin-left: 24px; }
.estimate-fields input.code { min-width: 120px; }
.res-estimate { background: var(--warn); color: #fff; font-size: 13px; padding: 3px 10px; font-weight: 600; }
.cost-note { margin-top: 2px; white-space: nowrap; }
/* A cost's value: the one cell its basis uses, with « % » after a percentage of the goods' value */
.cost-value { white-space: nowrap; }
.cost-value .unit { margin-left: 4px; }
