:root {
  --navy: #1A237E;
  --accent: #FF8F00;
  --ink: #1f2937;
  --muted: #6b7280;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --line: #e5e7eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Montserrat", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

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

.topbar {
  width: min(1024px, 96%);
  margin: 0 auto;
  padding: 0.75rem 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.brand-link {
  font-weight: 700;
  color: var(--navy);
  text-decoration: none;
}

.topbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.chat-links {
  display: inline-flex;
  align-items: center;
  gap: 0.62rem;
}

.chat-links a {
  color: var(--navy);
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

.chat-links a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.status-pill {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #9a5a00;
  background: #fff5e8;
  border: 1px solid #ffd8ad;
  border-radius: 999px;
  padding: 0.3rem 0.62rem;
}

.exit-link {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
}

.chat-main {
  overflow-y: auto;
}

.thread {
  width: min(840px, 94%);
  margin: 0 auto;
  padding: 1.15rem 0 1.8rem;
  display: grid;
  gap: 1.15rem;
}

.turn {
  animation: fadeUp 0.25s ease both;
}

.turn.assistant {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: start;
  gap: 0.75rem;
}

.turn.user {
  max-width: min(86%, 680px);
  margin-left: auto;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffffff;
  background: var(--navy);
}

.bubble {
  font-size: 0.96rem;
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
}

.turn.assistant .bubble {
  padding-top: 0.22rem;
}

.turn.assistant .bubble p {
  margin: 0;
}

.turn.assistant .bubble p + p {
  margin-top: 0.62rem;
}

.turn.user .bubble {
  border: 1px solid #e1e3e8;
  border-radius: 16px;
  background: #f1f3f5;
  padding: 0.68rem 0.82rem;
}

.composer-dock {
  padding: 0.8rem 0 calc(0.9rem + env(safe-area-inset-bottom));
  background:
    linear-gradient(180deg, rgba(247, 247, 248, 0), rgba(247, 247, 248, 1) 28%),
    var(--bg);
}

.composer-wrap {
  width: min(840px, 94%);
  margin: 0 auto;
}

.composer {
  border: 1px solid #d8dce3;
  background: var(--panel);
  border-radius: 18px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.62rem;
  padding: 0.62rem;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.report-actions {
  margin-top: 0.62rem;
  border: 1px solid #d8dce3;
  border-radius: 14px;
  background: #ffffff;
  padding: 0.62rem 0.72rem;
}

.pdf-btn {
  border: 0;
  border-radius: 10px;
  background: #0f766e;
  color: #ffffff;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 0.52rem 0.78rem;
  cursor: pointer;
}

.pdf-btn:hover {
  background: #0d5f59;
}

.pdf-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.report-hint {
  margin: 0.42rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.attachments {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: 0.6rem;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid #cfd5df;
  border-radius: 999px;
  background: #ffffff;
  color: #1f2937;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.42rem 0.72rem;
  cursor: pointer;
}

.record-btn {
  border: 1px solid #cfd5df;
  border-radius: 999px;
  background: #ffffff;
  color: #1f2937;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.42rem 0.72rem;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.record-btn.is-recording {
  background: #b91c1c;
  border-color: #991b1b;
  color: #ffffff;
}

.record-btn.is-disabled,
.record-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

#attachment-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.attachment-status {
  font-size: 0.78rem;
  color: var(--muted);
}

.composer textarea {
  border: 0;
  resize: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  min-height: 26px;
  max-height: 180px;
  background: transparent;
  color: var(--ink);
  padding: 0.3rem 0.15rem;
}

.composer textarea:focus {
  outline: none;
}

.composer textarea::placeholder {
  color: #8a93a2;
}

.send-btn {
  align-self: end;
  border: 0;
  border-radius: 12px;
  background: var(--navy);
  color: #ffffff;
  font: inherit;
  font-weight: 700;
  padding: 0.62rem 0.86rem;
  cursor: pointer;
}

.send-btn:hover {
  background: #121a6a;
}

.send-btn:disabled,
.attach-btn[aria-disabled="true"] {
  opacity: 0.65;
  cursor: not-allowed;
}

.send-btn:focus-visible,
.exit-link:focus-visible,
.brand-link:focus-visible,
.chat-links a:focus-visible,
.record-btn:focus-visible,
.pdf-btn:focus-visible {
  outline: 3px solid rgba(26, 35, 126, 0.25);
  outline-offset: 2px;
}

.disclaimer {
  margin: 0.55rem 0 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--muted);
}

.disclaimer-links {
  margin-top: 0.35rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.disclaimer-links a {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.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;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 760px) {
  .topbar {
    padding: 0.92rem 0;
  }

  .status-pill {
    font-size: 0.7rem;
  }

  .turn.user {
    max-width: 72%;
  }
}

@media (max-width: 640px) {
  .topbar {
    width: min(1024px, 94%);
  }

  .topbar-right {
    width: 100%;
    justify-content: flex-start;
    gap: 0.45rem;
  }

  .chat-links {
    width: 100%;
    order: 3;
    overflow-x: auto;
    padding-bottom: 0.12rem;
  }

  .status-pill {
    order: 1;
  }

  .exit-link {
    order: 2;
    margin-left: auto;
  }

  .thread,
  .composer-wrap {
    width: min(840px, 94%);
  }

  .attachments {
    flex-wrap: wrap;
    gap: 0.45rem;
    padding-bottom: 0.5rem;
  }

  .attachment-status {
    width: 100%;
    padding-left: 0.06rem;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 0.52rem;
    border-radius: 15px;
    padding: 0.56rem;
  }

  .send-btn {
    width: 100%;
    justify-self: stretch;
  }

  .report-actions {
    padding: 0.56rem 0.64rem;
  }
}
