/* ============================================
   DDI智能体微信小程序 - 全局样式
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  color: #333; background: #f5f7fa; line-height: 1.6;
  max-width: 720px; margin: 0 auto; min-height: 100vh;
  position: relative; overflow-x: hidden;
  box-shadow: 0 0 36px rgba(17, 24, 39, 0.08);
}
a { color: #2e75b6; text-decoration: none; }
img { max-width: 100%; display: block; }
input, textarea, select, button { font-family: inherit; font-size: inherit; }
button { color: inherit; }
ul, ol { list-style: none; }

/* --- Color Variables --- */
:root {
  --primary: #1F6FEB;
  --primary-light: #E8F0FE;
  --primary-dark: #1557B0;
  --success: #2DA44E;
  --success-light: #E6F9ED;
  --warning: #F5A623;
  --warning-light: #FFF8E6;
  --danger: #E53E3E;
  --danger-light: #FEE8E8;
  --info: #5B9BD5;
  --text-primary: #1a1a1a;
  --text-secondary: #475467;
  --text-hint: #667085;
  --border: #e5e7eb;
  --bg-page: #f5f7fa;
  --bg-card: #fff;
  --bg-section: #f0f3f7;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.1);
}

/* --- Page Layout --- */
.page { min-height: 100vh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); background: var(--bg-page); }
.page-with-nav { padding-top: 56px; }
.page-content { padding: 16px; }

/* --- Navigation Bar --- */
.navbar {
  position: fixed; top: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 720px; height: 56px; z-index: 100;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; padding: 0 16px;
}
.navbar-back { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; background: transparent; border: 0; border-radius: 8px; }
.navbar-back svg { width: 20px; height: 20px; fill: #fff; }
.navbar-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; }
.navbar-action { width: 32px; flex-shrink: 0; }

/* --- Bottom Tab Bar --- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 720px; min-height: 64px; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
}
.tabbar-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  cursor: pointer; padding: 6px 0; flex: 1; transition: color .2s;
  color: var(--text-hint); font-size: 10px;
  background: transparent; border: 0; min-height: 52px;
}
.tabbar-item.active { color: var(--primary); }
.tabbar-item svg { width: 24px; height: 24px; }
.tabbar-item span { font-size: 10px; }

/* --- Cards --- */
.card {
  background: var(--bg-card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 12px; overflow: hidden;
}
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.card-body { padding: 16px; }
.card-footer { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-section); }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm); border: none;
  font-size: 15px; font-weight: 500; cursor: pointer; transition: all .2s;
  text-align: center; line-height: 1.4;
}
.btn-block { display: flex; width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--primary); color: var(--primary); }
.btn-outline:active { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 6px; }
.btn-lg { padding: 14px 28px; font-size: 17px; border-radius: var(--radius); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible, .navbar-back:focus-visible, .tabbar-item:focus-visible,
.role-card:focus-visible, .chip:focus-visible, input:focus-visible,
textarea:focus-visible, select:focus-visible, a:focus-visible, [role="button"]:focus-visible {
  outline: 3px solid rgba(31,111,235,0.35); outline-offset: 2px;
}

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 14px; font-weight: 500;
  color: var(--text-primary); margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; color: var(--text-primary);
  background: #fff; transition: border-color .2s; outline: none;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31,111,235,0.1);
}
.form-input::placeholder { color: var(--text-hint); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--text-hint); margin-top: 4px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* --- Search Bar --- */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--border); border-radius: 24px;
  padding: 8px 16px; margin-bottom: 12px;
}
.search-bar svg { width: 18px; height: 18px; fill: var(--text-hint); flex-shrink: 0; }
.search-bar input {
  flex: 1; border: none; outline: none; font-size: 15px;
  background: transparent; color: var(--text-primary);
}
.search-bar input::placeholder { color: var(--text-hint); }

/* --- Tags & Badges --- */
.tag {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border-radius: 12px; font-size: 12px; font-weight: 500;
}
.tag-danger { background: var(--danger-light); color: var(--danger); }
.tag-warning { background: var(--warning-light); color: #B87A00; }
.tag-success { background: var(--success-light); color: var(--success); }
.tag-info { background: var(--primary-light); color: var(--primary); }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 600;
}

/* --- Risk Level Indicators --- */
.risk-high { color: var(--danger); }
.risk-medium { color: var(--warning); }
.risk-low { color: var(--success); }
.risk-dot {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px;
}
.risk-dot-high { background: var(--danger); }
.risk-dot-medium { background: var(--warning); }
.risk-dot-low { background: var(--success); }

/* --- List Items --- */
.list-item {
  display: flex; align-items: center; padding: 14px 16px;
  background: #fff; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .15s;
}
.list-item:active { background: #f5f5f5; }
.list-item:last-child { border-bottom: none; }
.list-item-icon {
  width: 40px; height: 40px; border-radius: 10px; margin-right: 12px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-size: 15px; color: var(--text-primary); font-weight: 500; }
.list-item-desc { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.list-item-arrow { width: 16px; height: 16px; fill: var(--text-hint); flex-shrink: 0; margin-left: 8px; }
.list-item-extra { font-size: 13px; color: var(--text-hint); flex-shrink: 0; margin-left: 8px; }

/* --- Section Headers --- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 10px; margin-bottom: 4px;
}
.section-header h2 { font-size: 17px; font-weight: 600; color: var(--text-primary); }
.section-header .more { font-size: 13px; color: var(--text-hint); cursor: pointer; }

/* --- Grid --- */
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* --- Feature Entries (Home) --- */
.feature-card {
  background: #fff; border-radius: var(--radius); padding: 20px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .2s;
}
.feature-card:active { transform: scale(0.97); }
.feature-icon {
  width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.feature-card .name { font-size: 13px; color: var(--text-primary); font-weight: 500; text-align: center; }

/* --- Stats Row --- */
.stats-row { display: flex; gap: 10px; margin-bottom: 16px; }
.stat-card {
  flex: 1; background: #fff; border-radius: var(--radius-sm);
  padding: 14px 10px; text-align: center; box-shadow: var(--shadow);
}
.stat-card .num { font-size: 24px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

/* --- Modal / Popup --- */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,0.5); align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 85%; max-width: 360px;
  overflow: hidden; animation: modalIn .25s ease;
}
@keyframes modalIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header { padding: 20px 20px 0; text-align: center; }
.modal-header h3 { font-size: 17px; font-weight: 600; }
.modal-body { padding: 16px 20px; font-size: 14px; color: var(--text-secondary); text-align: center; line-height: 1.7; }
.modal-footer { display: flex; border-top: 1px solid var(--border); }
.modal-footer .btn { flex: 1; border-radius: 0; padding: 14px; font-size: 16px; }
.modal-footer .btn + .btn { border-left: 1px solid var(--border); }

/* --- Alert Banner (Risk) --- */
.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 12px;
  font-size: 14px; line-height: 1.5;
}
.alert-danger { background: var(--danger-light); color: #9B1C1C; }
.alert-warning { background: var(--warning-light); color: #92400E; }
.alert-success { background: var(--success-light); color: #065F46; }
.alert-info { background: var(--primary-light); color: #1E40AF; }
.alert-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

/* --- DDI Matrix Table --- */
.matrix-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.matrix-table th, .matrix-table td {
  padding: 8px 4px; text-align: center; border: 1px solid var(--border);
}
.matrix-table th { background: var(--bg-section); font-weight: 600; font-size: 11px; color: var(--text-secondary); }
.matrix-table .cell-high { background: #FEE2E2; cursor: pointer; }
.matrix-table .cell-medium { background: #FEF3C7; cursor: pointer; }
.matrix-table .cell-low { background: #D1FAE5; cursor: pointer; }
.matrix-table .cell-none { background: #F9FAFB; }
.matrix-table .cell-self { background: #E5E7EB; }

/* --- Accordion / Collapsible --- */
.accordion { border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 8px; background: #fff; }
.accordion-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; cursor: pointer; transition: background .15s;
}
.accordion-header:active { background: #f5f5f5; }
.accordion-arrow { width: 16px; height: 16px; fill: var(--text-hint); transition: transform .25s; }
.accordion.open .accordion-arrow { transform: rotate(180deg); }
.accordion-body { max-height: 0; overflow: hidden; transition: max-height .3s ease; }
.accordion.open .accordion-body { max-height: 600px; }
.accordion-content { padding: 0 16px 16px; font-size: 14px; color: var(--text-secondary); line-height: 1.7; }

/* --- Drug Item --- */
.drug-item {
  display: flex; align-items: center; padding: 12px 16px;
  background: #fff; border-bottom: 1px solid var(--border);
}
.drug-item-info { flex: 1; }
.drug-item-name { font-size: 15px; font-weight: 500; color: var(--text-primary); }
.drug-item-meta { font-size: 12px; color: var(--text-hint); margin-top: 2px; }
.drug-item-actions { display: flex; gap: 8px; align-items: center; }
.drug-item-remove {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: var(--danger-light); color: var(--danger); cursor: pointer;
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}

/* --- Upload Area --- */
.upload-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 40px 20px; text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s; background: #FAFBFC;
}
.upload-area:active { border-color: var(--primary); background: var(--primary-light); }
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-text { font-size: 15px; color: var(--text-secondary); }
.upload-hint { font-size: 12px; color: var(--text-hint); margin-top: 6px; }

/* --- Progress Steps --- */
.steps { display: flex; align-items: center; padding: 16px 0; }
.step {
  display: flex; flex-direction: column; align-items: center; flex: 1; position: relative;
}
.step-num {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; color: var(--text-hint); background: #fff;
  position: relative; z-index: 1;
}
.step.active .step-num { border-color: var(--primary); color: #fff; background: var(--primary); }
.step.done .step-num { border-color: var(--success); color: #fff; background: var(--success); }
.step-label { font-size: 11px; color: var(--text-hint); margin-top: 4px; text-align: center; }
.step.active .step-label { color: var(--primary); font-weight: 500; }
.step.done .step-label { color: var(--success); }
.step-line {
  position: absolute; top: 14px; left: 50%; width: 100%;
  height: 2px; background: var(--border); z-index: 0;
}
.step:last-child .step-line { display: none; }
.step.done .step-line { background: var(--success); }

/* --- Chip / Selector --- */
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  font-size: 13px; color: var(--text-secondary); cursor: pointer;
  transition: all .2s; background: #fff;
}
.chip.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.chip:active { transform: scale(0.96); }

/* --- Score Display --- */
.score-circle {
  width: 100px; height: 100px; border-radius: 50%; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 4px solid var(--border);
}
.score-circle.high { border-color: var(--danger); }
.score-circle.medium { border-color: var(--warning); }
.score-circle.low { border-color: var(--success); }
.score-value { font-size: 28px; font-weight: 700; line-height: 1; }
.score-label { font-size: 11px; color: var(--text-hint); margin-top: 2px; }

/* --- Toast --- */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.75); color: #fff; padding: 12px 24px;
  border-radius: var(--radius-sm); font-size: 14px; z-index: 999;
  display: none; animation: fadeIn .2s;
}
.toast.show { display: block; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* --- Loading --- */
.loading { display: flex; align-items: center; 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 .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Empty State --- */
.empty { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-text { font-size: 15px; color: var(--text-hint); }

/* --- Divider --- */
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.divider-text {
  display: flex; align-items: center; gap: 12px; color: var(--text-hint);
  font-size: 13px; margin: 16px 0;
}
.divider-text::before, .divider-text::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* --- Swipe Action (Drug List) --- */
.swipe-container { position: relative; overflow: hidden; }
.swipe-actions {
  position: absolute; right: 0; top: 0; bottom: 0;
  display: flex; align-items: stretch; transform: translateX(100%);
  transition: transform .3s;
}
.swipe-container.swiped .swipe-actions { transform: translateX(0); }

/* --- Role Selector --- */
.role-card {
  background: #fff; border: 2px solid var(--border); border-radius: var(--radius);
  padding: 24px 16px; text-align: center; cursor: pointer; transition: all .2s;
  width: 100%;
}
.role-card:active { transform: scale(0.97); }
.role-card.selected { border-color: var(--primary); background: var(--primary-light); }
.role-icon { font-size: 40px; margin-bottom: 8px; }
.role-name { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.role-desc { font-size: 12px; color: var(--text-hint); margin-top: 4px; }

/* --- Banner --- */
.banner {
  background: linear-gradient(135deg, #1F6FEB 0%, #4A9CF5 100%);
  border-radius: var(--radius); padding: 20px; color: #fff; margin-bottom: 16px;
}
.banner h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.banner p { font-size: 13px; opacity: 0.85; }

/* --- Floating Action Button --- */
.fab {
  position: fixed; bottom: 80px; right: 20px; z-index: 50;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  box-shadow: var(--shadow-lg); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; transition: transform .2s;
}
.fab:active { transform: scale(0.92); }

/* --- Scale Item (CGA) --- */
.scale-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.scale-question { font-size: 14px; color: var(--text-primary); margin-bottom: 8px; font-weight: 500; }
.scale-options { display: flex; flex-wrap: wrap; gap: 6px; }
.scale-option {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; cursor: pointer; transition: all .2s; background: #fff;
}
.scale-option.selected { background: var(--primary); color: #fff; border-color: var(--primary); }

/* --- Report Section --- */
.report-section { margin-bottom: 20px; }
.report-section-title {
  font-size: 15px; font-weight: 600; color: var(--primary);
  padding-bottom: 8px; border-bottom: 2px solid var(--primary); margin-bottom: 12px;
}

/* --- Feedback Buttons --- */
.feedback-group { display: flex; gap: 8px; margin-top: 12px; }
.feedback-btn {
  flex: 1; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; font-size: 13px; cursor: pointer; text-align: center; transition: all .2s;
}
.feedback-btn:active { background: #f0f0f0; }
.feedback-btn.selected-accept { border-color: var(--success); background: var(--success-light); color: var(--success); }
.feedback-btn.selected-ignore { border-color: var(--warning); background: var(--warning-light); color: #B87A00; }
.feedback-btn.selected-false { border-color: var(--danger); background: var(--danger-light); color: var(--danger); }

.text-link {
  appearance: none; border: 0; padding: 2px; background: transparent;
  color: var(--primary); cursor: pointer; font-size: inherit;
}

@media (hover: hover) {
  .btn:not(:disabled):hover, .feature-card:hover, .role-card:hover { transform: translateY(-1px); }
  .navbar-back:hover, .tabbar-item:hover { background: rgba(255,255,255,0.12); }
  .tabbar-item:hover { color: var(--primary); }
}

@media (max-width: 380px) {
  .page-content { padding-left: 12px; padding-right: 12px; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .form-row { flex-direction: column; gap: 0; }
  .stats-row { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (min-width: 640px) {
  .page-content { padding: 24px; }
  .card { margin-bottom: 16px; }
  .modal { max-width: 440px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-hint { color: var(--text-hint); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.fw-600 { font-weight: 600; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.p-16 { padding: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
