/* NutritionApp — Contemporary Understated Design System */
:root {
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --bg-card-subtle: #f1f5f9;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-subtle: #e2e8f0;
    --border-strong: #cbd5e1;
    --accent: #2563eb;
    --accent-subtle: #eff6ff;
    --emerald: #10b981;
    --emerald-subtle: #ecfdf5;
    --amber: #f59e0b;
    --rose: #f43f5e;
    --radius-sm: 0.375rem;
    --radius-md: 0.625rem;
    --radius-lg: 0.875rem;
    --max-app-width: 1100px;
    --top-header-height: 54px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-page);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Page shell & uniform width */
.app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-x: hidden;
}

/* Page Viewport & Stage for OllieClicker Nav Animation */
.page-viewport {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: clip;
    touch-action: pan-y;
}

.page-viewport.viewport-animating {
    overflow: hidden !important;
}

.page-stage {
    position: relative;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.page-viewport.viewport-animating .page-stage {
    will-change: transform, opacity;
}

.app-container {
    width: 100%;
    max-width: var(--max-app-width);
    margin: 0 auto;
    padding: 1.5rem 1.25rem 5.5rem;
}

/* Header & Top Bar */
.top-header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--top-header-height, 54px);
}

.header-inner {
    max-width: var(--max-app-width);
    margin: 0 auto;
    padding: 0 1.25rem;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    text-decoration: none;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.desktop-nav {
    display: none;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1.5rem;
}

@media (min-width: 769px) {
    .desktop-nav {
        display: flex;
    }
}

.desktop-nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}

.desktop-nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-card-subtle);
}

.desktop-nav-link.active {
    color: var(--accent);
    font-weight: 600;
    background: var(--accent-subtle);
}

/* PWA Install Banner (Subtle & Non-overlaying) */
.pwa-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--accent-subtle);
    color: var(--accent);
    border: 1px solid rgba(37, 99, 235, 0.2);
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.pwa-pill:hover {
    background: #dbeafe;
}

/* Modern Card Layout (Web: 2 columns, Mobile: 1 column) */
.card-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
    width: 100%;
}

@media (max-width: 768px) {
    .card-grid-2 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

.nutrition-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.card-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 0 0 1rem;
}

/* Vertical Form Flow — Every control on its own line */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1.1rem;
    width: 100%;
}

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

.form-input {
    width: 100%;
    height: 2.75rem;
    padding: 0 0.85rem;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-select {
    width: 100%;
    height: 2.75rem;
    padding: 0 0.85rem;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.85rem;
    background: var(--bg-card-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    user-select: none;
    margin-bottom: 1.1rem;
}

.form-toggle input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Standardized Buttons */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 2.75rem;
    padding: 0 1.25rem;
    background: var(--text-primary);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.1s;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 2.75rem;
    padding: 0 1.1rem;
    background: #ffffff;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
}

.btn-secondary:hover {
    background: var(--bg-card-subtle);
}

.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 2.75rem;
    padding: 0 1.1rem;
    background: #fff1f2;
    color: var(--rose);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid #fecdd3;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.btn-icon {
    width: 2.5rem;
    height: 2.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-strong);
    background: #ffffff;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
}

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

/* Segmented Control */
.segmented-control {
    display: flex;
    background: var(--bg-card-subtle);
    padding: 3px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    gap: 3px;
}

.segmented-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    padding: 0.55rem 0.75rem;
    border-radius: calc(var(--radius-md) - 2px);
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    text-align: center;
    user-select: none;
}

.segmented-btn:hover {
    color: var(--text-primary);
}

.segmented-btn.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Chips & Badges */
.badge-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
    background: var(--bg-card-subtle);
    color: var(--text-secondary);
}

.badge-chip.emerald {
    background: var(--emerald-subtle);
    color: var(--emerald);
}

.badge-chip.amber {
    background: #fffbeb;
    color: var(--amber);
}

.badge-chip.rose {
    background: #ffe4e6;
    color: #e11d48;
}

.badge-chip.purple {
    background: #f3e8ff;
    color: #7e22ce;
}

.badge-chip.blue {
    background: var(--accent-subtle);
    color: var(--accent);
}

/* Stepped Wizard Components */
.wizard-stepper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--bg-card-subtle);
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    gap: 0.5rem;
}

.wizard-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.wizard-step.active {
    color: var(--text-primary);
}

.wizard-step.completed {
    color: var(--emerald);
}

.wizard-step-circle {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    background: #e2e8f0;
    color: var(--text-secondary);
}

.wizard-step.active .wizard-step-circle {
    background: var(--text-primary);
    color: #ffffff;
}

.wizard-step.completed .wizard-step-circle {
    background: var(--emerald);
    color: #ffffff;
}

.wizard-step-line {
    flex: 1;
    height: 2px;
    background: #e2e8f0;
}

/* Side-by-side reconciliation table */
.reconciliation-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
    margin: 0.75rem 0 1.25rem;
}

.reconciliation-table th, .reconciliation-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-subtle);
}

.reconciliation-table th {
    background: var(--bg-card-subtle);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.reconciliation-table tr.divergence {
    background: #fffbeb;
}

/* Accessible High-Legibility Ingredients Breakdown */
.ingredient-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    transition: background 0.1s;
}

.ingredient-card:hover {
    background: var(--bg-card-subtle);
}

.ingredient-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.ingredient-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ingredient-notes {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Mobile Drawer & Modal Backdrop */
.drawer-backdrop,
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    animation: fadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    overscroll-behavior: contain;
    overscroll-behavior-y: contain;
}

.page-viewport:has(.drawer-backdrop),
.page-viewport:has(.modal-backdrop) {
    z-index: 2000;
}

/* Hide bottom navigation completely when any drawer or modal is open */
body:has(.drawer-backdrop) .bottom-nav,
body:has(.modal-backdrop) .bottom-nav,
body.has-open-drawer .bottom-nav,
.app-shell:has(.drawer-backdrop) .bottom-nav,
.app-shell:has(.modal-backdrop) .bottom-nav {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    transform: translateY(100%) !important;
}

@media (min-width: 769px) {
    .drawer-backdrop,
    .modal-backdrop {
        align-items: center;
    }
}

.modal-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 480px;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    animation: scaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    margin: auto;
}

.drawer-card {
    background: var(--bg-card);
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    overflow: hidden;
    border-top-left-radius: 1.25rem;
    border-top-right-radius: 1.25rem;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.32s cubic-bezier(0.16, 1, 0.3, 1);
    overscroll-behavior: contain;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
}

@media (min-width: 769px) {
    .drawer-card {
        max-width: 900px;
        max-height: 85vh;
        border-radius: 1rem;
        box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
        animation: scaleUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    }
}

.drawer-swipe-handle {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 6px 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    background: var(--bg-card);
    border-top-left-radius: 1.25rem;
    border-top-right-radius: 1.25rem;
    flex-shrink: 0;
}

.drawer-swipe-pill {
    width: 44px;
    height: 5px;
    background: var(--border-strong);
    border-radius: 9999px;
    transition: background 0.2s ease, transform 0.2s ease;
}

.drawer-swipe-handle:active .drawer-swipe-pill,
.drawer-card:hover .drawer-swipe-pill {
    background: var(--accent);
    transform: scaleY(1.25);
}

@media (min-width: 769px) {
    .drawer-swipe-handle {
        display: none;
    }
}

.drawer-header {
    padding: 0.85rem 1.25rem 0.95rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    z-index: 10;
    flex-shrink: 0;
}

.drawer-body {
    padding: 1.25rem;
    flex: 1;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

.drawer-footer {
    padding: 0.85rem 1.25rem calc(0.85rem + max(0.5rem, env(safe-area-inset-bottom)));
    border-top: 1px solid var(--border-subtle);
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    align-items: center;
    background: var(--bg-card);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.05);
}

@media (max-width: 768px) {
    .drawer-footer {
        padding: 0.75rem 1rem calc(0.75rem + max(0.6rem, env(safe-area-inset-bottom)));
    }

    .drawer-footer .btn-primary,
    .drawer-footer .btn-secondary,
    .drawer-footer .btn-danger {
        min-height: 2.75rem;
        font-size: 0.95rem;
        font-weight: 600;
    }
}

/* Mobile Bottom Navigation Bar */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4rem;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 40;
}

@media (min-width: 769px) {
    .bottom-nav {
        display: none;
    }
}

.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 500;
    padding: 0.4rem 1rem;
    transition: color 0.15s;
}

.nav-tab.active {
    color: var(--text-primary);
    font-weight: 700;
}

.nav-tab svg {
    width: 1.35rem;
    height: 1.35rem;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

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

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

@keyframes scaleUp {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.browse-spinner {
    width: 1.15rem;
    height: 1.15rem;
    border: 2.5px solid rgba(255, 255, 255, 0.35);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
    will-change: transform;
    flex-shrink: 0;
}

.app-spinner {
    display: inline-block;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    will-change: transform;
}

.browse-unrecognised-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    animation: fadeIn 0.18s ease-out;
}

.browse-unrecognised-card {
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-lg, 16px);
    padding: 1.75rem 1.5rem;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    animation: scaleUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.browse-btn-retry {
    width: 100%;
    justify-content: center;
    height: 2.75rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a !important;
    background: #ffffff !important;
    border: 1.5px solid #cbd5e1 !important;
    border-radius: var(--radius-md, 12px);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    transition: all 0.15s ease;
}

.browse-btn-retry:hover {
    background: #f1f5f9 !important;
    color: #000000 !important;
    border-color: #94a3b8 !important;
}

/* Browse Page Fullscreen Edge-to-Edge Camera & Ergonomic Dock */
.browse-fullscreen-viewport {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 25;
    background: #000000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 768px) {
    /* Hide top header on mobile on the camera page so viewfinder is full edge-to-edge */
    body:has(.browse-fullscreen-viewport) .top-header,
    .app-shell:has(.browse-fullscreen-viewport) .top-header,
    .app-shell.is-browse-page .top-header {
        display: none !important;
    }

    .browse-top-hud {
        position: fixed;
        top: calc(max(12px, env(safe-area-inset-top)) + 6px);
        left: 14px;
        right: 14px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 50;
        pointer-events: none;
    }

    .browse-marketing-toast {
        top: calc(max(12px, env(safe-area-inset-top)) + 3.2rem) !important;
    }
}

@media (min-width: 769px) {
    /* On desktop, keep top header navigation visible, camera positioned cleanly below */
    .browse-fullscreen-viewport {
        top: var(--top-header-height, 54px);
        height: calc(100vh - var(--top-header-height, 54px));
        height: calc(100dvh - var(--top-header-height, 54px));
    }

    .browse-top-hud {
        position: fixed;
        top: calc(var(--top-header-height, 54px) + 14px);
        left: 14px;
        right: 14px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 50;
        pointer-events: none;
    }

    .browse-marketing-toast {
        top: calc(var(--top-header-height, 54px) + 3.6rem) !important;
    }
}

.browse-fullscreen-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.browse-flash-overlay {
    position: absolute;
    inset: 0;
    background: #ffffff;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease-out;
    z-index: 25;
}

.browse-flash-overlay.flashing {
    opacity: 0.9;
    transition: none;
}

.browse-target-guide-chip {
    font-size: 0.72rem;
    font-weight: 700;
    background: rgba(9, 13, 22, 0.82);
    color: #ffffff;
    padding: 5px 12px;
    border-radius: 9999px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    letter-spacing: 0.02em;
    pointer-events: auto;
    user-select: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.browse-zoom-chip {
    font-size: 0.72rem;
    font-weight: 800;
    background: rgba(9, 13, 22, 0.82);
    color: #60a5fa;
    padding: 5px 11px;
    border-radius: 9999px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(96, 165, 250, 0.35);
    pointer-events: auto;
    user-select: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s ease;
}

.browse-zoom-chip:active {
    transform: scale(0.92);
}

.browse-torch-chip {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    background: rgba(9, 13, 22, 0.82);
    color: #e2e8f0;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    pointer-events: auto;
    user-select: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.16s ease;
}

.browse-torch-chip:hover {
    border-color: rgba(255, 255, 255, 0.45);
    transform: scale(1.08);
}

.browse-torch-chip:active {
    transform: scale(0.92);
}

.browse-torch-chip.is-active {
    background: #f59e0b !important;
    color: #000 !important;
    border-color: #fbbf24 !important;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.65), 0 4px 12px rgba(0, 0, 0, 0.4);
    animation: torchPulse 2s infinite ease-in-out;
}

@keyframes torchPulse {
    0%, 100% { box-shadow: 0 0 10px rgba(245, 158, 11, 0.5), 0 4px 12px rgba(0, 0, 0, 0.4); }
    50% { box-shadow: 0 0 18px rgba(245, 158, 11, 0.85), 0 4px 12px rgba(0, 0, 0, 0.4); }
}

/* Generic Viewfinder Overlay Torch Button */
.viewfinder-torch-btn {
    position: absolute;
    top: 0.65rem;
    right: 0.65rem;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    background: rgba(9, 13, 22, 0.82);
    color: #e2e8f0;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    z-index: 15;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.16s ease;
    user-select: none;
}

.viewfinder-torch-btn:hover {
    border-color: rgba(255, 255, 255, 0.45);
    transform: scale(1.08);
}

.viewfinder-torch-btn:active {
    transform: scale(0.92);
}

.viewfinder-torch-btn.is-active {
    background: #f59e0b !important;
    color: #000 !important;
    border-color: #fbbf24 !important;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.65);
    animation: torchPulse 2s infinite ease-in-out;
}

.browse-center-reticle {
    position: absolute;
    width: 78vw;
    max-width: 340px;
    height: 48vh;
    max-height: 380px;
    border: 2px dashed rgba(255, 255, 255, 0.45);
    border-radius: 16px;
    pointer-events: none;
    z-index: 22;
}

.browse-laser-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: #ef4444;
    box-shadow: 0 0 8px #ef4444;
    animation: laserSweep 2s ease-in-out infinite alternate;
}

@keyframes laserSweep {
    0% { transform: translateY(-40px); }
    100% { transform: translateY(40px); }
}

/* Ergonomic Button Dock (Floating right above the bottom nav menu) */
.browse-dock {
    position: fixed;
    bottom: calc(4.2rem + max(0.4rem, env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    background: rgba(9, 13, 22, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 16px;
    padding: 0.42rem 0.52rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.7);
    z-index: 35;
    max-width: calc(100vw - 16px);
    user-select: none;
}

.browse-dock-btn {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.10);
    color: #e2e8f0;
    border: 2px solid rgba(255, 255, 255, 0.20);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, background 0.15s ease;
    overflow: hidden;
    user-select: none;
    flex-shrink: 0;
    padding: 2px;
}

.browse-dock-btn:active {
    transform: scale(0.92);
}

.browse-dock-btn.is-captured {
    border-color: #10b981;
    background: #10b981;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.6);
}

.browse-dock-btn.has-thumbnail {
    background-size: cover;
    background-position: center;
    border-color: #10b981;
    box-shadow: 0 0 14px rgba(16, 185, 129, 0.65);
}

.browse-dock-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #10b981;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    border: 1.5px solid #090d16;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    z-index: 2;
}

.browse-dock-label {
    font-size: 0.52rem;
    font-weight: 700;
    line-height: 1;
    margin-top: 3px;
    text-transform: uppercase;
    letter-spacing: -0.01em;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: clip;
    max-width: 100%;
    text-align: center;
    padding: 0 1px;
}

.browse-dock-label-overlay {
    position: absolute;
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.50rem;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    line-height: 1.1;
    text-transform: uppercase;
    letter-spacing: 0.01em;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    max-width: calc(100% - 4px);
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 365px) {
    .browse-dock {
        gap: 0.25rem;
        padding: 0.35rem 0.4rem;
    }
    .browse-dock-btn {
        width: 54px;
        height: 54px;
        border-radius: 10px;
    }
    .browse-dock-label {
        font-size: 0.48rem;
    }
}

@media (min-width: 600px) {
    .browse-dock {
        gap: 0.65rem;
        padding: 0.55rem 0.75rem;
        border-radius: 18px;
    }
    .browse-dock-btn {
        width: 66px;
        height: 66px;
        border-radius: 14px;
    }
    .browse-dock-label {
        font-size: 0.56rem;
    }
}

/* Floating Recognise Action Button */
.browse-floating-recognise {
    position: fixed;
    bottom: calc(8.6rem + max(0.4rem, env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%);
    z-index: 35;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    animation: scaleUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
}

.browse-floating-recognise .btn-primary {
    height: 3.1rem;
    padding: 0 1.6rem;
    font-size: 0.98rem;
    font-weight: 700;
    border-radius: 9999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6), 0 0 14px rgba(37, 99, 235, 0.45);
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.browse-clear-btn {
    height: 3.1rem;
    padding: 0 1.3rem;
    font-size: 0.92rem;
    font-weight: 700;
    color: #f1f5f9;
    background: rgba(17, 24, 39, 0.88);
    border: 1.5px solid rgba(255, 255, 255, 0.22);
    border-radius: 9999px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.browse-clear-btn:hover {
    background: rgba(220, 38, 38, 0.9);
    border-color: rgba(239, 68, 68, 0.6);
    color: #ffffff;
}

.browse-clear-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.45);
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 0.82rem;
    font-weight: 700;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.browse-clear-chip:hover {
    background: rgba(220, 38, 38, 0.9);
    color: #ffffff;
}

/* Scanned Barcode and QR Code Graphic Rendering */
.code-visual-container {
    background: var(--bg-card-subtle);
    border-radius: var(--radius-md);
    padding: 0.9rem 1rem;
    border: 1px solid var(--border-subtle);
}

.code-format-toggle-group {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border-subtle);
    border-radius: 9999px;
    padding: 2px;
}

.code-toggle-pill {
    background: transparent;
    border: none;
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.code-toggle-pill:hover {
    color: var(--text-primary);
}

.code-toggle-pill.active {
    background: var(--accent);
    color: #ffffff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.code-visual-display {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.85rem;
    background: #ffffff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    margin-top: 0.35rem;
}

.code-visual-display svg {
    max-width: 100%;
    height: auto;
}

/* Food Product Nutrition Table (Back-of-Pack authentic layout) */
.nutrition-pack-table {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-card);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}

.pack-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.65rem 0.85rem;
    background: var(--bg-card-subtle);
    border-bottom: 2px solid var(--border-strong);
}

.pack-table-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pack-table-base-mass {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
    text-align: right;
    gap: 0.15rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-left: auto;
}

.pack-table-typical-values,
.pack-table-serving {
    display: block;
    text-align: right;
}

.pack-table-serving {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
}

.pack-mass-input {
    width: 3.6rem;
    height: 1.85rem;
    padding: 0.15rem 0.35rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    text-align: right;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-card);
}

.pack-table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.88rem;
}

.pack-table-row:last-child {
    border-bottom: none;
}

.pack-table-row-sub {
    padding-left: 1.6rem;
    font-size: 0.84rem;
    color: var(--text-secondary);
    background: rgba(248, 250, 252, 0.55);
}

.pack-row-name {
    font-weight: 600;
}

.pack-table-row-sub .pack-row-name {
    font-weight: 400;
}

.pack-row-val {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
}

.pack-num-input {
    width: 4.8rem;
    height: 1.85rem;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    text-align: right;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-page);
    font-variant-numeric: tabular-nums;
    transition: border-color 0.15s, background-color 0.15s;
}

.pack-num-input:focus {
    border-color: var(--accent);
    outline: none;
    background: var(--bg-card);
}

.pack-unit {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 0.85rem;
}

.pack-energy-val {
    gap: 0.35rem;
}

.pack-kcal-badge {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 0.2rem;
}

/* Found Item Card Highlight on Menu */
.menu-card-found-highlight {
    border-color: var(--accent) !important;
    position: relative;
    box-shadow: 0 0 0 2.5px rgba(37, 99, 235, 0.4), 0 4px 16px rgba(37, 99, 235, 0.15) !important;
    animation: foundPulse 2.5s ease-in-out infinite;
}

.menu-found-badge {
    position: absolute;
    top: 6px;
    left: 92px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--accent);
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 9999px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    z-index: 5;
    box-shadow: 0 1px 4px rgba(37, 99, 235, 0.35);
}

@keyframes foundPulse {
    0%, 100% {
        box-shadow: 0 0 0 2.5px rgba(37, 99, 235, 0.4), 0 4px 16px rgba(37, 99, 235, 0.2);
    }
    50% {
        box-shadow: 0 0 0 5px rgba(37, 99, 235, 0.12), 0 2px 8px rgba(37, 99, 235, 0.08);
    }
}

/* Menu Top Action & Search Bar: Same line on web (>=769px), stacked on mobile */
.menu-action-toolbar {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 0.85rem;
}

.menu-search-wrapper {
    flex: 1;
    min-width: 0;
}

.menu-search-input {
    height: 2.75rem;
    font-size: 0.92rem;
}

.menu-search-clear {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    padding: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-search-clear:hover {
    color: var(--text-primary);
}

.menu-scan-wrapper,
.menu-add-wrapper {
    display: flex;
}

.menu-scan-btn,
.menu-add-btn {
    width: 100%;
    height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.92rem;
    font-weight: 600;
}

@media (min-width: 769px) {
    .menu-action-toolbar {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
    }

    .menu-scan-btn,
    .menu-add-btn {
        width: auto;
        padding-left: 1.35rem;
        padding-right: 1.35rem;
        white-space: nowrap;
    }
}

/* Menu Controls & Sort Bar */
.menu-controls-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    padding: 0 0.15rem;
    flex-wrap: wrap;
}

.menu-counts-badge {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.menu-counts-badge .count-num {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.menu-counts-badge .count-filter-label {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
}

.menu-sort-group {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-sort-label {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.sort-segmented-control {
    display: inline-flex;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: 9999px;
    padding: 2px;
    gap: 2px;
}

.sort-pill-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    transition: all 0.16s ease;
    user-select: none;
}

.sort-pill-btn:hover {
    color: var(--text-primary);
    background: rgba(0, 0, 0, 0.04);
}

.sort-pill-btn.is-active {
    background: var(--bg-card);
    color: var(--accent);
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.sort-direction-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sort-direction-indicator.is-desc {
    transform: rotate(180deg);
}

.sort-pill-btn:not(.is-active) .sort-direction-indicator {
    opacity: 0.45;
}

/* Menu Sections */
.menu-section {
    margin-bottom: 2rem;
}

.menu-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
    padding: 0 0.15rem;
}

.menu-section-title {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.menu-section-badge {
    font-size: 0.72rem;
    font-weight: 700;
    background: var(--bg-card-subtle);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
    line-height: 1.2;
}

/* Compact Menu Item Cards */
.menu-compact-card {
    position: relative;
    padding: 0 !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: stretch !important;
    cursor: pointer;
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    user-select: none;
    overflow: hidden;
    min-height: 86px;
}

.menu-compact-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border-color: var(--accent);
}

.menu-compact-card:active {
    transform: scale(0.99);
}

/* Full height thumbnail on left */
.menu-compact-thumb {
    position: relative;
    width: 86px;
    min-width: 86px;
    align-self: stretch;
    flex-shrink: 0;
    overflow: hidden;
    background: var(--bg-card-subtle);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
}

.menu-compact-thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.menu-compact-thumb-placeholder {
    position: relative;
    width: 86px;
    min-width: 86px;
    align-self: stretch;
    flex-shrink: 0;
    background: var(--bg-card-subtle);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

/* Content Area */
.menu-compact-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.18rem;
    padding: 0.75rem 0.85rem;
    padding-right: 4.85rem; /* Clearance for top-right Action buttons (Star + Diary) */
}

.menu-compact-name {
    font-size: 0.96rem;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.25;
}

.menu-compact-brand {
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.menu-compact-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.2rem;
}

.menu-compact-meta .badge-chip {
    font-size: 0.72rem;
    padding: 0.12rem 0.5rem;
}

.menu-compact-size {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Card Action Buttons (Star + Diary) */
.menu-card-actions {
    position: absolute;
    top: 0.55rem;
    right: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    z-index: 5;
}

.menu-card-action-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 0;
}

.menu-card-action-btn:hover {
    transform: scale(1.08);
}

.menu-card-action-btn:active {
    transform: scale(0.92);
}

.menu-card-star-btn {
    color: var(--text-muted);
}

.menu-card-star-btn:hover {
    color: var(--amber);
    border-color: rgba(245, 158, 11, 0.4);
    background: #fffbeb;
}

.menu-card-star-btn.is-favorite {
    color: var(--amber);
    background: #fffbeb;
    border-color: rgba(245, 158, 11, 0.5);
}

.menu-card-star-btn.is-favorite:hover {
    background: #fef3c7;
    border-color: var(--amber);
}

.menu-card-diary-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: var(--accent);
}

.menu-card-diary-btn.added-success {
    background: var(--emerald-subtle) !important;
    color: var(--emerald) !important;
    border-color: var(--emerald) !important;
    animation: diaryPop 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes diaryPop {
    0% { transform: scale(0.85); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

/* Subtle tap chevron in bottom right */
.menu-compact-chevron {
    position: absolute;
    bottom: 0.55rem;
    right: 0.75rem;
    color: var(--text-muted);
    opacity: 0.35;
    transition: opacity 0.15s ease, transform 0.15s ease, color 0.15s ease;
    pointer-events: none;
}

.menu-compact-card:hover .menu-compact-chevron {
    opacity: 0.85;
    transform: translateX(2px);
    color: var(--accent);
}

/* Toast confirmation for Diary add */
.diary-toast-banner {
    position: fixed;
    bottom: 4.8rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #ffffff;
    padding: 0.65rem 1.15rem;
    border-radius: 9999px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.86rem;
    z-index: 100;
    animation: toastSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
    max-width: 90vw;
}

@keyframes toastSlideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 15px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

.diary-toast-btn {
    background: var(--accent);
    color: #ffffff;
    border: none;
    border-radius: 9999px;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.diary-toast-btn:hover {
    background: #1d4ed8;
    transform: scale(1.04);
}

/* Diary Date Navigator & Macro Summary */
.diary-date-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 0.65rem 1rem;
    margin-bottom: 1.25rem;
}

.diary-macro-strip {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.65rem;
    margin-bottom: 1.25rem;
}

@media (max-width: 600px) {
    .diary-macro-strip {
        grid-template-columns: repeat(2, 1fr);
    }
}

.diary-macro-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.65rem;
    text-align: center;
}

.diary-macro-num {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.2;
}

.diary-macro-lbl {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-top: 0.2rem;
}

/* Diary Card Wrapper & Sub-card (poke-out effect inspired by KidsCal) */
.diary-card-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
}

.diary-item-card {
    position: relative;
    z-index: 2;
    width: 100%;
}

.diary-subcard {
    width: calc(100% - 16px);
    align-self: center;
    background: var(--bg-card-subtle);
    border: 1px solid var(--border-subtle);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 16px 14px 9px 14px;
    margin-top: -12px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    gap: 3px;
    position: relative;
    z-index: 1;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    user-select: none;
}

.diary-subcard:hover {
    background: #e2e8f0;
    border-color: var(--border-strong);
}

.diary-subcard:active {
    transform: scale(0.99);
}

.diary-subcard-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.35;
}

.diary-subcard-times {
    color: var(--text-muted);
    font-size: 0.72rem;
    margin: 0 1px;
}

.diary-subcard-mass {
    color: var(--text-primary);
}

/* Diary Entry Editor Drawer Controls (No descriptive text, just intuitive controls) */
.diary-editor-pair-row {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.75rem;
    background: var(--bg-card-subtle);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.diary-stepper {
    display: inline-flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    overflow: hidden;
    height: 2.6rem;
}

.diary-stepper-btn {
    width: 2.2rem;
    height: 100%;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1.15rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.1s ease;
}

.diary-stepper-btn:hover {
    background: var(--bg-card-subtle);
}

.diary-stepper-btn:active {
    background: var(--border-subtle);
}

.diary-stepper-input {
    width: 3.2rem;
    height: 100%;
    border: none;
    border-left: 1px solid var(--border-subtle);
    border-right: 1px solid var(--border-subtle);
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    background: transparent;
    outline: none;
}

.diary-editor-times {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-muted);
    user-select: none;
}

.diary-mass-box {
    display: inline-flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    overflow: hidden;
    height: 2.6rem;
    padding: 0 0.65rem 0 0.75rem;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.diary-mass-input {
    width: 100%;
    min-width: 0;
    height: 100%;
    border: none;
    text-align: right;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    background: transparent;
    outline: none;
}

.diary-mass-unit {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-muted);
    user-select: none;
}

.diary-editor-del-btn {
    width: 2.4rem;
    height: 2.4rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--rose);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.diary-editor-del-btn:hover {
    background: #fee2e2;
    border-color: var(--rose);
}

.diary-editor-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 2.6rem;
    border-radius: var(--radius-md);
    border: 1.5px dashed var(--border-strong);
    background: transparent;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    transition: all 0.15s ease;
}

.diary-editor-add-btn:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

/* Fullscreen Photo Gallery Overlay */
.gallery-backdrop {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
    touch-action: none;
    overscroll-behavior: none;
    animation: fadeIn 0.22s ease-out;
}

body.has-open-gallery {
    overflow: hidden !important;
}

.gallery-top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(max(10px, env(safe-area-inset-top)) + 6px) 16px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 3010;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0) 100%);
    pointer-events: none;
}

.gallery-meta {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    flex: 1;
    pointer-events: auto;
}

.gallery-counter-pill {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    letter-spacing: 0.04em;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    flex-shrink: 0;
}

.gallery-title-text {
    color: #f1f5f9;
    font-size: 0.92rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

.gallery-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    pointer-events: auto;
}

.gallery-action-btn {
    border: none;
    border-radius: 9999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.gallery-zoom-pill {
    background: rgba(37, 99, 235, 0.35);
    color: #93c5fd;
    border: 1px solid rgba(96, 165, 250, 0.4);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 5px 11px;
    gap: 0.35rem;
    backdrop-filter: blur(8px);
}

.gallery-zoom-pill:hover {
    background: rgba(37, 99, 235, 0.6);
    color: #ffffff;
}

.gallery-close-btn {
    width: 38px;
    height: 38px;
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.22);
    backdrop-filter: blur(8px);
}

.gallery-close-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.05);
}

.gallery-close-btn:active {
    transform: scale(0.92);
}

.gallery-delete-btn {
    width: 38px;
    height: 38px;
    background: rgba(239, 68, 68, 0.22);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.35);
    backdrop-filter: blur(8px);
}

.gallery-delete-btn:hover {
    background: rgba(239, 68, 68, 0.5);
    color: #ffffff;
    transform: scale(1.05);
}

.gallery-delete-btn:active {
    transform: scale(0.92);
}

.gallery-viewport {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

.gallery-img-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    touch-action: none;
    overscroll-behavior: none;
}

.gallery-incoming-image {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
    pointer-events: none;
    z-index: 2;
}

.gallery-image {
    max-width: 96vw;
    max-height: 82vh;
    max-height: 82dvh;
    object-fit: contain;
    border-radius: var(--radius-sm, 8px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: auto;
    touch-action: none;
    overscroll-behavior: none;
    will-change: transform;
}

.gallery-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.22);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 3010;
    transition: all 0.15s ease;
}

.gallery-nav-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: translateY(-50%) scale(1.08);
}

.gallery-nav-btn:active {
    transform: translateY(-50%) scale(0.92);
}

.gallery-nav-prev {
    left: 16px;
}

.gallery-nav-next {
    right: 16px;
}

@media (max-width: 600px) {
    .gallery-nav-btn {
        display: none;
    }
}

.gallery-bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px calc(max(12px, env(safe-area-inset-bottom)) + 4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
    z-index: 3010;
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%);
    pointer-events: none;
}

.gallery-gesture-hint {
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.72rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

.gallery-thumb-strip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 90vw;
    overflow-x: auto;
    padding: 4px;
    scrollbar-width: none;
    pointer-events: auto;
}

.gallery-thumb-strip::-webkit-scrollbar {
    display: none;
}

.gallery-thumb-dot {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    overflow: hidden;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: #000000;
    cursor: pointer;
    flex-shrink: 0;
    opacity: 0.6;
    transition: all 0.16s ease;
}

.gallery-thumb-dot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-thumb-dot:hover {
    opacity: 0.9;
    transform: scale(1.08);
}

.gallery-thumb-dot.is-active {
    opacity: 1;
    border-color: var(--accent, #3b82f6);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.7);
    transform: scale(1.12);
}

/* Packaging Photo Thumbnail Zoom Badges */
.photo-zoom-hint-badge {
    position: absolute;
    bottom: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    background: rgba(15, 23, 42, 0.75);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    opacity: 0.8;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.menu-compact-thumb {
    position: relative;
    cursor: pointer;
}

.menu-thumb-zoom-icon {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.75;
    transition: opacity 0.15s ease, transform 0.15s ease, background 0.15s ease;
}

.menu-compact-thumb:hover .menu-thumb-zoom-icon {
    opacity: 1;
    transform: scale(1.12);
    background: var(--accent, #3b82f6);
}

.confirm-drawer-backdrop {
    z-index: 3200 !important;
}




