/* --- CSS VARIABLES & BASE --- */
:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --bg-input: rgba(255, 255, 255, 0.05);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.12);
    
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    
    --accent-primary: #8b5cf6;
    --accent-secondary: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.4);
    
    --protein: #3b82f6;
    --protein-glow: rgba(59, 130, 246, 0.3);
    --carbs: #10b981;
    --carbs-glow: rgba(16, 185, 129, 0.3);
    --fats: #f59e0b;
    --fats-glow: rgba(245, 158, 11, 0.3);
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px var(--accent-glow);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* --- BACKGROUND EFFECTS --- */
.bg-gradient {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at top, rgba(139, 92, 246, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at bottom right, rgba(59, 130, 246, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at bottom left, rgba(16, 185, 129, 0.08) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

.bg-orbs {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s ease-in-out infinite;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: var(--accent-primary);
    top: -200px;
    right: -100px;
    animation-delay: 0s;
}

.orb-2 {
    width: 300px;
    height: 300px;
    background: var(--protein);
    bottom: -150px;
    left: -100px;
    animation-delay: -7s;
}

.orb-3 {
    width: 250px;
    height: 250px;
    background: var(--carbs);
    top: 50%;
    left: 50%;
    animation-delay: -14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -30px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(-30px, -20px) scale(1.02); }
}

/* --- CONTAINER --- */
.container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 100px;
}

.hidden { display: none !important; }

/* --- AUTH SCREEN --- */
.auth-container {
    min-height: 90vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.auth-logo {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.logo-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--accent-primary), var(--protein));
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px var(--accent-glow);
}

.logo-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.auth-header {
    text-align: center;
    margin-bottom: 36px;
}

.auth-header h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.input-group {
    position: relative;
    margin-bottom: 16px;
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color 0.3s;
}

.input-icon svg {
    width: 100%;
    height: 100%;
}

.modern-input {
    width: 100%;
    padding: 16px 16px 16px 52px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
}

.modern-input::placeholder {
    color: var(--text-muted);
}

.modern-input:hover {
    border-color: var(--border-light);
}

.modern-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: rgba(139, 92, 246, 0.05);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.modern-input:focus + .input-icon,
.input-group:focus-within .input-icon {
    color: var(--accent-primary);
}

.error-msg {
    color: var(--danger);
    font-size: 0.875rem;
    min-height: 24px;
    text-align: center;
    margin-bottom: 8px;
}

.auth-btn {
    width: 100%;
    padding: 16px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.auth-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
}

.auth-btn.primary {
    background: linear-gradient(135deg, var(--accent-primary), #6366f1);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
    margin-bottom: 12px;
}

.auth-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.auth-btn.primary:hover svg {
    transform: translateX(4px);
}

.auth-btn.secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.auth-btn.secondary:hover {
    border-color: var(--border-light);
    background: var(--bg-input);
}

.auth-footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.auth-footer span {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- APP HEADER --- */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding: 8px 0;
}

.header-left {
    display: flex;
    flex-direction: column;
}

.greeting {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    gap: 12px;
}

.icon-btn-header {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.icon-btn-header svg {
    width: 20px;
    height: 20px;
}

.icon-btn-header:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.icon-btn-header.logout:hover {
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

/* --- DASHBOARD --- */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 32px;
}

/* Main Calorie Card */
.main-stats {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 24px;
    position: relative;
    overflow: hidden;
}

.main-stats::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--accent-primary), transparent);
}

.main-stats-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.cal-info {
    flex: 1;
}

.cal-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
    display: block;
}

.cal-info h2 {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    transition: all 0.3s;
}

.cal-info h2.over {
    background: linear-gradient(135deg, var(--danger) 0%, #f87171 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

.goal-label {
    font-size: 0.95rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.goal-label.over {
    color: var(--danger);
}

.ring-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ring-container.large {
    width: 100px;
    height: 100px;
}

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

.ring-bg {
    fill: none;
    stroke: var(--bg-input);
    stroke-width: 8;
}

.ring-fill {
    fill: none;
    stroke: var(--accent-primary);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 264;
    stroke-dashoffset: 264;
    transition: stroke-dashoffset 0.8s ease, stroke 0.3s;
}

#ring-cals.over {
    stroke: var(--danger);
}

.ring-center {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ring-center span {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.calorie-bar {
    margin-top: 8px;
}

.bar-track {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 3px;
    transition: width 0.8s ease, background 0.3s;
    width: 0%;
}

.bar-fill.over {
    background: linear-gradient(90deg, var(--danger), #f87171);
}

/* Prediction Card */
.prediction-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 20px;
}

.pred-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.pred-header svg {
    width: 20px;
    height: 20px;
    color: var(--carbs);
}

.pred-header span {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pred-body {
    text-align: center;
    padding: 16px 0;
}

.pred-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 8px;
    transition: color 0.3s;
}

.pred-value.gain {
    color: var(--warning);
}

.pred-change {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.change-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.change-indicator.gain {
    background: var(--warning);
}

.change-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.pred-footer {
    text-align: center;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    margin-top: 16px;
}

.pred-footer span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Macro Grid */
.macro-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.macro-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    transition: all 0.3s ease;
}

.macro-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-light);
}

.macro-card.protein { border-top: 3px solid var(--protein); }
.macro-card.carbs { border-top: 3px solid var(--carbs); }
.macro-card.fats { border-top: 3px solid var(--fats); }

.macro-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.macro-card.protein .macro-icon {
    background: var(--protein-glow);
    color: var(--protein);
}

.macro-card.carbs .macro-icon {
    background: var(--carbs-glow);
    color: var(--carbs);
}

.macro-card.fats .macro-icon {
    background: var(--fats-glow);
    color: var(--fats);
}

.macro-icon svg {
    width: 18px;
    height: 18px;
}

.macro-val {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 2px;
}

.macro-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.macro-bar {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
}

.macro-card.protein .macro-bar .bar-fill {
    background: var(--protein);
}

.macro-card.carbs .macro-bar .bar-fill {
    background: var(--carbs);
}

.macro-card.fats .macro-bar .bar-fill {
    background: var(--fats);
}

/* --- SECTIONS --- */
.section {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 24px;
    margin-bottom: 20px;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.section-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    background: rgba(139, 92, 246, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
}

.section-icon svg {
    width: 20px;
    height: 20px;
}

.section-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* --- FORM --- */
.meal-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-row.full {
    width: 100%;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.form-field label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.form-field label.protein-label { color: var(--protein); }
.form-field label.carbs-label { color: var(--carbs); }
.form-field label.fats-label { color: var(--fats); }

.form-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:hover {
    border-color: var(--border-light);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
}

.input-with-unit {
    position: relative;
}

.input-with-unit .form-input {
    padding-right: 48px;
}

.input-with-unit .unit {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    color: var(--text-muted);
    pointer-events: none;
}

.submit-btn {
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--accent-primary), #6366f1);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.submit-btn svg {
    width: 20px;
    height: 20px;
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.submit-btn:active {
    transform: translateY(0);
}

/* --- LOG LIST --- */
.log-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.log-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    animation: slideUp 0.3s ease;
}

.log-item:hover {
    border-color: var(--border-light);
}

.log-item.old {
    opacity: 0.5;
}

.item-details h4 {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 4px;
}

.item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.item-macros {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.item-macros span {
    font-size: 0.8rem;
    font-weight: 500;
}

.item-macros .p { color: var(--protein); }
.item-macros .c { color: var(--carbs); }
.item-macros .f { color: var(--fats); }

.item-cals {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
}

.del-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.del-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

/* --- MODAL --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 32px;
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    text-align: center;
    margin-bottom: 32px;
}

.modal-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: rgba(139, 92, 246, 0.1);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-primary);
}

.modal-icon svg {
    width: 28px;
    height: 28px;
}

.modal-header h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.modal-header p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.settings-section {
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.settings-section:last-of-type {
    border-bottom: none;
}

.settings-section h4 {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 16px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.setting-field label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-field label.protein-label { color: var(--protein); }
.setting-field label.carbs-label { color: var(--carbs); }
.setting-field label.fats-label { color: var(--fats); }

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.modal-btn {
    flex: 1;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--accent-primary), #6366f1);
    border: none;
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.modal-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.modal-btn.secondary {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.modal-btn.secondary:hover {
    border-color: var(--border-light);
    background: var(--bg-input);
}

/* --- ANIMATIONS --- */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- RESPONSIVE --- */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }
    
    .auth-card {
        padding: 32px 24px;
    }
    
    .cal-info h2 {
        font-size: 2.75rem;
    }
    
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .macro-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .macro-card {
        padding: 12px;
    }
    
    .macro-val {
        font-size: 1.25rem;
    }
    
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}