:root {
  --bg: #f4f1ec;
  --surface: #fffefb;
  --ink: #1c1b19;
  --muted: #5c5854;
  --accent: #0d5c63;
  --accent-hover: #094a50;
  --border: #e0dcd4;
  --error-bg: #fdecea;
  --error-border: #e8a29a;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(28, 27, 25, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

.layout {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  margin-bottom: 1.75rem;
}

.title {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.75rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.subtitle-tip {
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--muted);
  text-underline-offset: 3px;
}

.index-info {
  margin: 0.65rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
}

.index-info.index-info-loading {
  font-style: italic;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 0.75rem;
  color: var(--accent);
}

.label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.35rem;
  margin-top: 0.85rem;
}

.label:first-of-type {
  margin-top: 0;
}

.input {
  width: 100%;
  font: inherit;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.textarea {
  resize: vertical;
  min-height: 6rem;
}

.chat-model-row {
  margin-bottom: 0.25rem;
}

.chat-model-row .label {
  margin-top: 0;
}

.chat-model-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
}

.chat-model-select {
  flex: 1 1 12rem;
  min-width: 10rem;
}

.chat-model-custom {
  flex: 1 1 14rem;
  min-width: 8rem;
}

.chat-model-custom.hidden {
  display: none !important;
}

.chat-model-hint {
  margin-top: 0.35rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--accent);
}

.btn-secondary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.status {
  font-size: 0.9rem;
  color: var(--muted);
}

.panel-error {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: #5c2e28;
  font-size: 0.95rem;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.chat-toolbar-title {
  margin: 0;
}

.chat-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

.chat-thread {
  min-height: 8rem;
  max-height: min(50vh, 28rem);
  overflow-y: auto;
  padding: 0.5rem 0.25rem;
  margin: 0 -0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #faf9f7;
}

.chat-empty-hint {
  margin: 0 0 0.5rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.chat-msg {
  margin-bottom: 1rem;
}

.chat-msg:last-child {
  margin-bottom: 0.25rem;
}

.chat-msg-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.chat-msg-body {
  word-break: break-word;
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-msg-body-plain {
  white-space: pre-wrap;
}

.chat-msg-body-md {
  white-space: normal;
}

.chat-msg-body-md p {
  margin: 0.4em 0;
}

.chat-msg-body-md p:first-child {
  margin-top: 0;
}

.chat-msg-body-md p:last-child {
  margin-bottom: 0;
}

.chat-msg-body-md ul,
.chat-msg-body-md ol {
  margin: 0.4em 0;
  padding-left: 1.35rem;
}

.chat-msg-body-md li {
  margin: 0.2em 0;
}

.chat-msg-body-md strong,
.chat-msg-body-md b {
  font-weight: 600;
}

.chat-msg-body-md code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.88em;
  background: rgba(28, 27, 25, 0.06);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.chat-msg-body-md pre {
  margin: 0.5em 0;
  padding: 0.65rem 0.75rem;
  background: #1c1b19;
  color: #f4f1ec;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.45;
}

.chat-msg-body-md pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.chat-msg-body-md blockquote {
  margin: 0.5em 0;
  padding-left: 0.85rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.chat-msg-body-md a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(13, 92, 99, 0.45);
  text-underline-offset: 2px;
}

.chat-msg-body-md a:hover {
  color: var(--accent-hover);
}

.chat-msg-body-md h1,
.chat-msg-body-md h2,
.chat-msg-body-md h3,
.chat-msg-body-md h4 {
  margin: 0.65em 0 0.35em;
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  color: var(--accent);
  line-height: 1.25;
}

.chat-msg-body-md h1:first-child,
.chat-msg-body-md h2:first-child,
.chat-msg-body-md h3:first-child {
  margin-top: 0;
}

.chat-msg-body-md table {
  border-collapse: collapse;
  margin: 0.5em 0;
  font-size: 0.9em;
}

.chat-msg-body-md th,
.chat-msg-body-md td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.5rem;
  text-align: left;
}

.chat-msg-body-md th {
  background: var(--bg);
  font-weight: 600;
}

.chat-msg-user .chat-msg-body {
  margin-left: 1.5rem;
  background: #e8f4f5;
  border: 1px solid #c5e0e3;
}

.chat-msg-assistant .chat-msg-body {
  margin-right: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
}

.usage-box-chat {
  margin-top: 0.35rem;
}

.sources-details {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}

.sources-summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  list-style-position: outside;
  padding: 0.15rem 0;
}

.sources-details[open] .sources-summary {
  margin-bottom: 0.5rem;
}

.answer {
  white-space: pre-wrap;
  word-break: break-word;
}

.usage-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

.usage-main {
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.usage-detail {
  font-size: 0.82rem;
}

.usage-cost {
  margin-top: 0.5rem;
  font-size: 0.88rem;
  color: var(--ink);
}

.sources {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.source-item {
  border-left: 3px solid var(--accent);
  padding: 0.65rem 0 0.65rem 0.85rem;
  background: var(--bg);
  border-radius: 0 6px 6px 0;
}

.source-path-wrap {
  font-size: 0.85rem;
  font-weight: 600;
  font-family: ui-monospace, monospace;
  word-break: break-all;
}

.source-path {
  color: var(--accent);
}

a.source-path-link {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(13, 92, 99, 0.45);
  text-underline-offset: 2px;
}

a.source-path-link:hover {
  color: var(--accent-hover);
  text-decoration-color: var(--accent-hover);
}

.source-section {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.source-excerpt {
  margin-top: 0.45rem;
  font-size: 0.9rem;
  color: var(--ink);
}

.footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}

.footer a {
  color: var(--accent);
  text-decoration: none;
}

.footer a:hover {
  text-decoration: underline;
}

.sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

.hidden {
  display: none !important;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.hint kbd {
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  padding: 0.1rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.doc-sources-row {
  margin-bottom: 0.75rem;
}

.doc-sources-row > .label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
  font-size: 0.92rem;
}

.doc-sources-fieldset {
  margin: 0;
  padding: 0;
  border: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.doc-source-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.doc-source-caption {
  color: var(--ink);
}

.doc-sources-hint {
  margin-top: 0.35rem;
}

.source-kind {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

