:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-2: #f0f4f4;
  --ink: #17201d;
  --muted: #66736f;
  --line: #dbe3e1;
  --accent: #0b7a75;
  --accent-strong: #075b57;
  --accent-soft: #e4f5f2;
  --warn: #a15c00;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(20, 37, 35, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

.auth-screen {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-card {
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 24px 0 16px;
}

.auth-tab {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 750;
}

.auth-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.auth-form input {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 122, 117, 0.12);
}

.auth-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  font-weight: 750;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: calc(var(--radius) - 2px);
  object-fit: cover;
}

.brand-block h1,
.topbar h2,
.panel h2 {
  margin: 0;
}

.brand-block h1 {
  font-size: 18px;
}

.brand-block p,
.eyebrow,
.composer-meta,
.upload-zone small,
.message-time,
.empty-mini {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 32, 29, 0.02);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.panel h2 {
  font-size: 14px;
}

.status-pill,
.message-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 650;
}

.status-pill.muted {
  background: var(--surface-2);
  color: var(--muted);
}

.upload-zone {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 86px;
  padding: 14px;
  border: 1px dashed #9eb6b2;
  border-radius: var(--radius);
  background: #f8fbfa;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-icon {
  display: grid;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.inline-error {
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
}

.wiki-panel {
  min-height: 220px;
}

.wiki-list {
  display: grid;
  gap: 8px;
}

.wiki-item {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfc;
  text-align: left;
}

.wiki-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.wiki-item span {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-clamp: 5;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
}

.wiki-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(14px);
}

.topbar h2 {
  margin-top: 3px;
  font-size: 22px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 700;
}

.primary-button {
  min-width: 76px;
  padding: 10px 16px;
  background: var(--accent);
  color: white;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button.loading,
.secondary-button.loading {
  position: relative;
  color: transparent;
}

.primary-button.loading::after,
.secondary-button.loading::after {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: currentColor;
  content: "";
}

.primary-button.loading::before,
.secondary-button.loading::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  content: "";
  animation: spin 0.8s linear infinite;
}

.primary-button.loading::before {
  border-color: white;
  border-right-color: transparent;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.secondary-button {
  padding: 9px 12px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 30px;
  height: 30px;
  border-color: var(--line);
  background: var(--surface);
}

.chat-board {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  padding: 22px;
  scroll-behavior: smooth;
}

.welcome-card {
  max-width: 760px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.welcome-card h3 {
  margin: 0 0 8px;
  font-size: 22px;
}

.welcome-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.message-card {
  display: grid;
  grid-template-columns: 4px minmax(0, 1fr);
  width: min(920px, 100%);
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(20, 37, 35, 0.05);
}

.thread-node {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}

.thread-node > .message-card.user {
  align-self: flex-end;
}

.thread-node > .message-card.assistant {
  align-self: flex-start;
}

.comment-thread .thread-node > .message-card {
  width: 100%;
  box-shadow: none;
}

.message-card.user {
  align-self: flex-end;
  width: min(760px, 88%);
}

.message-card.assistant {
  align-self: flex-start;
  width: min(980px, 100%);
}

.message-rail {
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--accent);
}

.message-card.user .message-rail {
  background: #26312e;
}

.message-main {
  min-width: 0;
  padding: 14px 16px;
}

.message-header,
.message-meta-row,
.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.interaction-label {
  display: inline-flex;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.message-body {
  margin-top: 10px;
  line-height: 1.65;
  max-height: none;
  overflow: visible;
  overflow-wrap: anywhere;
  white-space: normal;
}

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

.message-body pre {
  overflow-x: auto;
  margin: 12px 0;
  padding: 14px;
  border-radius: var(--radius);
  background: #101816;
  color: #e7f3ef;
  font-size: 13px;
  line-height: 1.55;
}

.message-body code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #eef3f2;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message-body pre code {
  padding: 0;
  background: transparent;
}

.agent-thinking {
  display: grid;
  gap: 12px;
  padding: 4px 0 2px;
}

.thinking-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-strong);
}

.thinking-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.agent-thinking ol {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.agent-thinking li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.agent-thinking li span {
  width: 8px;
  height: 8px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
}

.agent-thinking li.active {
  color: var(--ink);
  font-weight: 700;
}

.agent-thinking li.active span {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(11, 122, 117, 0.12);
}

.agent-thinking li.done span {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.message-meta-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}

.comment-thread {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-left: 16px;
  border-left: 2px solid var(--accent-soft);
}

.comment-thread .message-card {
  background: #fbfcfc;
}

.composer-wrap {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  z-index: 2;
}

.reply-banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
}

.reply-banner button {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  font-weight: 800;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.composer textarea {
  width: 100%;
  max-height: 180px;
  min-height: 48px;
  resize: none;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  line-height: 1.5;
  outline: none;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 122, 117, 0.12);
}

.composer-meta {
  margin-top: 8px;
  justify-content: space-between;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.error {
  border-left-color: var(--danger);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app-shell {
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar {
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-area {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .chat-board {
    overflow: visible;
  }

  .message-card.user,
  .message-card.assistant {
    width: 100%;
  }

  .topbar,
  .message-header,
  .composer-meta {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions,
  .composer {
    width: 100%;
  }

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

  .primary-button {
    width: 100%;
  }
}
