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

:root {
    --bg: #0f172a;
    --card: #1e293b;
    --border: #334155;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --yellow: #f59e0b;
    --red: #ef4444;
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: env(safe-area-inset-bottom, 20px);
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.header h1 { font-size: 20px; }
.garmin-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-dim);
}
.garmin-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
}
.garmin-dot.expired { background: var(--red); }
.garmin-dot.unknown { background: var(--text-dim); }

/* Views */
.view { display: none; padding: 20px; }
.view.active { display: block; }

/* Main view */
.input-section { margin-bottom: 24px; }
.input-section label {
    display: block;
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.photo-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 20px;
    font-size: 18px;
    font-weight: 600;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    margin-bottom: 16px;
}
.photo-btn:active { border-color: var(--accent); }
.photo-btn .icon { font-size: 24px; }

#photo-input { display: none; }

.text-input-row {
    display: flex;
    gap: 8px;
}
.text-input-row input {
    flex: 1;
    padding: 14px 16px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    outline: none;
}
.text-input-row input:focus { border-color: var(--accent); }
.text-input-row button {
    padding: 14px 20px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    background: var(--accent);
    color: white;
    cursor: pointer;
    white-space: nowrap;
}

/* Today's summary */
.summary-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 24px;
}
.summary-card h3 {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 12px;
}
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    text-align: center;
}
.summary-item .value {
    font-size: 22px;
    font-weight: 700;
}
.summary-item .label {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

/* Recent entries */
.entries-list { margin-top: 16px; }
.entry-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.entry-item .name { flex: 1; }
.entry-item .cals {
    font-weight: 600;
    color: var(--yellow);
}
.entry-item .garmin-icon {
    margin-left: 8px;
    font-size: 12px;
}

/* Garmin banner */
.garmin-banner {
    background: #7f1d1d;
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    display: none;
}
.garmin-banner.show { display: block; }

/* Loading overlay */
.loading {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
}
.loading.show { display: flex; }
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; color: var(--text-dim); }

/* Result views */
.result-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.result-card h2 {
    font-size: 18px;
    margin-bottom: 16px;
}
.nutrition-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    text-align: center;
    margin-bottom: 16px;
}
.nutrition-item .value {
    font-size: 24px;
    font-weight: 700;
}
.nutrition-item .unit {
    font-size: 12px;
    color: var(--text-dim);
}

/* Servings stepper */
.stepper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 16px 0;
}
.stepper button {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    border-radius: 50%;
    background: var(--card);
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stepper button:active { border-color: var(--accent); }
.stepper .amount {
    font-size: 28px;
    font-weight: 700;
    min-width: 60px;
    text-align: center;
}

/* Slider */
.slider-container { margin: 20px 0; }
.slider-labels {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}
.slider-label-low, .slider-label-high {
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
}
.slider-label-low strong, .slider-label-high strong {
    display: block;
    font-size: 16px;
    color: var(--text);
}
.slider-current {
    text-align: center;
    margin-bottom: 12px;
}
.slider-current .value {
    font-size: 36px;
    font-weight: 800;
}
.slider-current .unit {
    font-size: 16px;
    color: var(--text-dim);
    font-weight: 400;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    border-radius: 5px;
    background: linear-gradient(to right, var(--green), var(--yellow), var(--red));
    outline: none;
    touch-action: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: white;
    border: 3px solid var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    cursor: pointer;
}

/* Meal type selector */
.meal-selector {
    display: flex;
    gap: 8px;
    margin: 16px 0;
    flex-wrap: wrap;
}
.meal-btn {
    flex: 1;
    min-width: 70px;
    padding: 10px 8px;
    font-size: 13px;
    font-weight: 600;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text-dim);
    cursor: pointer;
    text-align: center;
}
.meal-btn.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(59, 130, 246, 0.1);
}

/* Action buttons */
.action-btn {
    width: 100%;
    padding: 16px;
    font-size: 18px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    background: var(--green);
    color: white;
    cursor: pointer;
    margin-top: 8px;
}
.action-btn:active { filter: brightness(0.9); }

.back-btn {
    display: block;
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
    margin-top: 12px;
    cursor: pointer;
    padding: 8px;
    background: none;
    border: none;
    width: 100%;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--card);
    border: 1px solid var(--border);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
