/* ===== 基础变量 ===== */
:root {
  --primary: #2B6CB0;
  --primary-light: #EBF4FF;
  --primary-dark: #1A4971;
  --success: #38A169;
  --warning: #D69E2E;
  --danger: #E53E3E;
  --bg: #F7F8FC;
  --white: #FFFFFF;
  --text: #1A202C;
  --text-secondary: #718096;
  --text-light: #A0AEC0;
  --border: #E2E8F0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ===== Header ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  height: 56px;
}

.header-inner {
  max-width: 768px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.logo-icon { font-size: 24px; }
.logo-text { font-size: 18px; font-weight: 700; color: var(--primary); }

.header-actions { display: flex; gap: 12px; }

.btn-icon {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-size: 20px;
  color: var(--text);
}
.btn-icon small { font-size: 10px; color: var(--text-secondary); }

.sub-header { transition: transform 0.3s; }

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text);
  display: flex;
  align-items: center;
}

.sub-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  text-align: center;
}

/* ===== Main ===== */
.main {
  max-width: 768px;
  margin: 0 auto;
  padding-top: 56px;
  min-height: 100vh;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.page { display: none; }
.page.active { display: block; animation: fadeIn 0.25s ease; }

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

/* ===== 搜索栏 ===== */
.search-section { padding: 12px 16px; }

.search-box {
  background: var(--white);
  border-radius: 24px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.search-placeholder { color: var(--text-light); font-size: 14px; }
.search-icon { flex-shrink: 0; }

/* ===== 城市Tab ===== */
.city-section {
  padding: 0 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.city-section::-webkit-scrollbar { display: none; }

.city-tabs {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.city-tab {
  padding: 6px 18px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.city-tab.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* ===== 快捷入口 ===== */
.quick-entry {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 4px 16px 16px;
}

.quick-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.quick-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.quick-item span { font-size: 12px; color: var(--text-secondary); }

/* ===== Section ===== */
.section {
  padding: 0 16px 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h2 { font-size: 16px; font-weight: 600; }

.section-more {
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
}

/* ===== 医院卡片 ===== */
.hospital-list { display: flex; flex-direction: column; gap: 10px; }

.hospital-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.hospital-card:active {
  transform: scale(0.98);
}

.hospital-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.hospital-name {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hospital-level {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  margin-left: 8px;
}

.level-sanjia { background: #FFF5F5; color: #E53E3E; }
.level-sanyi { background: #FEFCBF; color: #D69E2E; }
.level-erjia { background: #EBF4FF; color: #2B6CB0; }
.level-default { background: #F0FFF4; color: #38A169; }

.hospital-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.hospital-meta span { display: flex; align-items: center; gap: 4px; }

.hospital-address {
  font-size: 13px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== 症状标签 ===== */
.symptom-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.symptom-tag {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--white);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
}

.symptom-tag:active, .symptom-tag.selected {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== 搜索页 ===== */
.search-bar-fixed {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--white);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.search-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border-radius: 24px;
  padding: 8px 14px;
}

.search-input {
  flex: 1;
  border: none;
  background: none;
  font-size: 14px;
  outline: none;
  color: var(--text);
}

.search-clear {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
}

.search-btn {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.search-filters {
  padding: 8px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--border);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label { font-size: 13px; color: var(--text-secondary); white-space: nowrap; }

.filter-options { display: flex; gap: 6px; flex-wrap: wrap; }

.filter-btn {
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn.active {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

/* ===== 医院详情 ===== */
.detail-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  margin: 12px 16px;
  box-shadow: var(--shadow);
}

.detail-name {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.4;
}

.detail-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.detail-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.detail-badge.level { background: #FFF5F5; color: #E53E3E; }
.detail-badge.type { background: #EBF4FF; color: #2B6CB0; }
.detail-badge.category { background: #F0FFF4; color: #38A169; }

.detail-info {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-info-item {
  display: flex;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
  align-items: flex-start;
}

.detail-info-item .label {
  color: var(--text-light);
  min-width: 50px;
  flex-shrink: 0;
}

.detail-info-item .value {
  color: var(--text);
  word-break: break-all;
}

.detail-info-item a {
  color: var(--primary);
  text-decoration: none;
}

.detail-intro {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  margin-top: 12px;
}

.dept-section-title {
  font-size: 16px;
  font-weight: 600;
  padding: 16px 16px 12px;
}

.dept-list {
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dept-item {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dept-name { font-size: 14px; font-weight: 500; }

.dept-location {
  font-size: 12px;
  color: var(--text-light);
}

/* ===== 科室页 ===== */
.dept-tree {
  padding: 12px 16px;
}

.dept-group {
  margin-bottom: 16px;
}

.dept-group-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--primary);
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.dept-children {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dept-child {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--white);
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.dept-child:active { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ===== 智能分诊 ===== */
.triage-container { padding: 16px; }

.triage-step { display: none; }
.triage-step.active { display: block; animation: fadeIn 0.3s ease; }

.triage-header {
  text-align: center;
  padding: 20px 0;
}

.triage-icon { font-size: 48px; margin-bottom: 12px; }

.triage-header h2 { font-size: 20px; margin-bottom: 8px; }
.triage-header p { color: var(--text-secondary); font-size: 14px; }

.triage-input-section { margin-top: 20px; }

.triage-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

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

.triage-quick {
  margin-top: 24px;
  text-align: left;
}

.triage-quick-title {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.guide-questions {
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guide-question {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.guide-question-text {
  font-size: 15px;
  font-weight: 500;
  margin-bottom: 12px;
}

.guide-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.guide-option {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--white);
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.guide-option:active, .guide-option.selected {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.guide-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  margin-top: 4px;
}

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

/* 分诊结果 */
.triage-result { text-align: left; }

.result-section {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.result-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-dept-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.result-dept-item:last-child { border-bottom: none; }

.dept-rank {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.dept-rank.rank-1 { background: #FFF5F5; color: #E53E3E; }
.dept-rank.rank-2 { background: #FEFCBF; color: #D69E2E; }
.dept-rank.rank-3 { background: #EBF4FF; color: #2B6CB0; }
.dept-rank.rank-n { background: var(--bg); color: var(--text-secondary); }

.result-dept-name { font-size: 15px; font-weight: 500; }

.result-reason {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.result-hospitals {
  margin-top: 8px;
}

.result-hospital-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
}

.result-hospital-item:active { background: var(--primary-light); }

.result-hospital-name { font-size: 14px; font-weight: 500; flex: 1; }

.result-hospital-level {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #FFF5F5;
  color: #E53E3E;
}

.result-advice {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.result-warning {
  background: #FFF5F5;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
  font-size: 13px;
  color: #E53E3E;
  line-height: 1.6;
}

.triage-actions { margin-top: 16px; }

/* ===== 按钮 ===== */
.btn-primary {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-primary:active { background: var(--primary-dark); transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-outline {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-outline:active { background: var(--primary-light); }

.btn-block { display: block; width: 100%; }

/* ===== Loading ===== */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Empty ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75);
  color: var(--white);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* ===== 响应式 ===== */
@media (min-width: 768px) {
  .main { padding-top: 56px; }
  .hospital-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

@media (max-width: 360px) {
  .quick-entry { gap: 8px; }
  .quick-icon { width: 42px; height: 42px; font-size: 20px; }
}
