* { margin: 0; padding: 0; box-sizing: border-box; }
html { overflow-y: scroll; }

:root {
    --bg-primary: #ffffff; --bg-secondary: #f5f5f5; --bg-tertiary: #e0e0e0;
    --text-primary: #1a1a1a; --text-secondary: #666666;
    --accent: #4a9eff; --success: #4caf50; --danger: #f44336; --warning: #ff9800;
}
[data-theme="dark"] {
    --bg-primary: #1a1a1a; --bg-secondary: #2d2d2d; --bg-tertiary: #3d3d3d;
    --text-primary: #ffffff; --text-secondary: #b0b0b0;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif; background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; -webkit-font-smoothing: antialiased; }
#app { max-width: 600px; margin: 0 auto; min-height: 100vh; padding-bottom: 2rem; }
.view { display: none; padding: 1rem; padding-bottom: 5rem; }
.view.active { display: block; }

/* Branding */
.app-brand { text-align: center; padding: 0.5rem 0 0.25rem; margin-bottom: 0.5rem; }
.brand-name { font-size: 1.5rem; font-weight: 900; letter-spacing: 0.15em; color: var(--text-primary); }
.brand-by { font-size: 0.65rem; color: var(--text-secondary); font-weight: 400; letter-spacing: 0.05em; }

/* Welcome Overlay */
.welcome-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: #000; z-index: 20000;
    display: flex; align-items: center; justify-content: center;
    animation: welcomeFadeIn 0.5s ease;
    overflow-y: auto;
}
@keyframes welcomeFadeIn { from { opacity: 0; } to { opacity: 1; } }
.welcome-overlay.welcome-hiding {
    opacity: 0; transition: opacity 0.4s ease; pointer-events: none;
}
.welcome-content {
    text-align: center; padding: 2rem; max-width: 380px; width: 90%;
}
.welcome-brand {
    font-size: 3rem; font-weight: 900; letter-spacing: 0.12em;
    color: #fff; margin-bottom: 0.25rem;
}
.welcome-by {
    font-size: 0.75rem; color: #555; letter-spacing: 0.2em;
    margin-bottom: 2rem;
}
.welcome-pitch {
    font-size: 1rem; line-height: 1.7; color: #999;
    margin-bottom: 2rem;
}
.welcome-cta {
    display: block; width: 100%; padding: 1rem;
    background: #4a9eff; color: #fff; border: none;
    border-radius: 10px; font-size: 1.1rem; font-weight: 700;
    cursor: pointer; letter-spacing: 0.02em;
    transition: background 0.2s; font-family: inherit;
}
.welcome-cta:active { background: #3a8eef; }
.welcome-no-catch {
    font-size: 0.75rem; color: #444; margin-top: 0.75rem;
}
.welcome-email-group {
    margin-bottom: 1.75rem;
}
.welcome-email {
    width: 100%; padding: 0.85rem 1rem; background: #111;
    border: 1px solid #2a2a2a; border-radius: 8px;
    color: #fff; font-size: 0.95rem; text-align: center;
    font-family: inherit;
}
.welcome-email::placeholder { color: #444; }
.welcome-email:focus { outline: none; border-color: #4a9eff; }
.welcome-email-hint {
    font-size: 0.7rem; color: #444; margin-top: 0.6rem;
    line-height: 1.6;
}

/* Nudge Banners */
.nudge-banner { margin: 0 0 0.75rem; padding: 0.75rem 1rem; background: var(--bg-secondary); border-radius: 8px; border: 1px solid var(--bg-tertiary); font-size: 0.8rem; color: var(--text-secondary); cursor: pointer; position: relative; }
.nudge-dismiss { float: right; opacity: 0.5; font-size: 0.7rem; }

/* Status Card */
.status-card { background: var(--bg-secondary); border-radius: 12px; padding: 1rem; margin-bottom: 1rem; }
.cal-progress { margin-bottom: 1rem; }
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; font-size: 1.25rem; font-weight: 600; }
.cal-remaining { font-size: 0.875rem; color: var(--text-secondary); font-weight: normal; }
.progress-bar { width: 100%; height: 10px; background: var(--bg-tertiary); border-radius: 5px; overflow: hidden; }
.progress-fill { height: 100%; transition: all 0.3s ease; border-radius: 5px; }
.progress-green { background: var(--success); }
.progress-yellow { background: var(--warning); }
.progress-red { background: var(--danger); }
.macros-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--bg-tertiary); }
.macro-item { text-align: center; }
.macro-label { font-size: 0.75rem; color: var(--text-secondary); margin-bottom: 0.5rem; text-transform: uppercase; }
.macro-values { font-size: 1rem; font-weight: 600; }

/* Section */
.section-header { margin-bottom: 0.75rem; }
.section-header h2 { font-size: 1.125rem; color: var(--text-primary); font-weight: 600; }
.section-hint { font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.25rem; line-height: 1.4; }
.section-divider { height: 2rem; }

/* Bottom Actions */
.bottom-actions { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-secondary); padding: 0.5rem; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.25rem; box-shadow: 0 -2px 10px rgba(0,0,0,0.3); max-width: 600px; margin: 0 auto; z-index: 90; }
.btn-nav { padding: 0.65rem 0; font-size: 0.6rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.01em; text-align: center; }
.btn-nav-icon { display: flex; align-items: center; justify-content: center; }
.btn-eat { padding: 0.65rem 0; font-size: 0.7rem; }

/* Buttons */
.btn { padding: 0.75rem 1rem; border: none; border-radius: 8px; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:active { background: #3a8eef; }
.btn-secondary { background: var(--bg-tertiary); color: var(--text-primary); }
.btn-secondary:active { background: #4d4d4d; }
.btn-danger { background: var(--danger); color: white; margin-top: 1rem; }
.btn-small { padding: 0.5rem 0.75rem; font-size: 0.75rem; }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); z-index: 1000; overflow-y: auto; }
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg-secondary); border-radius: 12px; padding: 1.5rem; width: 90%; max-width: 500px; margin: 2rem auto; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.modal-header h2 { font-size: 1.5rem; }
.close-btn { background: none; border: none; font-size: 2rem; color: var(--text-secondary); cursor: pointer; padding: 0; width: 2rem; height: 2rem; line-height: 1; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.form-group input { width: 100%; padding: 0.75rem; background: var(--bg-tertiary); border: 1px solid transparent; border-radius: 8px; color: var(--text-primary); font-size: 1rem; }
.form-group input:focus { outline: none; border-color: var(--accent); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1.5rem; }
.checkbox-group { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--bg-tertiary); }
.checkbox-group label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.checkbox-group input[type="checkbox"] { width: 1.25rem; height: 1.25rem; }

/* Autocomplete */
#autocomplete-suggestions { background: var(--bg-tertiary); border-radius: 8px; margin-top: 0.5rem; max-height: 200px; overflow-y: auto; }
.suggestion-item { padding: 0.75rem; cursor: pointer; border-bottom: 1px solid var(--bg-secondary); }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--bg-secondary); }
.suggestion-name { font-weight: 600; margin-bottom: 0.25rem; }
.suggestion-macros { font-size: 0.75rem; color: var(--text-secondary); }

/* View Header */
.view-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; }
.back-btn { background: var(--bg-secondary); border: none; color: var(--accent); font-size: 1rem; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; }

/* Compact Entries */
.entries-list-compact { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.entry-card-compact { background: var(--bg-secondary); border-radius: 8px; padding: 0.75rem; display: flex; justify-content: space-between; align-items: center; border: 1px solid var(--bg-tertiary); }
.entry-info-compact { flex: 1; }
.entry-name-compact { font-size: 0.875rem; font-weight: 600; margin-bottom: 0.25rem; }
.entry-time { font-size: 0.7rem; color: var(--text-secondary); font-weight: normal; margin-left: 0.5rem; }
.entry-macros-compact { font-size: 0.75rem; color: var(--text-secondary); }
.entry-actions-compact { display: flex; gap: 0.5rem; }
.entry-actions-compact button { background: var(--bg-tertiary); border: none; padding: 0.4rem; border-radius: 6px; cursor: pointer; font-size: 1rem; }
.empty-state-compact { text-align: center; padding: 1.5rem; color: var(--text-secondary); font-size: 0.875rem; }

/* Food Grid */
.food-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; margin-bottom: 1rem; }
.food-card { border-radius: 6px; padding: 0.5rem; cursor: pointer; transition: all 0.15s; border: 1px solid rgba(74, 158, 255, 0.35); background: linear-gradient(135deg, rgba(74, 158, 255, 0.15) 0%, rgba(74, 158, 255, 0.25) 100%); }
.food-card:active { transform: scale(0.95); opacity: 0.8; }
.food-card-name { font-size: 0.75rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--text-primary); line-height: 1.2; }
.food-card-macros { font-size: 0.65rem; color: var(--text-secondary); line-height: 1.3; }

/* Manage List (flat rows) */
.manage-list { display: flex; flex-direction: column; gap: 0; margin: 0 0 1rem; }
.manage-row { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1rem; border-bottom: 1px solid var(--bg-tertiary); cursor: pointer; transition: background 0.15s; }
.manage-row:active { background: var(--bg-tertiary); }
.manage-row-name { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.manage-row-macros { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; margin-left: 1rem; }

/* Edit Mode */
.food-card-edit { cursor: default !important; padding: 0.5rem 0.4rem !important; }
.food-card-edit:active { transform: none !important; }
.edit-move-btns { display: flex; justify-content: space-between; margin-bottom: 0.3rem; }
.btn-move { background: rgba(255,255,255,0.2); border: none; color: var(--text-primary); font-size: 0.65rem; padding: 0.15rem 0.4rem; border-radius: 4px; cursor: pointer; line-height: 1; }
.btn-move:active { background: rgba(255,255,255,0.4); }
.btn-move-spacer { width: 1.2rem; }
.colour-picker { display: flex; gap: 0.2rem; margin-top: 0.35rem; justify-content: center; flex-wrap: wrap; }
.colour-dot { width: 0.9rem; height: 0.9rem; border-radius: 50%; border: 2px solid transparent; cursor: pointer; transition: all 0.15s; }
.colour-dot:active { transform: scale(1.2); }
.colour-dot-active { border-color: var(--text-primary) !important; transform: scale(1.15); }

/* Settings */
.settings-section { background: var(--bg-secondary); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; }
.settings-section h3 { font-size: 1rem; margin-bottom: 1rem; color: var(--text-secondary); }
.settings-toggle-row { display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-weight: 600; padding: 0.5rem 0; border-bottom: 1px solid var(--bg-tertiary); }
.settings-toggle-row:last-child { border-bottom: none; }

/* Weekly Summary */
.week-day { background: var(--bg-secondary); border-radius: 8px; padding: 1rem; margin-bottom: 0.75rem; }
.week-day-header { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
.week-day-date { font-weight: 600; }
.week-day-total { color: var(--text-secondary); }
.week-day-macros { font-size: 0.875rem; color: var(--text-secondary); display: flex; gap: 1rem; }
.week-section { background: var(--bg-secondary); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
.week-section-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.75rem; color: var(--text-primary); }
.week-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.week-table th { text-align: left; padding: 0.35rem 0.4rem; color: var(--text-secondary); font-weight: 600; font-size: 0.7rem; border-bottom: 1px solid var(--bg-tertiary); }
.week-table td { padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--bg-tertiary); }
.week-table .r { text-align: right; }
.week-table .b { font-weight: 600; }
.week-total-row { border-top: 2px solid var(--text-secondary); }
.week-total-row td { padding-top: 0.75rem; }
.week-diff { font-size: 0.65rem; margin-top: 0.1rem; }
.week-note { font-size: 0.65rem; color: var(--text-secondary); margin-top: 0.5rem; font-style: italic; }

/* Track Tabs */
.track-tabs { display: flex; gap: 0; margin: 0 1rem; border-bottom: 2px solid var(--bg-tertiary); }
.track-tab { flex: 1; padding: 0.75rem; background: none; border: none; color: var(--text-secondary); font-size: 0.875rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; font-family: inherit; }
.track-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.track-panel { display: none; }
.track-panel.active { display: block; }

/* Insights */
.insight-card { background: var(--bg-secondary); border-radius: 10px; padding: 1rem; margin-bottom: 0.75rem; }
.insight-label { font-size: 0.7rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.35rem; }
.insight-value { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.25rem; }
.insight-context { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5; }
.insight-chart-container { background: var(--bg-secondary); border-radius: 12px; padding: 1rem; margin-bottom: 0.75rem; }
.insight-chart-title { font-size: 0.7rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.insight-minimum { text-align: center; padding: 3rem 1.5rem; color: var(--text-secondary); font-size: 0.875rem; line-height: 1.6; }

/* Empty State */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-secondary); }
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; }

/* Macro Sliders */
.macro-slider-group { margin: 1.5rem 0; }
.macro-slider { margin-bottom: 1.5rem; }
.macro-slider label { display: block; margin-bottom: 0.5rem; font-size: 0.875rem; color: var(--text-primary); }
.macro-slider input[type="range"] { width: 100%; height: 8px; background: var(--bg-tertiary); border-radius: 4px; outline: none; -webkit-appearance: none; }
.macro-slider input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; background: var(--accent); border-radius: 50%; cursor: pointer; }
.macro-slider input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; background: var(--accent); border-radius: 50%; cursor: pointer; border: none; }
.macro-total { font-size: 1.25rem; font-weight: 600; text-align: center; padding: 1rem; border-radius: 8px; margin-bottom: 1rem; transition: all 0.3s ease; }
.macro-total-valid { background: rgba(76, 175, 80, 0.2); color: var(--success); }
.macro-total-invalid { background: rgba(244, 67, 54, 0.2); color: var(--danger); }
.macro-total-close { background: rgba(255, 152, 0, 0.2); color: var(--warning); }

/* Quantity Slider */
.quantity-display { font-size: 1.5rem; font-weight: 600; text-align: center; margin-bottom: 1rem; color: var(--accent); }

/* kJ Toggle */
.btn-kj-toggle { background: var(--bg-tertiary); border: 1px solid transparent; color: var(--text-secondary); font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 4px; cursor: pointer; text-transform: uppercase; transition: all 0.2s; }
.btn-kj-toggle.kj-active { background: var(--warning); color: #1a1a1a; border-color: var(--warning); }
.kj-hint { font-size: 0.75rem; color: var(--warning); margin-top: 0.25rem; }
.quantity-range { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-secondary); margin-top: 0.5rem; }
.quantity-macros { text-align: center; font-size: 0.875rem; color: var(--text-secondary); margin-top: 1rem; padding: 0.75rem; background: var(--bg-tertiary); border-radius: 8px; }

/* Help Content */
.help-body { font-size: 0.875rem; line-height: 1.7; color: var(--text-primary); padding-bottom: 2rem; }
.help-body h3 { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 0.5rem; color: var(--accent); }
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin-bottom: 0.75rem; color: var(--text-secondary); }
.help-body strong { color: var(--text-primary); }

/* ============================================
   Trial Banner
   ============================================ */
.trial-banner { text-align: center; padding: 0.5rem; border-radius: 8px; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.75rem; cursor: default; }
.trial-active { background: rgba(255, 152, 0, 0.15); color: var(--warning); border: 1px solid rgba(255, 152, 0, 0.3); }
.trial-expired { background: rgba(244, 67, 54, 0.15); color: var(--danger); border: 1px solid rgba(244, 67, 54, 0.3); cursor: pointer; }

/* ============================================
   Toast Notification
   ============================================ */
.toast-notification {
    position: fixed; bottom: 5rem; left: 50%; transform: translateX(-50%) translateY(20px);
    padding: 0.75rem 1.5rem; border-radius: 10px; font-size: 0.875rem; font-weight: 600;
    z-index: 9999; opacity: 0; transition: all 0.3s ease; pointer-events: none;
    max-width: 90%; text-align: center; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.toast-success { background: #2e7d32; color: white; }
.toast-error { background: #c62828; color: white; }
.toast-visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-hiding { opacity: 0; transform: translateX(-50%) translateY(-10px); }

/* ============================================
   Custom Confirm Dialog
   ============================================ */
.confirm-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7); z-index: 10000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.2s ease;
}
.confirm-overlay.confirm-visible { opacity: 1; }
.confirm-dialog {
    background: var(--bg-secondary); border-radius: 12px; padding: 1.5rem;
    width: 85%; max-width: 350px; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.confirm-message { font-size: 1rem; margin-bottom: 1.5rem; text-align: center; line-height: 1.5; color: var(--text-primary); }
.confirm-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
