:root {
  --fg: #1a1a1a;
  --muted: #6b7280;
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #e5e7eb;
  --accent: #2563eb;
  --ok: #16a34a;
  --bad: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar { flex-shrink: 0; }
main { flex: 1 1 auto; min-height: 0; max-width: 960px; width: 100%; margin: 0 auto; padding: 1.5rem; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1.5rem; background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar .brand { font-weight: 600; text-decoration: none; color: var(--fg); }
.topbar nav { display: flex; gap: 0.75rem; align-items: center; }
.topbar nav a { color: var(--muted); text-decoration: none; }
h1 { margin: 0 0 0.5rem; }
h2 { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
section { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; }
.centered { max-width: 360px; margin: 3rem auto; }
form.stack { display: flex; flex-direction: column; gap: 0.5rem; }
form .row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--muted); }
input, textarea, button {
  font: inherit; padding: 0.4rem 0.6rem; border: 1px solid var(--border);
  border-radius: 6px; background: white; color: var(--fg);
}
textarea { resize: vertical; font-family: ui-monospace, "SF Mono", Menlo, monospace; }
button { cursor: pointer; background: var(--accent); color: white; border-color: var(--accent); }
button:hover { filter: brightness(0.95); }
button.link { background: none; color: var(--muted); border: none; padding: 0.2rem 0.4rem; }
button.danger { background: var(--bad); border-color: var(--bad); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.muted { color: var(--muted); }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
details { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem; margin-top: 0.75rem; }
details > summary { cursor: pointer; }
details[open] > summary { margin-bottom: 0.5rem; }
ul.threads { list-style: none; padding: 0; }
ul.threads li { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.chat { display: flex; flex-direction: column; height: 100%; padding: 0; overflow: hidden; }
.chat .chat-header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat .chat-header h1 { margin: 0; font-size: 1.1rem; }
.chat #messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.chat .chat-bottom { flex-shrink: 0; border-top: 1px solid var(--border); padding: 0.6rem 1.25rem 0.9rem; background: var(--panel); }
.chat .composer { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.chat .composer textarea { flex: 1; }
.chat .uploads-panel { margin-top: 0; }
.msg { padding: 0.6rem 0.8rem; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.msg header { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.msg-user { background: #eff6ff; border-color: #bfdbfe; }
.msg-system { background: #fef2f2; border-color: #fecaca; }
.msg pre { margin: 0; white-space: pre-wrap; word-wrap: break-word; font-family: ui-monospace, Menlo, monospace; }
.msg .msg-md { font-family: inherit; }
.msg .msg-md p { margin: 0.4rem 0; }
.msg .msg-md p:first-child { margin-top: 0; }
.msg .msg-md p:last-child { margin-bottom: 0; }
.msg .msg-md ul, .msg .msg-md ol { margin: 0.4rem 0; padding-left: 1.25rem; }
.msg .msg-md code { font-size: 0.92em; }
.msg .msg-md pre { background: #f3f4f6; padding: 0.5rem 0.7rem; border-radius: 6px; overflow-x: auto; }
.msg .msg-md pre code { background: transparent; padding: 0; }
.msg .msg-md table { border-collapse: collapse; margin: 0.4rem 0; }
.msg .msg-md th, .msg .msg-md td { border: 1px solid var(--border); padding: 0.3rem 0.6rem; text-align: left; }
.msg .msg-md th { background: var(--bg); }
.msg .msg-md a { color: var(--accent); }
.msg .msg-md blockquote { border-left: 3px solid var(--border); margin: 0.4rem 0; padding: 0.2rem 0.8rem; color: var(--muted); }
code { font-family: ui-monospace, Menlo, monospace; background: var(--bg); padding: 0.05rem 0.3rem; border-radius: 4px; }
.push-status { font-size: 0.85rem; }
.uploads-panel { margin-top: 1rem; }
ul.uploads { list-style: none; padding: 0; margin: 0.5rem 0; }
ul.uploads li { display: flex; align-items: center; gap: 0.6rem; padding: 0.2rem 0; border-bottom: 1px solid var(--border); }
ul.uploads li a { font-family: ui-monospace, Menlo, monospace; }
ul.browse { list-style: none; padding: 0; margin: 0.5rem 0; max-height: 360px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; }
ul.browse li { padding: 0.25rem 0.6rem; border-bottom: 1px solid var(--border); }
ul.browse li:last-child { border-bottom: none; }
ul.browse li label.row-inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.managed-scope { margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px dashed var(--border); }
.msg-pending { background: #fffbeb; border-color: #fde68a; opacity: 1; }
.msg .activity { list-style: none; padding: 0; margin: 0.3rem 0; font-size: 0.85rem; color: var(--muted); }
.msg .activity li { padding: 0.1rem 0; font-family: ui-monospace, Menlo, monospace; }
.msg .text:empty { display: none; }
.spinner { display: inline-block; animation: spin 1.6s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

#toasts {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 9999;
  display: flex; flex-direction: column; gap: 0.5rem;
  max-width: min(420px, calc(100vw - 2rem));
  pointer-events: none;
}
#toasts .toast {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 2rem 0.6rem 0.8rem;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
  position: relative;
  transform: translateX(20px);
  opacity: 0;
  transition: transform 200ms ease, opacity 200ms ease;
  font-size: 0.9rem;
}
#toasts .toast.toast-show { transform: translateX(0); opacity: 1; }
#toasts .toast.toast-hide { transform: translateX(20px); opacity: 0; }
#toasts .toast-ok  { border-left-color: var(--ok); }
#toasts .toast-bad { border-left-color: var(--bad); }
#toasts .toast-close {
  position: absolute; top: 0.2rem; right: 0.4rem;
  background: none; border: none; color: var(--muted);
  font-size: 1.1rem; line-height: 1; padding: 0.2rem 0.4rem; cursor: pointer;
}
#toasts .toast-close:hover { color: var(--fg); }
