:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --panel: #ffffff;
  --ink: #1e2420;
  --muted: #68736c;
  --line: #d9ded8;
  --accent: #1f6f5b;
  --accent-dark: #164f42;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

.shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

p {
  margin: 6px 0 0;
  color: var(--muted);
}

.ai-warning {
  max-width: 860px;
  margin-top: 10px;
  padding: 10px 12px;
  border-left: 4px solid #b36b1f;
  background: #fff7eb;
  color: #5d4122;
  border-radius: 6px;
  line-height: 1.45;
}

button {
  border: 1px solid var(--accent-dark);
  background: var(--accent);
  color: white;
  min-width: 44px;
  height: 44px;
  border-radius: 6px;
  font-size: 20px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

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

.documents-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--accent-dark);
  border-radius: 6px;
  background: #ffffff;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.documents-link:hover {
  background: #e9f3ef;
}

.topbar-button {
  min-width: 0;
  height: 34px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
}

.topbar-button:hover {
  background: #e9f3ef;
}

.logout-button {
  min-width: 0;
  height: 34px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--accent-dark);
  font-size: 14px;
}

.logout-button:hover {
  background: #e9f3ef;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.login-panel h1 {
  font-size: 22px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--ink);
  font-weight: 700;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
}

.login-form button {
  width: 100%;
}

.login-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 4px solid #b3261e;
  background: #fff0ee;
  color: #7d221d;
  border-radius: 6px;
}

.chat {
  position: relative;
  height: clamp(520px, calc(100vh - 360px), 760px);
  min-height: 320px;
  max-height: calc(100vh - 220px);
  overflow: auto;
  resize: vertical;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.chat::after {
  content: "";
  position: sticky;
  display: block;
  width: 14px;
  height: 14px;
  margin-left: auto;
  margin-top: -14px;
  bottom: 0;
  background:
    linear-gradient(135deg, transparent 50%, #a4aaa5 50%) right bottom / 6px 6px no-repeat,
    linear-gradient(135deg, transparent 50%, #c3c8c3 50%) right 4px bottom / 10px 10px no-repeat;
  pointer-events: none;
}

.message {
  position: relative;
  max-width: 82%;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfbfa;
}

.message.assistant {
  padding-top: 36px;
}

.message.user {
  margin-left: auto;
  background: #e9f3ef;
  border-color: #b7d3c9;
}

.copy-answer {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 0;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  border-radius: 5px;
  font-size: 12px;
  line-height: 1;
}

.copy-answer:hover {
  color: var(--accent-dark);
  border-color: #b7d3c9;
}

.copy-answer:disabled {
  opacity: 1;
  color: var(--accent-dark);
  cursor: default;
}

.message-content {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
  line-height: 1.5;
}

.message-content p {
  margin: 0 0 10px;
  color: inherit;
}

.message-content p:last-child,
.message-content ul:last-child,
.message-content ol:last-child {
  margin-bottom: 0;
}

.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
  margin: 12px 0 6px;
  font-size: 15px;
  line-height: 1.3;
}

.message-content h3:first-child,
.message-content h4:first-child,
.message-content h5:first-child,
.message-content h6:first-child {
  margin-top: 0;
}

.message-content ul,
.message-content ol {
  margin: 0 0 10px 22px;
  padding: 0;
}

.message-content li {
  margin: 4px 0;
}

.message-content code {
  background: #eef1ee;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.message-content table,
.document-content table {
  width: 100%;
  margin: 12px 0;
  border-collapse: collapse;
  font-size: 14px;
  white-space: normal;
}

.message-content th,
.message-content td,
.document-content th,
.document-content td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  vertical-align: top;
}

.message-content th,
.document-content th {
  background: #eef1ee;
  color: var(--ink);
  font-weight: 700;
}

.message-content td,
.document-content td {
  background: #ffffff;
}

.message-content table.source-hit,
.document-content table.source-hit,
.message-content tr.source-hit td,
.document-content tr.source-hit td {
  background: #fff2a8;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 12px 0 16px;
}

.composer-actions {
  display: grid;
  gap: 10px;
  align-content: start;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font: inherit;
  line-height: 1.45;
  background: white;
}

.message-sources {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.message-sources summary {
  color: var(--accent-dark);
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
}

.message-sources summary:hover {
  color: var(--accent);
}

.source-list {
  margin-top: 8px;
}

.source {
  display: grid;
  gap: 4px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.source:first-child {
  border-top: 0;
}

.source span,
.source code {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.source-link {
  display: inline;
  width: fit-content;
  min-width: 0;
  height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent-dark);
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  text-align: left;
  text-decoration: underline;
  overflow-wrap: anywhere;
}

.source-link:hover {
  color: var(--accent);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 27, 23, 0.48);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  width: min(980px, calc(100vw - 32px));
  max-height: min(86vh, 900px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.22);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-header p {
  margin: 4px 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.document-search {
  display: grid;
  gap: 4px;
  width: min(300px, 38vw);
  margin-left: auto;
}

.document-search input {
  width: 100%;
  height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbfa;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.document-search input:focus {
  outline: 2px solid #b7d3c9;
  outline-offset: 1px;
  border-color: #8ab8a8;
  background: #fff;
}

.document-search-controls {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 4px;
  min-height: 24px;
}

.document-search-controls span {
  color: var(--muted);
  font-size: 12px;
}

.document-search-controls button {
  min-width: 28px;
  width: 28px;
  height: 24px;
  padding: 0;
  border-color: var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.document-search-controls button:hover:not(:disabled) {
  border-color: #8ab8a8;
  background: #e9f3ef;
}

.document-search-controls button:disabled {
  opacity: 0.45;
  cursor: default;
}

#document-close {
  flex: 0 0 auto;
}

.examples-panel {
  width: min(760px, calc(100vw - 32px));
}

.info-panel {
  width: min(760px, calc(100vw - 32px));
}

.info-content {
  overflow: auto;
  padding: 18px;
  line-height: 1.55;
}

.info-content p {
  margin: 0 0 12px;
  color: var(--ink);
}

.info-content h3 {
  margin: 18px 0 6px;
  color: var(--ink);
  font-size: 16px;
}

.examples-content {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 18px;
}

.example-question {
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbfa;
  color: var(--ink);
  font: inherit;
  line-height: 1.35;
  text-align: left;
}

.example-question:hover {
  border-color: #b7d3c9;
  background: #f2f8f5;
}

.document-content {
  overflow: auto;
  padding: 18px;
  line-height: 1.55;
}

.document-content h3,
.document-content h4,
.document-content h5,
.document-content h6 {
  margin: 18px 0 8px;
}

.document-content h6 {
  display: inline-block;
  margin-top: 16px;
  padding: 3px 8px;
  background: #eef1ee;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 15px;
}

.document-content p {
  color: var(--ink);
}

.document-content .source-hit {
  background: #fff2a8;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  border-radius: 4px;
  padding: 2px 4px;
}

.document-content li.source-hit {
  padding-left: 4px;
}

.document-content mark.document-search-hit {
  padding: 1px 3px;
  border-radius: 4px;
  background: #b7f0c1;
  color: inherit;
  box-shadow: inset 0 0 0 1px #59a869;
}

.document-content mark.document-search-hit.active {
  background: #ffc766;
  box-shadow: inset 0 0 0 2px #c16d12;
}

.documents-shell {
  max-width: 1100px;
}

.documents-view-switch {
  display: inline-flex;
  gap: 4px;
  margin: 0 0 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.documents-view-link {
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 6px;
  color: var(--accent-dark);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.documents-view-link:hover {
  background: #e9f3ef;
}

.documents-view-link.active {
  background: var(--accent);
  color: #fff;
}

.documents-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.documents-topic-list {
  align-content: start;
}

.documents-topic {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbfa;
}

.documents-topic[open] {
  background: #fff;
}

.documents-topic summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 12px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}

.documents-topic summary::-webkit-details-marker {
  display: none;
}

.documents-topic summary:hover {
  background: #f2f8f5;
}

.documents-topic-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.documents-topic-toggle {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--accent-dark);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  transition: transform 0.15s ease, background 0.15s ease;
}

.documents-topic[open] .documents-topic-toggle {
  transform: rotate(90deg);
  background: #e9f3ef;
}

.documents-topic-title {
  font-weight: 800;
  line-height: 1.3;
}

.documents-topic-count {
  min-width: 30px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e8eee9;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.documents-topic-documents {
  display: grid;
  gap: 8px;
  padding: 0 12px 12px;
}

.documents-search-view {
  display: grid;
  gap: 10px;
}

.documents-search-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.documents-search-form input {
  width: 100%;
  height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbfa;
  color: var(--ink);
  font: inherit;
}

.documents-search-form input:focus {
  outline: 2px solid #b7d3c9;
  outline-offset: 1px;
  border-color: #8ab8a8;
  background: #fff;
}

.documents-search-form button {
  min-width: 0;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
}

#documents-search-clear {
  border-color: var(--line);
  background: #fff;
  color: var(--accent-dark);
}

#documents-search-clear:hover {
  background: #e9f3ef;
}

.documents-search-status {
  margin: 0;
  padding: 0 2px;
  color: var(--muted);
  font-size: 14px;
}

.documents-search-results:empty {
  display: none;
}

.documents-search-snippet {
  display: -webkit-box;
  margin-top: 6px;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  color: var(--ink);
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.documents-search-hit {
  padding: 1px 3px;
  border-radius: 4px;
  background: #fff2a8;
  color: inherit;
}

.document-list-item {
  display: grid;
  gap: 4px;
  width: 100%;
  height: auto;
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfbfa;
  color: var(--ink);
  font: inherit;
  text-align: left;
}

.document-list-item:hover {
  border-color: #b7d3c9;
  background: #f2f8f5;
}

.documents-search-result {
  min-height: 132px;
  align-content: start;
  gap: 7px;
}

.document-list-title {
  font-weight: 700;
  line-height: 1.35;
}

.document-list-meta {
  color: var(--muted);
  font-size: 13px;
}

.document-list-path {
  color: var(--accent-dark);
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 1100px);
    padding: 12px 0;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .documents-search-form {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 100%;
  }

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

  .modal {
    padding: 10px;
  }

  .modal-panel {
    width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
  }

  .modal-header {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .document-search {
    grid-column: 1 / -1;
    width: 100%;
    margin-left: 0;
  }
}
