:root {
    --bg-dark: hsl(220, 25%, 7%);
    --surface: hsl(220, 25%, 12%);
    --surface-light: hsl(220, 25%, 18%);
    --text-main: hsl(0, 0%, 98%);
    --text-muted: hsl(220, 10%, 60%);

    --glass-bg: hsla(220, 25%, 15%, 0.7);
    --glass-border: hsla(0, 0%, 100%, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

    /* Meal colors */
    --breakfast: hsl(200, 85%, 55%);
    /* sky blue  */
    --lunch: hsl(150, 75%, 48%);
    /* green     */
    --dinner: hsl(28, 92%, 55%);
    /* orange    */
    --snacks: hsl(290, 60%, 62%);
    /* purple    */

    --accent: hsl(200, 85%, 55%);
    /* default to breakfast */

    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    --font-main: 'Outfit', sans-serif;
    --font-logo: 'Outfit', sans-serif;
    --box-border-style: solid;
}

/* ── Reset & Base ──────────────────────────────── */

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

html,
body {
    overscroll-behavior-y: none;
}

#crt-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), 
                linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 9999;
    background-size: 100% 3px, 3px 100%;
    pointer-events: none;
    opacity: 0.6;
}

.theme-pixel #crt-overlay,
.theme-console #crt-overlay {
    display: block;
    animation: crt-flicker 0.1s infinite;
}

@keyframes crt-flicker {
    0% { opacity: 0.55; }
    50% { opacity: 0.6; }
    100% { opacity: 0.58; }
}

body {
    font-family: var(--font-main);
    font-size: calc(1rem * var(--font-size-adjust, 1));
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

body.modal-open {
    overflow: hidden;
}

/* ── Layout ─────────────────────────────────────── */
.app-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Header ─────────────────────────────────────── */
header {
    margin-top: 8px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.logo-text {
    font-family: var(--font-logo);
    font-size: clamp(1.2rem, 5vw, 2.1rem);
    font-weight: 600;
    letter-spacing: -1.2px;
    line-height: 1;
    color: var(--text-main);
    margin-bottom: 4px;
}

.logo-text span {
    font-weight: 900;
    color: var(--accent);
    /* No soft glows in pixel mode */
    text-shadow: none;
}


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

.date-picker-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 10px;
    transition: var(--transition);
    user-select: none;
    position: relative;
}

.date-picker-trigger:hover {
    background: var(--surface-light);
}

.date-picker-trigger:hover #current-date-label {
    color: var(--text-main);
}

#current-date-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: var(--transition);
}

.calendar-icon {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
    transition: var(--transition);
}

.date-picker-trigger:hover .calendar-icon {
    color: var(--accent);
}

#prev-day,
#next-day {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: var(--transition);
}

#prev-day:hover,
#next-day:hover {
    color: var(--text-main);
    background: var(--surface-light);
}

#prev-day i,
#next-day i {
    width: 18px;
    height: 18px;
}

/* ── Flatpickr Overrides ─────────────────────────
   Only override colors, fonts, and borders.
   Do NOT override width, padding, or flex on
   layout elements — Flatpickr's internal pixel
   math handles alignment automatically.
──────────────────────────────────────────────── */
.flatpickr-calendar {
    background: var(--surface) !important;
    border: 1px solid var(--glass-border) !important;
    box-shadow: var(--glass-shadow) !important;
    border-radius: var(--radius-md) !important;
    font-family: var(--font-main) !important;
}

.flatpickr-months .flatpickr-month {
    color: var(--text-main) !important;
    background: transparent !important;
}

.flatpickr-current-month {
    font-size: 1rem !important;
    font-weight: 700 !important;
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
    font-weight: 800 !important;
    color: var(--text-main) !important;
    background: var(--surface) !important;
}

.flatpickr-monthDropdown-month {
    background: var(--surface) !important;
}

.flatpickr-current-month input.cur-year {
    font-weight: 400 !important;
    color: var(--text-muted) !important;
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
    fill: var(--text-main) !important;
    transition: var(--transition);
}

.flatpickr-months .flatpickr-prev-month:hover,
.flatpickr-months .flatpickr-next-month:hover {
    background: var(--surface-light) !important;
    border-radius: 8px;
}

/* Weekday header: color & font only */
.flatpickr-weekdays {
    background: hsla(0, 0%, 100%, 0.04) !important;
}

.flatpickr-weekday {
    color: var(--text-muted) !important;
    font-weight: 700 !important;
    font-size: 0.72rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.04em !important;
}

/* Days */
.flatpickr-day {
    color: var(--text-main) !important;
    border-radius: var(--radius-sm) !important;
    font-family: var(--font-main) !important;
}

.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover {
    color: var(--text-muted) !important;
    opacity: 0.3;
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: white !important;
    box-shadow: 0 4px 12px hsla(200, 85%, 55%, 0.4) !important;
}

.flatpickr-day:hover {
    background: var(--surface-light) !important;
    border-color: transparent !important;
}

.flatpickr-day.today {
    border-color: var(--accent) !important;
}

/* Day has data indicator */
.flatpickr-day.has-stats:not(.selected) {
    position: relative;
}

.flatpickr-day.has-stats:not(.selected)::after {
    content: '';
    position: absolute;
    bottom: 3px;
    left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 3px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 4px var(--accent);
}

.flatpickr-day.has-stats.selected::after {
    display: none;
}

.flatpickr-calendar.arrowTop:after,
.flatpickr-calendar.arrowTop:before {
    border-bottom-color: var(--surface) !important;
}








#settings-btn,
#history-btn {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: 42px;
    height: 42px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

#settings-btn:hover,
#history-btn:hover {
    background: var(--surface-light);
}

#settings-btn:active,
#history-btn:active {
    transform: scale(0.93);
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sync-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.sync-btn:hover {
    color: var(--text-main);
    background: var(--surface-light);
}

.sync-btn.active {
    color: #4ade80;
    /* Success green */
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--accent);
    box-shadow: 0 0 10px hsla(200, 85%, 55%, 0.3);
}

.sync-btn.loading {
    animation: sync-pulse 1.5s infinite;
}

@keyframes sync-pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

/* ── Summary Card ───────────────────────────────── */
.summary-card {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    box-shadow: var(--glass-shadow);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    inset: -50%;
    background: radial-gradient(circle at 50% 0%, var(--accent) 0%, transparent 65%);
    opacity: 0.06;
    pointer-events: none;
    transition: opacity 0.5s;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
}

.stat-value {
    font-size: clamp(1.2rem, 6vw, 2.25rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

.stat-value.secondary {
    font-size: 1.1rem;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value.over-limit {
    color: var(--dinner);
    text-shadow: none;
}


.stat-divider {
    width: 1px;
    height: 56px;
    background: linear-gradient(to bottom, transparent, var(--glass-border), transparent);
}

@media (max-width: 480px) {
    .stat-divider {
        height: 40px;
    }
}

.goal-stat {
    grid-column: 1 / span 3;
    border-top: 1px solid var(--glass-border);
    padding-top: 16px;
    margin-top: 4px;
    flex-direction: row;
    justify-content: space-between;
    width: 100%;
}

/* ── Progress Bar ───────────────────────────────── */
.progress-container {
    width: 100%;
    height: 14px;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

/* The actual bar fills the container and lays segments side by side */
.progress-bar {
    display: flex;
    height: 100%;
    width: 100%;
}

/* Each meal segment sits inline inside the bar */
.progress-segment {
    height: 100%;
    min-width: 4px;
    /* always at least a sliver visible */
    transition: width 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.progress-segment:first-child {
    border-radius: 7px 0 0 7px;
}

.progress-segment:last-child {
    border-radius: 0 7px 7px 0;
}

.progress-segment:only-child {
    border-radius: 7px;
}

/* ── Meal Selector ──────────────────────────────── */
.meal-selector {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.meal-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px 12px;
    background: var(--surface);
    border: 1.5px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    min-height: 68px;
    justify-content: center;
}


/* Row 1: dot + label side by side */
.meal-btn .meal-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.meal-btn .meal-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: var(--transition);
}

.meal-btn .meal-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    line-height: 1;
}


/* Row 2: calorie total */
.meal-btn .meal-cals {
    font-size: clamp(0.6rem, 2vw, 0.9rem);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* Per-meal dot + active colors */
#meal-breakfast .meal-dot {
    background: var(--breakfast);
    box-shadow: 0 0 8px var(--breakfast);
}

#meal-lunch .meal-dot {
    background: var(--lunch);
    box-shadow: 0 0 8px var(--lunch);
}

#meal-dinner .meal-dot {
    background: var(--dinner);
    box-shadow: 0 0 8px var(--dinner);
}

#meal-snacks .meal-dot {
    background: var(--snacks);
    box-shadow: 0 0 8px var(--snacks);
}

#meal-breakfast.active {
    border-color: var(--breakfast);
    color: var(--breakfast);
    background: hsla(200, 85%, 55%, 0.12);
}


#meal-lunch.active {
    border-color: var(--lunch);
    color: var(--lunch);
    background: hsla(150, 75%, 48%, 0.12);
}

#meal-dinner.active {
    border-color: var(--dinner);
    color: var(--dinner);
    background: hsla(28, 92%, 55%, 0.12);
}

#meal-snacks.active {
    border-color: var(--snacks);
    color: var(--snacks);
    background: hsla(290, 60%, 62%, 0.12);
}

.settings-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--surface-light);
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.settings-user-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}



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

/* ── Box Grid ───────────────────────────────────── */
.box-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    gap: 10px;
}

.box {
    aspect-ratio: 1;
    background: var(--surface);
    border: 1.5px var(--box-border-style) var(--glass-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.box::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: var(--box-meal-color, var(--accent));
    opacity: 0;
    transform: scale(0.4);
    border-radius: inherit;
    transition: var(--transition);
    z-index: 1;
}

.box-label {
    position: relative;
    z-index: 10;
    font-size: 0.68rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: scale(0.6);
    transition: var(--transition);
    pointer-events: none;
}

.box.filled .box-label {
    opacity: 1;
    transform: scale(1);
}

.box.beyond-goal {
    border-style: dashed;
    border-color: hsla(28, 92%, 55%, 0.4);
}

.box.filled {
    border-color: transparent;
}

.box.filled.beyond-goal {
    border: 1.5px solid hsla(28, 92%, 55%, 0.4);
}

.box.beyond-goal.filled::after {
    background-image: repeating-linear-gradient(-45deg,
            rgba(255, 255, 255, 0.2),
            rgba(255, 255, 255, 0.2) 6px,
            transparent 6px,
            transparent 12px);
}

.box.filled::after {
    opacity: 1;
    transform: scale(1);
}

/* Per-meal box colors */
.box.meal-breakfast {
    --box-meal-color: var(--breakfast);
}

.box.meal-lunch {
    --box-meal-color: var(--lunch);
}

.box.meal-dinner {
    --box-meal-color: var(--dinner);
}

.box.meal-snacks {
    --box-meal-color: var(--snacks);
}

.box:hover:not(.filled) {
    background: var(--surface-light);
    transform: scale(1.05);
}

@keyframes pop {
    0% {
        transform: scale(0.88);
    }

    55% {
        transform: scale(1.12);
    }

    100% {
        transform: scale(1);
    }
}

.box.pop {
    animation: pop 0.22s ease-out forwards;
}

/* ── History Modal ───────────────────────────────── */
.modal-history-list {
    padding: 0;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 0;
    border-bottom: 1px solid var(--glass-border);
}

.history-item:last-child {
    border-bottom: none;
}

.history-date {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.debug-output {
    background: #000;
    color: #4ade80;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    max-height: 400px;
    overflow: auto;
    border: 1px solid var(--glass-border);
    white-space: pre-wrap;
    word-break: break-all;
}

.history-item.clickable {
    cursor: pointer;
    transition: var(--transition);
}

.history-item.clickable:hover {
    background: var(--surface-light);
    padding-left: 12px;
    padding-right: 12px;
    border-radius: var(--radius-sm);
}

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

.history-cals {
    font-weight: 700;
}

/* ── Stats Dashboard ────────────────────────────── */
.stats-modal-content {
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-light) transparent;
}

@media (max-width: 600px) {
    .stats-modal-content {
        max-width: 100%;
        max-height: 100%;
    }
}

.stats-modal-content::-webkit-scrollbar {
    width: 4px;
}

.stats-modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.stats-modal-content::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}


/* Stats Overview Cards */
.stats-overview {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 380px) {
    .stats-overview {
        grid-template-columns: 1fr;
    }
}

.stats-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.stats-card:hover {
    border-color: hsla(0, 0%, 100%, 0.15);
    background: hsla(220, 25%, 15%, 0.9);
}

.stats-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: hsla(200, 85%, 55%, 0.12);
    color: var(--accent);
}

.stats-card-icon i {
    width: 18px;
    height: 18px;
}

/* Color each card icon differently */
.stats-card:nth-child(1) .stats-card-icon {
    background: hsla(28, 92%, 55%, 0.12);
    color: var(--dinner);
}

.stats-card:nth-child(2) .stats-card-icon {
    background: hsla(200, 85%, 55%, 0.12);
    color: var(--breakfast);
}

.stats-card:nth-child(3) .stats-card-icon {
    background: hsla(150, 75%, 48%, 0.12);
    color: var(--lunch);
}

.stats-card:nth-child(4) .stats-card-icon {
    background: hsla(290, 60%, 62%, 0.12);
    color: var(--snacks);
}

.stats-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.stats-card-value {
    font-size: 1.35rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-card-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

/* Section Titles */
.stats-section-title {
    display: block;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Global Range Bar */
.stats-range-bar {
    display: flex;
    justify-content: center;
    margin: 0;
}

.stats-modal-body {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-top: 8px;
}

/* Chart Section */
.stats-chart-section {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
}

.stats-range-toggle {
    display: flex;
    gap: 4px;
    background: var(--bg-dark);
    border-radius: 8px;
    padding: 3px;
    border: 1px solid var(--glass-border);
}

.range-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.range-btn:hover {
    color: var(--text-main);
}

.range-btn.active {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 8px hsla(200, 85%, 55%, 0.35);
}

.stats-chart-wrapper {
    height: 180px;
    position: relative;
    margin-top: 10px;
}

@media (max-width: 600px) {
    .stats-chart-wrapper {
        height: 220px;
    }
}

.stats-chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Meal Breakdown */
.stats-meal-breakdown {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
}

.meal-breakdown-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.meal-bar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.meal-bar-label {
    width: 72px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--surface-light);
    padding: 4px 8px;
    border-radius: 6px;
}

.theme-pixel .history-month-days {
    font-size: 0.45rem;
    padding: 3px 5px;
}
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.meal-bar-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.meal-bar-track {
    flex: 1;
    height: 10px;
    background: var(--bg-dark);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.meal-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
    min-width: 0;
}

.meal-bar-value {
    width: 50px;
    text-align: right;
    font-size: 0.78rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    flex-shrink: 0;
}

/* Records */
.stats-records {
    display: flex;
    flex-direction: column;
    gap: 0;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.stats-record-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--glass-border);
}

.stats-record-item:last-child {
    border-bottom: none;
}

.stats-record-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
}

.stats-record-label i {
    width: 16px;
    height: 16px;
}

.stats-record-item:nth-child(1) .stats-record-label i {
    color: #fbbf24;
}

.stats-record-item:nth-child(2) .stats-record-label i {
    color: var(--breakfast);
}

.stats-record-item:nth-child(3) .stats-record-label i {
    color: #4ade80;
}

.stats-record-value {
    font-size: 0.85rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}

/* Daily Log */
.stats-daily-log {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    padding: 16px;
}

.stats-daily-log .modal-history-list {
    margin-top: 2px;
}

/* Month-grouped history */
.history-month-group {
    border-bottom: 1px solid var(--glass-border);
}

.history-month-group:last-child {
    border-bottom: none;
}

.history-month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 14px 16px;
    background: hsla(0, 0%, 100%, 0.03);
    border: none;
    border-bottom: 1px solid var(--glass-border);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-main);
    gap: 12px;
}

.theme-pixel .history-month-header {
    padding: 10px;
    gap: 4px;
}
.history-month-header:hover {
    background: hsla(0, 0%, 100%, 0.03);
    border-radius: var(--radius-sm);
}

.history-month-header:active {
    transform: scale(0.99);
}

.history-month-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-month-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.25s ease;
    flex-shrink: 0;
}

.history-month-group.expanded .history-month-chevron {
    transform: rotate(90deg);
}

.history-month-label {
    font-size: 1.1rem;
    font-weight: 800;
}


.history-month-summary {
    display: flex;
    align-items: center;
    gap: 12px;
}


.history-month-days {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 2px 7px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.history-month-avg {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
}

    font-variant-numeric: tabular-nums;
}

.history-month-body {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease, opacity 0.25s ease;
    opacity: 0;
}

.history-month-group.expanded .history-month-body {
    max-height: 2000px;
    opacity: 1;
}

.history-month-body .history-item {
    padding-left: 28px;
}

/* History items with meal dots */
.history-meal-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}

.history-meal-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    opacity: 0.7;
}

.history-item-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.history-goal-badge {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 4px;
}

    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.history-goal-badge.under {
    background: hsla(150, 75%, 48%, 0.15);
    color: var(--lunch);
}

.history-goal-badge.over {
    background: hsla(28, 92%, 55%, 0.15);
    color: var(--dinner);
}

/* Loading state */
.stats-loading {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.stats-loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--glass-border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}

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

/* ── Modal ──────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--surface);
    width: 100%;
    max-width: 400px;
    border-radius: var(--radius-lg);
    padding: 0;
    /* Header and body handle all padding */
    border: 1px solid var(--glass-border);
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 24px 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--surface-light) transparent;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 10px;
}


@media (max-width: 600px) {
    .modal {
        padding: 0;
        align-items: flex-end;
        /* Slide up from bottom */
    }

    .modal-content {
        max-width: 100%;
        max-height: 100%;
        height: auto;
        min-height: 300px;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        /* Start off-screen */
        padding: 0;
        /* Remove padding, handled by header/body */
        display: flex;
        flex-direction: column;
    }

    .modal-body {
        padding: 0 16px 40px 16px;
    }

    .modal.active .modal-content {
        transform: translateY(0);
    }

    .modal-header {
        background: var(--surface);
        padding: 20px 16px 12px 16px;
        border-bottom: 1px solid var(--glass-border);
        margin-bottom: 16px;
    }
}

.modal.active .modal-content {
    transform: translateY(0);
}

.debug-modal-content {
    max-width: 600px;
}

@media (max-width: 600px) {
    .debug-modal-content {
        max-width: 100%;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    padding: 20px 24px 12px 24px;
    border-bottom: 1px solid var(--glass-border);
    margin-bottom: 8px;
    flex-shrink: 0;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.icon-btn:hover {
    color: var(--text-main);
}

.confirm-body p {
    color: var(--text-muted);
    line-height: 1.6;
    font-size: 1rem;
    white-space: pre-line;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}


.settings-user-info {
    background: hsla(0, 0%, 100%, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 4px;
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
}

.settings-user-info span {
    color: var(--text-main);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.settings-user-info i {
    color: #4ade80;
    flex-shrink: 0;
}

/* Advanced Collapsible */
.debug-collapsible {
    margin-top: 12px;
    background: hsla(0, 0%, 100%, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: var(--transition);
}

.debug-collapsible[open] {
    background: hsla(0, 0%, 100%, 0.05);
}

.debug-summary {
    list-style: none;
    padding: 14px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
    transition: var(--transition);
}

.debug-summary::-webkit-details-marker {
    display: none;
}

.debug-summary:hover {
    background: hsla(0, 0%, 100%, 0.06);
}

.debug-summary:active {
    background: hsla(0, 0%, 100%, 0.08);
}

.debug-summary-content {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.debug-summary-content i {
    width: 16px;
    height: 16px;
    color: var(--accent);
}

.debug-summary .chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.debug-collapsible[open] .chevron {
    transform: rotate(180deg);
}

.debug-content {
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.debug-section {
    margin-top: 8px;
    padding: 16px;
    background: hsla(0, 0%, 100%, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.debug-content .debug-section {
    margin-top: 0;
    padding: 0;
    background: transparent;
    border: none;
    gap: 10px;
}

.debug-label {
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    opacity: 0.8;
}

.debug-group {
    display: flex;
    gap: 8px;
}

.btn-debug {
    flex: 1;
    background: transparent;
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    padding: 8px;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: var(--transition);
}

.btn-debug i {
    width: 14px;
    height: 14px;
}

.btn-debug:hover {
    background: var(--surface-light);
    color: var(--text-main);
}

.btn-debug.danger {
    color: #ff6b6b;
    border-color: hsla(0, 85%, 60%, 0.2);
}

/* ── Mobile Optimization ────────────────────────── */
@media (max-width: 480px) {
    .app-container {
        padding: 16px 16px 32px;
        gap: 16px;
    }

    .logo-text {
        font-size: 1.75rem;
        margin-bottom: 2px;
    }

    .date-display {
        gap: 2px;
    }

    .date-picker-trigger {
        padding: 4px 8px;
    }

    #current-date-label {
        font-size: 0.75rem;
    }

    #prev-day,
    #next-day {
        padding: 6px;
    }

    .header-actions {
        gap: 6px;
    }

    #settings-btn,
    #history-btn {
        width: 38px;
        height: 38px;
    }

    .sync-btn {
        padding: 6px;
    }
}

@media (max-width: 360px) {
    .logo-text {
        font-size: 1.5rem;
    }

    .header-content {
        align-items: flex-start;
    }

    .header-actions {
        margin-top: 4px;
    }
}

.btn-debug.danger:hover {
    background: hsla(0, 85%, 60%, 0.1);
}

.form-group select {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 12px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 1rem;
    width: 100%;
}


/* Custom number input */
.number-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 5px;
}

.number-input-container input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    padding: 6px;
}


input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

.num-btn {
    background: var(--surface-light);
    border: none;
    color: var(--text-main);
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}

.num-btn:hover {
    background: var(--accent);
}

.num-btn:active {
    transform: scale(0.9);
}

.form-actions {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 13px;
    border-radius: var(--radius-sm);
    border: none;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--accent);
    color: white;
}



.btn-primary:hover {
    filter: brightness(1.12);
}

.btn-secondary {
    background: var(--surface-light);
    color: var(--text-muted);
}

.btn-secondary:hover {
    color: var(--text-main);
}

.btn-danger {
    background: hsla(0, 85%, 60%, 0.1);
    color: #ff6b6b;
    border: 1px solid hsla(0, 85%, 60%, 0.2);
}

.btn-danger:hover {
    background: hsla(0, 85%, 60%, 0.2);
    color: #ff8787;
}

/* ── Auth Modal ────────────────────────────────── */
.auth-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.auth-error {
    background: hsla(0, 85%, 60%, 0.15);
    color: #ff6b6b;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    border: 1px solid hsla(0, 85%, 60%, 0.3);
    text-align: center;
    display: none;
    /* Default to hidden */
}

.hidden-date-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    left: 0;
    top: 0;
}

.confirm-actions,
.debug-actions,
.conflict-actions {
    margin-top: 24px;
}

.conflict-actions {
    flex-direction: column;
    gap: 12px;
}

.btn-full {
    width: 100%;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
}

.btn-ghost:hover {
    background: var(--surface-light);
    color: var(--text-main);
}

.google-btn {
    background: #ffffff;
    color: #1f1f1f !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
    border: none;
    transition: var(--transition);
}

.google-btn:hover {
    background: #f1f3f4;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.google-btn:active {
    transform: translateY(1px);
}

.auth-divider {
    display: flex;
    align-items: center;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--glass-border);
}

.auth-divider span {
    padding: 0 10px;
}

.auth-actions {
    gap: 10px;
}

.auth-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-toggle .btn-ghost {
    padding: 6px 12px;
    font-size: 0.85rem;
    border: none;
    color: var(--accent);
}

.auth-toggle .btn-ghost:hover {
    background: hsla(200, 85%, 55%, 0.1);
    color: var(--accent);
}

.field-helper {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
}

.btn-link-sm {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
}

.btn-link-sm:hover {
    color: var(--accent);
    background: hsla(200, 85%, 55%, 0.05);
}

.auth-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-top: 12px;
}

.auth-options input {
    background: var(--bg-dark);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    padding: 14px;
    border-radius: var(--radius-sm);
    width: 100%;
    font-family: inherit;
    transition: var(--transition);
}

.auth-options input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-light);
}

/* ── Conflict Modal ────────────────────────────── */
.conflict-comparison {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.conflict-option {
    flex: 1;
    background: var(--bg-dark);
    padding: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
    text-align: center;
}

.conflict-option h3 {
    font-size: 0.85rem;
    color: var(--text-main);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.conflict-option p {
    font-size: 0.75rem !important;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.last-updated {
    display: block;
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 600;
}

.conflict-option.newest {
    border-color: var(--accent);
    background: hsla(200, 85%, 55%, 0.05);
    box-shadow: 0 0 15px hsla(200, 85%, 55%, 0.1);
}

.conflict-option.newest h3 {
    color: var(--accent);
}

.conflict-option.newest::after {
    content: 'NEWER';
    display: inline-block;
    background: var(--accent);
    color: white;
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 8px;
    font-weight: 800;
}

/* ── Responsive ─────────────────────────────────── */
/* ── Footer ─────────────────────────────────────── */
footer {
    margin-top: auto;
    padding-top: 20px;
    text-align: center;
}

.footer-user-info {
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.6;
    transition: var(--transition);
}

.footer-user-info:hover {
    opacity: 1;
}

@media (max-width: 480px) {
    .app-container {
        padding: 12px 12px 30px;
        gap: 12px;
    }

    .summary-card {
        padding: 20px 16px;
        gap: 8px;
        border-radius: var(--radius-md);
    }

    .stat-value {
        font-size: 1.85rem;
    }

    .stat-label {
        font-size: 0.65rem;
        letter-spacing: 1px;
    }

    h1 {
        font-size: 1.6rem;
    }
}

@media (max-width: 420px) {
    .meal-selector {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .meal-btn {
        padding: 10px 8px;
        min-height: 60px;
    }

    .meal-btn .meal-label {
        font-size: 0.68rem;
    }
}

@media (max-width: 360px) {
    .app-container {
        padding: 10px 10px 20px;
    }

    .box-grid {
        grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
        gap: 6px;
    }

    .meal-btn .meal-label {
        font-size: 0.62rem;
    }

    .stat-value {
        font-size: 1.6rem;
    }
}

/* ── Custom Switch ──────────────────────────────── */
.form-group.toggle-group {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: hsla(0, 0%, 100%, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    margin-top: 4px;
}

.form-group.toggle-group label {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-main);
    font-weight: 700;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--surface-light);
    transition: var(--transition);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: var(--transition);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .slider {
    background-color: var(--accent);
    border-color: transparent;
}

input:checked + .slider:before {
    transform: translateX(20px);
}