:root {
  --primary: #4a90d9;
  --primary-light: #6bb6e8;
  --primary-dark: #357abd;
  --danger: #e85d6d;
  --warning: #f5a623;
  --success: #4ecdc4;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #e0e6ed;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 16px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a2e;
    --card-bg: #16213e;
    --text: #e0e0e0;
    --text-light: #a0a0b0;
    --border: #2a2a4e;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
  }
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  padding-top: max(20px, env(safe-area-inset-top));
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 32px;
}

.header h1 {
  font-size: 20px;
  font-weight: 700;
}

.subtitle {
  font-size: 11px;
  color: var(--text-light);
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-light);
  transition: background 0.3s;
}

.status-badge.active .status-dot {
  background: var(--success);
  animation: pulse 1.5s infinite;
}

.status-badge.crying .status-dot {
  background: var(--danger);
  animation: pulse 0.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.3); }
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 80px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 16px;
}

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

.card-header .card-title {
  margin-bottom: 0;
}

/* Monitor Card */
.monitor-card {
  text-align: center;
}

.monitor-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 48px;
  border: none;
  border-radius: 50%;
  width: 140px;
  height: 140px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 25px rgba(74,144,217,0.4);
  transition: all 0.3s;
  margin: 8px auto;
}

.monitor-btn:active {
  transform: scale(0.95);
}

.monitor-btn.recording {
  background: linear-gradient(135deg, var(--danger), #c62828);
  box-shadow: 0 8px 25px rgba(232,93,109,0.4);
  animation: record-pulse 2s infinite;
}

@keyframes record-pulse {
  0%, 100% { box-shadow: 0 8px 25px rgba(232,93,109,0.4); }
  50% { box-shadow: 0 8px 35px rgba(232,93,109,0.7); }
}

.btn-icon {
  font-size: 36px;
}

.btn-text {
  font-size: 14px;
}

/* Audio Meter */
.audio-meter-container {
  margin-top: 20px;
}

.meter-label-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 6px;
}

.audio-meter {
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}

.meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
  border-radius: 6px;
  transition: width 0.1s;
}

.meter-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text);
  left: 30%;
  opacity: 0.5;
}

/* Cry Indicator */
.cry-indicator {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.cry-icon-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 28px;
  transition: all 0.3s;
}

.cry-icon-circle.crying {
  background: rgba(232,93,109,0.15);
  animation: cry-shake 0.5s infinite;
}

@keyframes cry-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.cry-status-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.cry-timer {
  font-size: 24px;
  font-weight: 800;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

/* Current Cry */
.current-cry {
  border-left: 4px solid var(--danger);
}

.current-cry-info {
  display: flex;
  gap: 16px;
}

.info-item {
  flex: 1;
  text-align: center;
}

.info-label {
  display: block;
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.info-value {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat-item {
  text-align: center;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 4px;
}

/* History */
.history-actions {
  display: flex;
  gap: 8px;
}

.btn-small {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-small:active {
  transform: scale(0.95);
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.cry-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-light);
  padding: 30px 0;
  font-size: 14px;
}

.cry-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.cry-item:active {
  transform: scale(0.98);
}

.cry-item-time {
  flex-shrink: 0;
  text-align: center;
  min-width: 56px;
}

.cry-item-time .time {
  font-size: 15px;
  font-weight: 700;
}

.cry-item-time .date {
  font-size: 10px;
  color: var(--text-light);
}

.cry-item-duration {
  flex: 1;
}

.cry-item-duration .duration {
  font-size: 15px;
  font-weight: 600;
}

.cry-item-duration .reason {
  font-size: 12px;
  color: var(--primary);
  margin-top: 2px;
}

.cry-item-duration .no-reason {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.cry-item-actions {
  display: flex;
  gap: 6px;
}

.cry-item-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
}

.cry-item-btn.analyze {
  border-color: var(--primary);
  color: var(--primary);
}

.cry-item-btn.analyzing {
  opacity: 0.5;
  cursor: wait;
}

/* Settings */
.setting-item {
  margin-bottom: 20px;
}

.setting-item:last-child {
  margin-bottom: 0;
}

.setting-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 500;
}

.setting-value {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}

.range-hints {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-light);
  margin-top: 4px;
}

.number-input, .text-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.number-input:focus, .text-input:focus {
  border-color: var(--primary);
}

.toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 500;
}

.switch {
  position: relative;
  width: 44px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--border);
  transition: 0.3s;
  border-radius: 26px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.switch input:checked + .slider {
  background: var(--primary);
}

.switch input:checked + .slider:before {
  transform: translateX(18px);
}

/* Footer */
.footer {
  text-align: center;
  padding: 20px 0;
  font-size: 11px;
  color: var(--text-light);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-small {
  max-width: 320px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px 8px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.ai-result {
  font-size: 14px;
  line-height: 1.8;
}

.ai-loading {
  text-align: center;
  padding: 40px 0;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 1s linear infinite;
}

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

.ai-reason-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
}

.ai-reason-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-reason-probability {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.probability-high {
  background: rgba(232,93,109,0.15);
  color: var(--danger);
}

.probability-medium {
  background: rgba(245,166,35,0.15);
  color: var(--warning);
}

.probability-low {
  background: rgba(78,205,196,0.15);
  color: var(--success);
}

.ai-suggestion {
  background: rgba(74,144,217,0.1);
  border-left: 3px solid var(--primary);
  padding: 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 16px;
  font-size: 13px;
}

.ai-features {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.feature-tag {
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  color: var(--text-light);
}

/* Confirm */
.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 2000;
  white-space: nowrap;
  animation: toast-in 0.3s;
}

@keyframes toast-in {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

/* Responsive */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .stat-value {
    font-size: 18px;
  }
  .cry-item-actions {
    flex-direction: column;
    gap: 4px;
  }
}

/* ==================== 知识分享 ==================== */

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.knowledge-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.knowledge-btn:active {
  transform: scale(0.9);
}

/* 知识分享弹窗 */
.modal-knowledge {
  max-width: 520px;
  max-height: 85vh;
}

.knowledge-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.knowledge-tab {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.knowledge-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.knowledge-panel {
  display: none;
}

.knowledge-panel.active {
  display: block;
}

/* 育儿知识文章列表 */
.articles-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.article-card {
  background: var(--bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: all 0.2s;
}

.article-header {
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}

.article-header:active {
  opacity: 0.7;
}

.article-icon {
  font-size: 24px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(74,144,217,0.12);
  border-radius: 10px;
}

.article-title-area {
  flex: 1;
  min-width: 0;
}

.article-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.article-summary {
  font-size: 12px;
  color: var(--text-light);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.article-chevron {
  font-size: 12px;
  color: var(--text-light);
  transition: transform 0.3s;
  flex-shrink: 0;
}

.article-card.expanded .article-chevron {
  transform: rotate(180deg);
}

.article-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.article-card.expanded .article-body {
  max-height: 1000px;
}

.article-content {
  padding: 0 16px 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text);
}

.article-content p {
  margin-bottom: 8px;
}

.article-content ul {
  margin: 4px 0 8px 16px;
}

.article-content li {
  margin-bottom: 4px;
}

.article-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}

.tag-new {
  background: rgba(232,93,109,0.15);
  color: var(--danger);
}

.tag-hot {
  background: rgba(245,166,35,0.15);
  color: var(--warning);
}

/* AI 问答 */
.qa-input-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.qa-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  resize: none;
  font-family: inherit;
  outline: none;
  line-height: 1.5;
}

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

.qa-send-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.qa-send-btn:active {
  transform: scale(0.95);
}

.qa-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.qa-result {
  min-height: 100px;
}

.qa-hint {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.qa-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.qa-suggestion {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
}

.qa-suggestion:active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.qa-answer {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-size: 14px;
  line-height: 1.8;
  animation: qa-fade 0.3s;
}

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

.qa-answer-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--primary);
}

.qa-answer-body {
  color: var(--text);
}

.qa-answer-body p {
  margin-bottom: 6px;
}

.qa-answer-body ul {
  margin: 4px 0 8px 16px;
}

.qa-answer-body li {
  margin-bottom: 3px;
}

.qa-loading-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  color: var(--text-light);
  font-size: 14px;
}

.qa-loading-inline .loading-spinner {
  width: 20px;
  height: 20px;
  border-width: 2px;
  margin: 0;
}

.qa-error {
  background: rgba(232,93,109,0.1);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  color: var(--danger);
}

/* 分享应用 */
.share-content {
  text-align: center;
}

.share-card {
  background: linear-gradient(135deg, rgba(74,144,217,0.08), rgba(78,205,196,0.08));
  border-radius: var(--radius);
  padding: 28px 20px;
  margin-bottom: 20px;
}

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

.share-card h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.share-desc {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.6;
  margin-bottom: 16px;
}

.share-features {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.share-feature {
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow);
}

.share-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 10px;
}

.share-btn:active {
  transform: scale(0.97);
}

.share-btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

@media (max-width: 380px) {
  .knowledge-tab {
    font-size: 11px;
    padding: 10px 4px;
  }
  .header-right {
    gap: 6px;
  }
  .knowledge-btn {
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
  .status-badge {
    padding: 4px 10px;
    font-size: 12px;
  }
}
