:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-strong: #eef3f1;
  --ink: #17211f;
  --muted: #596663;
  --soft: #75817d;
  --line: #d9e1dd;
  --line-strong: #b8c5bf;
  --green: #146b5f;
  --green-strong: #0d5148;
  --blue: #2f5f98;
  --amber: #a66321;
  --red: #aa3d34;
  --shadow: 0 18px 48px rgba(20, 33, 31, 0.12);
}

* {
  box-sizing: border-box;
}

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

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

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark,
.dialog-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: var(--green);
  background: #e3efeb;
  border: 1px solid #c7dad3;
  flex: 0 0 auto;
}

.brand h1,
.dialog-heading h2,
.topbar h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.dialog-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-panel,
.suggestions-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.status-line {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.status-line span,
.status-grid span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.status-line strong {
  color: var(--blue);
  font-size: 12px;
  text-align: left;
  overflow-wrap: anywhere;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-grid div {
  min-height: 78px;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.status-grid div:nth-child(2n) {
  border-right: 0;
}

.status-grid div:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  line-height: 1;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.suggestions {
  display: grid;
  gap: 0;
}

.suggestion-button {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.suggestion-button:last-child {
  border-bottom: 0;
}

.suggestion-button:hover,
.suggestion-button:focus-visible {
  background: var(--surface-strong);
  outline: none;
}

.follow-up-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.suggestion-button.compact {
  width: auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 12px;
}

.chat-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 100vh;
}

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

.topbar h2 {
  margin-top: 4px;
  font-size: 20px;
  line-height: 1.25;
}

.environment-label {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid #d8c8a9;
  border-radius: 6px;
  color: #744416;
  background: #fff6e8;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 28px;
  overflow: auto;
}

.message {
  display: grid;
  gap: 8px;
  max-width: 86%;
}

.message.user {
  align-self: flex-end;
}

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

.bubble {
  border-radius: 8px;
  padding: 13px 15px;
  line-height: 1.45;
  box-shadow: 0 1px 0 rgba(20, 33, 31, 0.03);
}

.message.user .bubble {
  color: #ffffff;
  background: var(--green);
}

.message.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 48px;
  min-height: 24px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--soft);
  animation: typing-pulse 1s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.12s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes typing-pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--soft);
  font-size: 12px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.tag.warn {
  color: var(--amber);
  border-color: #dec7a2;
  background: #fff8eb;
}

.source-details {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.source-details summary {
  width: fit-content;
  padding-top: 10px;
  color: var(--blue);
  cursor: pointer;
  font-weight: 700;
}

.source-details dl {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 12px;
  margin: 8px 0 0;
}

.source-details dt {
  font-weight: 700;
}

.source-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.answer-table-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.answer-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
  font-size: 13px;
}

.answer-table th,
.answer-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.answer-table th {
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 12px;
  text-transform: uppercase;
}

.answer-table tr:last-child td {
  border-bottom: 0;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  gap: 10px;
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 18px 28px 24px;
}

.composer textarea {
  width: 100%;
  min-height: 58px;
  max-height: 160px;
  resize: none;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  line-height: 1.35;
}

.composer textarea:focus {
  border-color: var(--green);
  outline: 3px solid rgba(20, 107, 95, 0.16);
}

.send-button,
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--green);
  background: #ffffff;
}

.send-button {
  width: 58px;
  height: 58px;
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.send-button:hover,
.send-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible {
  background: var(--green-strong);
  outline: none;
}

.secondary-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 700;
}

.secondary-button {
  color: var(--green);
  border: 1px solid var(--line);
  background: #ffffff;
}

.primary-button {
  color: #ffffff;
  border: 1px solid var(--green);
  background: var(--green);
}

.access-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.access-dialog::backdrop {
  background: rgba(23, 33, 31, 0.38);
}

.access-dialog form {
  display: grid;
  gap: 14px;
  padding: 20px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.access-dialog label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.access-dialog input {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

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

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .chat-main {
    order: 1;
  }

  .sidebar {
    order: 2;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .messages,
  .composer {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .sidebar,
  .topbar,
  .messages,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .message {
    max-width: 100%;
  }

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

  .status-grid div,
  .status-grid div:nth-child(2n),
  .status-grid div:nth-last-child(-n + 2) {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .status-grid div:last-child {
    border-bottom: 0;
  }
}
