/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #00B4A0;
  --primary-light: #E6F7F5;
  --primary-dark: #009688;
  --blue: #007AFF;
  --bg: #F0F4F8;
  --white: #FFFFFF;
  --text: #333333;
  --text-secondary: #999999;
  --text-light: #CCCCCC;
  --border: #E8E8E8;
  --doctor-bubble: #D4F0ED;
  --patient-bubble: #FFFFFF;
  --shadow: 0 -2px 16px rgba(0, 0, 0, 0.08);
  --panel-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --font: 'Noto Sans SC', -apple-system, 'PingFang SC', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: #E8ECF0;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===== Demo Layout ===== */
.demo-wrapper {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 40px;
  min-height: 100vh;
  padding: 24px;
}

.demo-controls {
  width: 280px;
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  position: sticky;
  top: 24px;
}

.demo-controls h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.demo-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.demo-btn {
  width: 100%;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.2s;
}

.demo-btn.primary {
  background: var(--primary);
  color: var(--white);
  font-weight: 500;
}

.demo-btn:hover { opacity: 0.85; }

.demo-tips {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.demo-tips h4 {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.demo-tips ul {
  list-style: none;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.demo-tips li::before {
  content: '·';
  margin-right: 6px;
  color: var(--primary);
}

/* ===== Phone Frame ===== */
.phone-frame {
  width: 390px;
  height: 844px;
  background: var(--bg);
  border-radius: 40px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15), inset 0 0 0 2px #333;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== Status Bar ===== */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 28px 4px;
  background: var(--white);
  font-size: 15px;
  font-weight: 600;
}

.status-icons {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  padding: 8px 16px 12px;
  background: var(--white);
  gap: 8px;
}

.back-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.patient-info {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.patient-name {
  font-size: 17px;
  font-weight: 600;
}

.patient-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

.next-patient {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
}

/* ===== Consultation Banner ===== */
.consult-banner {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 16px 8px;
  padding: 8px 14px;
  background: var(--primary-light);
  border-radius: 20px;
  font-size: 13px;
  color: var(--primary-dark);
}

.banner-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.countdown {
  margin-left: auto;
  font-size: 12px;
}

/* ===== Chat Area ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
  scroll-behavior: smooth;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 16px;
}

.message-group {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.message-group.doctor {
  flex-direction: row-reverse;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FFB6C1, #FF8FAB);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.message-content {
  max-width: 75%;
}

.message-name {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.message-group.doctor .message-name {
  text-align: right;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
}

.message-group.patient .message-bubble {
  background: var(--patient-bubble);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.message-group.doctor .message-bubble {
  background: var(--doctor-bubble);
  border-top-right-radius: 4px;
}

/* ===== Bottom Area ===== */
.bottom-area {
  position: relative;
  background: var(--white);
  flex-shrink: 0;
}

/* 键盘状态 */
.bottom-area.keyboard-down .mock-keyboard { display: none; }
.bottom-area.keyboard-up .mock-keyboard { display: block; }

.bottom-area.keyboard-down .ai-panel {
  max-height: 480px;
}

.bottom-area.keyboard-down #contentAiReply {
  overflow-y: visible;
}

.bottom-area.keyboard-up .ai-panel {
  max-height: 210px;
}

.bottom-area.keyboard-up #contentAiReply {
  overflow-y: auto;
  max-height: 160px;
}

/* ===== AI Floating Panel ===== */
.ai-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  background: var(--white);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--panel-shadow);
  display: flex;
  flex-direction: column;
  z-index: 10;
  animation: slideUp 0.3s ease;
  transition: max-height 0.25s ease;
}

.ai-panel[hidden] { display: none; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.ai-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 0;
  flex-shrink: 0;
}

.ai-panel-tabs {
  display: flex;
  gap: 20px;
}

.tab-btn {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 0 8px;
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s;
}

.tab-btn.active {
  color: var(--primary);
  font-weight: 500;
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
  border-radius: 1px;
}

.tab-icon {
  color: var(--primary);
}

.close-panel {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.tab-content {
  display: none;
  overflow-y: auto;
  flex: 1;
  padding: 0 16px 12px;
}

.tab-content.active { display: block; }

/* ===== AI Reply Items ===== */
.ai-replies-list {
  display: flex;
  flex-direction: column;
}

.ai-reply-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.ai-reply-item:last-child { border-bottom: none; }

.ai-reply-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 10px;
}

.ai-reply-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.feedback-btns {
  display: flex;
  gap: 8px;
}

.feedback-btn {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--text-light);
  transition: color 0.2s;
  display: flex;
  align-items: center;
}

.feedback-btn.active-like { color: var(--primary); }
.feedback-btn.active-dislike { color: #FF6B6B; }

.action-btns {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.btn-edit {
  padding: 5px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--white);
  font-size: 13px;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
}

.btn-send-reply {
  padding: 5px 16px;
  border: none;
  border-radius: 16px;
  background: var(--primary);
  font-size: 13px;
  font-family: var(--font);
  color: var(--white);
  cursor: pointer;
  font-weight: 500;
}

.btn-edit:hover, .btn-send-reply:hover { opacity: 0.85; }

/* ===== Script Tab ===== */
.ai-hint-banner {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.ai-hint-banner span { line-height: 1.5; }

.script-category {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.script-category:last-child { border-bottom: none; }

.script-category:hover { background: rgba(0,180,160,0.03); }

.script-category-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.script-category-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

/* ===== Sug Mode ===== */
.script-sug { padding-top: 4px; }

.sug-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.7;
  cursor: pointer;
  transition: background 0.15s;
}

.sug-item:last-child { border-bottom: none; }

.sug-item:hover { background: rgba(0,180,160,0.04); }

.sug-item .highlight {
  color: var(--primary);
  font-weight: 500;
}

.sug-empty {
  padding: 20px 0;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* ===== Input Bar ===== */
.input-bar {
  padding: 10px 12px 8px;
  background: var(--white);
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 20;
}

.input-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 输入框胶囊 */
.input-capsule {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--white);
  border: 1px solid #DEDEDE;
  border-radius: 8px;
  padding: 10px 12px;
  min-height: 44px;
}

.message-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 80px;
  min-width: 0;
}

.message-input::placeholder { color: var(--text-light); }

.capsule-btn, .toolbar-btn {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.capsule-inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ---- 键盘降下：按钮在输入框内 ---- */
.bottom-area.keyboard-down .input-toolbar { display: none; }
.bottom-area.keyboard-down .capsule-inline-actions { display: flex; }
.bottom-area.keyboard-down .attach-btn-inline { display: flex; }

/* ---- 键盘升起：按钮落到第二行 ---- */
.bottom-area.keyboard-up .input-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 2px;
}

.bottom-area.keyboard-up .capsule-inline-actions { display: none; }
.bottom-area.keyboard-up .attach-btn-inline { display: none; }

.bottom-area.keyboard-up .input-capsule {
  padding: 10px 14px;
}

.toolbar-spacer { flex: 1; }

/* 发送按钮：仅键盘升起且有文字时显示 */
.send-btn {
  padding: 6px 18px;
  border: none;
  border-radius: 18px;
  background: var(--primary);
  color: var(--white);
  font-size: 14px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  display: none;
  transition: opacity 0.2s;
}

.bottom-area.keyboard-up.has-text .send-btn {
  display: block;
}

.send-btn:not(:disabled):hover { opacity: 0.85; }

/* ===== Mock Keyboard ===== */
.mock-keyboard {
  background: #D1D5DB;
  padding: 6px 4px 0;
}

.mock-keyboard[hidden] { display: none; }

.keyboard-suggestions {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px 8px;
  overflow-x: auto;
  position: relative;
}

.keyboard-suggestions span {
  padding: 4px 12px;
  font-size: 16px;
  color: var(--text);
  white-space: nowrap;
  cursor: pointer;
}

.keyboard-dismiss {
  margin-left: auto;
  background: none;
  border: none;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.keyboard-keys { padding: 4px 2px 8px; }

.key-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  margin-bottom: 6px;
}

.key-row.indent { padding: 0 16px; }

.key-row span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 40px;
  background: var(--white);
  border-radius: 6px;
  font-size: 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.2);
  cursor: default;
  user-select: none;
}

.key-wide { min-width: 42px !important; background: #ACB4BC !important; font-size: 14px !important; }
.key-fn { min-width: 42px !important; background: #ACB4BC !important; font-size: 12px !important; }
.key-space { flex: 1; max-width: 180px; font-size: 13px !important; }
.key-send {
  min-width: 56px !important;
  background: var(--blue) !important;
  color: white !important;
  font-size: 14px !important;
  font-weight: 500;
  cursor: pointer;
}

/* ===== Home Indicator ===== */
.home-indicator {
  width: 134px;
  height: 5px;
  background: #333;
  border-radius: 3px;
  margin: 8px auto 6px;
  flex-shrink: 0;
}

/* ===== Edit Modal ===== */
.edit-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-modal[hidden] { display: none; }

.edit-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
}

.edit-modal-content {
  position: relative;
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
}

.edit-modal-content h4 {
  font-size: 16px;
  margin-bottom: 12px;
}

.edit-modal-content textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.edit-modal-content textarea:focus {
  border-color: var(--primary);
}

.edit-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.edit-cancel, .edit-confirm {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  cursor: pointer;
  border: none;
}

.edit-cancel {
  background: var(--bg);
  color: var(--text);
}

.edit-confirm {
  background: var(--primary);
  color: var(--white);
}

/* ===== AI Loading State ===== */
.ai-loading {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 20px 0;
  font-size: 13px;
  color: var(--text-secondary);
  justify-content: center;
}

.loading-dot {
  width: 6px;
  height: 6px;
  background: var(--primary);
  border-radius: 50%;
  animation: loadingPulse 1.2s infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes loadingPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}

.typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--patient-bubble);
  border: 1px solid var(--border);
  border-radius: 12px;
  border-top-left-radius: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* ===== Responsive ===== */
@media (max-width: 800px) {
  .demo-wrapper {
    flex-direction: column;
    align-items: center;
    padding: 16px;
  }

  .demo-controls {
    width: 100%;
    max-width: 390px;
    position: static;
  }

  .phone-frame {
    width: 100%;
    max-width: 390px;
    height: 780px;
  }
}
