:root {
  --cw-bg: #f6f3ec;
  --cw-paper: #fffdf9;
  --cw-line: #ded8ca;
  --cw-text: #2c261f;
  --cw-muted: #6e665c;
  --cw-primary: #2d6a4f;
  --cw-primary-dark: #1f4f3a;
  --cw-me-bg: #e1efe6;
  --cw-me-border: #bfd9c9;
  --cw-assist-bg: #faf6ed;
  --cw-assist-border: #e4dccb;
  --cw-danger: #b42318;
  --cw-danger-bg: #fef3f2;
  --cw-danger-border: #fecdca;
  --cw-composer-h: 78px;
  --cw-kb-offset: 0px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--cw-bg);
  color: var(--cw-text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}

button,
textarea,
input {
  font: inherit;
}

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

.cw-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--cw-composer-h) + var(--cw-kb-offset) + env(safe-area-inset-bottom, 0px) + 22px);
}

.cw-read-only .cw-main {
  padding-bottom: 22px;
}

.cw-intro {
  background: var(--cw-paper);
  border: 1px solid var(--cw-line);
  border-radius: 14px;
  padding: 16px 16px 14px;
  margin-bottom: 16px;
  box-shadow: 0 4px 14px rgba(44, 38, 31, 0.04);
}

.cw-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.cw-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--cw-text);
}

.cw-status {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(45, 106, 79, 0.1);
  color: var(--cw-primary-dark);
  font-size: 12px;
  font-weight: 600;
}

.cw-desc {
  margin: 10px 0 8px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--cw-text);
}

.cw-disclaimer {
  margin: 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--cw-danger-bg);
  border: 1px solid var(--cw-danger-border);
  font-size: 13px;
  line-height: 1.55;
  color: #7a271a;
}

.cw-urgent {
  color: var(--cw-danger);
  font-weight: 600;
}

.cw-quick-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.cw-quick-form {
  margin: 0;
}

.cw-quick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid rgba(45, 106, 79, 0.35);
  background: #fff;
  color: var(--cw-primary-dark);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.cw-quick-btn:hover {
  background: rgba(45, 106, 79, 0.08);
  border-color: var(--cw-primary);
}

.cw-quick-btn:active {
  background: rgba(45, 106, 79, 0.14);
}

.cw-quick-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.cw-chat-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cw-empty {
  margin: 28px 0;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
  color: var(--cw-muted);
}

.cw-row {
  display: flex;
  width: 100%;
}

.cw-row.cw-from-me {
  justify-content: flex-end;
}

.cw-row.cw-from-doctor,
.cw-row.cw-from-assistant {
  justify-content: flex-start;
}

.cw-bubble {
  max-width: min(86%, 560px);
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.6;
  box-shadow: 0 2px 6px rgba(44, 38, 31, 0.04);
}

.cw-from-me .cw-bubble {
  background: var(--cw-me-bg);
  border: 1px solid var(--cw-me-border);
  border-bottom-right-radius: 4px;
}

.cw-from-assistant .cw-bubble {
  background: var(--cw-assist-bg);
  border: 1px solid var(--cw-assist-border);
  border-bottom-left-radius: 4px;
}

.cw-from-doctor .cw-bubble {
  background: #ffffff;
  border: 1px solid rgba(45, 106, 79, 0.28);
  border-left: 4px solid var(--cw-primary);
  border-bottom-left-radius: 4px;
}

.cw-bubble-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  font-size: 12px;
  line-height: 1.3;
}

.cw-role-tag {
  font-weight: 600;
  color: var(--cw-muted);
}

.cw-from-doctor .cw-role-tag {
  color: var(--cw-primary-dark);
}

.cw-from-me .cw-role-tag {
  color: #2b543f;
}

.cw-time {
  color: var(--cw-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.cw-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: var(--cw-text);
}

.cw-img-link {
  display: inline-block;
  margin-top: 6px;
  max-width: 100%;
}

.cw-bubble-text + .cw-img-link {
  margin-top: 8px;
}

.cw-bubble-img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  border: 1px solid rgba(44, 38, 31, 0.1);
  background: #f2efe8;
}

.cw-new-pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--cw-composer-h) + var(--cw-kb-offset) + env(safe-area-inset-bottom, 0px) + 10px);
  z-index: 15;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  background: var(--cw-primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(31, 79, 58, 0.25);
  cursor: pointer;
}

.cw-new-pill:active {
  background: var(--cw-primary-dark);
}

.cw-composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--cw-kb-offset);
  z-index: 20;
  background: rgba(255, 253, 249, 0.97);
  border-top: 1px solid var(--cw-line);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  backdrop-filter: blur(8px);
}

.cw-kb-open .cw-composer {
  padding-bottom: 8px;
}

.cw-composer-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cw-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  background: #fff8eb;
  border: 1px solid #f2d29b;
  color: #7a4508;
  font-size: 13px;
  line-height: 1.45;
}

.cw-alert.cw-alert-error {
  background: var(--cw-danger-bg);
  border-color: var(--cw-danger-border);
  color: var(--cw-danger);
}

.cw-alert-text {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.cw-alert-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cw-alert-btn {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid currentColor;
  background: #fff;
  color: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.cw-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--cw-bg);
  border: 1px solid var(--cw-line);
  font-size: 13px;
}

.cw-attachment-thumb {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--cw-line);
  flex-shrink: 0;
}

.cw-attachment-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--cw-text);
}

.cw-attachment-remove {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid var(--cw-line);
  background: #fff;
  color: var(--cw-muted);
  font-size: 12px;
  cursor: pointer;
}

.cw-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
}

.cw-attach-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid var(--cw-line);
  background: #fff;
  color: var(--cw-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

.cw-attach-btn.cw-disabled {
  opacity: 0.55;
  pointer-events: none;
}

.cw-textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 132px;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--cw-line);
  background: #fff;
  color: var(--cw-text);
  font-size: 16px; /* >=16px 防止手机聚焦自动放大 */
  line-height: 1.4;
  resize: none;
  outline: none;
}

.cw-textarea:focus {
  border-color: var(--cw-primary);
  box-shadow: 0 0 0 2px rgba(45, 106, 79, 0.16);
}

.cw-send-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-width: 64px;
  padding: 0 15px;
  border: none;
  border-radius: 9px;
  background: var(--cw-primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.cw-send-btn:hover {
  background: var(--cw-primary-dark);
}

.cw-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.cw-file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.cw-noscript-media {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--cw-line);
}

@media (max-width: 480px) {
  .cw-main {
    padding-left: 10px;
    padding-right: 10px;
  }
  .cw-intro {
    padding: 14px 13px 12px;
  }
  .cw-bubble {
    max-width: 90%;
  }
}
