:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #65748b;
  --paper: #ffffff;
  --wash: #f3f7fc;
  --line: #d7e3f4;
  --blue: #1f5fbf;
  --blue-dark: #143f7d;
  --blue-soft: #e9f2ff;
  --chat-dark: #18263b;
  --warn: #ad3d2c;
  --shadow: 0 12px 34px rgba(29, 62, 108, 0.12);
  --chat-width: clamp(320px, 25vw, 470px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: "Avenir Next", "Helvetica Neue", "PingFang SC", sans-serif;
  background:
    linear-gradient(180deg, rgba(232, 242, 255, 0.8), rgba(246, 249, 253, 0) 260px),
    var(--wash);
}

button,
textarea,
a {
  font: inherit;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1fr) 10px minmax(300px, var(--chat-width));
  gap: 0;
  width: 100vw;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
}

.docs-panel,
.chat-panel {
  min-width: 0;
  min-height: 0;
}

.docs-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.docs-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.docs-header {
  min-height: 88px;
  padding: 16px 24px;
}

.chat-header {
  min-height: 76px;
  padding: 16px 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--blue-dark);
  font-family: Georgia, "Times New Roman", "Songti SC", serif;
  font-weight: 600;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 22px;
}

.docs-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.docs-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  background: var(--blue-soft);
}

.docs-actions a:hover {
  border-color: #a9c3ec;
  background: #f5f9ff;
}

.docs-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--wash);
}

.split-handle {
  position: relative;
  width: 10px;
  min-width: 10px;
  border: 0;
  border-inline: 1px solid var(--line);
  cursor: col-resize;
  background: #edf4fd;
}

.split-handle::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 52px;
  border-radius: 999px;
  background: #9eb8dc;
  transform: translate(-50%, -50%);
}

.split-handle:hover,
.split-handle.is-dragging {
  background: #dbeaff;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  overflow: hidden;
  background: #fbfdff;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  background: var(--paper);
}

.status-pill.busy {
  color: var(--blue-dark);
  border-color: #9dbbea;
  background: var(--blue-soft);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 18px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.message.user {
  flex-direction: row-reverse;
}

.avatar {
  display: grid;
  flex: 0 0 30px;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  background: var(--blue);
}

.message.user .avatar {
  background: var(--chat-dark);
}

.bubble {
  max-width: calc(100% - 40px);
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.68;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--paper);
  box-shadow: 0 8px 20px rgba(23, 32, 51, 0.05);
}

.message.user .bubble {
  color: #ffffff;
  border-color: var(--chat-dark);
  background: var(--chat-dark);
  box-shadow: none;
}

.bubble.markdown-body {
  white-space: normal;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 8px 0 10px;
  padding-left: 20px;
}

.markdown-body li + li {
  margin-top: 4px;
}

.markdown-body h3,
.markdown-body h4,
.markdown-body h5 {
  margin: 12px 0 8px;
  color: var(--blue-dark);
  font-family: "Avenir Next", "Helvetica Neue", "PingFang SC", sans-serif;
  font-size: 15px;
  font-weight: 800;
}

.markdown-body code {
  padding: 1px 5px;
  border-radius: 5px;
  color: #103f79;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.92em;
  background: #edf4fd;
}

.markdown-body pre {
  max-width: 100%;
  margin: 10px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid #c9dcf4;
  border-radius: 6px;
  background: #f7faff;
}

.markdown-body pre code {
  display: block;
  padding: 0;
  color: var(--ink);
  line-height: 1.55;
  white-space: pre;
  background: transparent;
}

.message.error .avatar {
  background: var(--warn);
}

.message.error .bubble {
  color: var(--warn);
  border-color: rgba(173, 61, 44, 0.26);
  background: #fff8f6;
}

.sources {
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.sources li + li {
  margin-top: 4px;
}

.bubble.incomplete {
  border-color: #d88924;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

textarea {
  width: 100%;
  min-height: 78px;
  max-height: 180px;
  resize: vertical;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  background: var(--paper);
  outline: none;
}

textarea:focus {
  border-color: rgba(31, 95, 191, 0.62);
  box-shadow: 0 0 0 4px rgba(31, 95, 191, 0.12);
}

#sendButton {
  align-self: stretch;
  min-width: 72px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  background: var(--blue);
}

#sendButton:hover {
  background: var(--blue-dark);
}

#sendButton:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

body.is-resizing {
  cursor: col-resize;
  user-select: none;
}

body.is-resizing .docs-frame {
  pointer-events: none;
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(54vh, 1fr) minmax(420px, 46vh);
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .split-handle {
    display: none;
  }

  .docs-panel {
    min-height: 54vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-panel {
    min-height: 420px;
  }
}

@media (max-width: 640px) {
  .docs-header,
  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .docs-header {
    padding: 15px 16px;
  }

  .chat-header,
  .messages {
    padding: 15px;
  }

  h1 {
    font-size: 25px;
  }

  h2 {
    font-size: 20px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  #sendButton {
    min-height: 44px;
  }
}
