:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #17221f;
  background: #eef2f0;
  letter-spacing: 0;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #74ad9f; outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: #64716d; font-size: 13px; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  color: #fff;
  background: #173d35;
  border-bottom: 1px solid #0e2d27;
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 2px; color: #cce0da; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.connection-status { color: #d8e8e3; font-size: 13px; }

.workspace {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  overflow: hidden;
}

.inbox {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border-right: 1px solid #cbd4d1;
  background: #f9fbfa;
}
.section-heading {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #dde4e1;
}
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1, h2 { font-size: 18px; }
h3 { font-size: 15px; }

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  color: inherit;
  background: transparent;
}
.icon-button:hover { border-color: #c7d2ce; background: #edf3f1; }
.icon-button svg { width: 19px; height: 19px; }
.text-button { min-height: 36px; padding: 7px 11px; border: 1px solid #b9cac5; border-radius: 6px; background: transparent; }
.text-button.inverse { color: #fff; border-color: #63877e; }

.inbox-controls { padding: 13px 14px 11px; border-bottom: 1px solid #dde4e1; background: #fff; }
.search-field {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 11px;
  border: 1px solid #aab7b3;
  border-radius: 6px;
  background: #fff;
}
.search-field svg { width: 17px; height: 17px; color: #5d6c67; }
.search-field input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; }
.status-filters { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; margin-top: 10px; }
.filter-button {
  min-height: 34px;
  padding: 5px 4px;
  overflow: hidden;
  border: 1px solid #c9d2cf;
  border-radius: 5px;
  color: #47544f;
  background: #fff;
  font-size: 12px;
  text-overflow: ellipsis;
}
.filter-button:hover { background: #f0f5f3; }
.filter-button.active { color: #fff; border-color: #176b57; background: #176b57; }

.conversation-list { min-height: 0; overflow-y: auto; }
.conversation-item {
  width: 100%;
  min-height: 106px;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid #e2e8e5;
  text-align: left;
  color: inherit;
  background: #fff;
}
.conversation-item:hover { background: #f1f6f4; }
.conversation-item.active { box-shadow: inset 4px 0 #176b57; background: #e7f1ee; }
.conversation-item-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.conversation-item-row strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.conversation-item-row time { flex: 0 0 auto; color: #697671; font-size: 11px; }
.conversation-preview {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: #52615c;
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-badge {
  display: inline-block;
  margin-top: 9px;
  padding: 3px 6px;
  border-radius: 4px;
  color: #41504b;
  background: #e7ecea;
  font-size: 11px;
  font-weight: 700;
}
.status-pending { color: #744c0b; background: #f8e9c8; }
.status-doctor_review_required { color: #842b32; background: #f8dfe1; }
.status-closed { color: #4f5b57; background: #dde3e1; }
.list-empty { padding: 26px 18px; color: #65736e; text-align: center; font-size: 13px; }

.conversation {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #f2f5f3;
}
.conversation-header {
  min-height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid #d7dfdc;
  background: #fff;
}
.conversation-identity { min-width: 0; flex: 1; }
.conversation-identity h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-identity span { display: block; margin-top: 4px; }
.status-control { display: grid; gap: 4px; flex: 0 0 190px; }
.status-control span { color: #5b6964; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.status-control select { height: 38px; padding: 0 32px 0 10px; border: 1px solid #aab7b3; border-radius: 6px; color: #27332f; background: #fff; }
.mobile-back { display: none; }
.reply-shortcut { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; color: #173d35; background: #fff; }
.reply-shortcut svg { width: 17px; height: 17px; }
.reply-shortcut:disabled { cursor: not-allowed; opacity: .5; }

.conversation-body { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 330px); overflow: hidden; }
.chat-column { min-width: 0; min-height: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
.messages { min-height: 0; padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 11px; }
.message {
  width: fit-content;
  max-width: min(680px, 82%);
  padding: 10px 13px;
  border: 1px solid #d3dcd8;
  border-radius: 7px;
  background: #fff;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.message.outbound { align-self: flex-end; color: #fff; border-color: #176b57; background: #176b57; }
.message small { display: block; margin-top: 6px; opacity: .72; font-size: 11px; }
.message-empty { margin: auto; color: #66736f; }
.empty-selection { margin: auto; color: #66736f; text-align: center; }
.empty-selection svg { width: 32px; height: 32px; }

.learning-panel { min-width: 0; overflow-y: auto; border-left: 1px solid #d7dfdc; background: #fff; }
.learning-heading { display: flex; justify-content: space-between; gap: 12px; padding: 17px 16px; border-bottom: 1px solid #e1e7e4; }
.learning-heading .muted { display: block; margin-top: 3px; }
.read-only-label { height: fit-content; padding: 3px 6px; border-radius: 4px; color: #4a5a55; background: #e6ece9; font-size: 10px; font-weight: 700; white-space: nowrap; }
.learning-examples { padding: 0 16px; }
.learning-example { padding: 15px 0; border-bottom: 1px solid #e4e9e7; }
.learning-example strong { display: block; color: #3f4e49; font-size: 11px; text-transform: uppercase; }
.learning-example p { margin: 5px 0 13px; color: #25322e; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }
.learning-example p:last-child { margin-bottom: 0; }
.learning-empty { color: #65736e; font-size: 13px; line-height: 1.5; }

.reply-composer {
  min-height: 126px;
  display: grid;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid #d4ddda;
  background: #fff;
  box-shadow: 0 -4px 14px rgb(20 52 44 / 8%);
}
.composer-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.composer-heading strong { font-size: 13px; }
.composer-tools { position: relative; display: flex; align-items: center; gap: 6px; }
.composer-tool { color: #173d35; }
.composer-tool.text-button { display: inline-flex; align-items: center; gap: 7px; }
.composer-tool svg { width: 17px; height: 17px; }
.composer-popover {
  position: absolute;
  left: 0;
  bottom: calc(100% + 7px);
  z-index: 30;
  max-width: min(430px, calc(100vw - 48px));
  padding: 8px;
  border: 1px solid #c7d2ce;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgb(20 52 44 / 16%);
}
.emoji-picker { display: grid; grid-template-columns: repeat(8, 34px); gap: 3px; }
.emoji-button { width: 34px; height: 34px; border: 0; border-radius: 4px; background: transparent; font-size: 20px; }
.emoji-button:hover { background: #edf3f1; }
.quick-replies { width: min(430px, calc(100vw - 48px)); max-height: 280px; overflow-y: auto; }
.quick-reply-button { width: 100%; display: grid; gap: 3px; padding: 9px 10px; border: 0; border-radius: 4px; text-align: left; background: transparent; }
.quick-reply-button:hover { background: #edf3f1; }
.quick-reply-button strong { font-size: 13px; }
.quick-reply-button span { color: #52615c; font-size: 12px; line-height: 1.35; }
.composer-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; }
.composer-row textarea {
  width: 100%;
  min-height: 48px;
  max-height: 120px;
  resize: vertical;
  padding: 10px 11px;
  border: 1px solid #aab7b3;
  border-radius: 6px;
  color: #1d2925;
  background: #fff;
  font: inherit;
  line-height: 1.4;
}
.composer-row textarea:focus { outline: 2px solid #8abbb0; outline-offset: 1px; }
.send-button {
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: #176b57;
  font-weight: 700;
}
.send-button svg { width: 17px; height: 17px; }
.send-button:disabled, .composer-row textarea:disabled { cursor: not-allowed; opacity: .55; }

.primary-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: #176b57;
  font-weight: 700;
}
.primary-button svg { width: 18px; height: 18px; }
.login { width: min(390px, calc(100% - 32px)); margin: 12vh auto; padding: 28px; border: 1px solid #d0d9d6; border-radius: 8px; background: #fff; }
.login-mark { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 6px; color: #fff; background: #176b57; }
.login-mark svg { width: 22px; height: 22px; }
.login p { color: #52635e; }
.error { min-height: 20px; color: #a22f2f !important; font-size: 13px; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: minmax(300px, 350px) minmax(0, 1fr); }
  .conversation-body { grid-template-columns: 1fr; }
  .learning-panel { max-height: 38vh; border-top: 1px solid #d7dfdc; border-left: 0; }
}

@media (max-width: 760px) {
  .topbar { height: 58px; padding: 0 13px; }
  .brand strong { font-size: 14px; }
  .connection-status { display: none; }
  .workspace { height: calc(100vh - 58px); grid-template-columns: 1fr; }
  .inbox, .conversation { grid-column: 1; grid-row: 1; }
  .conversation { display: none; }
  .workspace.conversation-selected .inbox { display: none; }
  .workspace.conversation-selected .conversation { display: grid; }
  .mobile-back { display: inline-grid; }
  .conversation-header { padding: 10px 12px; }
  .status-control { flex-basis: 145px; }
  .status-control select { width: 145px; }
  .status-filters { overflow-x: auto; grid-template-columns: repeat(5, minmax(78px, 1fr)); }
  .messages { padding: 14px; }
  .message { max-width: 90%; }
  .learning-panel { max-height: 34vh; }
  .reply-composer { padding: 10px 12px; }
  .quick-replies { width: min(390px, calc(100vw - 32px)); }
}

@media (max-width: 430px) {
  .conversation-header { align-items: flex-start; flex-wrap: wrap; }
  .conversation-identity { width: calc(100% - 50px); }
  .status-control { width: calc(100% - 50px); flex: 0 0 calc(100% - 50px); margin-left: 50px; }
  .status-control select { width: 100%; }
  .reply-shortcut { margin-left: 50px; }
}
