:root {
    --primary-color: #2ecc71; --primary-dark: #27ae60; --accent-color: #6c5ce7;
    --bg-color: #f0f2f5; --text-color: #2c3e50; --card-bg: #ffffff;
    --meal-header-bg: #f1f8e9; --input-bg: #ffffff; --input-border: #e0e0e0;
    --shadow-color: rgba(0,0,0,0.05); --modal-bg: #ffffff;
    --lang-modal-bg: #ffffff; --lang-text: #2c3e50; --lang-opt-bg: #f8f9fa; --lang-opt-border: #e0e0e0; --lang-cancel-color: #666;
    --nav-bg: #ffffff; --nav-text: #95a5a6; --nav-active: #2ecc71;
}
[data-theme="dark"] {
    --primary-color: #2ecc71; --primary-dark: #27ae60; --accent-color: #a29bfe;
    --bg-color: #121212; --text-color: #e0e0e0; --card-bg: #1e1e1e;
    --meal-header-bg: #2d3436; --input-bg: #2d2d2d; --input-border: #444444;
    --shadow-color: rgba(0,0,0,0.5); --modal-bg: #2d2d2d;
    --lang-modal-bg: #2d3436; --lang-text: #ffffff; --lang-opt-bg: rgba(255,255,255,0.1); --lang-opt-border: rgba(255,255,255,0.2); --lang-cancel-color: #aaa;
    --nav-bg: #1e1e1e; --nav-text: #7f8c8d; --nav-active: #2ecc71;
}
body { font-family: 'Segoe UI', sans-serif; background-color: var(--bg-color); color: var(--text-color); margin: 0; padding: 15px; padding-bottom: 90px; display: flex; justify-content: center; transition: 0.3s; }
.container { max-width: 800px; width: 100%; display: grid; gap: 20px; }
.card, .pet-card { background: var(--card-bg); border-radius: 16px; padding: 20px; box-shadow: 0 4px 12px var(--shadow-color); transition: 0.3s; }

/* 日期控制區 */
.date-control { display: flex; justify-content: center; align-items: center; gap: 10px; margin-bottom: 15px; color: var(--text-color); }
/* ✨ 新增：強制日期標籤不換行，並修正對齊 */
.date-control label { white-space: nowrap; margin-bottom: 0; }
.date-control input { padding: 8px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text-color); border-radius: 8px; }

.dashboard-header {
    background:
        radial-gradient(circle at top right, rgba(255,255,255,0.18), transparent 30%),
        linear-gradient(155deg, #5fd37b 0%, #48bf6a 42%, #2fa65f 100%);
    color: white;
    padding: 22px;
    border-radius: 24px;
    margin-bottom: 10px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.dashboard-header:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(39, 174, 96, 0.2); }
.dashboard-header:focus-visible { outline: 3px solid rgba(255,255,255,0.75); outline-offset: 2px; }
.dashboard-hero { display: flex; align-items: stretch; justify-content: space-between; gap: 16px; }
.dashboard-hero-copy { min-width: 0; }
.dashboard-header .big-cal { display: flex; align-items: baseline; gap: 8px; font-size: 3em; font-weight: 700; line-height: 1; margin: 8px 0; }
.cal-unit-inline { font-size: 0.28em; font-weight: 600; letter-spacing: 0.08em; opacity: 0.9; text-transform: uppercase; }
.dashboard-status-panel {
    min-width: 145px;
    background: rgba(255,255,255,0.16);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 18px;
    padding: 14px 15px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
    text-align: left;
    backdrop-filter: blur(8px);
}
.summary-pill {
    width: fit-content;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.2);
    font-size: 0.9em;
    font-weight: 700;
}
.summary-status { font-size: 1.02em; font-weight: 700; line-height: 1.35; }
.summary-status-sub { font-size: 0.82em; opacity: 0.9; line-height: 1.4; }
.companion-hero {
    display: grid;
    gap: 14px;
    padding: 18px 18px 16px;
    border: 1px solid rgba(46, 204, 113, 0.2);
    background:
        radial-gradient(circle at top right, rgba(108, 92, 231, 0.08), transparent 28%),
        linear-gradient(135deg, rgba(46, 204, 113, 0.10), rgba(255, 255, 255, 0.98));
}
.companion-hero-main {
    display: flex;
    align-items: center;
    gap: 16px;
}
.companion-hero-copy {
    flex: 1;
    min-width: 0;
}
.companion-kicker {
    font-size: 0.76em;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-dark);
    opacity: 0.9;
}
.companion-title {
    margin-top: 8px;
    font-size: 1.45em;
    font-weight: 800;
    line-height: 1.2;
    color: var(--text-color);
}
.companion-summary {
    margin-top: 10px;
    line-height: 1.55;
    color: var(--text-color);
    opacity: 0.82;
}
.companion-pet-shell {
    width: 124px;
    min-width: 124px;
    height: 124px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(46, 204, 113, 0.08));
    border: 1px solid rgba(46, 204, 113, 0.14);
}
.companion-stat-row,
.companion-meta-row,
.companion-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.companion-action-row {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) repeat(2, minmax(0, 1fr));
}
.companion-stat-chip {
    min-width: 0;
    flex: 1;
    padding: 10px 12px;
    border-radius: 16px;
    background: rgba(255,255,255,0.74);
    border: 1px solid rgba(46, 204, 113, 0.14);
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.companion-stat-label {
    font-size: 0.75em;
    color: var(--primary-dark);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.companion-stat-value {
    font-size: 1.02em;
    font-weight: 700;
    color: var(--text-color);
}
.companion-meta-chip {
    padding: 7px 11px;
    border-radius: 999px;
    background: rgba(255,255,255,0.62);
    border: 1px solid rgba(46, 204, 113, 0.14);
    font-size: 0.82em;
    color: var(--text-color);
}
.companion-action-btn {
    width: 100%;
    min-width: 0;
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(46, 204, 113, 0.12);
    color: var(--text-color);
    box-shadow: none;
    font-size: 0.92em;
    font-weight: 700;
}
.companion-action-btn--primary {
    background: linear-gradient(135deg, rgba(39, 174, 96, 0.96), rgba(46, 204, 113, 0.92));
    border-color: transparent;
    color: white;
}
.companion-action-btn--secondary {
    background: rgba(255, 255, 255, 0.82);
}
.home-common-food-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.common-food-shortcut {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    width: 100%;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(46, 204, 113, 0.16);
    background: rgba(255, 255, 255, 0.82);
    color: var(--text-color);
    text-align: left;
    box-shadow: none;
}
.common-food-shortcut-label {
    font-size: 0.92em;
    font-weight: 700;
}
.common-food-shortcut-meta {
    font-size: 0.78em;
    color: var(--nav-text);
}
.home-log-form {
    padding: 16px;
    border-radius: 18px;
    background: rgba(46, 204, 113, 0.06);
    border: 1px solid rgba(46, 204, 113, 0.12);
}
.home-log-launcher {
    display: grid;
    gap: 10px;
}
.home-log-launcher-card {
    width: 100%;
    padding: 15px 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(46, 204, 113, 0.10);
    color: var(--text-color);
    text-align: left;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.home-log-launcher-title {
    font-size: 0.98em;
    font-weight: 800;
}
.home-log-launcher-copy {
    font-size: 0.84em;
    line-height: 1.5;
    color: var(--nav-text);
}
.home-signal-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 16px;
}
.home-signal-card {
    padding: 14px;
    border-radius: 18px;
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.18);
    backdrop-filter: blur(10px);
}
.home-signal-label {
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.9);
}
.home-signal-value {
    margin-top: 8px;
    font-size: 1.6em;
    font-weight: 800;
    line-height: 1.1;
    color: white;
}
.home-signal-copy {
    margin-top: 6px;
    font-size: 0.88em;
    line-height: 1.45;
    color: rgba(255,255,255,0.88);
}
.nutrition-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 15px; }
.nutrition-grid--summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.nutri-box {
    background: rgba(255,255,255,0.18);
    padding: 12px 10px;
    border-radius: 18px;
    text-align: center;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.14);
}
.nutri-box.featured { background: rgba(255,255,255,0.13); }
.nutri-box .n-val { display: flex; align-items: baseline; justify-content: center; gap: 4px; font-weight: bold; font-size: 1.35em; }
.nutri-box .n-unit { font-size: 0.58em; opacity: 0.85; }
.nutri-box .n-label { font-size: 0.75em; opacity: 0.9; }
.dashboard-hidden-values { display: none; }
.dashboard-header[data-progress-state="good"] .summary-pill { background: rgba(255,255,255,0.28); }
.dashboard-header[data-progress-state="over"] .summary-pill { background: rgba(255, 234, 167, 0.28); }
.dashboard-header[data-progress-state="over"] .summary-status { color: #fff9d6; }
.quick-start-card {
    background: linear-gradient(135deg, rgba(46, 204, 113, 0.1), rgba(108, 92, 231, 0.08));
    border: 1px solid rgba(46, 204, 113, 0.18);
    border-radius: 20px;
    padding: 18px 20px;
    box-shadow: 0 10px 24px rgba(46, 204, 113, 0.08);
}
.quick-start-card[hidden] { display: none !important; }
.quick-start-eyebrow,
.ai-guide-eyebrow { font-size: 0.78em; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary-dark); opacity: 0.9; }
.quick-start-title,
.ai-guide-title { margin-top: 8px; font-size: 1.2em; font-weight: 700; color: var(--text-color); }
.quick-start-copy,
.ai-guide-copy { margin-top: 8px; line-height: 1.6; color: var(--text-color); opacity: 0.82; }
.onboarding-card { margin-bottom: 6px; }
.onboarding-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}
.onboarding-meta--missing { margin-top: 10px; }
.onboarding-missing-chip {
    background: rgba(255, 245, 230, 0.92);
    border-color: rgba(243, 156, 18, 0.18);
}
.onboarding-cta {
    margin-top: 14px;
    padding: 11px 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
}
.coach-card {
    background:
        radial-gradient(circle at top right, rgba(108, 92, 231, 0.10), transparent 30%),
        linear-gradient(135deg, rgba(46, 204, 113, 0.10), rgba(116, 185, 255, 0.10));
    border: 1px solid rgba(46, 204, 113, 0.14);
}
.coach-headline { margin-top: 8px; font-size: 1.18em; font-weight: 700; color: var(--text-color); }
.coach-summary { margin-top: 8px; line-height: 1.6; color: var(--text-color); opacity: 0.84; }
.coach-tip-list {
    margin: 14px 0 0;
    padding-left: 18px;
    color: var(--text-color);
}
.coach-tip-list li + li { margin-top: 6px; }
.coach-weekly-block {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(46, 204, 113, 0.12);
}
.coach-weekly-title {
    font-size: 0.9em;
    font-weight: 700;
    color: var(--primary-dark);
}
.coach-weekly-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.coach-stat-chip {
    padding: 7px 11px;
    border-radius: 999px;
    background: rgba(255,255,255,0.58);
    border: 1px solid rgba(46, 204, 113, 0.14);
    font-size: 0.86em;
    color: var(--text-color);
}
.rhythm-card[hidden] { display: none !important; }
.rhythm-card {
    border: 1px solid rgba(46, 204, 113, 0.14);
    background:
        radial-gradient(circle at top right, rgba(116, 185, 255, 0.08), transparent 30%),
        linear-gradient(135deg, rgba(46, 204, 113, 0.06), rgba(255, 255, 255, 0.96));
}
.rhythm-kicker {
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-dark);
    opacity: 0.9;
}
.rhythm-headline {
    margin-top: 8px;
    font-size: 1.12em;
    font-weight: 700;
    color: var(--text-color);
}
.rhythm-summary {
    margin-top: 8px;
    line-height: 1.6;
    color: var(--text-color);
    opacity: 0.84;
}
.rhythm-signal-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 14px;
}
.rhythm-signal {
    padding: 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.64);
    border: 1px solid rgba(46, 204, 113, 0.12);
}
.rhythm-signal-label {
    font-size: 0.76em;
    font-weight: 700;
    color: var(--primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.rhythm-signal-copy {
    margin-top: 6px;
    font-size: 0.9em;
    line-height: 1.45;
    color: var(--text-color);
}
.rhythm-card--dashboard {
    margin-top: -4px;
}
.today-meals-card {
    border: 1px solid rgba(46, 204, 113, 0.14);
    background:
        radial-gradient(circle at top left, rgba(46, 204, 113, 0.05), transparent 35%),
        linear-gradient(180deg, rgba(255,255,255,0.98), rgba(249, 253, 250, 0.98));
}
.today-meals-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.today-meals-copy {
    min-width: 0;
}
.today-meals-kicker {
    font-size: 0.76em;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary-dark);
}
.today-meals-title {
    margin-top: 8px;
    font-size: 1.16em;
    font-weight: 800;
    color: var(--text-color);
}
.today-meals-hint {
    margin-top: 6px;
    font-size: 0.9em;
    line-height: 1.55;
    color: var(--nav-text);
}
.today-meals-date-btn {
    width: auto;
    min-width: 0;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(46, 204, 113, 0.08);
    border: 1px solid rgba(46, 204, 113, 0.12);
    color: var(--primary-dark);
    font-size: 0.88em;
    white-space: nowrap;
    box-shadow: none;
}
.today-meals-date-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}
.meal-sections-container {
    display: grid;
    gap: 12px;
}
.meal-empty-row { display: block !important; }
.meal-empty-card {
    padding: 6px 0;
    text-align: left;
}
.meal-empty-title { font-weight: 700; color: var(--text-color); }
.meal-empty-copy { margin-top: 4px; font-size: 0.92em; color: var(--nav-text); }
.chart-container { position: relative; height: 250px; width: 100%; margin-bottom: 20px; }
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 600px) { .chart-grid { grid-template-columns: 1fr 1fr; } }
.meal-section {
    border: 1px solid rgba(46, 204, 113, 0.12);
    border-radius: 18px;
    overflow: hidden;
    background: rgba(255,255,255,0.92);
}
.meal-header {
    padding: 14px 16px 10px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}
.meal-title-wrap {
    min-width: 0;
}
.meal-title {
    font-weight: 800;
    font-size: 1em;
    color: var(--text-color);
}
.meal-goal {
    display: block;
    margin-top: 4px;
    font-size: 0.82em;
    color: var(--nav-text);
}
.meal-progress {
    padding: 7px 10px;
    border-radius: 999px;
    background: rgba(46, 204, 113, 0.08);
    color: var(--primary-dark);
    font-size: 0.82em;
    font-weight: 800;
    white-space: nowrap;
}
.meal-list {
    list-style: none;
    margin: 0;
    padding: 0 14px 14px;
    display: grid;
    gap: 10px;
}
.meal-list li {
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--input-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--card-bg);
}
.food-info {
    min-width: 0;
    flex: 1;
}
.food-info .name {
    font-weight: 700;
    color: var(--text-color);
}
.food-info .detail {
    margin-top: 4px;
    font-size: 0.84em;
    line-height: 1.45;
    color: var(--nav-text);
}
.form-group { margin-bottom: 15px; } label { display: block; margin-bottom: 6px; font-weight: 600; }
input, select, textarea { width: 100%; padding: 12px; border: 2px solid var(--input-border); background-color: var(--input-bg); color: var(--text-color); border-radius: 10px; box-sizing: border-box; }
button { width: 100%; padding: 14px; background-color: var(--primary-color); color: white; border: none; border-radius: 10px; font-size: 16px; font-weight: bold; cursor: pointer; }
button.btn-ai { background: linear-gradient(135deg, #6c5ce7 0%, #5b4cc4 100%); }
button.btn-analyze { background: linear-gradient(135deg, #ff7675 0%, #d63031 100%); margin-top: 15px; display: none; }
button.btn-delete { width: auto; padding: 4px 10px; background-color: #ff7675; font-size: 12px; border-radius: 6px; margin-left: 10px; }
.fav-controls { display: flex; gap: 8px; margin-top: 8px; }
.btn-fav-save { background-color: #ff7675; width: auto; padding: 10px; flex:1; font-size: 14px; }
.btn-fav-load { background-color: #0984e3; width: auto; padding: 10px; flex:1; font-size: 14px; }
.fav-item-row { display: flex; justify-content: space-between; align-items: center; padding: 10px; border-bottom: 1px solid var(--input-border); }
.fav-item-name { font-weight: bold; cursor: pointer; flex-grow: 1; color: var(--text-color); }
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(3px); }
.modal { background: var(--modal-bg); padding: 25px; border-radius: 16px; width: 90%; max-width: 400px; max-height: 90vh; overflow-y: auto; text-align: center; color: var(--text-color); box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.modal--wide { max-width: 520px; }
.modal--sheet {
    width: min(92vw, 520px);
    max-height: min(88vh, 720px);
    border-radius: 24px;
    text-align: left;
}
.modal-sheet-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
}
.modal-sheet-header h3 {
    margin: 0;
}
.modal-sheet-copy {
    margin: 6px 0 0;
    font-size: 0.92em;
    line-height: 1.5;
    color: var(--nav-text);
}
.modal-close-btn {
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--input-border);
    background: rgba(255,255,255,0.85);
    color: var(--nav-text);
    font-size: 1.4rem;
    line-height: 1;
    box-shadow: none;
}
.home-log-form--modal {
    margin-top: 8px;
}
.date-control--modal {
    margin-bottom: 16px;
}
.lang-modal-box { background: var(--lang-modal-bg); width: 85%; max-width: 350px; border-radius: 12px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.lang-option { background: var(--lang-opt-bg); border: 1px solid var(--lang-opt-border); padding: 15px; border-radius: 8px; font-size: 16px; cursor: pointer; text-align: left; color: var(--lang-text); margin-bottom: 10px; }
.lang-cancel-btn { background: transparent; border: 1px solid var(--lang-opt-border); margin-top: 20px; width: 100%; padding: 12px; color: var(--lang-cancel-color); border-radius: 8px; cursor: pointer; }
.meal-selector { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.meal-btn { padding: 12px; border: none; border-radius: 8px; font-weight: bold; cursor: pointer; }
.meal-btn.breakfast { background-color: #fab1a0; color: #2d3436; } .meal-btn.lunch { background-color: #55efc4; color: #2d3436; } .meal-btn.dinner { background-color: #74b9ff; color: #2d3436; } .meal-btn.snack { background-color: #ffeaa7; color: #2d3436; }
.loading-spinner { display: none; text-align: center; padding: 20px; color: var(--accent-color); font-weight: bold; }
#image-preview { width: 100%; border-radius: 10px; margin-top: 15px; display: none; }
.goal-section { display: none; margin-top: 20px; background: rgba(46, 204, 113, 0.1); padding: 15px; border-radius: 10px; text-align: center; }
.ai-guide-card {
    background: linear-gradient(135deg, rgba(108, 92, 231, 0.08), rgba(46, 204, 113, 0.08));
    border: 1px solid rgba(108, 92, 231, 0.14);
    border-radius: 18px;
    padding: 16px 18px;
    margin-bottom: 16px;
    text-align: left;
}
.ai-guide-list {
    margin: 12px 0 0;
    padding-left: 18px;
    color: var(--text-color);
    opacity: 0.88;
}
.ai-guide-list li + li { margin-top: 6px; }
.ai-status-note {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(231, 76, 60, 0.12);
    color: var(--text-color);
    font-size: 0.88em;
    line-height: 1.5;
    text-align: left;
}
.fab-container { display: none; }
.fab-main { display: none; }
.fab-menu { display: none; }
.fab-item { display: none; }

/* === View Management === */
.view-section { display: none; animation: fadeIn 0.3s ease; }
.active-view { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* === Bottom Navigation === */
.bottom-nav { position: fixed; bottom: 0; left: 0; width: 100%; background: var(--nav-bg); box-shadow: 0 -2px 10px rgba(0,0,0,0.05); display: flex; justify-content: space-around; padding: 10px 0 15px 0; z-index: 1000; border-top: 1px solid var(--input-border); }
@supports (padding-bottom: env(safe-area-inset-bottom)) { .bottom-nav { padding-bottom: calc(15px + env(safe-area-inset-bottom)); } }
.nav-item { display: flex; flex-direction: column; align-items: center; text-decoration: none; color: var(--nav-text); font-size: 11px; font-weight: 600; gap: 4px; transition: 0.2s; position: relative; }
.nav-item svg { width: 24px; height: 24px; stroke-width: 2; transition: transform 0.2s; }
.nav-item.active { color: var(--nav-active); }
.nav-item.active svg { transform: scale(1.1); }
.nav-item.nav-ai { transform: translateY(-20px); }
.nav-ai-button { width: 56px; height: 56px; background: linear-gradient(135deg, var(--primary-color), var(--primary-dark)); border-radius: 50%; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4); color: white; border: 4px solid var(--bg-color); position: relative; }
.nav-item.active .nav-ai-button { transform: scale(1.05); box-shadow: 0 6px 20px rgba(46, 204, 113, 0.6); }
.nav-ai-button svg { width: 28px; height: 28px; }
.ai-badge { position: absolute; bottom: -18px; color: var(--nav-text); font-size: 11px; white-space: nowrap; }
.nav-item.active .ai-badge { color: var(--nav-active); }

/* === Settings View === */
.settings-list { display: flex; flex-direction: column; gap: 8px; }
.settings-item { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--input-bg); border-radius: 12px; border: 1px solid var(--input-border); }
.settings-item label { margin: 0; font-weight: 600; color: var(--text-color); flex-shrink: 0; white-space: nowrap; }
.settings-item select, .settings-item .settings-input { flex-grow: 1; min-width: 0; background: transparent; border: none; text-align: right; text-align-last: right; padding: 0; font-size: 16px; font-weight: normal; margin: 0; color: var(--text-color); direction: rtl; }
.settings-item select option { direction: ltr; } /* 將選單內項目改回左或正常對齊 */
.settings-item select:focus, .settings-item .settings-input:focus { outline: none; }
.settings-item.clickable { cursor: pointer; transition: background 0.2s; }
.settings-item.clickable:hover { background: rgba(0,0,0,0.02); }
.settings-item .chevron { color: #aaa; font-weight: bold; }
.app-settings { margin-top: 20px; }

/* === Weight Card === */
.weight-card { margin-top: 15px; }

/* Pet Card Styling */
.pet-card {
    border: 2px solid var(--primary-color);
    background: var(--card-bg);
}
.pet-message {
    font-size: 1.1em;
    padding: 8px 15px;
    border-radius: 20px;
    background: rgba(46, 204, 113, 0.15);
    color: var(--primary-dark);
    display: inline-flex;
    margin-top: 10px;
}
.manual-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.manual-grid input { width: 100%; font-size: 14px; }
.small-input-group { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 10px; }
.small-input-group input { padding: 8px; font-size: 12px; }
.manual-select-row { margin-bottom: 10px; }
.macro-goal-box { background: rgba(46, 204, 113, 0.1); padding: 10px; border-radius: 8px; margin-top: 10px; font-size: 0.9em; line-height: 1.6; color: var(--text-color); }

/* Phase 4: Chart Range Toggle */
.chart-range-toggle { display: flex; gap: 5px; }
.range-btn {
    padding: 4px 12px; border-radius: 15px; border: 1.5px solid var(--primary-color);
    background: transparent; color: var(--text-color); font-size: 12px; cursor: pointer; transition: 0.2s;
}
.range-btn.active-range {
    background: var(--primary-color); color: #fff;
}

/* Phase 4: AI Nutrition Grid */
.ai-nutri-grid {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px;
}
.ai-nutri-item {
    background: var(--bg-color); border-radius: 10px; padding: 8px 6px; text-align: center;
    display: flex; flex-direction: column; gap: 2px;
}
.ai-nutri-item--soft { background: rgba(46, 204, 113, 0.08); }
.ai-nutri-item--primary {
    padding: 12px 10px;
    background: rgba(46, 204, 113, 0.1);
    border: 1px solid rgba(46, 204, 113, 0.14);
}
.ai-nutri-grid--primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 0;
}
.ai-n-val { font-weight: 700; font-size: 0.95em; }
.ai-n-lbl { font-size: 0.72em; opacity: 0.7; }

.nutrition-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 12px;
}

.nutrition-panel-header,
.nutrition-panel-section-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nutrition-panel-title,
.nutrition-panel-section-title {
    font-size: 0.92em;
    font-weight: 700;
    color: var(--primary-dark);
}

.nutrition-panel-copy,
.nutrition-panel-section-copy {
    font-size: 0.8em;
    line-height: 1.5;
    opacity: 0.72;
}

.nutrition-panel-section {
    padding: 12px;
    border-radius: 14px;
    background: rgba(46, 204, 113, 0.05);
    border: 1px solid rgba(46, 204, 113, 0.12);
}

.nutrition-focus-card[hidden] { display: none !important; }
.nutrition-focus-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nutrition-focus-kicker {
    font-size: 0.82em;
    font-weight: 700;
    color: var(--primary-dark);
}

.nutrition-focus-subtitle,
.nutrition-focus-summary,
.nutrition-focus-detail {
    font-size: 0.82em;
    line-height: 1.5;
    opacity: 0.75;
}

.nutrition-focus-headline {
    font-size: 1.02em;
    font-weight: 700;
    color: var(--text-color);
}

.nutrition-focus-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.nutrition-focus-signal {
    padding: 12px;
    border-radius: 14px;
    background: rgba(46, 204, 113, 0.06);
    border: 1px solid rgba(46, 204, 113, 0.1);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nutrition-focus-label {
    font-size: 0.75em;
    opacity: 0.7;
}

.nutrition-focus-value {
    font-size: 1em;
    font-weight: 700;
}

/* Phase 4: AI Item Rows */
.ai-item-row {
    display: flex; gap: 6px; align-items: center; margin-bottom: 5px;
}
.ai-item-row input {
    padding: 6px 8px; border: 1px solid var(--primary-color); border-radius: 8px;
    background: var(--bg-color); color: var(--text-color); font-size: 13px;
}

.food-preset-panel {
    margin: 12px 0 14px;
    padding: 12px;
    border: 1px solid rgba(46, 204, 113, 0.18);
    border-radius: 12px;
    background: rgba(46, 204, 113, 0.06);
}
.food-preset-panel--simple {
    margin: 0;
}

.food-preset-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}

.food-preset-title {
    font-size: 0.95em;
    font-weight: 700;
    color: var(--primary-dark);
}

.food-preset-hint {
    font-size: 0.8em;
    opacity: 0.75;
}

.food-preset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.food-preset-grid--single {
    grid-template-columns: minmax(0, 1fr);
}

.food-preset-field,
.food-preset-modifier-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.food-preset-label,
.food-preset-modifier-label {
    font-size: 0.8em;
    font-weight: 600;
    opacity: 0.8;
}

.food-preset-field select,
.food-preset-modifier-group select {
    width: 100%;
}

.food-preset-chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.food-preset-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(46, 204, 113, 0.18);
    font-size: 0.8em;
}

.food-preset-preview {
    margin: 6px 0 10px;
    font-size: 0.82em;
    opacity: 0.82;
}
.food-preset-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 2px 0 6px;
    font-size: 0.84em;
    color: var(--nav-text);
}
.food-preset-region-chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(46, 204, 113, 0.1);
    color: var(--primary-dark);
    font-weight: 700;
}
.food-preset-meta-copy {
    opacity: 0.86;
}

.btn-preset-apply {
    width: 100%;
    margin-top: 2px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(46, 204, 113, 0.92);
    color: #fff;
    font-weight: 700;
}
.food-preset-secondary-btn {
    width: auto;
    margin-top: 4px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--primary-dark);
    font-size: 0.85em;
    font-weight: 700;
    text-align: left;
}

.toast-container { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { padding: 12px 24px; border-radius: 8px; color: white; font-size: 14px; font-weight: bold; opacity: 0; transform: translateY(-20px); transition: all 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background-color: #e74c3c; }
.toast.success { background-color: #2ecc71; }
.toast.info { background-color: #3498db; }

[dir="rtl"] .dashboard-hero,
[dir="rtl"] .meal-header,
[dir="rtl"] .fav-item-row,
[dir="rtl"] .ai-item-row {
    direction: rtl;
}

[dir="rtl"] .dashboard-status-panel,
[dir="rtl"] .meal-empty-card,
[dir="rtl"] .ai-guide-card,
[dir="rtl"] .quick-start-card,
[dir="rtl"] .ai-status-note,
[dir="rtl"] .companion-hero,
[dir="rtl"] .home-log-launcher,
[dir="rtl"] .today-meals-card,
[dir="rtl"] .nutrition-panel,
[dir="rtl"] .nutrition-focus-card,
[dir="rtl"] #detail-content {
    text-align: right;
}

[dir="rtl"] .companion-hero-main,
[dir="rtl"] .companion-stat-row,
[dir="rtl"] .companion-meta-row,
[dir="rtl"] .companion-action-row,
[dir="rtl"] .home-signal-grid {
    direction: rtl;
}

[dir="rtl"] .food-preset-meta {
    flex-direction: row-reverse;
}

[dir="rtl"] .modal-sheet-header,
[dir="rtl"] .home-log-launcher,
[dir="rtl"] .home-common-food-strip {
    direction: rtl;
}

[dir="rtl"] .ai-guide-list {
    padding-right: 18px;
    padding-left: 0;
}

[dir="rtl"] .coach-tip-list {
    padding-right: 18px;
    padding-left: 0;
}

@media (max-width: 640px) {
    .companion-hero-main,
    .dashboard-hero {
        flex-direction: column;
    }

    .companion-pet-shell {
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 8px 0;
    }

    .dashboard-status-panel {
        min-width: 0;
    }

    .nutrition-grid,
    .ai-nutri-grid,
    .rhythm-signal-grid,
    .home-signal-grid,
    .nutrition-focus-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .food-preset-grid {
        grid-template-columns: 1fr;
    }

    .home-common-food-strip {
        grid-template-columns: 1fr;
    }

    .companion-action-row {
        grid-template-columns: 1fr;
    }

    .today-meals-header {
        flex-direction: column;
    }

    .companion-action-btn,
    .companion-stat-chip,
    .today-meals-date-btn {
        width: 100%;
    }
}
