/**
 * 食物热量分析器 - 样式文件
 */

:root {
  --primary: #4CAF50; --primary-dark: #388E3C; --primary-light: #C8E6C9;
  --secondary: #2196F3; --secondary-dark: #1976D2;
  --bg: #F5F5F5; --card: #FFFFFF; --text: #333333; --text2: #666666; --text3: #999999;
  --border: #E0E0E0; --error: #F44336; --warning: #FF9800;
  --shadow: 0 2px 8px rgba(0,0,0,0.1); --radius: 12px; --radius-sm: 8px;
  /* 基础字号加大 */
  --fs-base: 18px;
  --fs-sm: 15px;
  --fs-xs: 13px;
  --fs-lg: 20px;
  --fs-xl: 24px;
  --fs-2xl: 32px;
  --fs-3xl: 48px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: var(--fs-base);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.container { max-width: 900px; margin: 0 auto; padding: 16px 20px; }

/* 标题 */
.header { text-align: center; padding: 24px 0 16px; }
.header h1 { font-size: 2.4rem; color: var(--primary); margin-bottom: 8px; }
.subtitle { color: var(--text2); font-size: var(--fs-lg); }

/* 状态栏 */
.status-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-radius: var(--radius-sm);
  margin-bottom: 16px; font-size: var(--fs-sm);
}
.status-ok    { background: #E8F5E9; color: #2E7D32; border: 1px solid #A5D6A7; }
.status-warn  { background: #FFF3E0; color: #E65100; border: 1px solid #FFCC80; }
.status-error { background: #FFEBEE; color: #C62828; border: 1px solid #EF9A9A; }
.status-icon  { font-size: 1.3rem; }

/* 配置面板 */
.config-panel {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden;
}
.config-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; cursor: pointer;
  background: linear-gradient(135deg, var(--primary-light), #fff);
  transition: background 0.3s;
}
.config-header:hover { background: var(--primary-light); }
.config-header h2 { font-size: var(--fs-lg); color: var(--primary-dark); }
.toggle-icon { color: var(--primary); transition: transform 0.3s; font-size: 1.1rem; }
.config-content { padding: 16px 18px; }
.config-content.collapsed { display: none; }
.config-hint {
  font-size: var(--fs-sm); color: var(--text2); margin-bottom: 14px;
  padding: 10px 14px; background: #FFF8E1;
  border-radius: var(--radius-sm); border-left: 3px solid var(--warning);
}

/* 表单 */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: var(--fs-sm); }
.form-hint-inline { font-size: var(--fs-xs); color: var(--text3); font-weight: normal; }
.form-control {
  width: 100%; padding: 12px 14px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: var(--fs-base); transition: border-color 0.3s;
  background: #fff;
}
.form-control:focus { outline: none; border-color: var(--primary); }

/* 上传 */
.upload-section {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.upload-section h2 { font-size: var(--fs-lg); margin-bottom: 14px; }
.upload-box {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 28px 20px; text-align: center;
  transition: all 0.3s; position: relative;
}
.upload-box:hover, .upload-box.dragover {
  border-color: var(--primary); background: rgba(76,175,80,0.05);
}
.upload-content { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.upload-icon { font-size: 3.2rem; }
.upload-text { font-size: var(--fs-lg); font-weight: 500; }
.upload-hint { font-size: var(--fs-sm); color: var(--text3); }
.file-count {
  position: absolute; top: 10px; right: 15px;
  font-size: var(--fs-sm); color: var(--text2);
  background: var(--primary-light); padding: 4px 12px; border-radius: 20px;
}

/* 预览 */
.preview-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-top: 14px;
}
.preview-item {
  position: relative; aspect-ratio: 1;
  border-radius: var(--radius-sm); overflow: hidden; background: var(--bg);
}
.preview-item img, .preview-item video {
  width: 100%; height: 100%; object-fit: cover;
}
.preview-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.55); color: #fff;
  font-size: var(--fs-sm); text-align: center; padding: 4px 0;
}
.preview-item .remove-btn {
  position: absolute; top: 6px; right: 6px;
  width: 28px; height: 28px;
  background: rgba(244,67,54,0.9); color: #fff;
  border: none; border-radius: 50%; cursor: pointer;
  font-size: 16px; line-height: 28px;
  opacity: 0; transition: opacity 0.3s; z-index: 2;
}
.preview-item:hover .remove-btn { opacity: 1; }

/* 重量 */
.weight-section {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px;
}
.weight-section h2 { font-size: var(--fs-lg); margin-bottom: 6px; }
.weight-desc { font-size: var(--fs-sm); color: var(--text3); margin-bottom: 14px; }
.weight-input-wrapper { display: flex; align-items: center; gap: 12px; }
.weight-input { flex: 1; font-size: var(--fs-lg); text-align: center; }
.weight-unit { font-size: var(--fs-lg); color: var(--text2); font-weight: 500; white-space: nowrap; }

/* 按钮 */
.btn {
  padding: 12px 24px; border: none; border-radius: var(--radius-sm);
  font-size: var(--fs-base); font-weight: 500; cursor: pointer; transition: all 0.3s;
  touch-action: manipulation;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { background: var(--border); cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { background: var(--secondary-dark); }
.btn-secondary:active { transform: scale(0.97); }
.action-section { text-align: center; margin-bottom: 20px; }
.btn-analyze { padding: 16px 52px; font-size: var(--fs-xl); }
.btn-analyze .btn-loading { display: flex; align-items: center; justify-content: center; gap: 10px; }
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== 结果 ========== */

.result-section { margin-bottom: 20px; }
.result-section h2 { font-size: var(--fs-xl); margin-bottom: 16px; }
.result-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px;
}
.result-card h3 { font-size: var(--fs-lg); margin-bottom: 12px; }

/* 总热量卡片 */
.main-result { text-align: center; background: linear-gradient(135deg, var(--primary-light), #fff); }
.total-summary { display: flex; justify-content: center; gap: 40px; flex-wrap: wrap; }
.total-cal-box, .total-weight-box, .total-items-box {
  display: flex; flex-direction: column; align-items: center;
}
.total-label { font-size: var(--fs-sm); color: var(--text2); margin-bottom: 4px; }
.total-value { font-size: var(--fs-3xl); font-weight: 700; color: var(--primary); line-height: 1.1; }
.total-value-sm { font-size: var(--fs-2xl); }
.total-unit { font-size: var(--fs-sm); color: var(--text3); margin-top: 2px; }

.cal-flash { animation: flash 0.6s ease; }
@keyframes flash {
  0%   { color: var(--secondary); transform: scale(1.08); }
  100% { color: var(--primary); transform: scale(1); }
}

/* 份量校准 */
.calibrate-card { border-left: 4px solid var(--secondary); }
.calibrate-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.calibrate-header h3 { margin-bottom: 0; }
.calibrate-badge {
  font-size: var(--fs-xs); padding: 3px 12px;
  border-radius: 20px; color: #fff; font-weight: 500;
}
.badge-estimated  { background: var(--warning); }
.badge-user       { background: var(--primary); }
.badge-calibrated { background: var(--secondary); }
.calibrate-desc { font-size: var(--fs-sm); color: var(--text2); margin-bottom: 12px; line-height: 1.6; }
.calibrate-input-wrapper { display: flex; align-items: center; gap: 10px; }
.calibrate-input { flex: 1; }
.btn-calibrate { white-space: nowrap; flex-shrink: 0; }

/* 食材明细表 */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.food-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.food-table th {
  background: var(--bg); padding: 10px 14px; text-align: left;
  font-weight: 600; color: var(--text2); border-bottom: 2px solid var(--border);
  white-space: nowrap; font-size: var(--fs-sm);
}
.food-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.food-table tbody tr:hover { background: #f9f9f9; }
.row-alt { background: #fafafa; }
.food-table tfoot td { border-top: 2px solid var(--border); border-bottom: none; background: var(--primary-light); font-weight: 600; }
.td-name { font-weight: 600; color: var(--text); white-space: nowrap; }
.td-cal { font-weight: 600; color: var(--primary-dark); }
.cooking-tag {
  display: inline-block; background: #E3F2FD; color: #1565C0;
  padding: 3px 10px; border-radius: 12px; font-size: var(--fs-xs); white-space: nowrap;
}
.td-note { color: var(--text2); font-size: var(--fs-xs); max-width: 180px; line-height: 1.5; }

/* 置信度标记 */
.conf-tag {
  display: inline-block; font-size: 11px; padding: 1px 6px;
  border-radius: 8px; margin-left: 4px; vertical-align: middle;
  line-height: 1.4;
}
.conf-low { background: #FFF3E0; color: #E65100; }
.conf-med { background: #E3F2FD; color: #1565C0; }

/* 候选食材标签 */
.td-alts { min-width: 120px; }
.alt-tag {
  display: inline-block; background: #F3E5F5; color: #7B1FA2;
  border: 1px solid #CE93D8; padding: 2px 8px; border-radius: 12px;
  font-size: 12px; cursor: pointer; transition: all 0.2s;
  margin: 1px 2px; white-space: nowrap;
}
.alt-tag:hover { background: #7B1FA2; color: #fff; }
.alt-tag:active { transform: scale(0.95); }

/* 建议 & 警告 */
.suggestion-card h3 { margin-bottom: 8px; }
.suggestion-text { line-height: 1.9; white-space: pre-line; font-size: var(--fs-sm); }
.warning-card { background: #FFF3E0; border-left: 4px solid var(--warning); }
.warning-text { color: #E65100; line-height: 1.9; white-space: pre-line; font-size: var(--fs-sm); }

/* 追问/修正 */
.followup-card {
  background: linear-gradient(135deg, #E3F2FD, #fff);
  border-left: 4px solid var(--secondary);
}
.followup-card h3 { margin-bottom: 6px; }
.followup-desc { font-size: var(--fs-sm); color: var(--text2); margin-bottom: 12px; }
.followup-examples {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 14px;
}
.followup-tag {
  background: #fff; border: 1.5px solid var(--secondary);
  color: var(--secondary-dark); padding: 6px 14px;
  border-radius: 20px; font-size: var(--fs-xs);
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.followup-tag:hover {
  background: var(--secondary); color: #fff;
}
.followup-tag:active { transform: scale(0.96); }
.followup-input-wrapper {
  display: flex; gap: 10px; align-items: flex-end;
}
.followup-textarea {
  flex: 1; resize: vertical; min-height: 48px;
  font-size: var(--fs-base); font-family: inherit;
}
.btn-followup {
  white-space: nowrap; flex-shrink: 0;
  height: 48px; padding: 0 20px;
}
.btn-followup .btn-loading {
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* 错误提示 */
.error-toast {
  position: fixed; top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-120px);
  background: var(--error); color: #fff;
  padding: 14px 22px; border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  display: flex; align-items: center; gap: 12px;
  z-index: 1000; transition: transform 0.3s;
  font-size: var(--fs-sm);
  max-width: calc(100vw - 40px);
}
.error-toast.show { transform: translateX(-50%) translateY(0); }
.error-close { background: none; border: none; color: #fff; font-size: 1.6rem; cursor: pointer; }

/* ========== 响应式 - 平板 ========== */
@media (max-width: 768px) {
  :root {
    --fs-base: 17px;
    --fs-sm: 15px;
    --fs-xs: 13px;
    --fs-lg: 19px;
    --fs-xl: 22px;
    --fs-2xl: 28px;
    --fs-3xl: 40px;
  }
  .container { padding: 12px 16px; }
  .header { padding: 18px 0 12px; }
  .header h1 { font-size: 2rem; }
  .total-summary { gap: 24px; }
  .preview-grid { gap: 8px; }
  .result-card { padding: 14px; }
  .upload-box { padding: 22px 16px; }
}

/* ========== 响应式 - 手机 ========== */
@media (max-width: 480px) {
  :root {
    --fs-base: 16px;
    --fs-sm: 14px;
    --fs-xs: 12px;
    --fs-lg: 18px;
    --fs-xl: 20px;
    --fs-2xl: 26px;
    --fs-3xl: 36px;
  }
  .container { padding: 10px 12px; }
  .header { padding: 14px 0 10px; }
  .header h1 { font-size: 1.7rem; }
  .subtitle { font-size: var(--fs-sm); }

  .upload-section { padding: 14px; }
  .upload-box { padding: 20px 12px; }
  .upload-icon { font-size: 2.6rem; }
  .upload-text { font-size: var(--fs-lg); }
  .preview-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  .weight-section { padding: 14px; }
  .weight-input-wrapper { gap: 10px; }

  .btn-analyze { width: 100%; padding: 14px 20px; font-size: var(--fs-xl); }

  .result-card { padding: 12px; margin-bottom: 10px; }
  .result-section h2 { font-size: var(--fs-lg); }
  .total-summary { gap: 16px; }

  .food-table th, .food-table td { padding: 8px 6px; }
  .food-table { font-size: var(--fs-xs); }
  .td-note { min-width: 136px; max-width: 136px; font-size: 11px; line-height: 1.45; }
  .cooking-tag { font-size: 11px; padding: 2px 6px; }
  .td-alts { min-width: 72px; }
  .alt-tag { font-size: 11px; padding: 2px 6px; }
  .conf-tag { font-size: 10px; }
  .td-name { white-space: normal; min-width: 82px; }

  .calibrate-input-wrapper { flex-wrap: wrap; }
  .calibrate-input { min-width: 0; }
  .btn-calibrate { width: 100%; margin-top: 8px; }

  .config-content { padding: 14px; }
  .config-hint { padding: 8px 10px; }

  .suggestion-text, .warning-text { font-size: var(--fs-sm); }

  /* 追问区域 */
  .followup-examples { gap: 6px; }
  .followup-tag { font-size: 12px; padding: 5px 10px; }
  .followup-input-wrapper { flex-direction: column; align-items: stretch; }
  .btn-followup { width: 100%; height: auto; padding: 12px 20px; }
}

/* 超小屏幕 */
@media (max-width: 360px) {
  .header h1 { font-size: 1.5rem; }
  .total-value { font-size: 2rem; }
  .total-value-sm { font-size: 1.6rem; }
  .upload-text { font-size: var(--fs-base); }
}
