/* MealTracker PWA — Mobile-first CSS */
:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --accent: #4f8cff;
    --accent-dim: #3a6ad4;
    --green: #34d399;
    --red: #f87171;
    --orange: #fbbf24;
    --text: #e8eaed;
    --text-dim: #9ca3af;
    --text-muted: #6b7280;
    --border: #2d3140;
    --radius: 14px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}

/* Safe area for iPhone notch */
.app {
    padding-top: env(safe-area-inset-top);
    padding-bottom: calc(env(safe-area-inset-bottom) + 80px);
    max-width: 480px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.date-nav {
    display: flex;
    align-items: center;
    gap: 12px;
}

.date-nav button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}

.date-nav button:active { background: var(--surface); }

.date-nav .date-label {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    min-width: 100px;
    text-align: center;
}

/* Macro summary cards */
.macros {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 16px 20px;
}

.macro-card {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
}

.macro-card .value {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.macro-card .label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.macro-card.cal .value { color: var(--orange); }
.macro-card.protein .value { color: var(--accent); }
.macro-card.carbs .value { color: var(--green); }
.macro-card.fat .value { color: var(--red); }

/* Secondary macros (fiber, sugar, sodium) */
.macros-secondary {
    display: flex;
    justify-content: center;
    gap: 12px;
    padding: 0 20px 12px;
}

.macro-pill {
    font-size: 12px;
    color: var(--text-dim);
    background: var(--surface);
    padding: 4px 10px;
    border-radius: 99px;
}

.macro-pill b { color: var(--text); font-weight: 600; }

/* Confirm screen secondary nutrition */
.nutrition-grid-secondary {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-dim);
}

.nutrition-grid-secondary b { color: var(--text); font-weight: 600; }

/* Food log list */
.log-section {
    padding: 0 20px;
}

.log-section h2 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

/* Meal group headers */
.meal-group {
    margin-bottom: 16px;
}

.meal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 4px 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.meal-totals {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

.log-entry {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: transform 0.1s;
}

.log-entry:active { transform: scale(0.98); }

.log-entry .info {
    flex: 1;
}

.log-entry .food-name {
    font-size: 15px;
    font-weight: 600;
}

.log-entry .food-detail {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 2px;
}

.log-entry .time {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.log-entry .entry-macros {
    text-align: right;
    font-size: 14px;
    font-weight: 600;
    color: var(--orange);
}

.log-entry .entry-macros .small {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 400;
}

.log-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Delete button (always visible, small) */
.log-entry .delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    padding: 8px;
    margin-left: 6px;
    cursor: pointer;
    opacity: 0.4;
    transition: opacity 0.2s, color 0.2s;
}

.log-entry .delete-btn:hover,
.log-entry .delete-btn:active {
    opacity: 1;
    color: var(--red);
}

/* FAB (Add button) */
.fab {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 20px) + 24px);
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 32px;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79, 140, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    transition: transform 0.15s;
}

.fab:active { transform: scale(0.9); }

/* ===== ADD FOOD SCREEN ===== */
.screen {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    overflow-y: auto;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.screen.active { display: block; }

.screen-header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}

.screen-header .back-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 16px;
    cursor: pointer;
    padding: 4px 8px;
    margin-right: 8px;
}

.screen-header h2 {
    font-size: 17px;
    font-weight: 700;
}

/* Input method grid */
.input-methods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 20px;
}

.input-btn {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.1s;
    color: var(--text);
}

.input-btn:active { transform: scale(0.95); }
.input-btn:hover { border-color: var(--accent); }

.input-btn .icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.input-btn .btn-label {
    font-size: 14px;
    font-weight: 600;
}

/* Quick re-log section */
.quick-relog {
    padding: 0 20px 20px;
}

.quick-relog h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

.quick-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.1s;
}

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

.quick-info { flex: 1; min-width: 0; }
.quick-item .name { font-size: 14px; font-weight: 500; display: block; }
.quick-brand { font-size: 11px; color: var(--text-muted); display: block; margin-top: 1px; }
.quick-meta { text-align: right; flex-shrink: 0; margin-left: 12px; }
.quick-cal { font-size: 12px; color: var(--orange); display: block; }
.quick-item .count { font-size: 11px; color: var(--text-muted); display: block; }

/* ===== SEARCH SCREEN ===== */
.search-box {
    padding: 16px 20px;
}

.search-box input {
    width: 100%;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: var(--text-muted); }

.search-results {
    padding: 0 20px;
}

.search-result {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: transform 0.1s;
}

.search-result:active { transform: scale(0.98); }
.search-result .result-name { font-size: 15px; font-weight: 600; }
.search-result .result-brand { font-size: 12px; color: var(--text-dim); }
.search-result .result-macros {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ===== CONFIRM SCREEN ===== */
.confirm-food {
    padding: 20px;
}

.confirm-food .food-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 4px;
}

.confirm-food .food-brand {
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 20px;
}

.confirm-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.field-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field-row label {
    font-size: 14px;
    color: var(--text-dim);
    min-width: 70px;
}

.field-row input, .field-row select {
    flex: 1;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.field-row input:focus, .field-row select:focus { border-color: var(--accent); }

.nutrition-preview {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 24px;
}

.nutrition-preview h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
}

.nutrition-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    text-align: center;
}

.nutrition-grid .val { font-size: 18px; font-weight: 700; }
.nutrition-grid .lbl { font-size: 11px; color: var(--text-dim); }

.save-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: white;
    font-size: 17px;
    font-weight: 700;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.2s;
}

.save-btn:active { background: var(--accent-dim); }

/* ===== BARCODE SCANNER ===== */
#barcode-reader {
    width: 100%;
    max-width: 400px;
    margin: 20px auto;
}

#barcode-reader video {
    border-radius: var(--radius);
}

/* ===== VOICE INPUT ===== */
.voice-ui {
    padding: 40px 20px;
    text-align: center;
}

.voice-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: var(--surface);
    border: 3px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 48px;
    cursor: pointer;
    transition: border-color 0.3s, transform 0.1s;
}

.voice-circle.listening {
    border-color: var(--red);
    animation: pulse 1.5s infinite;
}

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

.voice-text {
    font-size: 18px;
    font-weight: 500;
    min-height: 60px;
    padding: 16px;
    background: var(--surface);
    border-radius: var(--radius);
    margin-top: 20px;
}

.voice-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 12px;
}

/* ===== PHOTO INPUT ===== */
.photo-ui {
    padding: 20px;
    text-align: center;
}

.photo-preview {
    width: 100%;
    max-height: 300px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.photo-capture-btn {
    padding: 14px 32px;
    background: var(--accent);
    color: white;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Hidden file input */
.hidden { display: none !important; }

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 17, 23, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 500;
    gap: 12px;
    font-size: 14px;
    color: var(--text-dim);
}

.loading-overlay.hidden { display: none; }

/* Toast */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface2);
    color: var(--text);
    padding: 12px 24px;
    border-radius: 99px;
    font-size: 14px;
    font-weight: 500;
    z-index: 600;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.toast.show { opacity: 1; }

/* Photo results list */
.photo-results {
    padding: 0 20px 20px;
}

.photo-result-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    cursor: pointer;
}

.photo-result-item .pr-name { font-size: 15px; font-weight: 600; }
.photo-result-item .pr-detail { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ===== OFFLINE BANNER ===== */
.offline-banner {
    background: var(--orange);
    color: #000;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px);
}

.offline-banner.hidden { display: none !important; }

.sync-btn {
    background: rgba(0, 0, 0, 0.15);
    border: none;
    color: #000;
    padding: 5px 14px;
    border-radius: 99px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.sync-btn:active { background: rgba(0, 0, 0, 0.25); }
.sync-btn:disabled { opacity: 0.5; }

/* ===== SETTINGS SCREEN ===== */
.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.settings-btn:active { opacity: 1; }

.settings-content {
    padding: 20px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 12px;
}

.setting-row {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setting-info { flex: 1; min-width: 0; }
.setting-label { font-size: 15px; font-weight: 500; display: block; }
.setting-desc { font-size: 12px; color: var(--text-muted); display: block; margin-top: 2px; }

.setting-row input[type="time"] {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 10px;
    font-size: 14px;
    width: 90px;
    text-align: center;
}

/* Toggle switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
    flex-shrink: 0;
}

.toggle.small { width: 40px; height: 24px; }

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 28px;
    transition: background 0.3s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s;
}

.toggle.small .toggle-slider::before {
    height: 18px;
    width: 18px;
}

.toggle input:checked + .toggle-slider { background: var(--green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle.small input:checked + .toggle-slider::before { transform: translateX(16px); }

.notif-schedule {
    margin-top: 8px;
    transition: opacity 0.3s;
}

.notif-schedule.disabled {
    opacity: 0.4;
    pointer-events: none;
}
