:root {
  --bg: #0b0d12;
  --surface: #141823;
  --surface-2: #1b2130;
  --border: #262d3d;
  --text: #e7eaf1;
  --muted: #8d95a9;
  --accent: #5b8def;
  --accent-ink: #0b0d12;
  --ok: #3ccf7a;
  --warn: #f2a93b;
  --danger: #ff5f5f;
  --radius: 12px;
  --nav-h: 58px;
  --top-h: 52px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---- shell ---- */
#top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  height: calc(var(--top-h) + var(--sat));
  padding: var(--sat) 14px 0;
  background: rgba(11, 13, 18, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
#top .brand { font-weight: 800; letter-spacing: 0.08em; font-size: 13px; color: var(--accent); }
#top .title { flex: 1; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#top .actions { display: flex; gap: 4px; }
button.icon {
  background: transparent; border: 0; color: var(--muted);
  width: 38px; height: 38px; border-radius: 10px; font-size: 20px; line-height: 1; cursor: pointer;
}
button.icon:active { background: var(--surface-2); color: var(--text); }
button.icon.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#view {
  padding: 14px 14px calc(var(--nav-h) + var(--sab) + 20px);
  max-width: 760px; margin: 0 auto;
}

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--nav-h) + var(--sab));
  padding-bottom: var(--sab);
  background: rgba(20, 24, 35, 0.96);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
#tabs a {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 10.5px; font-weight: 600; min-width: 0; padding: 0 2px; white-space: nowrap; overflow: hidden;
}
#tabs a .ico { font-size: 20px; line-height: 1; }
#tabs a.active { color: var(--accent); }
#tabs .badge {
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}

/* ---- composants ---- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
}
.card h3 { margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 11px 16px; font-weight: 600; cursor: pointer; min-height: 44px;
}
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }

input[type="text"], input[type="password"], textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px;
  outline: none; -webkit-appearance: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); color: var(--muted); }
.pill.new { background: var(--danger); border-color: var(--danger); color: #fff; }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.danger { color: var(--danger); border-color: var(--danger); }

.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; border: 1px solid; font-weight: 500; }
.banner.ok { border-color: var(--ok); background: rgba(60, 207, 122, 0.1); }
.banner.warn { border-color: var(--warn); background: rgba(242, 169, 59, 0.12); }
.banner.danger { border-color: var(--danger); background: rgba(255, 95, 95, 0.1); }
.banner.info { border-color: var(--accent); background: rgba(91, 141, 239, 0.1); }

.error { border: 1px solid var(--danger); background: rgba(255, 95, 95, 0.08); border-radius: var(--radius); padding: 14px; }
.error p { margin: 0 0 10px; }

.loading { color: var(--muted); padding: 24px 0; text-align: center; }
.loading::before { content: ""; display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -4px; margin-right: 8px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; position: relative;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .dot { position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bg); }

.subtabs { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.subtabs button { flex: 1; background: transparent; border: 0; border-radius: 8px; padding: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.subtabs button.active { background: var(--surface-2); color: var(--text); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; padding-top: 0; }
.commit .msg { font-weight: 500; }
.commit .meta { font-size: 12px; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + var(--sab) + 14px); z-index: 50; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 10px; padding: 11px 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); animation: pop 0.2s ease-out; }
.toast.ok { border-left-color: var(--ok); }
.toast.danger { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---- markdown ---- */
.md { line-height: 1.55; overflow-wrap: anywhere; }
.md h1 { font-size: 20px; margin: 0 0 12px; }
.md h2 { font-size: 17px; margin: 22px 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border); color: var(--accent); }
.md h3 { font-size: 15px; margin: 16px 0 6px; }
.md p { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 10px; }
.md li { margin: 4px 0; }
.md li.todo::marker { content: "☐  "; }
.md li.done::marker { content: "☑  "; }
.md li.done { color: var(--muted); }
.md code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 0.88em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; border: 0; padding: 0; }
.md blockquote { margin: 0 0 10px; padding: 4px 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.md .tbl { overflow-x: auto; margin: 0 0 12px; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); }
.md .lnk { text-decoration: underline dotted; }
.md strong { color: #fff; }

.arb .q { font-size: 14px; }
.arb .num { display: inline-block; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; text-align: center; line-height: 26px; font-weight: 700; margin-right: 8px; }
.arb .answer { border-left: 3px solid var(--ok); padding: 6px 10px; background: rgba(60, 207, 122, 0.06); border-radius: 6px; white-space: pre-wrap; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.token-screen { max-width: 480px; margin: 20px auto; }
.token-screen ol { padding-left: 20px; color: var(--muted); font-size: 13.5px; }
.token-screen li { margin: 4px 0; }

/* ---- v2 : dialogues, notifications, menu, visionneuse ---- */
.chip .dot.wait { background: var(--warn); }
.fil { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.bulle { max-width: 92%; border-radius: 14px; padding: 10px 12px; border: 1px solid var(--border); background: var(--surface); }
.bulle.moi { align-self: flex-end; background: rgba(91, 141, 239, 0.16); border-color: rgba(91, 141, 239, 0.5); border-bottom-right-radius: 4px; }
.bulle.agent { align-self: flex-start; border-bottom-left-radius: 4px; }
.bulle .who { font-size: 11px; font-weight: 700; letter-spacing: 0.03em; color: var(--muted); margin-bottom: 4px; }
.bulle.moi .who { color: var(--accent); }
.bulle .when { font-size: 11px; color: var(--muted); margin-top: 4px; text-align: right; }
.bulle .md p:last-child, .bulle .md ul:last-child, .bulle .md ol:last-child { margin-bottom: 0; }
.bulle .md h2, .bulle .md h3 { margin-top: 10px; }
.composer textarea { min-height: 72px; }
.banner.small { font-size: 13px; padding: 9px 12px; }
details.card > summary { cursor: pointer; font-weight: 600; }
.notif .md p { margin: 0; }
.menu li { padding: 0; }
.menu a { display: flex; text-decoration: none; color: var(--text); padding: 14px 4px; gap: 12px; }
.menu .ico { font-size: 22px; width: 32px; text-align: center; color: var(--accent); }
a.btn { text-decoration: none; }

body.viewer { display: flex; flex-direction: column; height: 100dvh; }
body.viewer #top { padding-left: 6px; }
body.viewer #frame { flex: 1; width: 100%; border: 0; background: #fff; }
body.viewer #status { padding: 24px 14px; }
body.viewer #status:empty { display: none; }
