.chat-screen {
  --chat-ink: #12345b;
  --chat-teal: #0a7f83;
  --chat-soft: #eef8fa;
  min-height: 100dvh;
  background: #f5f8fb;
}

.chat-app-header {
  border-bottom: 1px solid var(--line);
}

.chat-service-status {
  padding: 7px 10px;
  border: 1px solid #cddde6;
  border-radius: 999px;
  background: white;
  color: #64748b;
  font-size: .68rem;
  font-weight: 800;
}

.chat-service-status.ready {
  border-color: #a7d8cb;
  background: #ecfdf5;
  color: #12654f;
}

.chat-service-status.unavailable {
  border-color: #f0c9c9;
  background: #fff4f4;
  color: #9f3030;
}

.chat-privacy-notice,
.chat-emergency-alert {
  max-width: 1180px;
  margin: 16px auto 0;
  padding: 14px 18px;
  border-radius: 14px;
}

.chat-privacy-notice {
  border: 1px solid #b9d9e5;
  background: #eff9fc;
  color: #31566a;
}

.chat-emergency-alert {
  border: 2px solid #c93d3d;
  background: #fff1f1;
  color: #8d2020;
  box-shadow: 0 8px 24px rgba(145, 31, 31, .12);
}

.chat-privacy-notice strong,
.chat-emergency-alert strong {
  display: block;
  margin-bottom: 4px;
  color: inherit;
  font-size: .8rem;
}

.chat-privacy-notice p,
.chat-emergency-alert p {
  margin: 0;
  font-size: .75rem;
  line-height: 1.55;
}

.chat-layout {
  display: grid;
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100dvh - 245px);
  margin: 16px auto 100px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: white;
  box-shadow: 0 18px 48px rgba(18, 52, 91, .08);
}

.chat-sidebar {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(160deg, #f2fafb, #f8fbfd);
}

.chat-sidebar h2 {
  margin: 6px 0 0;
  color: var(--chat-ink);
  font-size: 1rem;
}

.chat-starters,
.chat-sidebar-actions {
  display: grid;
  gap: 8px;
}

.chat-starters button,
.chat-sidebar-actions button {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #d6e4eb;
  border-radius: 11px;
  background: white;
  color: #31566a;
  text-align: left;
  font: inherit;
  font-size: .72rem;
  font-weight: 700;
  line-height: 1.35;
}

.chat-starters button:hover,
.chat-starters button:focus-visible {
  border-color: var(--chat-teal);
  color: var(--chat-teal);
}

.chat-sidebar-actions {
  grid-template-columns: repeat(3, 1fr);
}

.chat-sidebar-actions button {
  padding: 8px;
  text-align: center;
  font-size: .65rem;
}

.chat-memory-note {
  margin: 0;
  color: #64748b;
  font-size: .66rem;
  line-height: 1.55;
}

.chat-workspace {
  display: grid;
  min-width: 0;
  grid-template-rows: minmax(340px, 1fr) auto auto;
}

.chat-history {
  display: grid;
  align-content: start;
  gap: 18px;
  min-height: 400px;
  max-height: calc(100dvh - 320px);
  padding: 22px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.chat-empty-state {
  display: grid;
  max-width: 560px;
  margin: auto;
  padding: 36px 18px;
  place-items: center;
  text-align: center;
}

.chat-empty-state > span {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 18px;
  background: linear-gradient(145deg, var(--chat-teal), var(--chat-ink));
  color: white;
  font-weight: 800;
}

.chat-empty-state h2 {
  margin: 0 0 8px;
  color: var(--chat-ink);
  font-size: 1.25rem;
}

.chat-empty-state p {
  margin: 0;
  color: #64748b;
  font-size: .78rem;
  line-height: 1.65;
}

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

.chat-message.user {
  justify-self: end;
}

.chat-message.assistant {
  width: min(760px, 100%);
  justify-self: start;
}

.chat-message-label {
  color: #64748b;
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.chat-message.user .chat-message-label {
  text-align: right;
}

.chat-user-bubble {
  padding: 13px 16px;
  border-radius: 16px 16px 4px 16px;
  background: var(--chat-ink);
  color: white;
  font-size: .79rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.chat-answer-card {
  overflow: hidden;
  border: 1px solid #dce7ed;
  border-radius: 18px 18px 18px 4px;
  background: white;
  box-shadow: 0 10px 26px rgba(18, 52, 91, .06);
}

.chat-answer-section {
  padding: 17px 18px;
  border-bottom: 1px solid #edf1f4;
}

.chat-answer-section:last-child {
  border-bottom: 0;
}

.chat-answer-section h3 {
  margin: 0 0 8px;
  color: var(--chat-ink);
  font-size: .84rem;
}

.chat-answer-section p,
.chat-answer-section li {
  color: #34495e;
  font-size: .76rem;
  line-height: 1.65;
}

.chat-answer-section p {
  margin: 0;
  white-space: pre-wrap;
}

.chat-answer-section ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 19px;
}

.chat-table-scroll {
  overflow-x: auto;
  border: 1px solid #dce7ed;
  border-radius: 10px;
}

.chat-comparison-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
}

.chat-comparison-table th,
.chat-comparison-table td {
  padding: 10px 11px;
  border-right: 1px solid #e3ebef;
  border-bottom: 1px solid #e3ebef;
  color: #34495e;
  font-size: .7rem;
  line-height: 1.5;
  text-align: left;
  vertical-align: top;
}

.chat-comparison-table th {
  background: #f1f7f9;
  color: var(--chat-ink);
  font-weight: 800;
}

.chat-comparison-table tr:last-child td { border-bottom: 0; }
.chat-comparison-table th:last-child,
.chat-comparison-table td:last-child { border-right: 0; }

.chat-answer-section.red-flags {
  background: #fff7f1;
}

.chat-answer-section.red-flags h3,
.chat-answer-section.red-flags li {
  color: #8a3b18;
}

.chat-answer-section.context {
  background: #f1f8fb;
}

.chat-sources {
  padding: 16px 18px;
  border-top: 1px solid #e4edf1;
  background: #f8fbfc;
}

.chat-sources h3 {
  margin: 0 0 9px;
  color: var(--chat-ink);
  font-size: .78rem;
}

.chat-sources ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 18px;
}

.chat-sources li,
.chat-source-notice {
  color: #526b79;
  font-size: .68rem;
  line-height: 1.55;
}

.chat-source-notice {
  margin: 0;
}

.chat-disclaimer {
  padding: 14px 18px;
  border-top: 1px solid #f0dcc0;
  background: #fff9ec;
  color: #73541d;
  font-size: .64rem;
  font-weight: 650;
  line-height: 1.55;
}

.chat-answer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chat-answer-actions button {
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid #d8e4ea;
  border-radius: 9px;
  background: white;
  color: #466275;
  font: inherit;
  font-size: .65rem;
  font-weight: 800;
}

.chat-loading {
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  padding: 13px 16px;
  border: 1px solid #dce7ed;
  border-radius: 16px 16px 16px 4px;
  color: #526b79;
  font-size: .72rem;
}

.chat-loading span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-teal);
  animation: chat-pulse 1s infinite alternate;
}

.chat-loading span:nth-child(2) { animation-delay: .2s; }
.chat-loading span:nth-child(3) { animation-delay: .4s; }

@keyframes chat-pulse {
  to { opacity: .25; transform: translateY(-3px); }
}

.chat-error {
  margin: 0 18px 12px;
  padding: 12px 14px;
  border: 1px solid #efc1c1;
  border-radius: 11px;
  background: #fff3f3;
  color: #8d2929;
  font-size: .72rem;
  line-height: 1.5;
}

.chat-error button {
  margin-left: 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 800;
  text-decoration: underline;
}

.chat-composer {
  padding: 16px 18px 18px;
  border-top: 1px solid var(--line);
  background: white;
}

.chat-composer > label {
  display: block;
  margin-bottom: 7px;
  color: var(--chat-ink);
  font-size: .68rem;
  font-weight: 800;
}

.chat-composer > div {
  display: grid;
  gap: 9px;
}

.chat-composer textarea {
  width: 100%;
  min-height: 84px;
  max-height: 200px;
  resize: vertical;
  padding: 12px 14px;
  border: 1.5px solid #cadbe4;
  border-radius: 13px;
  outline: none;
  color: #243746;
  font: inherit;
  font-size: .78rem;
  line-height: 1.55;
}

.chat-composer textarea:focus {
  border-color: var(--chat-teal);
  box-shadow: 0 0 0 3px rgba(10, 127, 131, .1);
}

.chat-composer button {
  min-height: 48px;
}

.chat-composer small {
  display: block;
  margin-top: 8px;
  color: #718493;
  font-size: .62rem;
}

@media (min-width: 860px) {
  .chat-layout {
    grid-template-columns: 255px minmax(0, 1fr);
    margin-bottom: 34px;
  }

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

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

  .chat-composer > div {
    grid-template-columns: minmax(0, 1fr) 120px;
    align-items: end;
  }
}

@media (min-width: 1024px) {
  .chat-privacy-notice,
  .chat-emergency-alert,
  .chat-layout {
    width: min(1120px, calc(100% - 150px));
    margin-right: 120px;
    margin-left: auto;
  }
}

@media (max-width: 599px) {
  .chat-privacy-notice,
  .chat-emergency-alert {
    margin-right: 14px;
    margin-left: 14px;
  }

  .chat-layout {
    width: calc(100% - 20px);
    margin-top: 10px;
    border-radius: 16px;
  }

  .chat-sidebar {
    padding: 16px;
  }

  .chat-starters {
    display: flex;
    padding-bottom: 5px;
    overflow-x: auto;
  }

  .chat-starters button {
    flex: 0 0 205px;
  }

  .chat-history {
    max-height: none;
    padding: 16px;
  }

  .chat-message {
    max-width: 96%;
  }

  .chat-answer-section {
    padding: 15px;
  }
}

@media print {
  .doctor-app > main > .screen { display: none !important; }
  .doctor-app > main > #chat-screen { display: block !important; }
  .chat-app-header,
  .chat-sidebar,
  .chat-composer,
  .chat-answer-actions,
  .bottom-nav,
  .chat-error {
    display: none !important;
  }
  .chat-layout {
    display: block;
    width: 100%;
    margin: 0;
    border: 0;
    box-shadow: none;
  }
  .chat-history {
    max-height: none;
    overflow: visible;
  }
}
