:root {
  --bg: #f7f7f5; --panel: #ffffff; --text: #1d1d1b; --muted: #6b6b66; --line: #e3e3de;
  --accent: #1f5f8b; --user: #eef4f8; --warn: #8a4b00;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161615; --panel: #1f1f1d; --text: #ececea; --muted: #a3a39d; --line: #33332f;
          --accent: #7fb6dc; --user: #22303a; --warn: #f0b060; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; overflow-x: hidden; }
.app, .denied-msg { display: none; }
body.ready .app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }
body.denied .denied-msg { display: block; margin: 20vh auto; text-align: center; color: var(--muted); padding: 0 16px; }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; }
.sidebar h1 { font-size: 17px; margin: 0 0 12px; }
.sidebar h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar button { all: unset; display: block; width: 100%; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.sidebar button:hover, .sidebar button:focus-visible { background: var(--user); }
.sidebar .date { display: block; font-size: 12px; color: var(--muted); }
.chat { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.chat-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; padding: 10px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg h3 { font-size: 17px; margin: 14px 0 6px; } .msg h4 { font-size: 15px; margin: 12px 0 4px; }
.msg > :first-child { margin-top: 0; }
.msg ul, .msg ol { margin: 0 0 8px; padding-left: 22px; } .msg li { margin: 2px 0; }
.msg li > ul, .msg li > ol { margin: 2px 0 0; }
.msg hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.msg code { font: 13px ui-monospace, Consolas, monospace; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.table-wrap { overflow-x: auto; margin: 4px 0 10px; border: 1px solid var(--line); border-radius: 8px; }
.msg table { border-collapse: collapse; width: 100%; font-size: 14px; overflow-wrap: normal; }
.msg th, .msg td { text-align: left; vertical-align: top; padding: 7px 10px; border-bottom: 1px solid var(--line); min-width: 90px; }
.msg th { background: var(--bg); font-weight: 600; }
.msg blockquote { margin: 4px 0 10px; padding: 6px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 6px 6px 0; }
.msg tbody tr:last-child td { border-bottom: 0; }
.msg tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 50%, transparent); }
.msg td:first-child { font-weight: 600; min-width: 0; }
.msg.error { color: var(--warn); }
.cite { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
.cite:hover { text-decoration: underline; }
.ask { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.ask textarea { flex: 1; min-width: 0; resize: vertical; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); }
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer; }
#send { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
@media (max-width: 760px) {
  body.ready .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; padding: 16px; }
  .chat { height: 70vh; }
  .chat-head, .messages, .ask { padding-left: 16px; padding-right: 16px; }
  .chat-head { flex-wrap: wrap; }
}
