/* ============================================
   NutriSnap - AI Nutrition Calculator
   ============================================ */

:root {
    --green: #22C55E;
    --green-light: #4ADE80;
    --green-dark: #16A34A;
    --teal: #2DD4BF;
    --lime: #A3E635;
    --bg: #070D0A;
    --card: rgba(22, 32, 26, 0.7);
    --card-solid: #131C16;
    --text: #E8F2EC;
    --text-light: #8FA699;
    --border: rgba(120, 200, 150, 0.14);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    --glow: 0 0 0 1px rgba(74, 222, 128, 0.08), 0 12px 40px rgba(16, 185, 80, 0.12);
    --protein: #FB7185;
    --carbs: #FBBF24;
    --fat: #60A5FA;
    --radius: 20px;
    --font: 'Prompt', sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --grad: linear-gradient(135deg, #16A34A 0%, #22C55E 45%, #2DD4BF 100%);
}

html { color-scheme: dark; }

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* Animated ambient gradient blobs */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(90px);
    opacity: 0.5;
    z-index: -1;
    pointer-events: none;
}
body::before {
    width: 600px;
    height: 600px;
    top: -200px;
    right: -150px;
    background: radial-gradient(circle, rgba(34, 197, 94, 0.35), transparent 70%);
    animation: float1 18s ease-in-out infinite;
}
body::after {
    width: 500px;
    height: 500px;
    bottom: -180px;
    left: -120px;
    background: radial-gradient(circle, rgba(45, 212, 191, 0.25), transparent 70%);
    animation: float2 22s ease-in-out infinite;
}
@keyframes float1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(-60px, 80px) scale(1.15); }
}
@keyframes float2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(80px, -60px) scale(1.1); }
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

img { max-width: 100%; display: block; }

/* ===== Topbar ===== */
.topbar {
    background: rgba(10, 16, 13, 0.6);
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}

.logo-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.4);
    position: relative;
    overflow: hidden;
}
.logo-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.4) 50%, transparent 70%);
    transform: translateX(-100%);
    animation: shine 4s ease-in-out infinite;
}
@keyframes shine {
    0%, 60% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.logo-text { display: flex; flex-direction: column; }
.logo-main {
    font-weight: 800;
    font-size: 20px;
    line-height: 1.1;
    background: linear-gradient(135deg, #fff, #A3E635);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.logo-sub { font-size: 11px; color: var(--text-light); letter-spacing: 1px; text-transform: uppercase; }

/* ===== Buttons ===== */
.btn-primary, .btn-ghost {
    font-family: var(--font);
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background: var(--grad);
    background-size: 180% 180%;
    color: #fff;
    padding: 14px 26px;
    font-size: 16px;
    box-shadow: 0 8px 22px rgba(22, 163, 74, 0.35);
    position: relative;
    overflow: hidden;
    z-index: 0;
    transition: var(--transition), background-position 0.6s ease;
}
.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
    transform: translateX(-120%);
    transition: transform 0.6s ease;
}
.btn-primary:hover:not(:disabled)::before { transform: translateX(120%); }

.btn-primary:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 14px 32px rgba(34, 197, 94, 0.5); background-position: right center; }
.btn-primary:active:not(:disabled) { transform: translateY(-1px) scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-full { width: 100%; margin-top: 18px; }

.btn-ghost {
    background: rgba(255, 255, 255, 0.04);
    color: var(--green-light);
    border: 1.5px solid var(--border);
    padding: 10px 18px;
    font-size: 14px;
    backdrop-filter: blur(8px);
}

.btn-ghost:hover { border-color: var(--green-light); color: var(--green); background: rgba(74, 222, 128, 0.1); transform: translateY(-1px); }
.btn-ghost.small { padding: 6px 12px; font-size: 13px; }

/* ===== Main ===== */
.main { padding: 48px 20px 60px; }

.intro { text-align: center; max-width: 700px; margin: 0 auto 32px; }
.intro-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--lime);
    background: rgba(163, 230, 53, 0.1);
    border: 1px solid rgba(163, 230, 53, 0.25);
    padding: 6px 16px;
    border-radius: 50px;
    margin-bottom: 18px;
    backdrop-filter: blur(8px);
}
.intro-badge i { animation: boltFlash 2s ease-in-out infinite; }
@keyframes boltFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.intro h1 {
    font-size: clamp(28px, 4.5vw, 44px);
    font-weight: 800;
    margin-bottom: 14px;
    line-height: 1.2;
    background: linear-gradient(135deg, #FFFFFF 20%, #4ADE80 60%, #2DD4BF 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.intro p { color: var(--text-light); font-size: 16px; }

.notice {
    display: flex;
    align-items: center;
    gap: 12px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.12), rgba(251, 191, 36, 0.04));
    border: 1px solid rgba(251, 191, 36, 0.3);
    color: #FCD34D;
    padding: 14px 20px;
    border-radius: 14px;
    margin-bottom: 28px;
    font-size: 14px;
    backdrop-filter: blur(8px);
}
.notice.hidden { display: none; }

/* ===== Grid layout ===== */
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    align-items: start;
}

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
}
.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(74, 222, 128, 0.5), transparent);
}
.panel:hover { border-color: rgba(74, 222, 128, 0.3); }

.panel-title { font-size: 19px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.panel-title i {
    color: var(--green-light);
    background: rgba(74, 222, 128, 0.12);
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

/* ===== Dropzone ===== */
.dropzone {
    display: block;
    margin-top: 18px;
    border: 2px dashed var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    overflow: hidden;
    transition: var(--transition);
    min-height: 220px;
    position: relative;
}

.dropzone:hover, .dropzone.dragover {
    border-color: var(--green-light);
    background: rgba(74, 222, 128, 0.06);
    box-shadow: inset 0 0 40px rgba(74, 222, 128, 0.08);
}
.dropzone.dragover { transform: scale(1.01); }

.dropzone-empty i {
    font-size: 44px;
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 14px;
    animation: bobUp 2.4s ease-in-out infinite;
}
@keyframes bobUp {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.dropzone-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    min-height: 220px;
    color: var(--text-light);
}
.dropzone-empty i { font-size: 44px; margin-bottom: 14px; }
.dropzone-empty p { font-size: 15px; margin-bottom: 4px; }
.dropzone-empty span { font-size: 12px; }

.preview { width: 100%; max-height: 340px; object-fit: cover; }

/* Upload action buttons */
.upload-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}
.upload-actions .btn-ghost { flex: 1; }
/* Camera button only makes sense on touch devices */
.camera-only { display: none; }
@media (hover: none) and (pointer: coarse) {
    .camera-only { display: inline-flex; }
}

/* ===== Meal type ===== */
.meal-type { margin-top: 18px; }
.meal-type label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }

select, input[type="password"], input[type="text"] {
    width: 100%;
    padding: 13px 16px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: #0F1712;
    outline: none;
    transition: var(--transition);
}

select:focus, input:focus { border-color: var(--green-light); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12); }

/* ===== Result ===== */
.result { margin-top: 22px; }
.result.hidden { display: none; }

.result-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}
.result-head h3 { font-size: 17px; font-weight: 700; }

.food-list { list-style: none; margin-bottom: 16px; }
.food-list li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    font-size: 14px;
}
.food-list li span:last-child { color: var(--text-light); font-weight: 600; }

.result-macros {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}
.rmacro {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 6px;
    text-align: center;
    transition: var(--transition);
}
.rmacro:hover { transform: translateY(-2px); border-color: rgba(74, 222, 128, 0.3); }
.rmacro b { display: block; font-size: 18px; font-weight: 800; }
.rmacro small { font-size: 11px; color: var(--text-light); }

/* ===== Totals ===== */
.summary-head { display: flex; justify-content: space-between; align-items: center; }

.totals {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: 20px 0 8px;
    flex-wrap: wrap;
}

.total-card {
    background: var(--grad);
    color: #fff;
    border-radius: 16px;
    padding: 20px 24px;
    text-align: center;
    min-width: 150px;
    box-shadow: 0 10px 30px rgba(34, 197, 94, 0.35);
    position: relative;
    overflow: hidden;
}
.total-card::after {
    content: '';
    position: absolute;
    top: -50%;
    right: -30%;
    width: 120px;
    height: 120px;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.25), transparent 70%);
    border-radius: 50%;
}
.total-value { display: block; font-size: 36px; font-weight: 800; line-height: 1; }
.total-label { font-size: 12px; opacity: 0.9; }

.macros { display: flex; flex-direction: column; gap: 8px; }
.macro-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 15px;
}
.macro-item small { color: var(--text-light); font-weight: 500; margin-left: 4px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.p { background: var(--protein); }
.dot.c { background: var(--carbs); }
.dot.f { background: var(--fat); }

/* ===== Meal log ===== */
.log-title { font-size: 15px; font-weight: 700; margin: 24px 0 12px; }
.empty-log { color: var(--text-light); font-size: 14px; text-align: center; padding: 20px 0; }

.log-item {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.02);
    transition: var(--transition);
}
.log-item:hover { border-color: rgba(74, 222, 128, 0.3); background: rgba(74, 222, 128, 0.04); transform: translateX(3px); }
.log-item img { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex-shrink: 0; }
.log-info { flex: 1; min-width: 0; }
.log-info h4 { font-size: 14px; font-weight: 700; }
.log-info .log-meta { font-size: 12px; color: var(--text-light); }
.log-tag {
    font-size: 11px;
    background: rgba(74, 222, 128, 0.15);
    color: var(--green-light);
    padding: 2px 10px;
    border-radius: 50px;
    font-weight: 600;
}
.log-cal {
    font-weight: 800;
    font-size: 15px;
    white-space: nowrap;
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.log-del { background: none; border: none; color: #3A4A40; cursor: pointer; font-size: 16px; padding: 4px; transition: var(--transition); }
.log-del:hover { color: var(--protein); transform: scale(1.2); }

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}
.modal.active { opacity: 1; visibility: visible; }

.modal-box {
    background: rgba(18, 26, 21, 0.92);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 32px;
    max-width: 460px;
    width: 100%;
    position: relative;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(24px) saturate(160%);
    -webkit-backdrop-filter: blur(24px) saturate(160%);
    animation: revealUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.modal-box::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(74, 222, 128, 0.6), transparent);
}
.modal-box h2 { font-size: 22px; display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.modal-box h2 i {
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}
.modal-desc { font-size: 14px; color: var(--text-light); margin-bottom: 22px; }
.modal-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-light);
}

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.key-input { display: flex; gap: 8px; }
.key-input input { flex: 1; }
.hint { display: block; font-size: 12px; color: var(--text-light); margin-top: 8px; }
.hint a { color: var(--green); }

.warn {
    display: flex;
    gap: 10px;
    background: #2A1414;
    border: 1px solid #4A1F1F;
    color: #FCA5A5;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 12.5px;
    margin-bottom: 20px;
}
.warn i { margin-top: 2px; }

/* ===== Loading ===== */
.loading {
    position: fixed;
    inset: 0;
    background: rgba(11, 19, 15, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    z-index: 200;
}
.loading[hidden] { display: none; }
.loading p { font-weight: 600; color: var(--green-light); }
.spinner {
    width: 54px;
    height: 54px;
    border: 5px solid #1F2E25;
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Topbar actions ===== */
.topbar-actions { display: flex; gap: 10px; }

/* ===== Profile bar ===== */
.profile-bar {
    display: flex;
    align-items: center;
    gap: 18px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    flex-wrap: wrap;
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    position: relative;
    overflow: hidden;
}
.profile-bar::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -20%;
    width: 300px;
    height: 200%;
    background: radial-gradient(ellipse, rgba(45, 212, 191, 0.1), transparent 70%);
    pointer-events: none;
}
.profile-bar[hidden] { display: none; }

.profile-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: var(--grad);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.2), 0 6px 18px rgba(34, 197, 94, 0.4);
    font-size: 22px;
    font-weight: 800;
    flex-shrink: 0;
    text-transform: uppercase;
}
.profile-meta { flex: 1; min-width: 120px; }
.profile-meta h3 { font-size: 18px; font-weight: 700; }
.profile-meta span { font-size: 13px; color: var(--text-light); }

.profile-stats { display: flex; gap: 26px; }
.pstat { text-align: center; }
.pstat b { display: block; font-size: 18px; font-weight: 800; }
.pstat small { font-size: 11px; color: var(--text-light); }

/* ===== Goal progress ===== */
.goal-progress { margin: 18px 0 4px; }
.goal-progress[hidden] { display: none; }
.goal-progress-head {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
}
.goal-progress-head span:last-child { color: var(--text-light); font-weight: 500; }
.progress-track {
    height: 12px;
    background: #0F1712;
    border: 1px solid var(--border);
    border-radius: 50px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--green), var(--green-light));
    border-radius: 50px;
    transition: width 0.5s ease, background 0.3s ease;
}
.progress-fill.over { background: linear-gradient(90deg, var(--carbs), var(--protein)); }

/* ===== Form row of 2 ===== */
.form-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type="number"] {
    width: 100%;
    padding: 13px 16px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: #0F1712;
    outline: none;
    transition: var(--transition);
}
input[type="number"]:focus { border-color: var(--green-light); box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.12); }

/* ===== Statistics ===== */
.stats-section { margin-top: 24px; }

.stats-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.period-tabs {
    display: flex;
    gap: 4px;
    background: #0F1712;
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 4px;
}
.period-tabs button {
    border: none;
    background: none;
    color: var(--text-light);
    font-family: var(--font);
    font-weight: 600;
    font-size: 14px;
    padding: 8px 18px;
    border-radius: 50px;
    cursor: pointer;
    transition: var(--transition);
}
.period-tabs button.active {
    background: var(--grad);
    color: #fff;
    box-shadow: 0 4px 14px rgba(34, 197, 94, 0.4);
}

.stats-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    margin: 22px 0;
}
.stats-nav button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    background: #0F1712;
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
}
.stats-nav button:hover:not(:disabled) { border-color: var(--green-light); color: var(--green-light); }
.stats-nav button:disabled { opacity: 0.35; cursor: not-allowed; }
#periodLabel { font-weight: 700; font-size: 16px; min-width: 200px; text-align: center; }

.stats-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 26px;
}
.scard {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px 12px;
    text-align: center;
    transition: var(--transition);
}
.scard:hover { transform: translateY(-3px); border-color: rgba(74, 222, 128, 0.3); background: rgba(74, 222, 128, 0.05); }
.scard b { display: block; font-size: 22px; font-weight: 800; }
.scard small { font-size: 12px; color: var(--text-light); }
.scard.avg b {
    background: var(--grad);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Bar chart */
.chart-wrap { overflow-x: auto; padding-bottom: 6px; }
.chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 200px;
    min-width: 100%;
    padding: 10px 4px 0;
    border-bottom: 1px solid var(--border);
}
.bar-col {
    flex: 1;
    min-width: 26px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    height: 100%;
}
.bar {
    width: 70%;
    max-width: 42px;
    background: linear-gradient(180deg, var(--lime), var(--green) 50%, var(--teal));
    border-radius: 8px 8px 0 0;
    min-height: 2px;
    position: relative;
    transition: height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.2s ease;
    cursor: default;
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.25);
}
.bar:hover { filter: brightness(1.2); }
.bar.empty { background: rgba(255, 255, 255, 0.06); box-shadow: none; }
.bar .bar-val {
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: var(--text-light);
    white-space: nowrap;
}
.bar-label { font-size: 11px; color: var(--text-light); white-space: nowrap; }

.stats-detail { margin-top: 22px; }
.stats-detail .empty-log { padding: 16px 0; }

/* ===== AI Chat ===== */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: var(--grad);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(34, 197, 94, 0.5);
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    animation: fabPulse 2.6s ease-in-out infinite;
}
@keyframes fabPulse {
    0%, 100% { box-shadow: 0 10px 30px rgba(34, 197, 94, 0.5), 0 0 0 0 rgba(34, 197, 94, 0.5); }
    50% { box-shadow: 0 10px 30px rgba(34, 197, 94, 0.5), 0 0 0 14px rgba(34, 197, 94, 0); }
}
.chat-fab:hover { transform: scale(1.12) rotate(8deg); animation-play-state: paused; }
.chat-fab.hide { opacity: 0; visibility: hidden; transform: scale(0.5); }

.chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 48px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
    z-index: 95;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatIn 0.25s ease;
}
.chat-window[hidden] { display: none; }
@keyframes chatIn {
    from { opacity: 0; transform: translateY(20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--green-dark), var(--green));
    color: #fff;
}
.chat-title { display: flex; align-items: center; gap: 12px; }
.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.chat-title strong { display: block; font-size: 15px; }
.chat-title small { font-size: 11px; opacity: 0.85; }
.chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
}
.chat-close:hover { opacity: 1; }

.chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.chat-msg.bot {
    background: #0F1712;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}
.chat-msg.user {
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: #fff;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}
.chat-msg.typing { color: var(--text-light); font-style: italic; }
.chat-msg.typing span {
    display: inline-block;
    animation: blink 1.4s infinite both;
}
.chat-msg.typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-msg.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }

.chat-suggestions {
    display: flex;
    gap: 8px;
    padding: 0 14px 10px;
    overflow-x: auto;
    flex-shrink: 0;
}
.chat-suggestions button {
    white-space: nowrap;
    font-family: var(--font);
    font-size: 12.5px;
    padding: 7px 14px;
    border-radius: 50px;
    border: 1px solid var(--border);
    background: #0F1712;
    color: var(--green-light);
    cursor: pointer;
    transition: var(--transition);
}
.chat-suggestions button:hover { border-color: var(--green-light); }

.chat-input {
    display: flex;
    gap: 8px;
    padding: 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-input input {
    flex: 1;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 50px;
    background: #0F1712;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
}
.chat-input input:focus { border-color: var(--green-light); }
.chat-input button {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--green), var(--green-light));
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: var(--transition);
}
.chat-input button:hover { transform: scale(1.06); }
.chat-input button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 30px 20px;
    color: var(--text-light);
    font-size: 13px;
}

/* ===== Entrance animations ===== */
@keyframes revealUp {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
}
.intro, .profile-bar, .panel, .stats-section {
    animation: revealUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.profile-bar { animation-delay: 0.05s; }
.grid .panel:nth-child(1) { animation-delay: 0.1s; }
.grid .panel:nth-child(2) { animation-delay: 0.18s; }
.stats-section { animation-delay: 0.24s; }

/* Custom scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(74, 222, 128, 0.25);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: rgba(74, 222, 128, 0.45); background-clip: padding-box; }

/* ===== Responsive ===== */

/* Tablet / small laptop */
@media (max-width: 960px) {
    .container { padding: 0 16px; }
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
}

/* Stack main columns */
@media (max-width: 860px) {
    .grid { grid-template-columns: 1fr; }
    .main { padding: 28px 16px 50px; }
    .panel { padding: 22px; }
}

/* Mobile */
@media (max-width: 640px) {
    .topbar-inner { height: 64px; }
    .logo-icon { width: 40px; height: 40px; font-size: 18px; }
    .logo-main { font-size: 18px; }
    .logo-sub { font-size: 10px; }

    .topbar-actions { gap: 8px; }
    .btn-ghost { padding: 9px 14px; font-size: 13px; }

    .intro h1 { font-size: 24px; }
    .intro p { font-size: 15px; }

    .profile-bar { gap: 14px; padding: 16px; }
    .profile-stats { width: 100%; justify-content: space-around; gap: 12px; order: 3; }
    .profile-meta { min-width: auto; }

    .totals { flex-direction: column; align-items: stretch; gap: 14px; }
    .total-card { width: 100%; }
    .macros { flex-direction: row; justify-content: space-around; }

    .modal { padding: 0; align-items: flex-end; }
    .modal-box {
        max-width: 100%;
        border-radius: 22px 22px 0 0;
        padding: 26px 20px calc(26px + env(safe-area-inset-bottom));
        max-height: 92vh;
        overflow-y: auto;
    }

    .chat-window {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        border: none;
    }
    .chat-input { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
    .chat-fab { bottom: 20px; right: 20px; }
}

@media (max-width: 480px) {
    .result-macros { grid-template-columns: repeat(2, 1fr); }
    .totals { justify-content: center; }
    .stats-cards { grid-template-columns: repeat(2, 1fr); }
    #periodLabel { min-width: 120px; font-size: 14px; }
    .profile-bar { justify-content: center; text-align: center; }
    .topbar-actions .btn-ghost span { display: none; }
    .topbar-actions .btn-ghost { padding: 10px 12px; }
    .period-tabs button { padding: 8px 12px; font-size: 13px; }
    .form-row2 { grid-template-columns: 1fr; gap: 0; }
    .bar-col { min-width: 20px; }
    .scard b { font-size: 18px; }
    .intro h1 { font-size: 22px; }
}

/* Touch devices: bigger tap targets, no hover lift jank */
@media (hover: none) and (pointer: coarse) {
    .btn-primary, .btn-ghost, .period-tabs button, .stats-nav button, .log-del {
        -webkit-tap-highlight-color: transparent;
    }
    .btn-primary:hover:not(:disabled) { transform: none; }
    select, input[type="text"], input[type="password"], input[type="number"] {
        font-size: 16px; /* prevents iOS zoom on focus */
    }
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
