@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --bg: #0a0a0f;
    --bg-soft: #12121a;
    --surface: #16161f;
    --surface-2: #1c1c28;
    --surface-3: #222230;
    --border: rgba(255,255,255,0.07);
    --border-hover: rgba(255,255,255,0.13);
    --text: #f0f0f5;
    --text-secondary: #a0a0b8;
    --text-muted: #6b6b82;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-bg: rgba(99,102,241,0.12);
    --primary-border: rgba(99,102,241,0.25);
    --danger: #f43f5e;
    --danger-bg: rgba(244,63,94,0.1);
    --danger-border: rgba(244,63,94,0.25);
    --success: #10b981;
    --success-bg: rgba(16,185,129,0.1);
    --success-border: rgba(16,185,129,0.3);
    --warning: #f59e0b;
    --protein: #3b82f6;
    --carbs: #f59e0b;
    --fat: #ef4444;
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow: 0 4px 24px rgba(0,0,0,0.25);
    --shadow-lg: 0 12px 48px rgba(0,0,0,0.35);
    --transition: 200ms cubic-bezier(0.4,0,0.2,1);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-vh: 100svh;
}

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

html {
    height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    height: 100%;
    min-height: var(--app-vh);
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    animation: pageIn 350ms ease-out;
    overflow-x: hidden;
    overscroll-behavior-y: none;
}

body.is-modal-open {
    overflow: hidden;
}

@keyframes pageIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

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

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
a, button, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}
a, button {
    touch-action: manipulation;
}

.app-shell {
    width: min(100%, 560px);
    margin: 0 auto;
    min-height: var(--app-vh);
    padding: 0 16px 100px;
    transition: opacity 110ms linear, transform 110ms ease;
}

body.is-nav-loading .app-shell {
    opacity: 0.9;
    transform: translateY(2px);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    margin: 0 -16px;
    padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
    background: rgba(10,10,15,0.82);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}

.brand-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

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

.chip-link {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    background: var(--surface);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
}

.chip-link:hover {
    border-color: var(--border-hover);
    background: var(--surface-2);
    color: var(--text);
}

.chip-link svg {
    width: 14px;
    height: 14px;
    opacity: 0.6;
}

.main-content {
    margin-top: 16px;
    display: grid;
    gap: 14px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    transition: border-color var(--transition);
}

.compact-card {
    padding: 12px 18px;
}

.card h1, .card h2, .card h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

.card h1 { font-size: 1.2rem; }
.card h2 { font-size: 1.05rem; }
.card h3 { font-size: 0.95rem; }

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 14px;
}

.card-head-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-head-title svg {
    width: 18px;
    height: 18px;
    color: var(--primary-light);
    flex-shrink: 0;
}

.link-inline {
    color: var(--primary-light);
    font-weight: 600;
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: color var(--transition);
}

.link-inline:hover {
    color: #a5b4fc;
}

.link-inline svg {
    width: 14px;
    height: 14px;
}

.muted {
    color: var(--text-muted);
    margin: 4px 0 0;
    font-size: 0.82rem;
    line-height: 1.4;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border: 1px solid var(--primary-border);
    color: var(--primary-light);
    background: var(--primary-bg);
    padding: 3px 10px;
}

.date-strip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
}

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

.date-center strong {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
}

.metric-line {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 4px 0 12px;
}

.metric-line strong {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

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

.progress {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    background: var(--surface-3);
    overflow: hidden;
    position: relative;
}

.progress > span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    transition: width 600ms cubic-bezier(0.4,0,0.2,1);
    position: relative;
}

.progress > span::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.15) 50%, transparent 100%);
}

.progress.thin {
    height: 6px;
    margin-top: 6px;
}

.progress.protein > span { background: linear-gradient(90deg, var(--protein), #60a5fa); }
.progress.carbs > span { background: linear-gradient(90deg, var(--carbs), #fbbf24); }
.progress.fat > span { background: linear-gradient(90deg, var(--fat), #f87171); }

.macro-grid {
    margin-top: 16px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.macro-item {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    min-height: 122px;
}

.macro-item .macro-label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 4px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    margin-bottom: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.macro-item .macro-label svg {
    width: 12px;
    height: 12px;
}

.macro-item strong {
    font-size: 1.08rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    display: block;
    margin: 0;
    line-height: 1;
}

.macro-item.protein .macro-label svg { color: var(--protein); }
.macro-item.carbs .macro-label svg { color: var(--carbs); }
.macro-item.fat .macro-label svg { color: var(--fat); }
.macro-item .progress.thin {
    width: 100%;
    margin-top: 0;
}

.entry-list {
    display: grid;
    gap: 8px;
}

.entry-row {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr);
    align-items: start;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    transition: all var(--transition);
    overflow: hidden;
    min-width: 0;
    cursor: pointer;
}

.entry-row:hover {
    border-color: var(--border-hover);
    background: var(--surface-2);
}

.entry-row:focus-visible {
    border-color: rgba(129, 140, 248, 0.55);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.24);
}

.entry-row:active {
    transform: scale(0.995);
}

.entry-thumb {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-xs);
    object-fit: cover;
    background: var(--surface-3);
    flex-shrink: 0;
}

.entry-thumb-wrap {
    width: 44px;
    height: 44px;
    position: relative;
    flex-shrink: 0;
}

.entry-thumb-placeholder {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.entry-thumb-placeholder svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    opacity: 0.4;
}

.entry-info {
    display: grid;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.entry-info strong {
    display: -webkit-box;
    font-size: 0.88rem;
    font-weight: 600;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.entry-meta {
    margin: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.entry-macros {
    color: var(--text-muted);
    margin: 2px 0 0;
    font-size: 0.78rem;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 8px;
}

.entry-macros .macro-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.entry-macros .macro-tag.kcal { color: var(--text-secondary); font-weight: 600; }
.entry-macros .macro-tag.p { color: var(--protein); }
.entry-macros .macro-tag.g { color: var(--carbs); }
.entry-macros .macro-tag.l { color: var(--fat); }

.meal-card .card-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.meal-card .card-head h2 svg {
    width: 18px;
    height: 18px;
    color: var(--primary-light);
}

.meal-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 12px 0;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.meal-empty svg {
    width: 24px;
    height: 24px;
    opacity: 0.3;
}

.history-list {
    display: grid;
    gap: 8px;
}

.history-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-soft);
    padding: 12px 14px;
    transition: all var(--transition);
}

.history-row:hover {
    border-color: var(--border-hover);
    background: var(--surface-2);
    transform: translateY(-1px);
}

.history-row.rich {
    align-items: flex-start;
}

.history-row strong {
    font-weight: 600;
    font-size: 0.9rem;
}

.history-row > span {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--primary-light);
    white-space: nowrap;
}

.history-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.history-summary .stat-block {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
}

.history-summary .stat-label {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 6px;
}

.history-summary .stat-label svg {
    width: 14px;
    height: 14px;
    color: var(--primary-light);
}

.history-summary .stat-value {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 18px;
    padding: 6px;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.tab-btn {
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: var(--radius-xs);
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: normal;
    word-break: break-word;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab-btn svg {
    width: 14px;
    height: 14px;
}

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

.tab-btn.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

.tab-panel {
    display: none;
    animation: fadeIn 250ms ease-out;
}

.tab-panel.active {
    display: block;
}

.food-list {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.food-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    background: var(--bg-soft);
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    transition: all var(--transition);
    animation: slideUp 250ms ease-out both;
}

.food-card:hover {
    border-color: var(--border-hover);
}

.food-card-top {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.food-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-xs);
    object-fit: cover;
    background: var(--surface-3);
    flex-shrink: 0;
}

.food-thumb-placeholder {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-xs);
    background: var(--surface-3);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.food-thumb-placeholder svg {
    width: 24px;
    height: 24px;
    color: var(--text-muted);
    opacity: 0.3;
}

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

.food-card-info h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.food-actions {
    display: grid;
    grid-template-columns: minmax(72px, 86px) minmax(98px, 116px) minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    min-width: 0;
}

.food-quantity-value,
.food-quantity-unit,
.food-meal {
    min-width: 0;
}

.scan-area {
    display: grid;
    gap: 10px;
}

.scan-area #start-scan {
    width: 100%;
}

.scan-overlay {
    position: fixed;
    inset: 0;
    z-index: 260;
    background: #03040a;
}

.scan-overlay[hidden] {
    display: none;
}

.scan-overlay-stage {
    position: relative;
    width: 100%;
    height: var(--app-vh);
    overflow: hidden;
    background: #000;
}

#scan-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.scan-overlay-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 14px;
    background: linear-gradient(180deg, rgba(3, 4, 10, 0.85) 0%, rgba(3, 4, 10, 0) 100%);
}

.scan-overlay-top strong {
    font-size: 0.92rem;
    font-weight: 700;
}

.scan-overlay-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.scan-torch-btn {
    min-height: 42px;
    padding: 8px 10px;
    gap: 5px;
}

.scan-torch-btn svg {
    width: 16px;
    height: 16px;
}

.scan-torch-btn.active {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.45);
    color: #fcd34d;
}

.scan-torch-label {
    font-size: 0.78rem;
}

.scan-close-btn {
    min-width: 42px;
    min-height: 42px;
    padding: 8px;
}

.scan-overlay-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    display: flex;
    justify-content: center;
    padding: 16px 14px calc(18px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(0deg, rgba(3, 4, 10, 0.88) 0%, rgba(3, 4, 10, 0) 100%);
}

.scan-overlay-bottom p {
    margin: 0;
    color: rgba(255, 255, 255, 0.92);
    font-size: 0.85rem;
    text-align: center;
}

.scan-focus {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(78vw, 340px);
    height: min(44vw, 230px);
    transform: translate(-50%, -50%);
    border-radius: 16px;
    border: 2px solid rgba(255, 255, 255, 0.86);
    box-shadow:
        0 0 0 9999px rgba(4, 6, 14, 0.36),
        0 10px 36px rgba(0, 0, 0, 0.45);
    z-index: 1;
    pointer-events: none;
}

.scan-focus::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    top: 14%;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(90deg, transparent 0%, #34d399 20%, #86efac 50%, #34d399 80%, transparent 100%);
    box-shadow: 0 0 10px rgba(52, 211, 153, 0.6);
    animation: scanSweep 1.8s ease-in-out infinite;
}

@keyframes scanSweep {
    0% {
        top: 14%;
        opacity: 0.5;
    }
    50% {
        top: 84%;
        opacity: 1;
    }
    100% {
        top: 14%;
        opacity: 0.5;
    }
}

.status-line {
    min-height: 1.3rem;
    font-size: 0.88rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-line.success { color: var(--success); }
.status-line.error { color: var(--danger); }

.range-form,
.inline-search-form {
    display: grid;
    gap: 10px;
}

.inline-search-form {
    grid-template-columns: minmax(0, 1fr) auto;
}

.inline-search-form > * {
    min-width: 0;
}

.stack-form {
    display: grid;
    gap: 12px;
}

.split-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
}

label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input, select, textarea {
    font: inherit;
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    outline: none;
    font-size: 0.9rem;
    transition: all var(--transition);
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

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

.checkbox-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.checkbox-line input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

button { font: inherit; }

.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-xs);
    padding: 10px 16px;
    cursor: pointer;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.88rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition);
}

.btn:focus,
.tab-btn:focus,
.chip-link:focus,
.nav-item:focus,
.link-inline:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
}

.btn:focus-visible,
.tab-btn:focus-visible,
.chip-link:focus-visible,
.nav-item:focus-visible,
.link-inline:focus-visible {
    box-shadow: 0 0 0 2px rgba(99,102,241,0.45);
}

.btn:active {
    transform: scale(0.97);
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99,102,241,0.3);
}

.btn-primary:hover {
    background: var(--primary-light);
    box-shadow: 0 4px 20px rgba(99,102,241,0.4);
}

.btn-ghost {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--text-secondary);
}

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

.btn-icon {
    padding: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--danger);
    border-color: var(--danger-border);
    background: var(--danger-bg);
}

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

.btn-danger-outline {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
    font-size: 0.8rem;
    padding: 7px 12px;
}

.btn-danger-outline:hover {
    background: rgba(244,63,94,0.18);
}

.alert {
    border-radius: var(--radius-sm);
    border: 1px solid;
    padding: 12px 16px;
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideUp 300ms ease-out;
}

.alert svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: #6ee7b7;
}

.alert-error {
    background: var(--danger-bg);
    border-color: var(--danger-border);
    color: #fca5a5;
}

.alert-info {
    background: var(--primary-bg);
    border-color: var(--primary-border);
    color: #a5b4fc;
}

.auth-page .topbar {
    position: static;
    margin: 0;
    background: transparent;
    border: 0;
    backdrop-filter: none;
    padding-top: 24px;
    justify-content: center;
}

.auth-card {
    max-width: 420px;
    margin: 32px auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px 24px;
    box-shadow: var(--shadow-lg);
}

.auth-card h1 {
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
}

.auth-card .stack-form {
    margin-top: 20px;
}

.auth-switch {
    margin-top: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.auth-switch a {
    color: var(--primary-light);
    font-weight: 600;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    border-top: 1px solid var(--border);
    background: rgba(10,10,15,0.88);
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
    padding-bottom: var(--safe-bottom);
}

.nav-item {
    text-align: center;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    padding: 8px 4px 6px;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    transition: color var(--transition);
    cursor: pointer;
    text-decoration: none;
}

.nav-item svg {
    width: 22px;
    height: 22px;
    transition: color var(--transition);
}

.nav-item:hover {
    color: var(--text-secondary);
}

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

.nav-item.active svg {
    color: var(--primary-light);
    filter: drop-shadow(0 0 6px rgba(99,102,241,0.4));
}

.inline-form {
    margin: 0;
}

.entry-editor-overlay {
    position: fixed;
    inset: 0;
    z-index: 220;
    background: rgba(8, 10, 16, 0.65);
    backdrop-filter: blur(2px);
    display: grid;
    place-items: center;
    padding: 16px;
    align-items: center;
}

.entry-editor-sheet {
    width: min(100%, 540px);
    border-radius: 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    padding: 14px;
    display: grid;
    gap: 10px;
    animation: slideUp 120ms ease-out;
    min-width: 0;
    max-height: calc(var(--app-vh) - 32px);
    overflow: auto;
}

.entry-editor-header {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.entry-editor-title {
    font-size: 0.96rem;
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.entry-editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.entry-editor-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

.entry-editor-danger {
    display: grid;
    gap: 8px;
    border: 1px solid var(--danger-border);
    background: var(--danger-bg);
    border-radius: 12px;
    padding: 10px;
}

.entry-editor-danger[hidden] {
    display: none;
}

.entry-editor-danger-actions {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
}

@media (min-width: 760px) {
    .app-shell {
        width: min(100%, 680px);
        padding-left: 24px;
        padding-right: 24px;
    }

    .main-content {
        grid-template-columns: 1fr 1fr;
    }

    .main-content > .card:first-child,
    .main-content > .card:nth-child(2),
    .main-content > .auth-card {
        grid-column: 1 / -1;
    }

    .range-form {
        grid-template-columns: repeat(3, 1fr);
        align-items: end;
    }
}

@media (max-width: 500px) {
    .card {
        padding: 14px;
    }

    .main-content {
        gap: 10px;
    }

    .tabs {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tab-btn {
        padding: 9px 8px;
        font-size: 0.74rem;
    }

    .inline-search-form {
        grid-template-columns: minmax(0, 1fr) 46px;
    }

    .inline-search-form .btn {
        padding-left: 10px;
        padding-right: 10px;
    }

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

    .food-actions .food-meal,
    .food-actions .btn {
        grid-column: span 1;
    }

    .food-actions .food-meal {
        grid-column: 1 / 2;
    }

    .food-actions .btn {
        grid-column: 2 / 3;
        width: 100%;
    }

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

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

    .date-strip {
        padding: 10px 8px;
    }

    .date-strip .btn {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    .entry-editor-sheet {
        width: 100%;
    }

    .entry-editor-grid {
        grid-template-columns: 1fr;
    }

    .scan-torch-label {
        display: none;
    }

    .scan-torch-btn {
        min-width: 42px;
        padding: 8px;
    }
}
