/* ===================================================================
   PHYSIQONOMICS LOGGER - Main Stylesheet
   =================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

button {
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

input:focus,
textarea:focus,
select:focus {
    border-width: 3px;
}

:root,
[data-theme="dark"] {
    --bg: #0B0C0C;
    --bg-card: #1E1F21;
    --bg-card-hover: #282a2c;
    --bg-input: #323335;
    --border: #3a3c3e;
    --text: #e4e6e8;
    --text-muted: #7a7c7e;
    --text-dim: #5a5c5e;
    --accent: #4e8cff;
    --accent-light: #6ba3ff;
    --green: #34d399;
    --green-dim: #065f46;
    --red: #f87171;
    --red-dim: #7f1d1d;
    --orange: #fb923c;
    --orange-dim: #7c2d12;
    --blue: #4e8cff;
    --protein-green: #34d399;
    --fiber-orange: #fb923c;
    --steps-orange: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --modal-overlay: rgba(0,0,0,0.7);
    --chart-grid: rgba(100,100,120,0.2);
    --chart-tick: #6b6e7a;
    --chart-crosshair: rgba(255,255,255,0.3);
    --chart-goal-line: rgba(255,255,255,0.25);
    --tooltip-bg: #f5f5f0;
    --tooltip-border: #d4d4cc;
    --tooltip-title: #1a1a1a;
    --tooltip-body: #4a4a4a;
    --input-color-scheme: dark;
    --plus-btn-shadow: rgba(78,140,255,0.4);
    --divider: rgba(255,255,255,0.06);
    --subtle-bg: rgba(255,255,255,0.04);
    --subtle-border: rgba(255,255,255,0.12);
    --subtle-hover: rgba(255,255,255,0.08);
    --focus-border: #ffffff;
}

[data-theme="light"] {
    --bg: #f5f5f5;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f0f0;
    --bg-input: #efefef;
    --border: #d5d5d5;
    --text: #1a1a1a;
    --text-muted: #5c5f6a;
    --text-dim: #7d808a;
    --accent: #3b7dff;
    --accent-light: #5a94ff;
    --green: #059669;
    --green-dim: #d1fae5;
    --red: #dc2626;
    --red-dim: #fee2e2;
    --orange: #ea580c;
    --orange-dim: #ffedd5;
    --blue: #3b7dff;
    --protein-green: #059669;
    --fiber-orange: #ea580c;
    --steps-orange: #d97706;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --modal-overlay: rgba(0,0,0,0.4);
    --chart-grid: rgba(0,0,0,0.08);
    --chart-tick: #6b6e72;
    --chart-crosshair: rgba(0,0,0,0.15);
    --chart-goal-line: rgba(0,0,0,0.2);
    --tooltip-bg: #ffffff;
    --tooltip-border: #e0e0e0;
    --tooltip-title: #1a1a1a;
    --tooltip-body: #4a4a4a;
    --input-color-scheme: light;
    --plus-btn-shadow: rgba(59,125,255,0.3);
    --divider: rgba(0,0,0,0.08);
    --subtle-bg: rgba(0,0,0,0.03);
    --subtle-border: rgba(0,0,0,0.10);
    --subtle-hover: rgba(0,0,0,0.06);
    --focus-border: #000000;
}

body {
    font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    color-scheme: var(--input-color-scheme);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.25s, color 0.25s;
}

/* --- Navigation --- */
.navbar {
    background: var(--bg-card);
    border-bottom: none;
    transition: background-color 0.25s;
    position: sticky;
    top: 0;
    z-index: 100;
    padding-top: env(safe-area-inset-top);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 14px;
    display: flex;
    align-items: center;
    height: 48px;
}

.nav-page-title {
    flex: 1;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin: 0;
    text-align: center;
}

.nav-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 44px;
    justify-content: flex-end;
}

.nav-header-actions-left {
    justify-content: flex-start;
}

.nav-header-actions:empty,
.nav-header-actions-left:empty {
    min-width: 44px;
}

/* --- Container --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 20px 80px;
}

/* --- Page Header (legacy, kept for pages that still use it) --- */
.page-header {
    display: none;
}

.page-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.card-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 16px;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.stat-positive { color: var(--green); }
.stat-negative { color: var(--red); }
.stat-neutral { color: var(--text-muted); }

/* --- Entry Form --- */
.entry-form {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 28px;
}

.entry-form h2 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    align-items: end;
}

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

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.form-group input {
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    width: 100%;
}

.form-group input:focus {
    border-color: var(--focus-border);
}

.form-group input[type="date"],
.modal-body input[type="date"] {
    -webkit-appearance: none;
    color-scheme: var(--input-color-scheme);
    min-width: 0;
}

.form-group input[type="date"]::-webkit-calendar-picker-indicator,
.modal-body input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
}

[data-theme="dark"] .form-group input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] .modal-body input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

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

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

.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    font-size: 0.8rem;
    padding: 6px 12px;
}

.btn-danger:hover {
    background: var(--red);
    color: #fff;
}

/* --- Chart Container --- */
.chart-container {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 28px;
}

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

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 280px;
}

.chart-wrapper.tall {
    height: 350px;
}

/* --- Segmented Controls --- */
.chart-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.segmented-control {
    display: flex;
    background: var(--bg-input);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.segmented-control button {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.segmented-control button:hover {
    color: var(--text);
}

.segmented-control button.active {
    background: var(--text);
    color: var(--bg);
}

.segmented-control-compact {
    display: inline-flex;
    flex: none;
}

/* --- Comparison Table --- */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.comparison-table th,
.comparison-table td {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.comparison-table th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-decrease {
    background: var(--green-dim);
    color: var(--green);
}

.badge-increase {
    background: var(--red-dim);
    color: var(--red);
}

.badge-same {
    background: var(--bg-input);
    color: var(--text-muted);
}

/* --- Heatmap --- */
.heatmap-section {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 28px;
}

.heatmap-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.heatmap-stats {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.heatmap-stat {
    text-align: center;
}

.heatmap-stat-value {
    font-size: 1.3rem;
    font-weight: 700;
}

.heatmap-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.heatmap-grid {
    display: flex;
    gap: 3px;
    overflow: hidden;
}

.heatmap-week {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex-shrink: 0;
}

.heatmap-day {
    width: 13px;
    height: 13px;
    border-radius: 2px;
    background: var(--bg-input);
    flex-shrink: 0;
}

.heatmap-day.tracked {
    background: var(--accent);
}

.heatmap-day.heatmap-day-future {
    background: rgba(78, 140, 255, 0.12);
}

.heatmap-day.heatmap-day-empty {
    background: transparent;
}

.heatmap-months-row {
    position: relative;
    height: 18px;
    margin-bottom: 4px;
}

.heatmap-month-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.heatmap-day-labels {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-right: 6px;
    justify-content: flex-start;
}

.heatmap-day-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    height: 13px; /* overridden by JS inline style */
    display: flex;
    align-items: center;
}

.heatmap-wrapper {
    display: flex;
}

/* --- Insights --- */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
}

.insight-item {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 14px;
}

.insight-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.insight-value {
    font-size: 1.2rem;
    font-weight: 700;
}

/* --- Mini Charts (Dashboard) --- */
.mini-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.mini-chart-card {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 16px;
}

a.mini-chart-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: transform 0.15s;
}
a.mini-chart-link:active {
    transform: scale(0.98);
}

.mini-chart-card h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.mini-chart-value {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.mini-chart-wrapper {
    height: 120px;
    position: relative;
}

/* --- Section headers --- */
.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 16px;
    margin-top: 8px;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .container {
        padding: 8px 14px 80px;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .form-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chart-container {
        padding: 16px 0;
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    .chart-container .chart-header,
    .chart-container .chart-controls,
    .chart-container > div:not(.chart-wrapper) {
        padding-left: 14px;
        padding-right: 14px;
    }

    .chart-wrapper {
        height: 50vh;
        min-height: 300px;
        max-height: 500px;
    }

    .chart-wrapper.tall {
        height: 55vh;
        min-height: 340px;
        max-height: 550px;
    }

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

    .card-value {
        font-size: 1.4rem;
    }

    .mini-charts {
        grid-template-columns: 1fr;
    }

    .comparison-table th,
    .comparison-table td {
        padding: 8px 10px;
        font-size: 0.8rem;
    }

    .heatmap-section {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    /* heatmap-day sizes are set dynamically by JS */

    .insights-grid {
        grid-template-columns: 1fr 1fr;
    }

    .chart-stack {
        gap: 8px;
    }

    .chart-stack .chart-summary {
        padding: 0 14px;
        gap: 8px;
    }

    .entry-form,
    .card {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }
}

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

    .form-grid {
        grid-template-columns: 1fr;
    }

    .insights-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Theme Selector --- */
.theme-selector {
    display: flex;
    gap: 12px;
}

.theme-option {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0;
    background: var(--bg-card);
    border: 2px solid var(--bg-input);
    border-radius: var(--radius);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s;
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    padding-bottom: 10px;
}

.theme-desc {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 400;
    margin-top: -2px;
}

.theme-option.active {
    border-color: var(--accent);
}

.theme-preview {
    width: 100%;
    height: 64px;
    border-radius: 0;
    position: relative;
    overflow: hidden;
}

.theme-preview-light {
    background: #f5f5f5;
}

.theme-preview-light .theme-preview-bar {
    height: 10px;
    background: #ffffff;
    border-bottom: 1px solid #d0d0d0;
}

.theme-preview-light .theme-preview-lines div {
    height: 6px;
    margin: 6px 8px 0;
    border-radius: 3px;
    background: #c0c2c4;
}

.theme-preview-light .theme-preview-lines div:first-child {
    width: 60%;
}

.theme-preview-light .theme-preview-lines div:nth-child(2) {
    width: 40%;
}

.theme-preview-light .theme-preview-lines div:nth-child(3) {
    width: 50%;
}

.theme-preview-dark {
    background: #1a1b1d;
}

.theme-preview-dark .theme-preview-bar {
    height: 10px;
    background: #252628;
    border-bottom: 1px solid #3a3c3f;
}

.theme-preview-dark .theme-preview-lines div {
    height: 6px;
    margin: 6px 8px 0;
    border-radius: 3px;
    background: #44464a;
}

.theme-preview-dark .theme-preview-lines div:first-child {
    width: 60%;
}

.theme-preview-dark .theme-preview-lines div:nth-child(2) {
    width: 40%;
}

.theme-preview-dark .theme-preview-lines div:nth-child(3) {
    width: 50%;
}

.theme-preview-system {
    display: flex;
    position: relative;
}

.theme-preview-system .theme-preview-half-light,
.theme-preview-system .theme-preview-half-dark {
    flex: 1;
    overflow: hidden;
}

.theme-preview-system .theme-preview-half-light {
    background: #f5f5f5;
    border-right: 1.5px solid #c0c0c0;
}

.theme-preview-system .theme-preview-half-light .theme-preview-bar {
    height: 10px;
    background: #ffffff;
    border-bottom: 1px solid #d0d0d0;
}

.theme-preview-system .theme-preview-half-light .theme-preview-lines div {
    height: 6px;
    margin: 6px 6px 0;
    border-radius: 3px;
    background: #c0c2c4;
}

.theme-preview-system .theme-preview-half-dark {
    background: #1a1b1d;
}

.theme-preview-system .theme-preview-half-dark .theme-preview-bar {
    height: 10px;
    background: #252628;
    border-bottom: 1px solid #3a3c3f;
}

.theme-preview-system .theme-preview-half-dark .theme-preview-lines div {
    height: 6px;
    margin: 6px 6px 0;
    border-radius: 3px;
    background: #44464a;
}

/* --- Settings --- */
.settings-form {
    max-width: 400px;
}

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

/* --- Settings Drill-Down --- */
.settings-group {
    margin-bottom: 20px;
}

.settings-group:first-child {
    margin-top: 8px;
}

.settings-group-label {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 0 4px 8px;
}

.settings-group-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}

.settings-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.12s;
    text-align: left;
}

.settings-row:active {
    background: var(--subtle-hover);
}

.settings-row-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    flex-shrink: 0;
}

.settings-row-text {
    flex: 1;
    min-width: 0;
}

.settings-row-title {
    font-size: 0.92rem;
    font-weight: 500;
    line-height: 1.3;
}

.settings-row-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
    margin-top: 1px;
}

.settings-row-chevron {
    flex-shrink: 0;
    color: var(--text-muted);
    opacity: 0.45;
}

.settings-row-divider {
    height: 1px;
    background: var(--divider);
    margin-left: 60px;
}

/* Section panels */
.settings-section {
    animation: settingsSlideIn 0.22s ease-out;
}

@keyframes settingsSlideIn {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.settings-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--accent);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 8px;
    -webkit-tap-highlight-color: transparent;
}

.settings-back-btn:active {
    opacity: 0.6;
}

.settings-section-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -0.01em;
}

/* ── Toggle Switch ── */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-input);
    border-radius: 26px;
    transition: background 0.25s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform 0.25s, background 0.25s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--accent, #4e8cff);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
    background: #fff;
}

/* ── Cycling Day Buttons ── */
.cycling-day-btn {
    font-size: 0.78rem;
    padding: 6px 12px;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-muted);
    border: 1.5px solid transparent;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.cycling-day-btn.active {
    background: rgba(78, 140, 255, 0.15);
    color: var(--accent, #4e8cff);
    border-color: var(--accent, #4e8cff);
}
.cycling-day-btn:active {
    transform: scale(0.94);
}

/* Mini chart chevron */
.mini-chart-chevron {
    float: right;
    color: var(--text);
    opacity: 0.3;
    margin-top: 2px;
}

/* --- Layout Preview (Settings) --- */
.layout-preview {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}

.layout-preview-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--divider);
}

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

.layout-preview-emoji {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.layout-preview-text {
    flex: 1;
    min-width: 0;
}

.layout-preview-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layout-preview-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.layout-preview-cal {
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* Preview: align-right */
.layout-preview.align-right .layout-preview-item {
    flex-direction: row-reverse;
}
.layout-preview.align-right .layout-preview-text {
    text-align: right;
}
.layout-preview.align-right .layout-preview-cal {
    text-align: left;
}

/* Preview + Food log: density-compact */
.layout-preview.density-compact .layout-preview-item,
.density-compact .food-item-main {
    padding: 6px 14px;
    gap: 8px;
}
.layout-preview.density-compact .layout-preview-emoji,
.density-compact .food-item-avatar {
    width: 28px;
    height: 28px;
    font-size: 1.1rem;
}
.layout-preview.density-compact .layout-preview-name,
.density-compact .food-item-name {
    font-size: 0.8rem;
}
.layout-preview.density-compact .layout-preview-meta,
.density-compact .food-item-meta {
    font-size: 0.65rem;
}
.layout-preview.density-compact .layout-preview-cal,
.density-compact .food-item-cal {
    font-size: 0.8rem;
}

/* Preview + Food log: density-spacious */
.layout-preview.density-spacious .layout-preview-item,
.density-spacious .food-item-main {
    padding: 14px;
    gap: 12px;
}
.layout-preview.density-spacious .layout-preview-emoji,
.density-spacious .food-item-avatar {
    width: 42px;
    height: 42px;
    font-size: 1.6rem;
}
.layout-preview.density-spacious .layout-preview-name,
.density-spacious .food-item-name {
    font-size: 0.9rem;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text);
}

/* --- Action Icons (History) --- */
.action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.action-icon:hover {
    color: var(--accent);
    background: rgba(78, 140, 255, 0.12);
}

.action-icon-danger:hover {
    color: var(--red);
    background: var(--red-dim);
}

/* --- Chart Summary Stats --- */
.chart-summary {
    display: flex;
    gap: 24px;
    padding: 20px 20px 16px;
    flex-wrap: wrap;
}

.chart-summary-item {
    flex: 1;
    min-width: 120px;
}

.chart-summary-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.chart-summary-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.chart-summary-value .unit {
    font-size: 0.5em;
    color: var(--text-muted);
    font-weight: 500;
}

.chart-summary-detail {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* --- Nutrition chart stack --- */
.chart-stack {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* --- Heatmap year sections --- */
.heatmap-year-section {
    margin-bottom: 20px;
}

.heatmap-year-section:last-child {
    margin-bottom: 0;
}

.heatmap-year-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

/* --- Entry Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 380px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 0;
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.modal-footer {
    padding: 0 20px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Bottom sheet modals on mobile */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-content {
        max-width: 100%;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        animation: slideUp 0.25s ease;
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }

    .modal-content::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--bg-input);
        border-radius: 2px;
        margin: 10px auto 0;
    }

}

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

/* --- Swipe-to-delete (old duplicate removed) --- */

/* --- Toast action button --- */
.food-toast-action {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
    margin-left: 12px;
    cursor: pointer;
    text-transform: uppercase;
    font-family: inherit;
}

/* --- Add Button (circular +) --- */
.add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
    flex-shrink: 0;
}

.add-btn:hover {
    background: var(--accent-light);
    transform: scale(1.05);
}

/* --- Section Add Button (text style) --- */
.section-add-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    transition: opacity 0.15s;
}

.section-add-btn:active {
    opacity: 0.6;
}

/* --- Section Header (title + add button) --- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

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

.view-all-link {
    display: block;
    text-align: center;
    padding: 12px;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.view-all-link:hover {
    color: var(--accent-light);
}

/* --- Measurement form (stacked like reference design) --- */
.measurement-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.measurement-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.measurement-field label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.measurement-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.measurement-input-wrap input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 14px 50px 14px 16px;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.measurement-input-wrap input:focus {
    border-color: var(--focus-border);
}

.measurement-input-wrap .unit-label {
    position: absolute;
    right: 16px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
}

.measurement-date-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 24px;
    margin-top: 8px;
    cursor: pointer;
    position: relative;
}

.measurement-date-bar svg {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.measurement-date-bar input[type="date"] {
    background: none;
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0;
    outline: none;
    -webkit-appearance: none;
    color-scheme: var(--input-color-scheme);
    text-align: center;
}

/* Hide native calendar icon so only our SVG shows */
.measurement-date-bar input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.measurement-save-btn {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: var(--bg);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 8px;
}

.measurement-save-btn:hover {
    opacity: 0.9;
}

/* Field modal layout */
.field-modal-date {
    text-align: center;
    font-size: 0.9rem;
    font-weight: 600;
    color: #a0a3a8;
    margin-bottom: 4px;
}

.field-modal-delete {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    margin-top: 8px;
}

.field-modal-delete:active {
    background: #3a2020;
    color: #f87171;
}

/* --- Body Metrics Page --- */
.metrics-page {
    padding-bottom: 100px;
}

/* Measurement grid tiles */
.measurement-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.measurement-tile {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 14px 12px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100px;
}

.measurement-tile:active {
    background: var(--bg-input);
}

.measurement-tile-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: auto;
}

.measurement-tile-name {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.measurement-tile-date {
    font-size: 0.7rem;
    font-weight: 600;
    color: #a0a3a8;
    white-space: nowrap;
    line-height: 1.2;
}

.measurement-tile-bottom {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-top: 10px;
}

.measurement-tile-value {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.measurement-tile-unit {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--text-muted);
}

.measurement-tile-spark {
    width: 80px;
    height: 32px;
    flex-shrink: 0;
}

.measurement-tile-spark canvas {
    width: 100%;
    height: 100%;
    display: block;
}

@media (max-width: 360px) {
    .measurement-grid {
        gap: 8px;
    }
    .measurement-tile {
        padding: 12px;
    }
    .measurement-tile-value {
        font-size: 1.15rem;
    }
    .measurement-tile-spark {
        width: 60px;
        height: 28px;
    }
}

/* Ratio display */
.ratio-display {
    text-align: center;
    padding: 8px 0;
}

.ratio-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.ratio-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Nav back button (detail views) */
.nav-back-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.15s;
    padding: 0;
}

.nav-back-btn:hover {
    background: var(--bg-input);
}

/* Measurement detail view — brighter labels */
#detailView .chart-summary-label {
    color: #a0a3a8;
}

#detailView .chart-summary-detail {
    color: #a0a3a8;
    font-weight: 600;
    white-space: nowrap;
}

/* --- Card Entrance Animations --- */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card,
.mini-chart-card,
.chart-container,
.heatmap-section,
.card {
    animation: fadeUp 0.4s ease-out both;
}

/* Stagger children in grids */
.stats-grid > :nth-child(1) { animation-delay: 0s; }
.stats-grid > :nth-child(2) { animation-delay: 0.05s; }
.stats-grid > :nth-child(3) { animation-delay: 0.1s; }
.stats-grid > :nth-child(4) { animation-delay: 0.15s; }
.stats-grid > :nth-child(5) { animation-delay: 0.2s; }
.stats-grid > :nth-child(6) { animation-delay: 0.25s; }

.mini-charts > :nth-child(1) { animation-delay: 0.1s; }
.mini-charts > :nth-child(2) { animation-delay: 0.15s; }
.mini-charts > :nth-child(3) { animation-delay: 0.2s; }


@media (prefers-reduced-motion: reduce) {
    .stat-card,
    .mini-chart-card,
    .chart-container,
    .heatmap-section,
    .card {
        animation: none;
    }
}

/* --- Goal Tile (Dashboard) --- */
.goal-tile {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    animation: fadeUp 0.4s ease-out both;
}

.goal-tile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.goal-tile-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.goal-tile-edit {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    transition: all 0.2s;
}

.goal-tile-edit:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.goal-tile-type {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.goal-tile-dates {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 16px;
}

.goal-tile-stats {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    gap: 0;
}

.goal-tile-stat {
    flex: 1;
}

.goal-tile-stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-bottom: 4px;
}

.goal-tile-stat-value {
    font-size: 1.6rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    line-height: 1.2;
    white-space: nowrap;
}

.goal-tile-stat-value-sm {
    font-size: 1.1rem;
}

.goal-tile-stat-unit {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.goal-tile-progress {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    margin: 14px 0 12px;
    overflow: hidden;
}

.goal-tile-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    min-width: 2px;
    transition: width 0.5s ease;
}

.goal-tile-footer {
    display: flex;
    gap: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.goal-tile-footer span {
    flex: 1;
    text-align: center;
    position: relative;
    padding: 0 10px;
}

.goal-tile-footer-label {
    color: var(--text-dim);
    margin-bottom: 2px;
}

.goal-tile-footer-value {
    color: var(--text-muted);
    font-weight: 500;
}

.goal-tile-footer span:not(:last-child)::after {
    content: '';
    position: absolute;
    right: 0;
    top: -2px;
    bottom: -2px;
    width: 1px;
    background: var(--border);
}

@media (max-width: 768px) {
    .goal-tile {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    .goal-tile-type {
        font-size: 1.5rem;
    }

    .goal-tile-stat-value {
        font-size: 1.2rem;
    }

    .goal-tile-stats {
        padding: 12px 14px;
    }

    .goal-tile-footer {
        font-size: 0.68rem;
    }
}

/* --- MacroFactor Nutrition Card --- */
.nutrition-card {
    background: var(--bg-card);
    border: none;
    border-radius: 0;
    padding: 16px 20px 16px;
    margin: -12px -20px 20px;
    width: calc(100% + 40px);
}

.nutrition-card-date {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ── Dashboard Weekly Grid ── */
.dash-wk-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.dash-wk-header-row,
.dash-wk-macro-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dash-wk-day-letter {
    width: 16px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    flex-shrink: 0;
}

.dash-wk-today-letter {
    flex: 1;
    min-width: 0;
    text-align: left;
    padding-left: 2px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
    text-transform: none;
    width: auto;
}

.dash-wk-sq {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    flex-shrink: 0;
}

.dash-wk-today-cell {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dash-wk-bar-wrap {
    flex: 1;
    height: 16px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    min-width: 0;
}

.dash-wk-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
}

.dash-wk-bar-info {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-shrink: 0;
    white-space: nowrap;
    min-width: 105px;
    justify-content: flex-end;
}

.dash-wk-bar-val {
    font-size: 0.82rem;
    font-weight: 700;
    opacity: 0.82;
}

[data-theme="light"] .dash-wk-bar-val {
    opacity: 1;
}

.dash-wk-bar-tgt {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.dash-wk-dots {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 10px;
}

.dash-wk-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bg-input);
    transition: background 0.2s, transform 0.2s;
}

.dash-wk-dot.active {
    background: var(--text-muted);
    transform: scale(1.2);
}

/* ── Dashboard Quick Actions Bottom Sheet ── */

.nutrition-card-log-link {
    font-size: 0.7rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.nutrition-card-log-link:hover {
    opacity: 1;
}

.nutrition-card-heatmap {
    display: flex;
    gap: 6px;
}

.nutrition-card .heatmap-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    text-decoration: none;
    cursor: pointer;
}

.nutrition-card .heatmap-day:hover .heatmap-day-dot:not(.heatmap-future) {
    border-color: var(--accent);
    transform: scale(1.1);
}

.nutrition-card .heatmap-day-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.nutrition-card .heatmap-day-dot {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1.5px solid var(--border);
    transition: all 0.2s ease;
}

.nutrition-card .heatmap-day-dot.heatmap-logged {
    background: rgba(78, 140, 255, 0.18);
    border-color: rgba(78, 140, 255, 0.45);
}

.nutrition-card .heatmap-day-dot.heatmap-today {
    box-shadow: 0 0 0 2px rgba(78, 140, 255, 0.5);
    border-color: rgba(78, 140, 255, 0.6);
}

.nutrition-card .heatmap-day-dot.heatmap-future {
    opacity: 0.25;
    cursor: default;
}

.macro-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.macro-row:last-child {
    margin-bottom: 0;
}

.macro-bar-track {
    flex: 1;
    height: 26px;
    background: var(--bg-input);
    border-radius: 8px;
    overflow: hidden;
}

.macro-bar-fill {
    height: 100%;
    border-radius: 8px;
    transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    min-width: 2px;
}

.macro-row-value {
    width: 130px;
    text-align: right;
    flex-shrink: 0;
    white-space: nowrap;
}

.macro-current {
    font-size: 1rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    opacity: 0.82;
}

[data-theme="light"] .macro-current {
    opacity: 1;
}

.macro-target {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

@media (max-width: 768px) {
    .nutrition-card {
        border-radius: 0;
        margin: -8px -14px 20px;
        width: calc(100% + 28px);
        padding: 14px 14px 14px;
    }

    .nutrition-card-heatmap {
        gap: 4px;
    }

    .nutrition-card .heatmap-day-dot {
        width: 24px;
        height: 24px;
    }

    .macro-row-value {
        width: 110px;
    }

    .macro-current {
        font-size: 0.9rem;
    }

    .macro-bar-track {
        height: 22px;
    }
}

/* --- Goal Calculator --- */
.calc-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.calc-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.calc-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.calc-field input[type="number"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.calc-field input[type="number"]:focus {
    border-color: var(--focus-border);
}

.calc-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.calc-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text);
}

.calc-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.calc-results {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-top: 8px;
}

.calc-results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.calc-result-item {
    text-align: center;
}

.calc-result-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.calc-result-value {
    font-size: 1.05rem;
    font-weight: 700;
}

.calc-result-highlight .calc-result-value {
    color: var(--accent);
    font-size: 1.2rem;
}

@media (max-width: 768px) {
    #goalCalcCard {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    .calc-row {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 8px;
    }

    .calc-field input[type="number"] {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    /* Make segmented controls inside calculator wrap on mobile */
    #goalCalcCard .segmented-control {
        flex-wrap: wrap;
    }

    #goalCalcCard .segmented-control button {
        font-size: 0.7rem;
        padding: 7px 8px;
        min-width: 0;
    }

    .calc-results-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .calc-result-value {
        font-size: 0.85rem;
    }

    .calc-result-highlight .calc-result-value {
        font-size: 0.95rem;
    }

    .calc-toggle {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .calc-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* Legacy grid (kept for non-measurement forms) */
.measurement-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 10px;
}

.measurement-form-grid .form-group input {
    padding: 10px;
    font-size: 0.9rem;
}

/* ===================================================================
   FOOD LOG PAGE — MacroFactor-inspired redesign
   =================================================================== */

/* Date Navigation */
/* ── Weekly Macro Card ── */
.weekly-card {
    background: var(--bg-card);
    border-radius: 0;
    padding: 12px 20px 14px;
    margin: -12px -20px 8px;
    width: calc(100% + 40px);
    animation: fadeUp 0.4s ease-out both;
}

.wk-date-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
}

.wk-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: none;
    color: #9a9da1;
    border: none;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

.wk-nav-btn:active {
    background: var(--bg-input);
}

.wk-date {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    cursor: pointer;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cycling-badge {
    font-size: 0.6rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cycling-badge.high {
    background: rgba(78, 140, 255, 0.15);
    color: var(--accent, #4e8cff);
}
.cycling-badge.low {
    background: rgba(122, 124, 126, 0.15);
    color: var(--text-muted);
}

/* Ring-style macro display */
.wk-rings-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 8px 8px;
}

.wk-ring-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.wk-ring-svg {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.wk-ring-value {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    white-space: nowrap;
}

.wk-ring-target {
    font-size: 0.8rem;
    font-weight: 400;
    color: #b8bbc0;
    white-space: nowrap;
    margin-left: -1px;
}

.wk-ring-suffix {
    font-size: 0.8rem;
    font-weight: 400;
    color: #b8bbc0;
    white-space: nowrap;
    margin-left: 1px;
}

/* Page label (shown for non-consumed pages) */
.wk-page-label {
    text-align: center;
    font-size: 0.68rem;
    font-weight: 600;
    color: #9a9da1;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

/* Dot indicators for swipeable pages */
.wk-dots-row {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 4px 0 0;
}

.wk-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--bg-input);
    transition: background 0.2s;
}

.wk-dot.active {
    background: #9a9da1;
}

/* Week day indicators */
.wk-days-row {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 12px;
}

.wk-day-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.wk-day-letter {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.wk-day-selected .wk-day-letter {
    color: var(--text);
}

.wk-day-box {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    border: 1.5px solid var(--subtle-border);
    background: transparent;
    transition: all 0.2s;
}

.wk-day-box.wk-day-filled {
    background: var(--subtle-hover);
    border-color: var(--subtle-border);
}

.wk-day-box.wk-day-future {
    border-color: var(--divider);
}

.wk-day-selected .wk-day-box {
    border-color: var(--accent);
    background: rgba(78,140,255,0.15);
}

/* (Old macro bar styles removed — replaced by ring design above) */

/* ── Meal Groups ── */
.food-meal-group {
    background: var(--bg-card);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
    animation: fadeUp 0.3s ease-out both;
}

.food-meal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
}

.food-meal-title {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
    font-size: 0.72rem;
    background: var(--subtle-bg);
    padding: 4px 10px;
    border-radius: 20px;
    color: #9a9c9e;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.food-meal-title svg {
    opacity: 0.5;
    width: 13px;
    height: 13px;
}

.food-meal-totals {
    display: flex;
    gap: 10px;
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.food-meal-totals span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--text);
    font-weight: 600;
}

.food-meal-totals svg {
    opacity: 0.85;
}

/* Macro circle badges — white letter in colored circle */
.macro-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 800;
    color: #fff !important;
    line-height: 1;
    flex-shrink: 0;
}
.macro-circle-cal { background: #2d5a9e; }
.macro-circle-p { background: #1e7a58; }
.macro-circle-f { background: #9e5418; }
.macro-circle-c { background: #6b4a99; }
.macro-circle-fi { background: #8e3a6b; }

/* Light mode — brighter circles */
[data-theme="light"] .macro-circle-cal { background: #4e8cff; }
[data-theme="light"] .macro-circle-p { background: #2fba85; }
[data-theme="light"] .macro-circle-f { background: #e0772a; }
[data-theme="light"] .macro-circle-c { background: #9b6dd7; }
[data-theme="light"] .macro-circle-fi { background: #f472b6; }

.food-meal-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.food-meal-action-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    display: flex;
    border-radius: 4px;
    transition: color 0.2s;
}

.food-meal-action-btn:hover {
    color: var(--text-muted);
}

.food-meal-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.food-meal-add-btn {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.10);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
}
.food-meal-add-btn:active {
    background: var(--text-muted);
    color: var(--bg);
}

/* ── Food Items (compact 2-line layout) ── */
.food-item {
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border-bottom: 1px solid var(--divider);
}

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

.food-item-swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding-left: 16px;
    background: var(--bg-card);
    visibility: hidden;
    z-index: 2;
}

.food-item.swiping .food-item-swipe-actions {
    visibility: visible;
}

.food-item-swipe-actions .swipe-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.food-item-swipe-actions .swipe-edit {
    background: #3a3d42;
    color: #fff;
}

.food-item-swipe-actions .swipe-delete {
    background: rgba(239, 68, 68, 0.35);
    color: #fff;
}

.food-item-swipe-actions .swipe-btn svg {
    width: 18px;
    height: 18px;
}

.food-item-main {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    padding: 10px 14px;
    transition: transform 0.2s ease;
}

.food-item-main:active {
    background: var(--subtle-bg);
}

.food-item-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.food-item-avatar.letter-icon {
    font-size: 0.8rem;
    opacity: 0.5;
}

.food-item-avatar.emoji-icon {
    font-size: 1.4rem;
    background: transparent !important;
}

/* 3D Fluent emoji images via Twemoji */
img.emoji {
    height: 1.2em;
    width: 1.2em;
    margin: 0 .05em 0 .1em;
    vertical-align: -0.15em;
}
.food-item-avatar img.emoji {
    height: 26px;
    width: 26px;
    margin: 0;
    vertical-align: middle;
}
.food-fav-avatar img.emoji {
    height: 28px;
    width: 28px;
    margin: 0;
    vertical-align: middle;
}

.food-item-info {
    flex: 1;
    min-width: 0;
}

.food-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.food-item-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.food-item-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    gap: 1px;
}

.food-item-cal {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* Right-aligned food log (MacroFactor style) */
.align-right .food-meal-header {
    flex-direction: row-reverse;
}
.align-right .food-meal-header-right {
    flex-direction: row-reverse;
}
.align-right .food-meal-totals {
    flex-direction: row-reverse;
}
.align-right .food-meal-totals span {
    flex-direction: row-reverse;
}
.align-right .food-item-main {
    flex-direction: row-reverse;
}
.align-right .food-item-info {
    text-align: right;
}
.align-right .food-item-right {
    align-items: flex-start;
}

.food-item-time {
    font-size: 0.6rem;
    color: var(--text-muted);
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.15s;
}
.food-item-time:active {
    background: rgba(255,255,255,0.08);
}
[data-theme="light"] .food-item-time:active {
    background: rgba(0,0,0,0.06);
}
.food-item-meal-tag {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(78, 140, 255, 0.12);
    color: var(--accent);
    vertical-align: middle;
    margin-left: 4px;
    text-transform: capitalize;
}
.alcohol-badge {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    background: rgba(127, 29, 29, 0.2);
    color: #f87171;
    vertical-align: middle;
    margin-left: 4px;
}

/* ── Empty State ── */
.food-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.food-empty-state svg {
    opacity: 0.3;
    margin-bottom: 12px;
}

.food-empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.food-empty-state p {
    font-size: 0.85rem;
}

/* ── Toolbar Search Bar (Food Log) ── */
.toolbar-home-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    background: var(--bg-input);
    color: var(--text);
    text-decoration: none;
    border-radius: 12px;
    transition: color 0.15s, background 0.15s;
}

.toolbar-home-btn:active {
    color: var(--text);
    background: var(--subtle-hover);
}

.bottom-toolbar.food-toolbar {
    height: calc(80px + env(safe-area-inset-bottom));
    padding: 0 20px 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    gap: 12px;
    justify-content: center;
}

.bottom-toolbar.food-toolbar::before {
    height: calc(100% + 40px);
    background: linear-gradient(to bottom, transparent 0%, color-mix(in srgb, var(--bg) 20%, transparent) 40%, var(--bg) 80%);
}

.toolbar-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    flex: 1;
    max-width: 340px;
    transition: background 0.15s;
}

.toolbar-search:active {
    background: var(--subtle-hover);
}

.toolbar-search svg {
    color: var(--text-muted);
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.toolbar-search span {
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 400;
    white-space: nowrap;
}

[data-theme="light"] .toolbar-home-btn,
[data-theme="light"] .toolbar-search {
    background: #e2e2e4;
}

/* ── FAB (Floating Action Button) ── */
.food-fab {
    position: fixed;
    bottom: 80px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(78, 140, 255, 0.35);
    z-index: 50;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.food-fab svg {
    width: 24px;
    height: 24px;
    transition: transform 0.2s;
}

.food-fab.open svg {
    transform: rotate(45deg);
}

/* ── Add Food Bottom Sheet ── */
.food-add-sheet {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    background: #000;
    overflow: hidden;
    touch-action: none;
}

.food-add-sheet-inner {
    background: var(--bg-card);
    border-radius: 0;
    overflow: hidden;
    flex: 1;
    min-height: 0;
    max-height: calc(100dvh - 140px);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.25s ease;
    touch-action: pan-y;
}

.food-sheet-handle {
    width: 36px;
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    margin: 10px auto 0;
}

/* Macro rings bar — sits above the sheet in the overlay */
.food-sheet-macro-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #000;
    padding: 16px 20px;
    border-radius: 16px 16px 0 0;
    margin-top: auto;
}

.food-sheet-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    margin-right: auto;
}

.food-sheet-macro-rings {
    display: grid;
    grid-template-columns: auto auto;
    gap: 8px 24px;
}

.food-sheet-macro-rings .wk-ring-value {
    font-size: 0.9rem;
    font-weight: 600;
}

.food-sheet-macro-rings .wk-ring-target,
.food-sheet-macro-rings .wk-ring-suffix {
    font-size: 0.9rem;
}

.food-sheet-macro-rings .wk-ring-svg {
    width: 28px;
    height: 28px;
}

.food-sheet-macro-rings .wk-ring-item {
    gap: 5px;
}

/* ── Tab Navigation ── */
.food-tab-nav {
    display: flex;
    gap: 0;
    padding: 10px 16px 0;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--bg-card);
}

.food-tab-nav::-webkit-scrollbar { display: none; }

.food-tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 10px 14px;
    cursor: pointer;
    white-space: nowrap;
    position: relative;
    transition: color 0.2s;
}

.food-tab-btn.active {
    color: var(--accent);
}

.food-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 8px;
    right: 8px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.food-tab-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px 16px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.food-tab-pane {
    display: none;
}

.food-tab-pane.active {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Search Tab ── */

/* Search bar at bottom of sheet */
.food-search-bar {
    padding: 8px 16px;
    padding-bottom: env(safe-area-inset-bottom, 8px);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.food-search-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border-radius: 24px;
    padding: 12px 16px;
    border: 1.5px solid transparent;
    transition: border-color 0.2s;
}

.food-search-bar-inner:focus-within {
    border-color: var(--focus-border);
    border-width: 3px;
}

.food-search-bar-inner svg {
    color: var(--text-muted);
    flex-shrink: 0;
}

.food-search-bar-inner input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    outline: none;
}

.food-search-bar-inner input::placeholder {
    color: var(--text-muted);
}

/* ── Multi-Select Food Logging ── */
.multi-select-bar {
    flex-shrink: 0;
    padding: 8px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.multi-select-bar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 8px 12px;
}

.multi-select-summary {
    flex: 1;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
}

.multi-select-cancel-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: rgba(248, 113, 113, 0.15);
    border: none;
    color: #f87171;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.multi-select-cancel-btn:active {
    background: rgba(248, 113, 113, 0.3);
}

.multi-select-log-btn {
    background: #fff;
    color: #000;
    border: none;
    border-radius: 20px;
    padding: 8px 18px;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    flex-shrink: 0;
}

.multi-select-log-btn:active {
    opacity: 0.8;
}

/* Expand button in bottom bar */
.ms-bar-expand {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex-shrink: 0;
}

.ms-bar-expand:active {
    background: rgba(255,255,255,0.2);
}

/* Multi-select plate (selected foods at top of search) */
.ms-plate {
    background: var(--bg-input);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 12px;
    position: sticky;
    top: -1px;
    z-index: 4;
}

.ms-plate-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.ms-plate-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    letter-spacing: 0.3px;
}

.ms-plate-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Collapse button: white circle, black chevron (added dynamically in expanded mode) */
.ms-expand-collapse {
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    background: #fff !important;
    color: #000 !important;
}

.ms-plate-clear {
    font-size: 0.72rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
}

/* ── Expanded multi-select full-screen overlay ── */
.ms-plate.expanded {
    position: fixed;
    inset: 0;
    z-index: 250;
    border-radius: 0;
    padding: 0;
    margin: 0;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    max-height: none;
}

.ms-plate.expanded .ms-plate-header {
    padding: calc(env(safe-area-inset-top, 12px) + 8px) 16px 12px;
    background: var(--bg);
    margin-bottom: 0;
    flex-shrink: 0;
}

.ms-plate.expanded .ms-plate-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.ms-plate.expanded .ms-plate-items {
    flex: 1;
    max-height: none;
    overflow-y: auto;
    padding: 0 16px 16px;
    gap: 0;
    display: flex;
    flex-direction: column;
}

.ms-plate.expanded .ms-plate-totals {
    display: none;
}

.ms-plate.expanded .ms-plate-log-btn {
    margin: 0 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    padding: 15px;
    border-radius: 12px;
    background: #fff;
    color: #000;
    font-size: 0.95rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    font-family: inherit;
    flex-shrink: 0;
}

.ms-plate.expanded .ms-plate-log-btn:active {
    opacity: 0.85;
}

/* ── Expanded: items header row ── */
.ms-exp-items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0 8px;
}

.ms-exp-count {
    font-size: 0.95rem;
    font-weight: 400;
    color: var(--text);
}

.ms-exp-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.ms-exp-clear {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
}

.ms-exp-section-hdr {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 20px 0 10px;
}

/* ── Expanded: item list ── */
.ms-exp-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Swipe-to-reveal wrapper */
.ms-exp-item-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    margin-bottom: 6px;
}

.ms-exp-swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    visibility: hidden;
}

.ms-exp-item-wrap.swiping .ms-exp-swipe-actions {
    visibility: visible;
}

.ms-exp-swipe-actions .swipe-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ms-exp-swipe-actions .swipe-delete {
    background: rgba(239, 68, 68, 0.35);
    color: #fff;
}

.ms-exp-swipe-actions .swipe-btn svg {
    width: 18px;
    height: 18px;
}

/* Item row */
.ms-exp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    background: var(--bg-card);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    z-index: 1;
    transition: transform 0.2s ease;
}

.ms-exp-item:active {
    background: var(--bg-card-hover);
}

.ms-exp-item-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.ms-exp-item-icon.letter-icon {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
    border-radius: 8px;
}

.ms-exp-item-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.ms-exp-item-name {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ms-exp-item-cal {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.ms-exp-item-serving {
    font-size: 0.78rem;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: auto;
}

/* ── Meal Info totals in expanded multi-select ── */
.ms-meal-totals {
    padding: 4px 0 8px;
    font-size: 0.95rem;
    gap: 14px;
}

.ms-meal-totals .macro-circle {
    width: 22px;
    height: 22px;
    font-size: 0.7rem;
}

/* ── Impact on Totals — grey card chips ── */
.ms-impact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.ms-impact-chip {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.ms-impact-label {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.ms-impact-vals {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.ms-impact-val {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.ms-impact-diff {
    font-size: 0.7rem;
    font-weight: 500;
}

.ms-impact-over {
    color: #f87171;
}

.ms-impact-under {
    color: var(--text-muted);
}

.ms-impact-exact {
    color: #34d399;
}

.ms-plate-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 160px;
    overflow-y: auto;
}

.ms-plate-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 0.78rem;
}

.ms-plate-item-icon {
    width: 22px;
    height: 22px;
    min-width: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    border-radius: 6px;
    flex-shrink: 0;
}

.ms-plate-item-icon.letter-icon {
    font-size: 0.65rem;
    font-weight: 700;
    color: #fff;
}

.ms-plate-item-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    font-weight: 500;
}

.ms-plate-item-detail {
    color: var(--text-muted);
    font-size: 0.72rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.ms-plate-item-remove {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}

.ms-plate-item-remove:active {
    background: rgba(248, 113, 113, 0.15);
    color: #f87171;
}

.ms-plate-totals {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 8px;
    margin-top: 6px;
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    font-weight: 600;
}
.ms-plate-totals-macros {
    display: flex;
    gap: 10px;
}
.ms-plate-totals-remaining {
    display: flex;
    gap: 8px;
    font-size: 0.7rem;
    font-weight: 500;
    opacity: 0.7;
}

/* Quick-add button transforms to checkmark when selected in multi-select */
.food-quick-add-btn.multi-selected {
    background: rgba(78, 140, 255, 0.3);
}

.food-quick-add-btn.multi-selected svg {
    display: none;
}

.food-quick-add-btn .multi-check-icon {
    display: none;
}

.food-quick-add-btn.multi-selected .multi-check-icon {
    display: block;
}

/* Checkmark badge for search results (no quick-add button) */
.food-multi-check {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: rgba(78, 140, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 8px;
    cursor: pointer;
}

.multi-select-active-indicator {
    font-size: 0.75rem;
    color: #6ba3ff;
    font-weight: 600;
    padding: 4px 6px 4px 12px;
    background: rgba(107, 163, 255, 0.15);
    border-radius: 12px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.ms-indicator-close {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(107, 163, 255, 0.3);
    border: none;
    color: #6ba3ff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.ms-indicator-close:active {
    background: rgba(107, 163, 255, 0.4);
}

.multi-review-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 50vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.multi-review-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

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

.multi-review-item:active {
    background: var(--bg-input);
}

.multi-review-info {
    flex: 1;
    min-width: 0;
}

.multi-review-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.multi-review-macros {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.multi-review-remove {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: rgba(248, 113, 113, 0.12);
    border: none;
    color: #f87171;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.multi-review-remove:active {
    background: rgba(248, 113, 113, 0.25);
}

.multi-review-total {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding: 12px 0 4px;
    font-size: 0.85rem;
    font-weight: 600;
    border-top: 1px solid var(--border);
}

/* Favorites horizontal scroll */
.food-fav-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 10px 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    background: var(--bg-input);
    border-radius: var(--radius);
}

.food-fav-row::-webkit-scrollbar { display: none; }

.food-fav-chip {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 64px;
    max-width: 72px;
    flex-shrink: 0;
    cursor: pointer;
    scroll-snap-align: start;
    transition: transform 0.15s;
}

.food-fav-chip:active {
    transform: scale(0.94);
}

.food-fav-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
    position: relative;
}

.food-fav-avatar.emoji-icon {
    font-size: 1.5rem;
    background: transparent !important;
}

.food-fav-avatar .fav-quick-add {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    font-weight: 700;
    color: #fff;
    border: none;
}

.food-fav-name {
    font-size: 0.65rem;
    color: #b0b2b5;
    text-align: center;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    max-height: 2.4em;
    width: 100%;
}

[data-theme="light"] .food-fav-name {
    color: #5a5c5e;
}

.food-search-divider {
    height: 1px;
    background: var(--border);
    opacity: 0.5;
    margin: 0 -16px;
    width: calc(100% + 32px);
}

/* Time-based picks */
.food-picks-section {
    margin-bottom: 12px;
}

.food-section-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
    padding: 0 2px;
}

.food-pick-item {
    display: flex;
    align-items: center;
    padding: 8px 4px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    -webkit-user-select: none;
    user-select: none;
}

.food-pick-item:active {
    background: var(--subtle-bg);
}

.food-pick-info {
    flex: 1;
    min-width: 0;
}

.food-pick-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.food-pick-macros {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.food-pick-count {
    font-size: 0.65rem;
    color: var(--text-dim);
    margin-left: 8px;
    flex-shrink: 0;
}

.food-pick-add {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    padding: 6px;
    display: flex;
    border-radius: 50%;
    margin-left: 4px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.food-pick-add:active {
    background: rgba(78,140,255,0.15);
}

.food-quick-add-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: rgba(78, 140, 255, 0.15);
    border: none;
    color: #4e8cff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: 8px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.food-quick-add-btn:active {
    background: rgba(78, 140, 255, 0.3);
}

/* Search results */
.food-search-result {
    display: flex;
    align-items: center;
    padding: 10px 4px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
    gap: 8px;
    -webkit-user-select: none;
    user-select: none;
}

.food-search-result:active {
    background: var(--subtle-bg);
}

.food-result-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.2rem;
    color: #fff;
    font-weight: 700;
}
.food-result-avatar.letter-icon {
    font-size: 0.75rem;
    opacity: 0.5;
}
.food-result-avatar.emoji-icon {
    background: transparent !important;
}
.food-result-avatar img.emoji {
    height: 24px;
    width: 24px;
    margin: 0;
    vertical-align: middle;
}

.food-result-info {
    flex: 1;
    min-width: 0;
}

.food-result-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.food-result-brand {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.food-result-macros {
    display: flex;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 500;
    margin-top: 2px;
}

.food-result-serving {
    font-size: 0.7rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

.food-src-badge {
    display: inline-block;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    vertical-align: middle;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.food-src-usda {
    background: rgba(52, 211, 153, 0.15);
    color: var(--green);
}

.food-src-off {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.food-src-fs {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

.food-src-ai {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.food-src-custom {
    background: rgba(20, 184, 166, 0.15);
    color: #14b8a6;
}

.food-src-history {
    background: rgba(78, 140, 255, 0.15);
    color: #6ba3ff;
}

.food-empty-msg {
    text-align: center;
    padding: 20px;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.food-loading {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* AI Generate button */
.food-ai-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 10px;
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 8px;
}

.food-ai-btn:hover {
    background: rgba(168, 85, 247, 0.18);
}

/* ── Scan Tab ── */
.food-scan-toggle {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-top: 10px;
    margin-bottom: 12px;
    gap: 2px;
}

.food-scan-toggle button {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: calc(var(--radius-sm) - 2px);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.food-scan-toggle button.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* Label scanner */
.food-label-capture {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 180px;
    background: var(--bg-input);
    border: 2px dashed var(--subtle-border);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: all 0.2s;
    padding: 24px;
}

.food-label-capture:active {
    border-color: var(--accent);
    background: rgba(78,140,255,0.05);
}

.food-label-capture svg {
    opacity: 0.5;
}

.food-label-preview-img {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: var(--radius);
    background: #111;
    margin-bottom: 8px;
}

.food-label-status {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 8px 0;
}

.food-label-form {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Label scan: read-only section */
.label-section-readonly {
    background: var(--bg-input);
    border-radius: 10px;
    padding: 10px 14px;
    opacity: 0.7;
}
.label-section-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.label-readonly-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.label-readonly-val {
    color: var(--text);
    font-weight: 600;
}
.label-readonly-sep {
    opacity: 0.3;
}

/* Label scan: editable amount */
.label-section-editable {
    padding: 0;
}
.label-amount-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.label-amount-input {
    flex: 1;
    background: var(--bg-input);
    border: 2px solid var(--accent);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text);
    font-size: 1.3rem;
    font-weight: 700;
    font-family: inherit;
    outline: none;
    color-scheme: var(--input-color-scheme);
}
.label-amount-input:focus {
    border-color: var(--focus-border);
    box-shadow: none;
}
.label-amount-unit {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Label scan: macro grid */
.label-macro-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
}
.label-macro-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: var(--bg-input);
    border-radius: 10px;
    padding: 10px 4px 8px;
}
.label-macro-value {
    width: 100%;
    text-align: center;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.05rem;
    font-weight: 700;
    font-family: inherit;
    outline: none;
    padding: 0;
}
.label-macro-value:focus {
    color: var(--accent);
}
.label-macro-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.food-label-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
}

.food-label-retake {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-input);
    border: none;
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s;
}

.food-label-retake:hover {
    background: var(--bg-card);
}

.food-scanner-viewport {
    width: 100%;
    min-height: 280px;
    border-radius: var(--radius);
    overflow: hidden;
    background: #111;
    margin-bottom: 12px;
    position: relative;
}

.food-scanner-viewport video {
    width: 100% !important;
    max-height: 320px;
    object-fit: cover;
    border-radius: var(--radius);
}

.food-scanner-status {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 8px 0;
}

.food-barcode-input {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.food-barcode-input input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
}

.food-barcode-input input:focus {
    border-color: var(--focus-border);
}

.food-barcode-input button {
    padding: 10px 16px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

/* Barcode result card */
.food-barcode-result {
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 12px;
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.food-barcode-img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--bg-card);
    flex-shrink: 0;
}

.food-barcode-info {
    flex: 1;
    min-width: 0;
}

.food-barcode-name {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.food-barcode-brand {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.food-barcode-macros {
    display: flex;
    gap: 8px;
    font-size: 0.72rem;
    font-weight: 500;
}

.food-barcode-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.food-barcode-actions .measurement-save-btn {
    flex: 1;
}

.food-scan-again-btn {
    padding: 10px 16px;
    border: 1px solid var(--bg-input);
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.food-scan-again-btn:active {
    background: var(--bg-input);
}

.barcode-fallback-options {
    display: flex;
    gap: 10px;
    margin: 4px 0 12px;
}

.barcode-fallback-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: 12px;
    border: 1px solid var(--bg-input);
    background: transparent;
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.barcode-fallback-btn svg {
    color: var(--text-muted);
}

.barcode-fallback-btn:active {
    background: var(--bg-input);
}

.custom-food-link {
    padding: 16px 6px 80px;
}

.custom-food-link button {
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    border-radius: 12px;
    width: 100%;
    transition: color 0.15s, background 0.15s;
}

.custom-food-link button:active {
    color: var(--text);
    background: var(--subtle-hover);
}

/* ── Serving Selector ── */
.food-serving-preview {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
}

.food-serving-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.food-serving-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.food-serving-option input[type="radio"] {
    display: none;
}

.food-serving-option.active {
    background: rgba(78, 140, 255, 0.12);
    color: var(--accent);
}

.food-qty-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.food-qty-control {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
}

.food-qty-control button {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1.1rem;
    font-weight: 700;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.food-qty-control button:hover {
    color: var(--accent-light);
}

.food-qty-control input {
    width: 48px;
    text-align: center;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    outline: none;
    -moz-appearance: textfield;
}

.food-qty-control input::-webkit-inner-spin-button,
.food-qty-control input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.food-grams-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.food-grams-input:focus {
    border-color: var(--focus-border);
}

/* ── MacroFactor-style Serving Selector ── */
.serving-modal .modal-body {
    padding-bottom: 8px;
}

.serving-macro-display {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 14px 0;
    text-align: center;
}

.serving-macro-row {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 12px 0 8px;
}

.serving-macro-main {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.serving-macro-cal-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.serving-macro-cal-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.serving-macro-secondary {
    display: flex;
    gap: 10px;
    font-size: 0.82rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

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

.serving-macro-cal .serving-macro-value {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
}

.serving-macro-value {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.serving-macro-pct {
    font-size: 0.6rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    margin-bottom: 1px;
}

.serving-macro-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 500;
}

.serving-modal-header {
    padding: 14px 16px 0;
}

.serving-modal-title-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
}

.serving-modal-title-row .edit-food-name-input {
    flex: 1;
    min-width: 0;
}

.serving-modal-title-row .serving-header-action {
    flex-shrink: 0;
    margin-top: 2px;
}

.edit-food-name-input {
    font-size: 1.1rem;
    font-weight: 600;
    background: transparent;
    border: none;
    color: var(--text);
    width: 100%;
    min-width: 0;
    padding: 2px 0;
    margin: 0;
    font-family: inherit;
    outline: none;
    line-height: 1.3;
    resize: none;
    overflow: hidden;
    display: block;
}

.serving-modal-actions-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.serving-modal-time {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    background: var(--bg-input);
    border-radius: 14px;
    padding: 4px 10px 4px 8px;
    color: var(--text-muted);
}

.serving-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.serving-header-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.serving-header-action:active {
    background: var(--subtle-hover);
    color: var(--text);
}

.serving-impact {
    padding: 10px 0;
}

.serving-impact-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 10px;
}

.serving-impact-rings {
    display: flex;
    justify-content: center;
    gap: 16px;
}

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

.serving-impact-item > span {
    font-size: 0.65rem;
    color: var(--text-muted);
}

.serving-ring {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: conic-gradient(var(--accent) 0deg, var(--bg-input) 0deg);
    position: relative;
}

.serving-ring > span {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.serving-qty-input-row {
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    overflow: hidden;
    margin: 8px 0 6px;
    transition: border-color 0.2s;
}

.serving-qty-input-row:focus-within {
    border-color: var(--focus-border);
    border-width: 3px;
}

.serving-qty-input-row input {
    flex: 1;
    height: 48px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 600;
    font-family: inherit;
    padding: 0 14px;
    outline: none;
    -moz-appearance: textfield;
    font-variant-numeric: tabular-nums;
}

.serving-qty-input-row input::-webkit-inner-spin-button,
.serving-qty-input-row input::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

.serving-qty-unit {
    font-size: 0.9rem;
    color: var(--text-muted);
    padding-right: 14px;
    font-weight: 500;
}

.serving-unit-tabs {
    display: flex;
    gap: 6px;
}

.serving-unit-tab {
    flex: 1;
    padding: 8px 0;
    background: var(--bg-input);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.serving-unit-tab.active {
    background: rgba(78, 140, 255, 0.12);
    color: var(--accent);
}

.serving-unit-tab:hover:not(.active) {
    background: var(--bg-card-hover);
}

/* ── Fit-to-Target ── */
.fit-to-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.fit-to-chips {
    display: flex;
    gap: 6px;
}
.fit-to-chip {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-muted);
    border: 1.5px solid transparent;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.fit-to-chip:active {
    transform: scale(0.94);
}
.fit-to-chip[data-macro="cal"].active {
    background: rgba(78, 140, 255, 0.15);
    color: #4e8cff;
    border-color: #4e8cff;
}
.fit-to-chip[data-macro="protein"].active {
    background: rgba(52, 211, 153, 0.15);
    color: #34d399;
    border-color: #34d399;
}
.fit-to-chip[data-macro="carbs"].active {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
    border-color: #a855f7;
}
.fit-to-chip[data-macro="fat"].active {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
    border-color: #f97316;
}
.fit-to-fill-btn {
    margin-left: auto;
    padding: 5px 10px;
    border-radius: 8px;
    background: transparent;
    color: var(--accent);
    border: 1px solid rgba(78, 140, 255, 0.3);
    font-size: 0.72rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.fit-to-fill-btn:active {
    transform: scale(0.96);
    background: rgba(78, 140, 255, 0.1);
}
.fit-to-input-row {
    margin-bottom: 12px;
}
.fit-to-input-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.fit-to-value {
    cursor: pointer;
    transition: opacity 0.15s;
    border-radius: 4px;
}
.fit-to-value:active {
    opacity: 0.7;
}

/* ── Meal Type Selector (pill tags with outlines) ── */
.food-meal-selector {
    display: flex;
    gap: 8px;
    background: none;
    padding: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.food-meal-selector::-webkit-scrollbar {
    display: none;
}

.food-meal-selector button {
    flex: 0 0 auto;
    background: none;
    border: 1.5px solid var(--bg-input);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.food-meal-selector button:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.food-meal-selector button.active {
    background: none;
    border-color: var(--text);
    color: var(--text);
}

/* ── AI Modal ── */
.food-ai-textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
    outline: none;
    transition: border-color 0.2s;
}

.food-ai-textarea:focus {
    border-color: var(--focus-border);
}

.food-ai-parse-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 12px;
    position: relative;
    background: transparent;
    color: #c4a3f7;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    z-index: 0;
}
.food-ai-parse-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    padding: 1.5px;
    background: linear-gradient(135deg, #a855f7, #6366f1, #a855f7, #ec4899);
    background-size: 300% 300%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: gradient-shift 4s ease infinite;
    z-index: -1;
}
.food-ai-parse-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.08), rgba(99, 102, 241, 0.05), rgba(236, 72, 153, 0.05));
    z-index: -2;
}
@keyframes gradient-shift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.food-ai-parse-btn:active {
    color: #d8b4fe;
}
.food-ai-parse-btn:active::after {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(99, 102, 241, 0.1), rgba(236, 72, 153, 0.1));
}

.food-ai-parse-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

[data-theme="light"] .food-ai-parse-btn {
    color: #7c3aed;
}
[data-theme="light"] .food-ai-parse-btn::after {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.06), rgba(99, 102, 241, 0.04), rgba(236, 72, 153, 0.04));
}

.food-ai-error {
    color: var(--red);
    font-size: 0.8rem;
    padding: 8px 0;
}

/* AI Parsed Results */
.food-ai-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 8px 0 4px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.food-ai-items {
    display: flex;
    flex-direction: column;
}

.food-ai-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--divider);
}

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

.food-ai-item-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.food-ai-item-macros {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.food-ai-item-qty {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ── Meal Templates ── */
.food-templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.food-template-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px;
}

.food-template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.food-template-name {
    font-size: 0.9rem;
    font-weight: 600;
}

.food-template-badges {
    display: flex;
    gap: 6px;
}

.food-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
}

.food-badge-blue {
    background: rgba(78, 140, 255, 0.12);
    color: var(--accent);
}

.food-badge-green {
    background: rgba(52, 211, 153, 0.12);
    color: var(--green);
}

.food-template-items {
    margin-bottom: 10px;
}

.food-template-item-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 3px 0;
}

.food-template-item-row span {
    color: var(--text-dim);
}

.food-template-log-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 9px;
    background: var(--bg-input);
    color: var(--text);
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.food-template-log-btn:hover {
    background: var(--bg-card-hover);
}

.food-template-log-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.food-template-create-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    background: var(--bg-input);
    color: var(--text);
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 12px;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.food-template-create-btn:active {
    background: var(--bg-card-hover, #2a2b2d);
}

.food-template-create-btn svg {
    opacity: 0.7;
}

.food-template-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    margin-left: 8px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.food-template-delete-btn:active {
    color: #ef4444;
}

/* ── My Foods Toggle ── */
.my-foods-toggle {
    display: flex;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 14px;
    gap: 2px;
}
.my-foods-toggle-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: calc(var(--radius-sm) - 2px);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}
.my-foods-toggle-btn.active {
    background: #fff;
    color: #0B0C0C;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* ── Custom Food Delete Btn (in list) ── */
.custom-food-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    outline: none;
}
.custom-food-delete-btn:active {
    color: #ef4444;
}

/* ── Recipe Builder ── */
.recipe-builder-modal {
    max-width: 440px !important;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
.recipe-builder-modal .modal-body {
    overflow-y: auto;
    flex: 1;
}
.recipe-totals-bar {
    background: var(--bg-input);
    border-radius: 10px;
    padding: 10px 14px;
    text-align: center;
}
.recipe-totals-row {
    display: flex;
    justify-content: center;
    gap: 12px;
    font-size: 0.8rem;
    flex-wrap: wrap;
}
.recipe-ingredient-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg-input);
}
.recipe-ingredient-row:last-child {
    border-bottom: none;
}

/* ── Food Search Result action btns ── */
.food-search-result .custom-food-delete-btn {
    opacity: 0.5;
}
.food-search-result .custom-food-delete-btn:active {
    opacity: 1;
}

/* ── Toast Notification ── */
.food-toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text);
    color: var(--bg);
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 0.85rem;
    font-weight: 600;
    z-index: 300;
    opacity: 0;
    transition: all 0.3s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

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

.food-toast-action {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
    margin-left: 12px;
    cursor: pointer;
    text-transform: uppercase;
    font-family: inherit;
}

/* ── Food Log Responsive ── */
@media (max-width: 768px) {
    .weekly-card {
        border-radius: 0;
        margin: -8px -14px 8px;
        width: calc(100% + 28px);
        padding: 10px 12px 12px;
    }

    .food-meal-group {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    .food-fab {
        bottom: 76px;
        right: 16px;
    }

    .food-add-sheet-inner {
        flex: 1;
        min-height: 0;
        max-height: calc(100dvh - 140px);
    }

    .food-template-card {
        border-radius: 0;
        margin-left: -14px;
        margin-right: -14px;
        width: calc(100% + 28px);
    }

    .food-templates-grid {
        grid-template-columns: 1fr;
    }
}

/* html5-qrcode overrides for dark theme */
#qr-reader-live {
    border: none !important;
    background: transparent !important;
    width: 100% !important;
}

#qr-reader-live video {
    border-radius: var(--radius) !important;
    width: 100% !important;
    object-fit: cover !important;
}

#qr-reader-live__scan_region {
    background: transparent !important;
}

#qr-reader-live__scan_region img[alt="Info icon"] {
    display: none !important;
}

/* Hide the built-in dashboard controls (we use our own UI) */
#qr-reader-live__dashboard {
    display: none !important;
}

/* The qr shaded region styling */
#qr-reader-live__scan_region > div {
    border-color: var(--accent) !important;
}

/* ══════════════════════════════════════════════
   Progress Photos
   ══════════════════════════════════════════════ */

.photo-page {
    max-width: 600px;
}

.photo-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* Compare button */
.btn-compare {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Photo timeline */
.photo-timeline {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.photo-date-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}

.photo-date-text {
    font-weight: 600;
    font-size: 0.95rem;
}

.photo-date-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Photo grid */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.photo-thumb {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.15s;
}

.photo-thumb:active {
    transform: scale(0.97);
}

.photo-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.photo-thumb.compare-selected {
    outline: 3px solid var(--accent);
    outline-offset: -3px;
}

.photo-category-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.65);
    color: white;
    font-size: 0.6rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: capitalize;
    backdrop-filter: blur(4px);
}

/* Upload buttons */
.photo-upload-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 4px;
}

.photo-upload-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 12px;
    border: 1.5px solid var(--bg-input);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
}

.photo-upload-option svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.photo-upload-option:active {
    border-color: var(--text-muted);
    background: var(--bg-input);
}

.photo-crop-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}

.photo-crop-btn:active {
    background: var(--bg-input);
    color: var(--text);
}

/* Lightbox */
.photo-lightbox {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.photo-lightbox-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px;
    padding-top: env(safe-area-inset-top, 16px);
}

.photo-lightbox-date {
    font-weight: 600;
    font-size: 1rem;
}

.photo-lightbox-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: capitalize;
    margin-top: 2px;
}

.photo-lightbox-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.photo-lightbox-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 16px;
}

.photo-lightbox-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.photo-lightbox-footer {
    display: flex;
    justify-content: center;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}

.btn-photo-delete {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 1px solid var(--red);
    color: var(--red);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
}

/* Compare bar (fixed bottom) */
.photo-compare-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.btn-compare-action {
    background: var(--accent);
    border: none;
    color: white;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
}

.btn-compare-cancel {
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.82rem;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
}

/* Comparison overlay */
.photo-compare-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--bg);
    flex-direction: column;
}

.photo-compare-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    padding-top: env(safe-area-inset-top, 12px);
    border-bottom: 1px solid var(--border);
}

.photo-compare-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.photo-compare-tabs {
    display: flex;
    gap: 0;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 3px;
    flex: 1;
}

.photo-compare-tabs button {
    flex: 1;
    padding: 6px 12px;
    border: none;
    border-radius: calc(var(--radius-sm) - 2px);
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.photo-compare-tabs button.active {
    background: var(--bg-card);
    color: var(--text);
}

.photo-compare-body {
    flex: 1;
    display: flex;
    gap: 4px;
    padding: 12px 8px;
    overflow: hidden;
}

.photo-compare-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
}

.photo-compare-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-align: center;
}

.photo-compare-img-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    width: 100%;
}

.photo-compare-img-wrap img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
}

.photo-compare-footer {
    text-align: center;
    padding: 12px;
    padding-bottom: env(safe-area-inset-bottom, 12px);
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.photo-compare-stats {
    padding: 8px 4px 0;
    width: 100%;
}

.compare-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.compare-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
}

.compare-stat-val {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
}

.compare-stat-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Swipeable items (recent/time picks) */
.swipeable-item {
    position: relative;
    overflow: hidden;
}

.swipeable-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: stretch;
    visibility: hidden;
}

.swipeable-item.swiping .swipeable-actions {
    visibility: visible;
}

.swipeable-actions .swipe-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    border: none;
    cursor: pointer;
    padding: 0;
}

.swipeable-actions .swipe-delete {
    background: var(--red, #ef4444);
    color: #fff;
}

.swipeable-main {
    position: relative;
    z-index: 1;
    background: var(--bg-card);
    transition: transform 0.2s ease;
}

/* Favorite edit mode (long-press jiggle) */
.food-fav-chip {
    position: relative;
}

.fav-delete-badge {
    display: none;
    position: absolute;
    top: -4px;
    left: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--red, #ef4444);
    color: white;
    font-size: 11px;
    font-weight: bold;
    align-items: center;
    justify-content: center;
    z-index: 2;
    cursor: pointer;
    line-height: 18px;
    text-align: center;
}

.fav-edit-mode .fav-delete-badge {
    display: flex;
}

.fav-edit-mode {
    animation: favJiggle 0.3s ease infinite alternate;
}

@keyframes favJiggle {
    0% { transform: rotate(-1.5deg); }
    100% { transform: rotate(1.5deg); }
}

.fav-edit-done-btn {
    display: block;
    margin: 4px auto 8px;
    background: var(--accent);
    border: none;
    color: white;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 20px;
    border-radius: 16px;
    cursor: pointer;
}

/* ── Bottom Toolbar ── */
.toolbar-spacer {
    height: calc(64px + env(safe-area-inset-bottom));
}

.bottom-toolbar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: transparent;
    border-top: none;
    z-index: 90;
    display: flex;
    justify-content: center;
    align-items: center;
}
.bottom-toolbar::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100% + 40px);
    background: linear-gradient(to bottom, transparent 0%, color-mix(in srgb, var(--bg) 20%, transparent) 45%, var(--bg) 85%);
    pointer-events: none;
    z-index: -1;
}

.toolbar-plus-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px var(--plus-btn-shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}

.bottom-toolbar.no-bar {
    /* already transparent via base styles */
}

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

/* ── Global Actions Overlay & Sheet ── */
.global-actions-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.global-actions-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.global-actions-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    z-index: 1000;
    padding: 12px 20px 28px;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    max-width: 500px;
    margin: 0 auto;
}

.global-actions-sheet.open {
    transform: translateY(0);
}

.global-actions-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0 4px;
    margin-bottom: 16px;
}

.global-actions-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-input);
}

.global-actions-gear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.global-actions-gear:active {
    color: var(--text);
    background: var(--bg-input);
}

.global-actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.global-action-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border-radius: 14px;
    background: var(--bg-input);
    text-decoration: none;
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 500;
    transition: background 0.15s;
    cursor: pointer;
}

.global-action-tile:active {
    background: var(--subtle-hover);
}

.global-action-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.global-actions-divider {
    height: 1px;
    background: var(--bg-input);
    margin: 12px 0;
}

.global-action-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 4px;
    color: var(--text);
    text-decoration: none;
    font-size: 0.85rem;
    border-radius: 8px;
    transition: background 0.15s;
}

.global-action-list-item:active {
    background: var(--bg-input);
}

/* ── Toolbar Config (Settings) ── */
.toolbar-config-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toolbar-config-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--bg-input);
}

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

.toolbar-config-drag {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.2rem;
    user-select: none;
    touch-action: none;
    padding: 8px;
    margin: -8px;
}

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

.toolbar-config-label {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
}

.toolbar-config-color {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--bg-input);
    cursor: pointer;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
    background: none;
}

.toolbar-config-color::-webkit-color-swatch-wrapper {
    padding: 0;
}

.toolbar-config-color::-webkit-color-swatch {
    border: none;
    border-radius: 50%;
}

.toolbar-config-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.15s;
}

.toolbar-config-remove:hover {
    color: #ef4444;
}

.toolbar-config-available {
    margin-top: 12px;
}

.toolbar-config-available h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0 0 8px;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.toolbar-config-add-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
}

.toolbar-config-add-item span {
    flex: 1;
    font-size: 0.9rem;
    color: var(--text);
}

.toolbar-config-add-btn {
    background: none;
    border: 1px solid var(--accent);
    color: var(--accent);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.toolbar-config-add-btn:hover {
    background: var(--accent);
    color: #fff;
}

.toolbar-config-save {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.toolbar-config-save:active {
    opacity: 0.8;
}

.toolbar-config-item.dragging {
    opacity: 0.5;
    background: var(--bg-input);
    border-radius: 8px;
}

/* ── Multi-Select Mode ── */
.food-item-avatar:active {
    transform: scale(0.9);
}

.food-item-avatar.unselected {
    background: var(--bg-input) !important;
    border: 2px solid var(--text-muted);
    box-sizing: border-box;
}

.food-item-avatar.selected {
    background: var(--accent) !important;
    border: none;
}

.select-action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--bg-input);
    z-index: 95;
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.select-bar-top {
    display: flex;
    align-items: center;
    gap: 10px;
}

.select-count {
    flex: 1;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.select-pill-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-input);
    border: none;
    color: var(--text);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}

.select-pill-btn:active {
    background: var(--subtle-hover);
}

.select-cancel-btn {
    color: var(--text-muted);
}

.select-bar-actions {
    display: flex;
    gap: 8px;
}

.select-action-tile {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    background: var(--bg-input);
    border: none;
    border-radius: 12px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.select-action-tile:active {
    background: var(--subtle-hover);
}

.select-action-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(78, 140, 255, 0.12);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}

.select-action-delete .select-action-icon {
    background: rgba(220, 38, 38, 0.12);
    color: var(--red);
}

.select-action-delete {
    color: var(--red);
}

/* Copy Mode Tags */
.copy-mode-tags {
    display: flex;
    gap: 8px;
}

.copy-mode-tag {
    flex: 1;
    padding: 8px 4px;
    border-radius: 8px;
    border: 1px solid var(--bg-input);
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    white-space: nowrap;
}

.copy-mode-tag.active {
    background: rgba(78, 140, 255, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

.copy-mode-tag:active {
    transform: scale(0.96);
}

/* ── Copy Week Day Buttons ── */
.copy-week-day {
    font-size: 0.72rem;
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-muted);
    border: 1.5px solid transparent;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.copy-week-day.selected {
    background: rgba(78, 140, 255, 0.15);
    color: var(--accent, #4e8cff);
    border-color: var(--accent, #4e8cff);
}
.copy-week-day.disabled {
    opacity: 0.35;
    text-decoration: line-through;
    cursor: default;
    background: transparent;
}
.copy-week-day:not(.disabled):active {
    transform: scale(0.94);
}

/* ── Calendar Date Picker ── */
.calendar-overlay {
    position: fixed;
    inset: 0;
    z-index: 210;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    animation: calFadeIn 0.25s ease;
}

@keyframes calFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.calendar-header {
    display: flex;
    align-items: center;
    padding: 12px 16px 10px;
    padding-top: calc(12px + env(safe-area-inset-top));
    gap: 10px;
    flex-shrink: 0;
}

.calendar-title {
    font-size: 1.1rem;
    font-weight: 700;
    flex: 1;
    letter-spacing: -0.02em;
}

.calendar-today-btn {
    background: var(--bg-input);
    border: none;
    color: var(--accent);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: inherit;
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}

.calendar-today-btn:active {
    background: var(--subtle-hover);
}

.calendar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-input);
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    transition: all 0.15s;
}

.calendar-close-btn:active {
    background: var(--subtle-hover);
}

.calendar-weekday-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    padding: 0 16px 8px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--bg-input);
}

.calendar-weekday-row span {
    text-align: center;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.calendar-months {
    flex: 1;
    overflow-y: auto;
    padding: 4px 16px 40px;
    -webkit-overflow-scrolling: touch;
}

.calendar-month {
    margin-bottom: 16px;
}

.calendar-month-label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    padding: 16px 4px 10px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px 0;
}

.calendar-day {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 6px 0;
    min-height: 48px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.15s;
}

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

.calendar-day.empty {
    pointer-events: none;
}

.calendar-day.future {
    opacity: 0.25;
    pointer-events: none;
}

.calendar-day-num {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-bottom: 2px;
}

.calendar-day.today .calendar-day-num {
    background: var(--accent);
    color: #fff;
}

.calendar-day.selected .calendar-day-num {
    box-shadow: 0 0 0 2px var(--accent);
}

.calendar-day.today.selected .calendar-day-num {
    box-shadow: 0 0 0 2px var(--accent), 0 0 0 4px rgba(78, 140, 255, 0.25);
}

.calendar-day.has-data .calendar-day-num {
    box-shadow: 0 0 0 1.5px var(--accent);
}

.calendar-day.today.has-data .calendar-day-num {
    box-shadow: none;
}

.calendar-day.no-data .calendar-day-num {
    color: var(--text-dim);
}

/* ── Scroll Wheel Picker ── */
.scroll-wheel-picker {
    display: flex;
    justify-content: center;
    gap: 0;
    position: relative;
    height: 220px;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--bg-input);
}

.wheel-column {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 35%, black 65%, transparent 100%);
    mask-image: linear-gradient(to bottom, transparent 0%, black 35%, black 65%, transparent 100%);
    position: relative;
}

.wheel-column::-webkit-scrollbar {
    display: none;
}

.wheel-item {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    scroll-snap-align: center;
    flex-shrink: 0;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.wheel-highlight {
    position: absolute;
    top: 50%;
    left: 8px;
    right: 8px;
    height: 44px;
    transform: translateY(-50%);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    pointer-events: none;
    z-index: 1;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
}

[data-theme="light"] .wheel-highlight {
    background: rgba(0,0,0,0.04);
}

/* ─── Check-In Page ─── */
.checkin-progress {
    height: 3px;
    background: var(--bg-input);
    border-radius: 3px;
    margin-bottom: 6px;
    overflow: hidden;
}
.checkin-progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.checkin-step-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 20px;
}
.checkin-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 24px 20px;
    margin-bottom: 16px;
}
.checkin-card-icon {
    margin-bottom: 12px;
}
.checkin-card-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0 0 4px;
}
.checkin-card-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 20px;
}
.checkin-stat-row {
    display: flex;
    gap: 24px;
}
.checkin-stat {
    flex: 1;
}
.checkin-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}
.checkin-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.checkin-macro-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    text-align: center;
}
.checkin-macro-val {
    font-size: 1.1rem;
    font-weight: 700;
}
.checkin-macro-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}
.checkin-subjective-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.checkin-subj-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.checkin-subj-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    width: 90px;
    flex-shrink: 0;
}
.checkin-subj-bar-wrap {
    flex: 1;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}
.checkin-subj-bar {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s;
}
.checkin-subj-val {
    font-size: 0.8rem;
    font-weight: 600;
    width: 36px;
    text-align: right;
    flex-shrink: 0;
}
.checkin-notes {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    border-radius: 10px;
    border: 1.5px solid var(--bg-input);
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
    transition: border-color 0.15s;
}
.checkin-notes:focus {
    border-color: var(--focus-border);
}
.checkin-notes::placeholder {
    color: var(--text-muted);
}
.checkin-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 16px;
}
.checkin-summary-item {
    padding: 10px 0;
}
.checkin-summary-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 2px;
}
.checkin-summary-val {
    font-size: 1rem;
    font-weight: 600;
}
.checkin-summary-notes {
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-input);
    border-radius: 10px;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
}
.checkin-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 24px;
}
.checkin-next-btn, .checkin-submit-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 22px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: opacity 0.15s;
}
.checkin-next-btn:active, .checkin-submit-btn:active {
    opacity: 0.85;
}
.checkin-submit-btn {
    width: 100%;
    justify-content: center;
    padding: 14px;
    font-size: 0.95rem;
}
.checkin-submit-btn:disabled {
    opacity: 0.5;
}
.checkin-back-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 16px;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-family: inherit;
    border: none;
    cursor: pointer;
}
.checkin-done {
    text-align: center;
    padding: 60px 20px;
}
.checkin-done h2 {
    margin: 16px 0 8px;
    font-size: 1.3rem;
}
.checkin-done-link {
    display: inline-block;
    margin-top: 24px;
    padding: 12px 28px;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9rem;
}
/* Check-in banner on dashboard */
.checkin-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border-radius: 14px;
    margin-bottom: 16px;
    border-left: 3px solid var(--accent);
    cursor: pointer;
    transition: opacity 0.15s;
    text-decoration: none;
    color: inherit;
}
.checkin-banner:active {
    opacity: 0.85;
}
.checkin-banner-text {
    flex: 1;
}
.checkin-banner-title {
    font-size: 0.88rem;
    font-weight: 600;
}
.checkin-banner-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── Copy Day ─── */
.copy-recent-days {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.copy-day-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.copy-day-row:active {
    background: var(--bg-input);
}
.copy-day-info {
    min-width: 0;
}
.copy-day-date {
    font-size: 0.88rem;
    font-weight: 600;
}
.copy-day-meta {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ─── AI Mode Selector ─── */
.ai-mode-selector {
    display: flex;
    gap: 4px;
    background: var(--bg-input);
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 12px;
}
.ai-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.ai-mode-btn.active {
    background: var(--bg-card);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.ai-mode-btn svg {
    flex-shrink: 0;
}
.ai-mode-pane {
    display: none;
}
.ai-mode-pane.active {
    display: block;
}

/* ─── Voice Area ─── */
.ai-voice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 0 12px;
    gap: 12px;
}
.ai-voice-record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
    border: 2px solid rgba(168, 85, 247, 0.25);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.ai-voice-record-btn:active {
    transform: scale(0.93);
}
.ai-voice-record-btn.recording {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    animation: voice-pulse 1.5s ease-in-out infinite;
}
[data-theme="light"] .ai-mode-btn.active {
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
[data-theme="light"] .ai-voice-record-btn {
    background: rgba(168, 85, 247, 0.08);
    border-color: rgba(168, 85, 247, 0.2);
}
[data-theme="light"] .ai-voice-record-btn.recording {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
}

/* ─── Photo Capture Buttons ─── */
.photo-capture-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.photo-capture-option {
    padding: 20px 12px;
}
.photo-capture-option span {
    font-size: 0.82rem;
}

/* ─── Undo Copy Toast ─── */
.undo-copy-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--bg-input);
    border-radius: 12px;
    padding: 10px 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.35);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    font-size: 0.85rem;
    color: var(--text);
}
.undo-copy-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.undo-copy-toast button {
    background: none;
    border: none;
    color: #4e8cff;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    -webkit-tap-highlight-color: transparent;
}
.undo-copy-toast button:active {
    background: rgba(78, 140, 255, 0.1);
}

/* ─── Voice Input (legacy) ─── */
.food-voice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.food-voice-btn:active {
    transform: scale(0.95);
}
.food-voice-btn.recording {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
    animation: voice-pulse 1.5s ease-in-out infinite;
}
@keyframes voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}
.food-voice-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    padding: 4px 0;
    font-style: italic;
}
[data-theme="light"] .food-voice-btn {
    background: rgba(168, 85, 247, 0.08);
    border-color: rgba(168, 85, 247, 0.15);
}
[data-theme="light"] .food-voice-btn.recording {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

/* ─── Photo Food Edit ─── */
.photo-food-item {
    background: var(--bg-card);
    border-radius: 10px;
    overflow: hidden;
    transition: background 0.15s;
}
.photo-food-item.editing {
    background: var(--bg-input);
}
.photo-food-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.photo-food-info {
    min-width: 0;
    flex: 1;
}
.photo-food-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.photo-food-qty {
    font-size: 0.78rem;
    color: var(--text-muted);
}
.photo-food-edit {
    padding: 0 12px 12px;
}
.photo-edit-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.photo-edit-row {
    display: flex;
    gap: 8px;
}
.photo-edit-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
}
.photo-edit-field label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.photo-edit-field input {
    padding: 7px 8px;
    border-radius: 8px;
    border: 1.5px solid var(--bg-input);
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.82rem;
    font-family: inherit;
    outline: none;
    width: 100%;
    transition: border-color 0.15s;
}
.photo-edit-field input:focus {
    border-color: var(--focus-border);
}
.photo-food-delete-btn {
    display: block;
    width: 100%;
    background: #fff;
    border: none;
    color: #111;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    margin-top: 10px;
    -webkit-tap-highlight-color: transparent;
}
.photo-food-delete-btn:active {
    background: #ddd;
}

/* ── Alcohol Conversion Preview (Serving Modal) ── */
.alcohol-convert-preview {
    background: rgba(127, 29, 29, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.15);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-top: 12px;
}

.alcohol-convert-header {
    font-size: 0.72rem;
    font-weight: 700;
    color: #f87171;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.alcohol-convert-detail {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.78rem;
    color: var(--text);
}

.alcohol-convert-detail strong {
    color: #f87171;
    font-weight: 600;
}

.alcohol-convert-effective {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Custom Food Icon Picker ── */
.custom-icon-picker {
    display: flex;
    align-items: center;
    gap: 10px;
}

.custom-icon-preview {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: var(--bg-input);
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.15s;
    flex-shrink: 0;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.custom-icon-preview:active {
    transform: scale(0.93);
}

.custom-icon-preview.active {
    border-color: var(--accent);
}

.custom-icon-preview img.emoji {
    height: 28px;
    width: 28px;
}

.custom-icon-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    padding: 10px;
    background: var(--bg-input);
    border-radius: 10px;
    margin-top: 6px;
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.custom-icon-option {
    width: 100%;
    aspect-ratio: 1;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 1.3rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

.custom-icon-option:hover {
    background: var(--bg-card-hover);
}

.custom-icon-option:active {
    transform: scale(0.88);
    background: var(--accent);
}

.custom-icon-option img.emoji {
    height: 24px;
    width: 24px;
}

/* ─── Menu Parser ─── */
.menu-input-modes {
    display: flex;
    gap: 6px;
    padding: 0 0 12px;
    border-bottom: 1px solid var(--bg-input);
    margin-bottom: 12px;
}
.menu-mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 8px;
    border-radius: 10px;
    border: 1px solid var(--bg-input);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.menu-mode-btn.active {
    background: #fff;
    color: #000;
    border-color: #fff;
}
.menu-input-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.menu-url-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.menu-url-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--bg-input);
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}
.menu-url-input:focus {
    border-color: var(--accent);
}
.menu-status {
    padding: 16px 0;
    text-align: center;
}
.menu-preview-img {
    width: 100%;
    max-height: 200px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}
.menu-results-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 10px;
    margin-bottom: 4px;
}
.menu-results-header span {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}
.menu-select-all-btn {
    background: transparent;
    border: 1px solid var(--bg-input);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
}
.menu-select-all-btn:active {
    background: var(--bg-input);
}
.menu-rec-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    font-weight: 700;
    color: #34d399;
    padding: 8px 0 6px;
}
.menu-section {
    margin-bottom: 8px;
}
.menu-section-header {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 0 6px;
    border-top: 1px solid var(--bg-input);
    margin-top: 4px;
}
.menu-section:first-child .menu-section-header {
    border-top: none;
    margin-top: 0;
}
.menu-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.12s;
    -webkit-tap-highlight-color: transparent;
}
.menu-item:active {
    background: var(--bg-input);
}
.menu-item.selected {
    background: rgba(78, 140, 255, 0.08);
}
.menu-item-check {
    flex-shrink: 0;
    padding-top: 1px;
}
.menu-item-info {
    flex: 1;
    min-width: 0;
}
.menu-item-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}
.menu-item-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
    line-height: 1.3;
}
.menu-item-macros {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}
.menu-macro {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-input);
}
.menu-macro.cal { color: #4e8cff; }
.menu-macro.pro { color: #34d399; }
.menu-macro.carb { color: #a78bfa; }
.menu-macro.fat { color: #c97a3a; }
.menu-item-price {
    flex-shrink: 0;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding-top: 2px;
}
.menu-item-rec-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    color: #34d399;
    background: rgba(52, 211, 153, 0.12);
    padding: 2px 7px;
    border-radius: 6px;
    margin-left: 4px;
    vertical-align: middle;
}
.menu-selection-bar {
    position: sticky;
    bottom: 0;
    background: var(--bg-card);
    border-top: 1px solid var(--bg-input);
    padding: 10px 0 calc(env(safe-area-inset-bottom, 0px) + 10px);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 5;
}
.menu-selection-summary {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-align: center;
    font-weight: 600;
}
.menu-log-btn {
    width: 100%;
}

/* ─── Menu Loading Animation ─── */
.menu-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px 20px;
}
.menu-loading-icon {
    position: relative;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    background: rgba(78, 140, 255, 0.08);
    animation: menu-icon-pulse 2s ease-in-out infinite;
}
.menu-loading-icon svg {
    animation: menu-icon-spin 3s linear infinite;
}
@keyframes menu-icon-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(78, 140, 255, 0.15); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(78, 140, 255, 0); }
}
@keyframes menu-icon-spin {
    0% { transform: rotate(0deg); }
    25% { transform: rotate(3deg); }
    50% { transform: rotate(0deg); }
    75% { transform: rotate(-3deg); }
    100% { transform: rotate(0deg); }
}
.menu-loading-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 240px;
}
.menu-loading-step {
    font-size: 0.82rem;
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--bg-input);
    text-align: center;
    opacity: 0.35;
    transform: scale(0.96);
    transition: all 0.4s ease;
}
.menu-loading-step.active {
    opacity: 1;
    color: #4e8cff;
    background: rgba(78, 140, 255, 0.1);
    transform: scale(1);
    font-weight: 600;
}
.menu-loading-step.done {
    opacity: 0.6;
    color: #34d399;
    background: rgba(52, 211, 153, 0.08);
    transform: scale(0.96);
}
.menu-loading-step.done::after {
    content: ' ✓';
}
.menu-loading-shimmer {
    width: 80%;
    max-width: 200px;
    height: 3px;
    border-radius: 2px;
    background: linear-gradient(90deg, var(--bg-input), #4e8cff, var(--bg-input));
    background-size: 200% 100%;
    animation: menu-shimmer 1.5s ease-in-out infinite;
}
@keyframes menu-shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Menu item edit button */
.menu-item-edit-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--bg-input);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    align-self: center;
}
.menu-item-edit-btn:active {
    background: rgba(78, 140, 255, 0.15);
    color: #4e8cff;
}

/* Light mode overrides */
@media (prefers-color-scheme: light) {
    .menu-mode-btn.active {
        background: #000;
        color: #fff;
        border-color: #000;
    }
    .menu-item.selected {
        background: rgba(78, 140, 255, 0.06);
    }
}

