:root {
  --bg: #f6f6f8;
  --panel: #ffffff;
  --ink: #1d1d22;
  --ink-2: #55555f;
  --muted: #8a8a96;
  --line: #e4e4ea;
  --line-2: #efeff3;
  --danger: #c0352b;
  --ok: #2e7d4f;
  --warn: #a8660a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .05), 0 4px 16px rgba(20, 20, 40, .05);
  /* accent set per event below */
  --accent: #4f86e8;
  --accent-ink: #ffffff;
  --accent-soft: #edf3fd;
  --accent-line: #c9daf8;
}
html[data-event="as"] {
  --accent: #4f86e8;
  --accent-strong: #2f63c4;
  --accent-soft: #eef3fd;
  --accent-line: #cddcf7;
}
html[data-event="cel"] {
  --accent: #a8127c;
  --accent-strong: #860d62;
  --accent-soft: #fbeef7;
  --accent-line: #efc6e2;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "DM Sans", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
code { font-size: .88em; background: var(--line-2); padding: 1px 5px; border-radius: 5px; }
a { color: var(--accent-strong); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
button, .ghost, .primary { cursor: pointer; }
.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 9px;
  padding: 8px 16px; font-weight: 600; transition: background .15s;
}
.primary:hover { background: var(--accent-strong); }
.primary:disabled { opacity: .5; cursor: default; }
.primary.wide { width: 100%; padding: 10px; }
.ghost {
  background: transparent; border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px;
  font-size: 14px; transition: border-color .15s, color .15s, background .15s;
}
.ghost:hover { border-color: var(--accent-line); color: var(--accent-strong); background: var(--accent-soft); }
.ghost.icon { padding: 6px 10px; }
.count {
  background: var(--accent-soft); color: var(--accent-strong); border-radius: 10px;
  padding: 0 7px; font-size: 12px; font-weight: 600;
}

/* ---------- top bar & event switch ---------- */
.topbar {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--accent); transition: border-color .25s;
}
.brand-mark { font-weight: 700; letter-spacing: .02em; color: var(--ink-2); }
.top-actions { display: flex; justify-content: flex-end; gap: 8px; }
.switch {
  display: grid; grid-template-columns: 1fr 1fr; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px;
}
.switch-side {
  border: 0; background: transparent; border-radius: 10px; padding: 6px 22px; height: 52px; width: 200px;
  display: flex; align-items: center; justify-content: center; opacity: .45; filter: grayscale(1);
  transition: opacity .2s, filter .2s, background .2s, box-shadow .2s;
}
.switch-side img { max-height: 40px; max-width: 150px; object-fit: contain; }
.switch-side[data-event="as"] img { mix-blend-mode: multiply; max-height: 48px; }
.switch-side:hover { opacity: .8; filter: none; }
.switch-side[aria-selected="true"] {
  opacity: 1; filter: none; background: var(--panel);
  box-shadow: 0 1px 3px rgba(0,0,0,.08), inset 0 -3px 0 var(--accent);
}

.banner {
  background: #fff6e5; border-bottom: 1px solid #f1dcae; color: #6b4a07;
  padding: 10px 20px; font-size: 14px;
}
.banner code { background: #fbe9c4; }
.demo-notice {
  background: var(--line-2); border-bottom: 1px solid var(--line); color: var(--ink-2);
  padding: 7px 20px; font-size: 13px; text-align: center;
}

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 260px 1fr auto; min-height: 0; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 12px; min-height: 0;
}
.side-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 6px 0; }
.threads { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.thread {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 6px;
  padding: 8px 10px; border-radius: 9px; cursor: pointer; color: var(--ink-2); border: 0;
  background: transparent; text-align: left; width: 100%;
}
.thread:hover { background: var(--bg); }
.thread.active { background: var(--accent-soft); color: var(--ink); }
.thread-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.thread-meta { font-size: 11.5px; color: var(--muted); grid-column: 1; }
.thread-del { grid-row: 1 / span 2; grid-column: 2; opacity: 0; border: 0; background: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.thread:hover .thread-del { opacity: 1; }
.thread-del:hover { color: var(--danger); background: #fdecea; }
.empty-side { color: var(--muted); font-size: 13px; padding: 6px; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.messages { flex: 1; overflow-y: auto; padding: 28px 24px 12px; scroll-behavior: smooth; }
.messages > * { max-width: 820px; margin-left: auto; margin-right: auto; }

/* ---------- empty state ---------- */
.welcome { padding-top: 6vh; text-align: center; }
.welcome img { max-height: 92px; max-width: 280px; mix-blend-mode: multiply; }
.welcome h1 { font-size: 22px; margin: 18px 0 4px; font-weight: 600; }
.welcome p { color: var(--ink-2); margin: 0 auto 26px; max-width: 540px; }
.starters { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; text-align: left; }
.starter {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; transition: border-color .15s, transform .15s; font-size: 14px; color: var(--ink);
}
.starter:hover { border-color: var(--accent); transform: translateY(-1px); }
.starter small { display: block; color: var(--accent-strong); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }

/* ---------- messages ---------- */
.msg { margin-bottom: 22px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble-user {
  background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 14px 14px 4px 14px;
  padding: 10px 14px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word;
}
.tag { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.tag b { color: var(--accent-strong); font-weight: 600; }
.att-list { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; margin-top: 6px; }
.chip { font-size: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; padding: 0; color: var(--muted); }
.chip.warn { border-color: #f1dcae; color: var(--warn); }

.bubble-ai {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 20px; box-shadow: var(--shadow);
}
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { line-height: 1.3; margin: 1.2em 0 .5em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.05em; }
.md p, .md ul, .md ol { margin: 0 0 .8em; }
.md li { margin: .2em 0; }
.md blockquote { margin: 0 0 .8em; padding: 2px 14px; border-left: 3px solid var(--accent-line); color: var(--ink-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 0 0 1em; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--bg); font-weight: 600; }
.md pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }

.activity { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.activity summary { cursor: pointer; list-style: none; display: inline-flex; gap: 6px; align-items: center; }
.activity summary::-webkit-details-marker { display: none; }
.activity summary::before { content: "▸"; transition: transform .15s; }
.activity[open] summary::before { transform: rotate(90deg); }
.activity ul { margin: 6px 0 0; padding-left: 18px; }
.activity li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.status:empty { display: none; }
.dots::after { content: ""; display: inline-block; width: 14px; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.sources { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line); font-size: 12.5px; }
.sources summary { cursor: pointer; color: var(--muted); }
.sources ol { margin: 6px 0 0; padding-left: 20px; }
.sources a { color: var(--ink-2); }

.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.actions .ghost { font-size: 12.5px; padding: 4px 10px; }
.error-box {
  background: #fdecea; border: 1px solid #f5c6c1; color: #7d241d; border-radius: var(--radius);
  padding: 12px 16px; font-size: 14px;
}

/* ---------- composer ---------- */
.composer-wrap { padding: 8px 24px 18px; }
.composer-wrap > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.tasks { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.task {
  border: 1px solid var(--line); background: var(--panel); border-radius: 20px; padding: 4px 13px;
  font-size: 13px; color: var(--ink-2); transition: all .15s;
}
.task:hover { border-color: var(--accent-line); }
.task[aria-checked="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.task .star { color: inherit; opacity: .7; margin-left: 2px; }
.note { font-size: 13px; color: var(--warn); margin-bottom: 8px; }
.composer {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 12px 8px; transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer.dragging { border-color: var(--accent); background: var(--accent-soft); }
.composer textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; max-height: 40vh; min-height: 26px;
  padding: 4px 2px;
}
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments:not(:empty) { margin-bottom: 8px; }
.composer-bar { display: flex; align-items: center; gap: 10px; }
.composer-bar .hint { flex: 1; font-size: 12px; color: var(--muted); }

/* ---------- documents drawer ---------- */
.drawer {
  width: 360px; background: var(--panel); border-left: 1px solid var(--line); padding: 16px 18px;
  overflow-y: auto; min-height: 0;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer h2 { font-size: 16px; margin: 0; }
.upload { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 18px; }
.upload select { width: 100%; margin-top: 4px; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.dropzone {
  border: 1.5px dashed var(--accent-line); border-radius: var(--radius); padding: 18px; text-align: center;
  display: flex; flex-direction: column; gap: 2px; cursor: pointer; background: var(--accent-soft); color: var(--accent-strong);
}
.dropzone.dragging { border-color: var(--accent); }
.upload-log { font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.upload-log .ok { color: var(--ok); } .upload-log .bad { color: var(--danger); } .upload-log .warn { color: var(--warn); }
.kgroup { margin-bottom: 14px; }
.kgroup h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 6px; font-weight: 600; }
.kfile {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 7px 9px; border: 1px solid var(--line-2);
  border-radius: 9px; margin-bottom: 4px; font-size: 13px;
}
.kfile .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kfile .meta { grid-column: 1; font-size: 11.5px; color: var(--muted); }
.kfile .meta .warn { color: var(--warn); }
.kfile button { grid-row: 1 / span 2; grid-column: 2; border: 0; background: none; color: var(--muted); border-radius: 6px; padding: 2px 6px; }
.kfile button:hover { color: var(--danger); background: #fdecea; }
.kempty { font-size: 12.5px; color: var(--muted); padding: 2px 0 4px; }

/* ---------- dialog & toast ---------- */
.dialog { border: 0; border-radius: 16px; padding: 0; width: min(820px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.dialog::backdrop { background: rgba(20, 20, 30, .35); }
.dialog-inner { padding: 22px; display: flex; flex-direction: column; gap: 10px; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog p { margin: 0; }
.dialog textarea { width: 100%; height: 52vh; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 14px; resize: vertical; }
.dialog-bar { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 10; max-width: 90vw;
}
.toast a { color: #fff; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 220px 1fr; }
  .drawer { position: fixed; right: 0; top: 0; bottom: 0; z-index: 5; box-shadow: -10px 0 30px rgba(0,0,0,.12); }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { grid-template-columns: 1fr; justify-items: center; }
  .brand-mark { display: none; }
  .switch-side { width: 44vw; }
  .messages, .composer-wrap { padding-left: 16px; padding-right: 16px; }
  .drawer { width: 100%; }
}

/* ---------- drawer tabs, facts, builder ---------- */
.drawer-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 10px; padding: 3px; }
.dtab { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13.5px; color: var(--ink-2); }
.dtab[aria-selected="true"] { background: var(--panel); color: var(--accent-strong); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.drawer-title { font-size: 15px; margin: 14px 0 4px; color: var(--ink); }
.facts-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.fact { border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: grid; grid-template-columns: 1fr auto; gap: 5px; }
.fact input { border: 1px solid var(--line-2); border-radius: 7px; padding: 5px 8px; font-size: 13.5px; width: 100%; background: var(--panel); }
.fact input:focus { outline: none; border-color: var(--accent); }
.fact .f-label { font-weight: 600; }
.fact .f-source { font-size: 12.5px; color: var(--ink-2); }
.fact .f-wide { grid-column: 1; }
.fact .f-del { grid-column: 2; grid-row: 1 / span 3; align-self: start; border: 0; background: none; color: var(--muted); border-radius: 6px; padding: 2px 6px; }
.fact .f-del:hover { color: var(--danger); background: #fdecea; }
.fact.empty { border-style: dashed; }
.facts-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; position: sticky; bottom: -16px; background: var(--panel); padding: 10px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.form-grid .span2 { grid-column: 1 / -1; }
.form-grid input, .form-grid select, .form-grid textarea {
  font-weight: 400; font-size: 14.5px; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: var(--panel);
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: none; border-color: var(--accent); }
.form-grid textarea { resize: vertical; height: auto; }
#builderBtn { color: var(--accent-strong); border-color: var(--accent-line); background: var(--accent-soft); }
@media (max-width: 760px) { .form-grid { grid-template-columns: 1fr; } .composer-bar .hint { display: none; } }
