:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #5f5f5a;
  --border: #d9d9d3;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fff4d6;
  --error-bg: #fde7e5;
  --user-bg: #e6eefb;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151517;
    --surface: #1f1f23;
    --text: #ececea;
    --muted: #a3a39d;
    --border: #36363c;
    --accent: #6aa3ff;
    --accent-text: #0b1530;
    --danger: #ff8a80;
    --warn-bg: #3b3115;
    --error-bg: #3d1f1d;
    --user-bg: #22304a;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.9em; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { text-decoration: none; color: var(--muted); padding: 0.25rem 0; }
.topbar nav a[aria-current="page"] { color: var(--text); border-bottom: 2px solid var(--accent); }
.usermenu { display: flex; align-items: center; gap: 0.75rem; }

main { max-width: 52rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}
.narrow { max-width: 26rem; margin-left: auto; margin-right: auto; }

.stack { display: flex; flex-direction: column; gap: 0.9rem; }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; color: var(--muted); }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  width: 100%;
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: var(--accent-text);
  align-self: flex-start;
}
button:disabled { opacity: 0.6; cursor: progress; }
button.link { background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button.danger { background: var(--danger); color: var(--surface); }

.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.flash { padding: 0.6rem 0.8rem; border-radius: 6px; margin: 0.5rem 0; }
.flash.error { background: var(--error-bg); }
.flash.warn { background: var(--warn-bg); }
#flash:empty { display: none; }

/* Message and note text: keep the author's line breaks without ever building HTML. */
.body, .snippet { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0.25rem 0; }

.messages { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.msg { padding: 0.6rem 0.9rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); max-width: 90%; }
.msg-user { align-self: flex-end; background: var(--user-bg); }
.msg-agent { align-self: flex-start; }
.msg header { font-size: 0.8rem; color: var(--muted); }
.msg .who { font-weight: 600; color: var(--text); }

.chat-form { display: flex; gap: 0.75rem; align-items: flex-end; }
.chat-form textarea { flex: 1; resize: vertical; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: block; }
.pending { color: var(--muted); font-style: italic; }

.items { list-style: none; margin: 1rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; }
.item .title { font-weight: 600; }
.meta { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; font-size: 0.85rem; color: var(--muted); margin: 0.25rem 0; }
.badge { border: 1px solid var(--border); border-radius: 999px; padding: 0 0.55rem; }
.badge.origin-external { border-color: var(--danger); color: var(--danger); }

@media (max-width: 36rem) {
  .chat-form { flex-direction: column; align-items: stretch; }
  .msg { max-width: 100%; }
}

.fuse-banner { background: var(--danger); color: var(--accent-text); padding: 0.6rem 1rem; font-weight: 600; }
.topbar nav { flex-wrap: wrap; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { text-align: left; padding: 0.35rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
td.payload { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.8rem; overflow-wrap: anywhere; }
.filters { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1rem; }
.token-once { border: 2px solid var(--danger); padding: 0.75rem; margin-bottom: 1rem; }
.scopes { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
input[type="checkbox"] { width: auto; }
.scopes label { flex-direction: row; align-items: center; }
.scroll { overflow-x: auto; }
