:root {
  --brand: #b3121a;
  --brand-dark: #8c0e14;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #677086;
  --border: #e2e5ec;
  --user-bubble: #fdecec;
  --source-bg: #f8f9fb;
  --ok: #1f9d55;
  --err: #d64545;
  --radius: 12px;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --surface: #1b1f29;
    --text: #e7e9ee;
    --muted: #9aa3b5;
    --border: #2b3140;
    --user-bubble: #3a1f22;
    --source-bg: #222734;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }

.layout { display: grid; grid-template-columns: 320px 1fr; height: 100vh; height: 100dvh; }

/* Sidebar */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 20px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 700; letter-spacing: 1px;
}
.brand-title { font-weight: 700; font-size: 18px; }
.brand-sub { font-size: 13px; color: var(--muted); }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 8px; }
.badge { background: var(--brand); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 11px; margin-left: 4px; }
.suggestions, .doc-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.suggestions button {
  width: 100%; text-align: left; background: var(--source-bg); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.suggestions button:hover { border-color: var(--brand); }
.doc-list li { font-size: 13px; padding: 6px 8px; border-radius: 6px; background: var(--source-bg); word-break: break-word; }
.doc-list small { color: var(--muted); display: block; }
.upload { display: grid; gap: 8px; }
.upload input { font-size: 13px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.upload-status { font-size: 12px; min-height: 16px; }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); }

/* Chat */
.chat { display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 16px 24px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.chat-head h1 { font-size: 18px; }
.chat-head p { margin: 2px 0 0; font-size: 13px; }
.status-dot { margin-left: auto; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); flex: none; }
.status-dot.ok { background: var(--ok); }
.status-dot.err { background: var(--err); }
.menu-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.welcome { max-width: 680px; margin: 40px auto; text-align: center; color: var(--muted); line-height: 1.6; }
.welcome h2 { color: var(--text); margin-bottom: 8px; }

.msg { max-width: 860px; width: 100%; margin: 0 auto; }
.msg-role { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.msg-body {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; line-height: 1.65; white-space: pre-wrap; word-wrap: break-word;
}
.msg.user .msg-body { background: var(--user-bubble); border-color: transparent; }
.msg.pending .msg-body::after { content: "..."; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.msg-sources { display: grid; gap: 6px; margin-top: 8px; }
.msg-sources details { background: var(--source-bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.msg-sources summary { cursor: pointer; }
.msg-sources p { margin: 6px 0 0; color: var(--muted); white-space: pre-wrap; }
.msg-foot { display: flex; gap: 8px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.msg-foot button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 6px; padding: 2px 10px; cursor: pointer; font-size: 12px;
}
.msg-foot button.active { border-color: var(--brand); color: var(--brand); }
.msg.error .msg-body { border-color: var(--err); }

.composer {
  display: flex; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 10px 12px; font: inherit; font-size: 15px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text);
}
.composer textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.btn-primary, .btn-secondary {
  border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: var(--source-bg); color: var(--text); border: 1px solid var(--border); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 25% 0 0; z-index: 10; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: block; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 10px; }
  .messages, .composer, .chat-head { padding-left: 16px; padding-right: 16px; }
}
