:root {
    color-scheme: light;

    /* Brand & Status Colors */
    --accent-color: #007AFF;
    --accent-rgb: 0, 122, 255;
    --danger-color: #FF3B30;
    --danger-rgb: 255, 59, 48;
    --success-color: #34C759;
    --success-rgb: 52, 199, 89;
    --warning-color: #FF9500;
    --warning-rgb: 255, 149, 0;

    /* Layout Colors */
    --bg-color: #F2F2F7;
    --card-bg: #FFFFFF;
    --text-primary: #000000;
    --text-secondary: #8E8E93;
    --border-color: rgba(0, 0, 0, 0.08);
    --nav-bg: rgba(249, 249, 249, 0.8);
    --nav-border: rgba(0, 0, 0, 0.1);

    /* Component Specific Colors */
    --calendar-bg-default: #E5E5EA;
    --calendar-bg-weekend: #C7C7CC;
    --calendar-bg-active: var(--success-color);
    --calendar-border-active: var(--success-color);
    --calendar-text-active: #FFFFFF;

    /* Nutrient Colors */
    --color-calories: var(--accent-color);
    --color-protein: var(--success-color);
    --color-fat: var(--warning-color);
    --color-carbs: var(--danger-color);

    /* Typography Scale - Base is 16px */
    --font-size-xs: 0.625rem;
    /* 10px */
    --font-size-sm: 0.8125rem;
    /* 13px */
    --font-size-base: 1rem;
    /* 16px */
    --font-size-md: 1.0625rem;
    /* 17px */
    --font-size-lg: 1.5rem;
    /* 24px */
    --font-size-xl: 2.125rem;
    /* 34px */

    /* Spacing Scale */
    --space-xs: 0.25rem;
    /* 4px */
    --space-sm: 0.5rem;
    /* 8px */
    --space-md: 1rem;
    /* 16px */
    --space-lg: 1.25rem;
    /* 20px */
    --space-xl: 1.875rem;
    /* 30px */

    /* Radius */
    --radius-sm: 0.5rem;
    /* 8px */
    --radius-md: 0.75rem;
    /* 12px */
    --radius-lg: 1.25rem;
    /* 20px */
    --radius-full: 9999px;

    /* Other Tokens */
    --safe-area-bottom: env(safe-area-inset-bottom);
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --logo-image: url('assets/brand/logo.svg');
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.02);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);

    --user-font-size: 16px;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg-color: #000000;
    --card-bg: #1C1C1E;
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --calendar-bg-default: #2C2C2E;
    --calendar-bg-weekend: #48484A;
    --border-color: rgba(255, 255, 255, 0.12);
    --nav-bg: rgba(28, 28, 30, 0.8);
    --nav-border: rgba(255, 255, 255, 0.1);
}

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

html {
    font-size: var(--user-font-size);
}

body {
    margin: 0;
    font-family: var(--font-stack);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    line-height: 1.5;
    overscroll-behavior-x: none;
}

#app {
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    padding-bottom: calc(120px + var(--safe-area-bottom));
}

.view {
    display: none;
    animation: fadeIn 0.2s ease;
}

.view.active {
    display: block;
}

header {
    padding-top: max(var(--space-lg), env(safe-area-inset-top));
    padding-bottom: var(--space-sm);
    background: var(--bg-color);
    position: sticky;
    top: 0;
    z-index: 10;
}

h1 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 700;
}

h2 {
    font-size: var(--font-size-lg);
    font-weight: 700;
    margin: 0 0 var(--space-md) 0;
}

h3 {
    font-size: var(--font-size-md);
    font-weight: 600;
    margin: 0;
}

#loading {
    height: 100vh;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

#loading.active {
    display: flex;
}

.app-logo {
    background-image: var(--logo-image);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    margin: 0 auto;
}

.main-logo {
    width: 7.5rem;
    /* 120px */
    height: 7.5rem;
    margin-bottom: var(--space-lg);
}

.footer-logo {
    width: 1rem;
    /* 16px */
    height: 1rem;
    margin: 0;
    display: inline-block;
}


/* Font Size Slider */
.range-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 999px;
    outline: none;
    margin: 16px 0 8px;
}

.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    border: 2px solid #FFFFFF;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.range-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    border: 2px solid #FFFFFF;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.slider-ticks {
    display: flex;
    justify-content: space-between;
    padding: 0 4px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* Advanced Settings Visibility */
body:not(.show-advanced) [data-advanced="true"] {
    display: none !important;
}

/* Custom Dropdown with Icons */
.custom-dropdown {
    width: auto;
    min-width: 180px;
    position: relative;
}

.custom-dropdown.has-icons .dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.custom-dropdown.has-icons .dropdown-item svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.flex-column {
    flex-direction: column;
    align-items: flex-start !important;
}

/* Navigation */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(3.75rem + var(--safe-area-bottom));
    /* 60px */
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--nav-border);
    display: flex;
    justify-content: space-around;
    padding-bottom: var(--safe-area-bottom);
    z-index: 100;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-xs);
    width: 3.75rem;
    cursor: pointer;
}

.nav-item.active {
    color: var(--accent-color);
}

.nav-item.highlight {
    color: var(--accent-color);
}

/* Cards & Lists */
.entry-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    height: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 2;
    transition: transform 0.2s ease-out;
    touch-action: pan-y;
}

/* Swipe Gestures */
.swipe-container {
    position: relative;
    margin-bottom: var(--space-md);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--card-bg);
}

.swipe-bg {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 1.5rem;
    /* 24px */
    font-weight: 600;
    font-size: 0.6875rem;
    /* 11px */
    z-index: 1;
    transition: opacity 0.2s;
    box-sizing: border-box;
}

.swipe-bg.delete {
    right: 0;
    /* Align to right side (revealed on left swipe) */
    background-color: var(--danger-color);
    color: white;
    align-items: flex-end;
    /* Text on right */
    text-align: right;
}

.swipe-bg.duplicate {
    left: 0;
    /* Align to left side (revealed on right swipe) */
    background-color: var(--color-calories);
    color: white;
    align-items: flex-start;
    /* Text on left */
    text-align: left;
}

.swipe-bg .icon {
    font-size: 1rem;
    /* 16px */
    margin: 0 0 var(--space-xs) 0;
}

.entry-info h3 {
    margin: 0 0 var(--space-xs) 0;
    font-size: var(--font-size-md);
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

.entry-info p {
    margin: 0;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.entry-calories {
    font-weight: 600;
    color: var(--color-calories);
}

.icon-frame {
    width: 3.125rem;
    /* 50px */
    height: 3.125rem;
    border-radius: var(--radius-sm);
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.icon-frame.small {
    width: 1.875rem;
    /* 30px */
    height: 1.875rem;
    border-radius: var(--radius-sm);
    margin-right: var(--space-sm);
}

/* Authentication Styles */
.login-options {
    max-width: 400px;
    margin: 0 auto;
}

.oauth-btn {
    width: 100%;
    padding: 0.875rem 1.25rem;
    /* 14px 20px */
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    cursor: pointer;
    margin-bottom: var(--space-md);
    transition: all 0.2s;
}

.oauth-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.oauth-btn.google-btn {
    border-color: #4285F4;
}

.oauth-btn.facebook-btn {
    border-color: #1877F2;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.5rem 0;
    /* 24px */
    color: var(--text-secondary);
}

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

.divider span {
    padding: 0 var(--space-md);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    font-weight: 500;
}

.auth-warning {
    background: #ff4444;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    animation: slideDown 0.3s ease;
}

.warning-content {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    line-height: 1.4;
}

.auth-warning a {
    color: white;
    text-decoration: underline;
    font-weight: 600;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.icon-frame svg {
    width: 20px;
    height: 20px;
    opacity: 0.7;
}

.icon-frame.small svg {
    width: 16px;
    height: 16px;
}

/* Forms */
.form-view {
    padding: var(--space-lg);
}

.inline-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    align-items: end;
}

.inline-fields .field-group label {
    margin-top: var(--space-lg);
}

label {
    display: block;
    margin-top: var(--space-lg);
    margin-bottom: var(--space-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    font-weight: 500;
}

input,
select {
    width: 100%;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: none;
    background: var(--card-bg);
    font-size: var(--font-size-md);
    color: var(--text-primary);
    appearance: none;
}

button.btn-primary {
    width: 100%;
    margin-top: var(--space-xl);
    padding: var(--space-md);
    background: var(--accent-color);
    color: white;
    font-size: var(--font-size-md);
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
}

button.btn-secondary {
    background: var(--card-bg);
    color: var(--accent-color);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    border: none;
    font-size: 0.9375rem;
    /* 15px */
    font-weight: 500;
}

button.btn-icon {
    background: none;
    border: none;
    color: var(--accent-color);
    padding: var(--space-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}

button.btn-icon:hover {
    background: rgba(var(--accent-rgb), 0.1);
}

.unit-toggle {
    display: flex;
    gap: 0;
    margin-top: var(--space-md);
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    border: 1px solid var(--border-color);
}

.unit-toggle button {
    flex: 1;
    padding: var(--space-sm);
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    /* 14px */
    font-weight: 600;
    cursor: pointer;
}

.unit-toggle button.active {
    background: var(--accent-color);
    color: white;
}

button:disabled,
button.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: #ccc !important;
    color: #666 !important;
}

.spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

/* Method Selector */
.method-selector {
    display: flex;
    justify-content: space-around;
    padding: 5rem 0;
    /* 80px */
    margin-bottom: var(--space-lg);
}

.method-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
    position: relative;
    padding: 0;
    flex: 1;
    height: 6.875rem;
    /* 110px */
    justify-content: center;
    margin: 0;
}

/* Zone Tags */
.zone-tag {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-full);
    font-size: 0.6875rem;
    /* 11px */
    font-weight: 700;
    color: white;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-left: var(--space-sm);
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.1);
}

.method-icon-circle {
    width: 6.875rem;
    /* 110px */
    height: 6.875rem;
    border-radius: 50%;
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    box-shadow: 0 0.25rem 1.25rem rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, background-color 0.2s;
    gap: 2px;
}

.method-btn:active .method-icon-circle {
    transform: scale(0.95);
    background-color: var(--bg-color);
}

.method-btn span {
    font-size: 0.625rem;
    /* 10px */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 6px;
}

.method-btn input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

#preview-img {
    width: 100%;
    border-radius: 12px;
    margin-bottom: 20px;
}

/* Utilities */
.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

button.btn-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    background: #E5E5EA;
    /* Gray */
    color: #8E8E93;
}

button.btn-circle.danger {
    background: #FF3B30;
    color: white;
}

/* Recent List */
#daily-list {
    padding-top: var(--space-lg);
}

.recent-list {
    margin: var(--space-lg) 0;
    margin-top: var(--space-xl);
}

.recent-list h3 {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: var(--space-sm);
}

.recent-item {
    background: var(--card-bg);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9375rem;
    /* 15px */
    cursor: pointer;
    box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.05);
}

.recent-item .cal {
    color: var(--color-calories);
    font-weight: 600;
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.2;
}

.recent-item .cal .cal-num {
    font-size: 0.9375rem;
    /* 15px */
}

.recent-item .cal .cal-unit {
    font-size: 0.625rem;
    /* 10px */
    opacity: 0.7;
}

.show-more {
    width: 100%;
    text-align: center;
    padding: var(--space-sm);
    color: var(--accent-color);
    background: none;
    border: none;
    font-size: 0.875rem;
    /* 14px */
    cursor: pointer;
}

/* Settings Fix */
#tmpl-settings .view-content {
    /* Ensure padding is consistent */
    padding: var(--space-lg);
}

.settings-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    /* 24px */
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.group-title {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: var(--space-xs);
    padding-left: var(--space-xs);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    margin-bottom: var(--space-sm);
}

.setting-item .info h3 {
    margin: 0;
    font-size: var(--font-size-base);
}

.setting-item .info p {
    margin: var(--space-xs) 0 0 0;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.select-input {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-primary);
    font-size: 14px;
}

.pill-option {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    font-weight: 600;
    cursor: pointer;
}

.pill-option input {
    accent-color: var(--accent-color);
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .2s;
    border-radius: 26px;
}

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

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

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

/* Textarea */
textarea {
    width: 100%;
    padding: 16px;
    border-radius: 12px;
    border: none;
    background: var(--card-bg);
    font-size: 17px;
    color: var(--text-primary);
    font-family: inherit;
    resize: none;
    min-height: 80px;
}

/* Header Action Row */
.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Calendar */
#calendar-strip {
    padding: var(--space-lg) 0 var(--space-xl) 0;
    background: var(--bg-color);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
    padding: 0 var(--space-xs);
}

.calendar-title {
    font-size: var(--font-size-md);
    font-weight: 600;
    text-transform: capitalize;
    cursor: pointer;
}

.calendar-nav-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    /* 20px */
    color: var(--accent-color);
    cursor: pointer;
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    justify-content: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: var(--space-sm);
    row-gap: 0.75rem;
    /* 12px */
}

.calendar-day {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2rem;
    /* 32px */
    border-radius: 1rem;
    /* 16px */
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
    background: var(--calendar-bg-default);
    cursor: pointer;
    transition: background-color 0.2s;
}

.calendar-day.weekend {
    background: var(--calendar-bg-weekend);
}

.calendar-day.has-data {
    background: var(--calendar-bg-active);
    color: var(--calendar-text-active);
    font-weight: 700;
}

.calendar-day.today {
    border: 3px solid var(--text-secondary) !important;
}

.calendar-day.other-month {
    opacity: 0.3;
    pointer-events: none;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Macros */
.macro-grid {
    display: flex;
    gap: var(--space-sm);
}

.macro-item {
    flex: 1;
    background: var(--bg-color);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    text-align: center;
    display: flex;
    flex-direction: column;
}

.macro-item .label {
    font-size: 0.6875rem;
    /* 11px */
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 600;
}

.macro-item .val {
    font-size: 0.9375rem;
    /* 15px */
    font-weight: 600;
    margin-top: var(--space-xs);
    color: var(--text-primary);
}

.detail-value {

    margin-bottom: 20px;
    margin-top: 20px;
    font-weight: 500;
}

.detail-img {
    width: 100%;
    /*aspect-ratio: 11 / 9;*/
    padding-top: 75%;
    border-radius: 12px;
    display: none;
    margin-bottom: 20px;
    background-repeat: no-repeat;
    background-position: center center;
    background-size: cover;
    /* background-attachment: fixed; */
}

/* Analytics */
.analytics-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
}

.control-group {
    display: flex;
    flex-direction: column;
}

.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-bottom: var(--space-lg);
    box-shadow: var(--shadow-sm);
}

.chart-container h3 {
    margin: 0 0 var(--space-md) 0;
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-primary);
}

.chart-container canvas {
    max-height: 300px;
    overflow-y: auto;
}

/* AI Insights Card */
.ai-insight-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    /* 14px */
    position: relative;
    transition: opacity 0.3s ease;
    border: 1px solid rgba(var(--accent-rgb), 0.2);
}

.ai-insight-icon {
    flex-shrink: 0;
    width: 1.75rem;
    /* 28px */
    height: 1.75rem;
    color: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.ai-insight-content {
    flex: 1;
    min-width: 0;
}

.ai-insight-title {
    font-size: 0.6875rem;
    /* 11px */
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-color);
    margin-bottom: var(--space-sm);
}

.ai-insight-text {
    font-size: 0.875rem;
    /* 14px */
    line-height: 1.6;
    color: var(--text-primary);
}

.ai-insight-dismiss {
    position: absolute;
    top: 0.75rem;
    /* 12px */
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-xs, 4px);
    transition: background 0.2s, color 0.2s;
}

.ai-insight-dismiss:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

:root[data-theme="dark"] .ai-insight-dismiss:hover {
    background: rgba(255, 255, 255, 0.1);
}

.ai-insight-dismiss svg {
    width: 1rem;
    /* 16px */
    height: 1rem;
}


/* Recording State in Add Food */
.recording-state {
    text-align: center;
    padding: 2.5rem;
    /* 40px */
    margin-top: 15vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    box-sizing: border-box;
}

.pulse-ring {
    position: relative;
    width: 5rem;
    /* 80px */
    height: 5rem;
    background: var(--danger-color);
    border-radius: 50%;
    margin-bottom: 1.875rem;
    /* 30px */
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    box-shadow: 0 0 0 0 rgba(var(--danger-rgb), 0.7);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(var(--danger-rgb), 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 1.25rem rgba(var(--danger-rgb), 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(var(--danger-rgb), 0);
    }
}

/* Token Tracker / Stats */
.usage-stats {
    display: flex;
    gap: var(--space-md);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat .label {
    font-size: 0.625rem;
    /* 10px */
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    opacity: 0.7;
}

.stat .value {
    font-size: var(--font-size-base);
    font-weight: 700;
    color: var(--accent-color);
}

.tracker-item {
    background: var(--card-bg);
}

@media (prefers-color-scheme: dark) {
    .tracker-item {
        background: rgba(255, 255, 255, 0.05);
    }
}

.section-title {
    font-size: 0.875rem;
    /* 14px */
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

/* Custom Dropdown */
.custom-dropdown {
    position: relative;
    width: 100%;
}

.dropdown-trigger {
    width: 100%;
    padding: var(--space-md);
    background: var(--card-bg);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: var(--font-size-md);
    color: var(--text-primary);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.dropdown-trigger:active {
    background: var(--bg-color);
}

.dropdown-trigger.active {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-color: var(--border-color);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg);
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    box-shadow: 0 0.625rem 1.25rem rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    max-height: 18.75rem;
    /* 300px */
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-top: none;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    padding: 0.875rem 1rem;
    /* 14px 16px */
    display: flex;
    align-items: center;
    gap: 0.75rem;
    /* 12px */
    cursor: pointer;
    transition: background 0.2s;
    font-size: var(--font-size-base);
}

.dropdown-item:hover {
    background: rgba(var(--accent-rgb), 0.05);
}

.dropdown-item.selected {
    color: var(--accent-color);
    font-weight: 600;
}

.dropdown-icon {
    width: 1.25rem;
    /* 20px */
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
}

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

.dropdown-arrow {
    width: 0.75rem;
    /* 12px */
    height: 0.75rem;
    opacity: 0.5;
    transition: transform 0.2s;
}

.dropdown-trigger.active .dropdown-arrow {
    transform: rotate(180deg);
}

/* Compact version for filters */
.custom-dropdown.compact {
    width: auto;
}

.custom-dropdown.compact .dropdown-trigger {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
}

.custom-dropdown.compact .dropdown-item {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
}

.custom-dropdown.compact .dropdown-icon {
    width: 0.875rem;
    /* 14px */
    height: 0.875rem;
}

.custom-dropdown.compact .dropdown-menu {
    border-radius: var(--radius-sm);
    min-width: 7.5rem;
    /* 120px */
}

/* AI Analysis Animations */
.ai-analysis-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-color);
    z-index: 3000;
    display: none;
    opacity: 0;
    visibility: hidden;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ai-analysis-overlay.active {
    display: flex;
    opacity: 1;
    visibility: visible;
}

.analysis-container {
    position: relative;
    width: 100%;
    max-width: 31.25rem;
    /* 500px */
    border-radius: 1.25rem;
    /* 20px */
    overflow: hidden;
    background: var(--card-bg);
    box-shadow: 0 0.9375rem 2.5rem rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16/9;
}

.analysis-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.analysis-image {
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
}

.analysis-audio-wave {
    width: 90%;
    height: 7.5rem;
    /* 120px */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.wave-bar {
    width: 0.5rem;
    /* 8px */
    flex: none;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 0.625rem;
    /* 10px */
    height: 20%;
    transition: background 0.3s ease, transform 0.3s ease;
}

.wave-bar.highlight {
    background: var(--accent-color);
    transform: scaleY(1.2);
}

.wave-bar:nth-child(2n) {
    height: 40%;
}

.wave-bar:nth-child(3n) {
    height: 60%;
}

.wave-bar:nth-child(4n) {
    height: 100%;
}

.wave-bar:nth-child(5n) {
    height: 70%;
}

.wave-bar:nth-child(odd) {
    opacity: 0.8;
}

.analysis-text {
    font-size: var(--font-size-lg);
    font-weight: 700;
    line-height: 1.4;
    text-align: center;
    padding: 1.875rem;
    /* 30px */
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
}

.analysis-text span.highlight {
    color: var(--accent-color);
    text-shadow: 0 0 0.5rem rgba(var(--accent-rgb), 0.3);
    transition: color 0.3s ease;
}

.scanner-line {
    position: absolute;
    top: 0;
    left: 0;
    width: 3.75rem;
    /* 60px */
    height: 100%;
    z-index: 10;
    animation: scanMove 3.5s infinite ease-in-out;
}

@keyframes scanMove {
    0% {
        left: 0%;
        opacity: 0.8;
        background: linear-gradient(to right, transparent, var(--accent-color));
        box-shadow: 0.25rem 0 0.9375rem -0.125rem var(--accent-color);
        transform: translateX(-100%);
    }

    49% {
        background: linear-gradient(to right, transparent, var(--accent-color));
        box-shadow: 0.25rem 0 0.9375rem -0.125rem var(--accent-color);
    }

    50% {
        left: 100%;
        opacity: 0.8;
        background: linear-gradient(to left, transparent, var(--accent-color));
        box-shadow: -0.25rem 0 0.9375rem -0.125rem var(--accent-color);
        transform: translateX(0%);
    }

    99% {
        background: linear-gradient(to left, transparent, var(--accent-color));
        box-shadow: -0.25rem 0 0.9375rem -0.125rem var(--accent-color);
    }

    100% {
        left: 0%;
        opacity: 0.8;
        background: linear-gradient(to right, transparent, var(--accent-color));
        box-shadow: 0.25rem 0 0.9375rem -0.125rem var(--accent-color);
        transform: translateX(-100%);
    }
}

.analysis-label {
    margin-top: 1.875rem;
    /* 30px */
    font-size: 1.125rem;
    /* 18px */
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.5px;
}

.analysis-label::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '.';
    }

    40% {
        content: '..';
    }

    60%,
    100% {
        content: '...';
    }
}