/* ============================================================
   白色明亮主题样式
   ============================================================ */

:root {
    --bg-page: #FFFFFF;
    --bg-card: #F8F9FA;
    --border: #E5E7EB;
    --primary: #10B981;
    --primary-light: #D1FAE5;
    --text-main: #1F2937;
    --text-secondary: #6B7280;
    --protein: #3B82F6;
    --carbs: #10B981;
    --fat: #F59E0B;
    --danger: #EF4444;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

/* 导航栏 */
.navbar {
    background: var(--bg-page);
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.nav-links {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.nav-links::-webkit-scrollbar {
    display: none;
}

.nav-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
    padding: 4px 0;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--primary);
}

/* 主内容区 */
.main-content {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
}

/* 卡片 */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-main);
}

/* 表单元素 */
input, textarea, select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--bg-page);
    color: var(--text-main);
    margin-bottom: 8px;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: opacity 0.15s;
}

.btn-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.6);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-secondary .btn-spinner {
    border-color: rgba(31,41,55,0.4);
    border-top-color: transparent;
}

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

.btn:active {
    opacity: 0.8;
}

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

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    width: auto;
}

/* 网格 */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.grid-4 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 10px;
}

/* 结果展示 */
.result-box {
    background: var(--primary-light);
    padding: 12px;
    border-radius: 8px;
    margin-top: 10px;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
}

.result-box.error {
    background: #FEE2E2;
    color: #DC2626;
}

.cache-badge {
    display: inline-block;
    background: #FEF3C7;
    color: #92400E;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    margin-top: 8px;
}

.cache-badge.hidden {
    display: none;
}

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

.template-item {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
}

.template-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

.template-meta {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.template-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.template-actions .btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    width: auto;
}

/* 食物项 */
.food-item {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
}

.food-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.food-name {
    font-weight: 600;
}

.food-meta {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.food-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.food-actions button {
    flex: 1;
}

/* 餐卡片 */
.meal-card {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
}

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

.meal-title {
    font-weight: 600;
    color: var(--primary);
}

.meal-kcal {
    font-size: 13px;
    color: var(--text-secondary);
}

.meal-notes {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 8px;
    background: #FEF9C3;
    border-radius: 4px;
    margin-top: 8px;
}

/* 底部悬浮按钮 */
.fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    margin-bottom: env(safe-area-inset-bottom, 0px);
}

/* 底部面板 */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-page);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    z-index: 200;
    transform: translateY(100%);
    transition: transform 0.3s ease;
}

.bottom-sheet.open {
    transform: translateY(0);
}

.sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 199;
    display: none;
}

.sheet-overlay.open {
    display: block;
}

.sheet-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.sheet-item {
    text-align: center;
    padding: 20px;
    border-radius: 12px;
    background: var(--bg-card);
    cursor: pointer;
    transition: background 0.15s;
}

.sheet-item:active {
    background: var(--border);
}

.sheet-item .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.sheet-item .label {
    font-size: 14px;
    color: var(--text-secondary);
}

/* 热量展示 */
.cal-display {
    text-align: center;
    padding: 20px 0;
}

.cal-label {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.cal-number {
    font-size: 48px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.cal-target {
    font-size: 16px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.cal-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    margin: 12px 0;
    overflow: hidden;
}

.cal-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #FBBF24, #10B981, #3B82F6);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.cal-bar-fill.over-budget {
    background: var(--danger);
}

/* 营养环形图容器 */
.nutri-charts {
    display: flex;
    justify-content: space-around;
    padding: 16px 0;
}

.nutri-chart-item {
    text-align: center;
}

.nutri-chart-item canvas {
    max-width: 80px;
    max-height: 80px;
}

.nutri-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.nutri-value {
    font-size: 14px;
    font-weight: 600;
    margin-top: 2px;
}

/* 日期选择器 */
.date-picker {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.date-picker::-webkit-scrollbar {
    display: none;
}

.date-item {
    flex-shrink: 0;
    text-align: center;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    min-width: 48px;
}

.date-item.active {
    background: var(--primary);
    color: white;
}

.date-item .day-name {
    font-size: 12px;
}

.date-item .day-num {
    font-size: 16px;
    font-weight: 600;
}

/* 隐藏类 */
.hidden {
    display: none !important;
}

/* 页面特定 */
.page-header {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 16px;
}

.tab-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.tab-bar .tab {
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.tab-bar .tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-panel {
    display: none;
}

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

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background: var(--bg-page);
    border-radius: 12px;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: var(--text-secondary);
}

.modal-body {
    padding: 16px 20px;
}

.modal-body label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: block;
}

.modal-body input,
.modal-body textarea {
    margin-bottom: 0;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 12px 20px 20px;
}

.modal-footer .btn {
    flex: 1;
}

/* ============================================================
   餐类型 / 菜品展示
   ============================================================ */

.meal-type-section {
    margin-bottom: 16px;
}

.meal-type-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 2px solid var(--primary);
    margin-bottom: 10px;
}

.meal-type-label {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

.meal-type-kcal {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.dish-card {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
}

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

.dish-raw {
    font-weight: 600;
    color: var(--text-main);
    font-size: 15px;
}

.dish-kcal {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.dish-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.dish-actions .btn-sm {
    padding: 4px 10px;
    font-size: 12px;
}

/* ============================================================
   摄像头 / 拍照
   ============================================================ */

.camera-viewport {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
}

.camera-viewport video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-fallback {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
    background: var(--bg-card);
}

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

.camera-fallback-text {
    font-size: 14px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.photo-preview {
    position: absolute;
    inset: 0;
    display: none;
}

.photo-preview.active {
    display: block;
}

.photo-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.retake-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}

.camera-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0;
}

.shutter-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #fff;
    border: 4px solid var(--text-secondary);
    cursor: pointer;
    position: relative;
    transition: all 0.15s;
}

.shutter-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #fff;
    transition: all 0.15s;
}

.shutter-btn:active::after {
    width: 42px;
    height: 42px;
    background: var(--primary);
}

/* ============================================================
   智能输入底部栏
   ============================================================ */

.chat-input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-page);
    border-top: 1px solid var(--border);
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.voice-btn,
.camera-btn,
.more-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    user-select: none;
    -webkit-user-select: none;
}

.voice-btn {
    background: linear-gradient(135deg, #10B981, #34C759);
    color: #fff;
    border: none;
    font-size: 20px;
}

.voice-btn:active,
.camera-btn:active,
.more-btn:active {
    transform: scale(0.95);
}

.more-btn {
    font-size: 26px;
    font-weight: 300;
    line-height: 1;
    padding-bottom: 3px;
}

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

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

.input-wrap {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    overflow: hidden;
}

.input-wrap textarea {
    width: 100%;
    min-height: 22px;
    max-height: 104px;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    font-family: inherit;
    margin-bottom: 0;
    padding: 0;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-btn:disabled {
    opacity: 0.5;
}

.voice-toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(31, 41, 55, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 24px 32px;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 250;
    color: #fff;
}

.voice-toast.active {
    display: flex;
}

.voice-toast .voice-icon {
    font-size: 48px;
    animation: pulse 1s infinite;
}

.voice-toast .voice-text {
    font-size: 16px;
}

.voice-toast .voice-hint {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ============================================================
   通用提示 Toast
   ============================================================ */

.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(31, 41, 55, 0.95);
    color: #fff;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 10000;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    max-width: 90%;
    text-align: center;
}

.toast.active {
    display: flex;
}

.toast.toast-error {
    background: rgba(220, 38, 38, 0.95);
}

.toast.toast-loading .toast-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================================
   智能输入结果卡片
   ============================================================ */

.smart-summary {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary);
}

.smart-action-card {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
}

.confidence-legend {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.confidence-legend span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.smart-food-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.smart-food-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.smart-food-weight {
    display: flex;
    align-items: center;
    gap: 4px;
}

.smart-food-weight input {
    width: 60px;
    padding: 4px 6px;
    text-align: right;
    font-size: 14px;
}

.smart-meal-select {
    font-size: 14px;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
}

