:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #dbeafe;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --danger: #ef4444;
    --success: #10b981;
    --bg: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
    --radius-sm: 8px;
    --radius: 16px;
    --radius-lg: 24px;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: calc(80px + var(--safe-bottom));
    padding-top: var(--safe-top);
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

input, select, textarea {
    font-family: inherit;
    font-size: 16px;
    border: none;
    outline: none;
    background: none;
    color: inherit;
}

a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }

.app-container {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--bg);
    position: relative;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    padding: 16px 20px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(248, 250, 252, 0.85);
}

.top-bar h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 15px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
}

.icon-btn:active { background: var(--border); }

.content {
    padding: 0 16px 24px;
}

.section-title {
    font-size: 22px;
    font-weight: 700;
    margin: 8px 4px 14px;
    letter-spacing: -0.02em;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 14px;
}

.card-title {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.01em;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.calorie-card {
    display: flex;
    align-items: center;
    gap: 16px;
}

.calorie-ring {
    flex-shrink: 0;
    position: relative;
    width: 140px;
    height: 140px;
}

.calorie-ring svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.calorie-ring-bg { stroke: var(--border); fill: none; stroke-width: 12; }
.calorie-ring-fg {
    fill: none;
    stroke-width: 12;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.calorie-ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.calorie-ring-number {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1;
}

.calorie-ring-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.calorie-stats {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.calorie-stat {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calorie-stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.calorie-stat-icon.goal { background: #f1f5f9; color: var(--text-secondary); }
.calorie-stat-icon.food { background: var(--primary-light); color: var(--primary); }
.calorie-stat-icon.exercise { background: var(--accent-light); color: var(--accent); }

.calorie-stat-info { display: flex; flex-direction: column; }
.calorie-stat-label { font-size: 11px; color: var(--text-secondary); font-weight: 500; }
.calorie-stat-value { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }

.macro-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.macro {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.macro-bar {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}

.macro-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
}

.macro-label { font-size: 11px; color: var(--text-secondary); font-weight: 500; }
.macro-value { font-size: 14px; font-weight: 700; }

.protein .macro-bar-fill { background: #ef4444; }
.carbs .macro-bar-fill { background: #f59e0b; }
.fat .macro-bar-fill { background: #8b5cf6; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.mini-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.mini-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.mini-card-title { font-size: 14px; font-weight: 600; color: var(--text-secondary); }

.mini-card-icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}

.mini-card-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.mini-card-icon-sm {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.steps-icon { color: #ec4899; }
.exercise-icon { color: var(--accent); }
.time-icon { color: var(--accent); }

.mini-card-value { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.mini-card-sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #ec4899 0%, #f43f5e 100%);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.meals-list { display: flex; flex-direction: column; gap: 12px; }

.meal-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

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

.meal-header-left { display: flex; align-items: center; gap: 12px; }

.meal-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.meal-icon.breakfast { background: #fef3c7; color: #d97706; }
.meal-icon.lunch { background: #dcfce7; color: #16a34a; }
.meal-icon.dinner { background: #ddd6fe; color: #7c3aed; }
.meal-icon.snack { background: #fce7f3; color: #db2777; }

.meal-name { font-weight: 700; font-size: 15px; }
.meal-cal { font-size: 12px; color: var(--text-secondary); }

.meal-add-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
}

.meal-add-btn:active { transform: scale(0.92); }

.meal-items { display: flex; flex-direction: column; gap: 8px; }

.meal-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--bg);
    border-radius: var(--radius-sm);
}

.meal-item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.meal-item-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-item-detail { font-size: 12px; color: var(--text-secondary); }
.meal-item-cal { font-size: 14px; font-weight: 700; color: var(--primary); margin-left: 12px; }
.meal-item-delete { color: var(--text-tertiary); padding: 4px 8px; margin-left: 4px; }

.meal-empty { font-size: 13px; color: var(--text-tertiary); padding: 8px 0; }

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 8px 16px calc(8px + var(--safe-bottom));
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 40;
}

.bottom-nav-inner {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    color: var(--text-tertiary);
    transition: color 0.15s;
    flex: 1;
}

.nav-item.active { color: var(--primary); }
.nav-item-label { font-size: 10px; font-weight: 600; }

.fab {
    position: fixed;
    bottom: calc(85px + var(--safe-bottom));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    z-index: 30;
    transition: transform 0.15s;
}

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

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s;
}

.modal-backdrop.active { display: flex; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal {
    background: var(--card);
    border-radius: 24px 24px 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    padding-bottom: calc(20px + var(--safe-bottom));
}

.modal-handle {
    width: 36px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 12px auto 8px;
}

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

.modal-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.modal-close { color: var(--text-secondary); padding: 4px; }

.modal-body { padding: 20px; }

.form-group { margin-bottom: 16px; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg);
    border: 1.5px solid transparent;
    border-radius: 12px;
    font-size: 16px;
    transition: border-color 0.15s, background 0.15s;
}

.form-input:focus {
    border-color: var(--primary);
    background: var(--card);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    transition: transform 0.15s, opacity 0.15s;
    width: 100%;
}

.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-ghost { background: transparent; color: var(--text-secondary); }

.search-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    margin-top: 12px;
}

.search-result-item {
    padding: 12px 14px;
    background: var(--bg);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.15s;
}

.search-result-item:active { background: var(--primary-light); }
.search-result-info { flex: 1; min-width: 0; }
.search-result-name { font-weight: 600; font-size: 14px; }
.search-result-detail { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.search-result-cal { font-size: 14px; font-weight: 700; color: var(--primary); }

.tabs {
    display: flex;
    background: var(--bg);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 16px;
    gap: 4px;
}

.tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }

.auth-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #6366f1 0%, #3b82f6 100%);
}

.auth-card {
    background: white;
    border-radius: 28px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.auth-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary) 0%, #6366f1 100%);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    margin: 0 auto 16px;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.auth-title {
    text-align: center;
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 4px;
    letter-spacing: -0.02em;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-link {
    text-align: center;
    margin-top: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-link a { color: var(--primary); font-weight: 600; }

.alert {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-error { background: #fef2f2; color: #991b1b; }
.alert-success { background: #f0fdf4; color: #166534; }

.weight-chart {
    height: 180px;
    position: relative;
    margin-top: 8px;
}

.weight-chart svg { width: 100%; height: 100%; overflow: visible; }

.chart-grid line { stroke: var(--border); stroke-dasharray: 3 3; }
.chart-axis { font-size: 10px; fill: var(--text-tertiary); }
.chart-line { fill: none; stroke: var(--success); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: var(--success); opacity: 0.1; }
.chart-dot { fill: var(--success); stroke: white; stroke-width: 2; }

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
}

.empty-state-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    background: var(--bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
}

.empty-state-text { font-size: 14px; }

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: none;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.spinner {
    width: 20px;
    height: 20px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.page-loader {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.3s;
}

.page-loader.hide { opacity: 0; pointer-events: none; }

.page-loader .spinner { border-color: var(--border); border-top-color: var(--primary); width: 32px; height: 32px; }

.profile-section { padding: 16px 0; }

.profile-stat {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--card);
    border-radius: 12px;
    margin-bottom: 8px;
}

.profile-stat-label { font-size: 14px; color: var(--text-secondary); }
.profile-stat-value { font-size: 15px; font-weight: 600; }

.exercise-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg);
    border-radius: 12px;
    margin-bottom: 8px;
}

.exercise-info { display: flex; align-items: center; gap: 10px; flex: 1; }

.exercise-icon-wrap {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.exercise-name { font-size: 14px; font-weight: 600; }
.exercise-detail { font-size: 12px; color: var(--text-secondary); }
.exercise-cal { font-size: 14px; font-weight: 700; color: var(--accent); }

.progress-section { display: flex; flex-direction: column; gap: 14px; }

.stat-tiles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 4px;
}

.stat-tile {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.stat-tile-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.stat-tile-value { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; }
.stat-tile-trend { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.intensity-pills { display: flex; gap: 8px; }

.intensity-pill {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    background: var(--bg);
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.intensity-pill.active { background: var(--primary); color: white; }

.exercise-presets { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; -webkit-overflow-scrolling: touch; }
.exercise-presets::-webkit-scrollbar { display: none; }

.exercise-preset {
    flex-shrink: 0;
    padding: 8px 14px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.exercise-preset:active { background: var(--primary-light); color: var(--primary); }

@media (display-mode: standalone) {
    body { padding-top: max(var(--safe-top), 12px); }
}

@supports (padding: max(0px)) {
    .top-bar { padding-top: max(16px, var(--safe-top)); }
}
