/* ===== 全局样式 ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #4A90D9;
  --primary-dark: #3A7BC8;
  --success: #27AE60;
  --danger: #E74C3C;
  --warning: #F39C12;
  --bg: #F0F4F8;
  --bg-white: #FFFFFF;
  --text: #2C3E50;
  --text-secondary: #7F8C8D;
  --text-light: #BDC3C7;
  --border: #E0E6ED;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ===== 病例选择遮罩 ===== */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 24px;
}

.overlay-content {
  width: 100%;
  max-width: 720px;
  text-align: center;
}

.overlay-header {
  color: white;
  margin-bottom: 32px;
}

.overlay-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.overlay-header p {
  font-size: 1.05rem;
  opacity: 0.9;
}

.case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.case-card {
  background: var(--bg-white);
  border-radius: var(--radius);
  padding: 24px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: left;
  box-shadow: var(--shadow);
}

.case-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
}

.case-card:active {
  transform: translateY(-1px);
}

.case-card .card-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.case-card .card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

.case-card .card-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
  line-height: 1.4;
}

.case-card .card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.case-card .badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-easy { background: #E8F5E9; color: #2E7D32; }
.badge-medium { background: #FFF3E0; color: #E65100; }
.badge-hard { background: #FFEBEE; color: #C62828; }

.loading {
  grid-column: 1 / -1;
  padding: 40px;
  color: white;
  font-size: 1rem;
}

/* ===== 主应用 ===== */
.app-container {
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
  background: var(--bg-white);
  box-shadow: var(--shadow-lg);
  position: relative;
  transition: background-image 0.5s ease;
}

/* 背景图片时加半透明遮罩 */
.app-container[style*="url"]::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 0;
  pointer-events: none;
}

/* 有背景时内容置顶 */
.app-container[style*="url"] > * {
  position: relative;
  z-index: 1;
}

.app-container[style*="url"] .chat-area {
  background: transparent;
}

.app-container[style*="url"] .message.patient .message-bubble {
  background: rgba(240,244,248,0.75);
}

.app-container[style*="url"] .message.doctor .message-bubble {
  background: rgba(74,144,217,0.85);
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-back {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-back:hover {
  background: var(--bg);
  color: var(--text);
}

.topbar-info {
  flex: 1;
  min-width: 0;
}

.case-title {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.case-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-diagnosis {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 500;
  transition: background 0.15s;
}

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

/* ===== 对话区 ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
}

.placeholder-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

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

/* 消息气泡 */
.message {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

.message.doctor {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.patient {
  align-self: flex-start;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.message.doctor .message-avatar {
  background: var(--primary);
}

.message.patient .message-avatar {
  background: #E8F5E9;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.patient .message-bubble {
  background: #F0F4F8;
  color: var(--text);
  border-top-left-radius: 4px;
}

/* 朗读按钮 */
.btn-speaker {
  display: inline-block;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  margin-top: 2px;
  opacity: 0.5;
  transition: opacity 0.15s;
  vertical-align: middle;
}

.btn-speaker:hover {
  opacity: 1;
}

.message.doctor .message-bubble {
  background: var(--primary);
  color: white;
  border-top-right-radius: 4px;
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-light);
  margin-top: 4px;
  padding: 0 4px;
}

.message.doctor .message-time {
  text-align: right;
}

/* 系统消息 */
.message.system {
  align-self: center;
  max-width: 100%;
}

.message.system .message-bubble {
  background: #FFF9E6;
  color: #856404;
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 20px;
  text-align: center;
}

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

/* 正在输入指示器 */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: #F0F4F8;
  border-radius: var(--radius);
  border-top-left-radius: 4px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-light);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== 输入区 ===== */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-voice {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg-white);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.btn-voice:hover {
  background: var(--bg);
  border-color: var(--primary);
}

.btn-voice.recording {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(231, 76, 60, 0); }
}

.input-wrapper {
  flex: 1;
  min-width: 0;
}

.input-wrapper textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  max-height: 120px;
}

.input-wrapper textarea:focus {
  border-color: var(--primary);
}

.input-wrapper textarea:disabled {
  background: #F8F9FA;
  cursor: not-allowed;
}

.btn-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

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

.btn-send:disabled {
  background: var(--text-light);
  cursor: not-allowed;
}

/* ===== 弹窗 ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: var(--bg-white);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
}

.modal-content h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.modal-content p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-content textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.modal-content textarea:focus {
  border-color: var(--primary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.btn-cancel {
  padding: 8px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.btn-cancel:hover { background: var(--bg); }

.btn-submit {
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-submit:hover { background: var(--primary-dark); }
.btn-submit:disabled {
  background: var(--text-light);
  cursor: not-allowed;
}

/* 评价结果 */
.evaluation-result {
  max-width: 700px;
}

.score-circle small {
  font-size: 0.9rem;
  opacity: 0.7;
}

.score-circle {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px auto;
  font-size: 2rem;
  font-weight: 700;
  color: white;
}

.score-high { background: var(--success); }
.score-medium { background: var(--warning); }
.score-low { background: var(--danger); }

.feedback-section {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.feedback-section h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  color: var(--text);
}

.feedback-section p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

/* 评分明细表 */
.score-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.score-table th {
  background: var(--bg);
  padding: 8px;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
}

.score-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.score-table tr:hover td {
  background: #FAFBFC;
}

.score-table td:first-child {
  white-space: nowrap;
  font-weight: 500;
}

/* ===== Toast 提示 ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
}

.toast-content {
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  text-align: center;
}

.recording-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 500;
}

.recording-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: blink 0.8s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.recording-hint {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 4px;
}

/* ===== 响应式 ===== */
@media (max-width: 600px) {
  .topbar {
    padding: 10px 12px;
    gap: 8px;
  }

  .btn-back {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .btn-diagnosis {
    padding: 6px 12px;
    font-size: 0.8rem;
  }

  .input-area {
    padding: 10px 12px;
    gap: 6px;
  }

  .message {
    max-width: 92%;
  }

  .overlay-header h1 {
    font-size: 1.5rem;
  }

  .case-grid {
    grid-template-columns: 1fr;
  }
}
