:root {
  --bg: #ffffff;
  --surface: #f6f7f8;
  --border: #e5e7eb;
  --text: #1a1a1a;
  --muted: #6b7280;
  --accent: #ff6b35;
  --accent-strong: #e85a24;
  --user-bubble: #eef2ff;
  --assistant-bubble: #ffffff;
  --tool-chip: #eef2ff;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.hide { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#sidebar header { padding: 16px; border-bottom: 1px solid var(--border); }
.brand-mark {
  font-weight: 800; letter-spacing: 0.06em;
  font-size: 13px; color: var(--muted);
}
.brand-sub { font-size: 18px; font-weight: 700; margin-top: 2px; }
button.primary {
  background: var(--text); color: white; border: 0; border-radius: 8px;
  padding: 10px 14px; font-weight: 600; cursor: pointer; width: 100%;
  margin-top: 12px; font-size: 13px; letter-spacing: 0.04em;
}
button.primary:hover { background: #000; }
button.link {
  background: transparent; border: 0; color: var(--accent);
  cursor: pointer; font-size: 13px; padding: 0; font-weight: 600;
}
#user-strip {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.who { font-size: 13px; font-weight: 600; }
#filter-row {
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: #fffbf7;
}
.check { font-size: 12px; display: flex; align-items: center; gap: 6px; cursor: pointer; }
#history {
  flex: 1; overflow-y: auto; padding: 8px;
}
.history-group { margin-bottom: 12px; }
.history-group h4 {
  font-size: 11px; text-transform: uppercase; color: var(--muted);
  letter-spacing: 0.06em; margin: 8px 8px 4px; font-weight: 700;
}
.conv-item {
  padding: 10px 12px; border-radius: 6px; cursor: pointer;
  font-size: 13px; line-height: 1.3; margin-bottom: 2px;
}
.conv-item:hover { background: #eaecef; }
.conv-item.active { background: #e5e7eb; font-weight: 600; }
.conv-meta { color: var(--muted); font-size: 11px; margin-top: 2px; }
#sidebar footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- Main / chat ---------- */
#chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--bg);
}
#chat > header {
  padding: 18px 28px; border-bottom: 1px solid var(--border);
}
#chat h1 { margin: 0; font-size: 18px; }
#chat header .muted { margin: 4px 0 0; font-size: 13px; }
#thread {
  flex: 1; overflow-y: auto; padding: 24px 28px;
  display: flex; flex-direction: column; gap: 16px;
  scroll-behavior: smooth;
}
#thread.empty { align-items: center; justify-content: center; padding: 24px; }
.welcome { max-width: 620px; width: 100%; text-align: center; }
.welcome h2 { font-weight: 700; margin: 0 0 8px; }
.example-grid { display: grid; gap: 8px; margin-top: 16px; }
.example {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  padding: 14px 16px; border-radius: 10px; cursor: pointer; font-size: 14px;
  color: var(--text);
}
.example:hover { border-color: var(--accent); }
.msg { max-width: 760px; width: 100%; line-height: 1.55; }
.msg.user {
  align-self: flex-end; background: var(--user-bubble);
  padding: 12px 14px; border-radius: 12px;
}
.msg.assistant {
  align-self: flex-start; background: var(--assistant-bubble);
  border: 1px solid var(--border); padding: 14px 16px; border-radius: 12px;
}
.msg.tool {
  align-self: flex-start; background: var(--tool-chip); color: var(--muted);
  padding: 4px 10px; border-radius: 99px; font-size: 12px;
}
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { margin: 12px 0 6px; }
.msg.assistant ul, .msg.assistant ol { margin: 6px 0 6px 20px; }
.msg.assistant code { background: #f3f4f6; padding: 1px 4px; border-radius: 3px; }
.msg.assistant pre {
  background: #f3f4f6; padding: 12px; border-radius: 6px; overflow-x: auto;
  font-size: 12px; line-height: 1.45;
}
.user-tag {
  font-weight: 700; font-size: 11px; color: var(--accent);
  margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.04em;
}
#composer {
  border-top: 1px solid var(--border); padding: 14px 28px;
  display: flex; gap: 10px; align-items: flex-end;
}
#input {
  flex: 1; border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; font-family: var(--font); font-size: 15px;
  resize: none; max-height: 200px; min-height: 44px;
}
#input:focus { outline: none; border-color: var(--accent); }
#send {
  width: 44px; height: 44px; border-radius: 50%; font-size: 18px;
  padding: 0; background: var(--accent); cursor: pointer;
}
#send:disabled { background: #ccc; cursor: not-allowed; }
#send:hover:not(:disabled) { background: var(--accent-strong); }
.footer-note { padding: 6px 28px 12px; text-align: center; margin: 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-inner {
  background: #fff; border-radius: 14px; max-width: 980px; width: 92vw;
  max-height: 86vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-inner header {
  padding: 18px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-inner h2 { margin: 0; font-size: 18px; }
.close { background: transparent; border: 0; font-size: 26px; cursor: pointer; color: var(--muted); }
.modal-body { padding: 16px 24px; overflow-y: auto; }
#users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#users-table th, #users-table td {
  padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
#users-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; }
#users-table .person { display: flex; flex-direction: column; gap: 2px; }
#users-table .person .em { font-size: 11px; color: var(--muted); }
#users-table .name-input {
  border: 1px solid transparent; background: transparent; padding: 2px 4px;
  font: 600 13px var(--font); border-radius: 4px; color: var(--text);
  width: 200px; max-width: 100%;
}
#users-table .name-input:hover { border-color: var(--border); background: #fff; }
#users-table .name-input:focus { outline: none; border-color: var(--accent); background: #fff; }
#users-table input[type=checkbox] { transform: scale(1.2); cursor: pointer; }
#users-table tr.you { background: #fffbf7; }
