:root {
  color-scheme: light;
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #18201c;
  --muted: #64706a;
  --line: #d9e1da;
  --accent: #286c73;
  --accent-strong: #19535a;
  --warm: #b3523d;
  --gold: #8a6f22;
  --shadow: 0 18px 60px rgba(24, 32, 28, 0.12);
}

* {
  box-sizing: border-box;
}

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

button,
input,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
}

button:hover {
  border-color: var(--accent);
}

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

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 84px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.topbar h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-right {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(7, minmax(72px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  overflow: hidden;
}

.mode-button {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0 14px;
  color: var(--muted);
}

.mode-button.active {
  background: var(--accent);
  color: #ffffff;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  padding: 0 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.status-pill.ok {
  border-color: rgba(40, 108, 115, 0.35);
  color: var(--accent-strong);
  background: #e8f3f0;
}

.status-pill.warn {
  border-color: rgba(179, 82, 61, 0.35);
  color: var(--warm);
  background: #fff0eb;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.side-panel {
  min-height: 0;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search-row input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search-row input {
  min-width: 0;
  height: 40px;
  padding: 0 12px;
}

.search-row input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(40, 108, 115, 0.14);
}

.verse-results {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 10px;
}

.verse-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.verse-id {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 6px;
}

.verse-text {
  margin: 0;
  color: var(--ink);
  line-height: 1.45;
  font-size: 14px;
}

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: linear-gradient(180deg, #f8faf7 0%, #eef3ef 100%);
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  width: min(840px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
  box-shadow: 0 8px 28px rgba(24, 32, 28, 0.06);
}

.message.user {
  align-self: flex-end;
  border-color: rgba(40, 108, 115, 0.28);
  background: #edf7f5;
}

.message.assistant {
  align-self: flex-start;
}

.message.error {
  border-color: rgba(179, 82, 61, 0.45);
  background: #fff3ef;
}

.message-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.message-text {
  white-space: pre-wrap;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.meta-grid {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.meta-row {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.meta-key {
  color: var(--muted);
  font-weight: 700;
}

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

.composer textarea {
  min-height: 72px;
  max-height: 180px;
  resize: vertical;
  padding: 12px 14px;
  line-height: 1.45;
}

.composer-actions {
  display: grid;
  align-content: end;
  gap: 8px;
  min-width: 120px;
}

.send-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 700;
}

.send-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: transparent;
}

.typing {
  color: var(--muted);
}

@media (max-width: 820px) {
  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px 16px;
  }

  .topbar-right {
    justify-items: start;
    width: 100%;
  }

  .status-strip {
    justify-content: flex-start;
  }

  .mode-switch {
    width: 100%;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .side-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 38vh;
  }

  .messages {
    padding: 16px;
    min-height: 44vh;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 14px 16px;
  }

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

  .meta-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
