/* ==========================================
   OLIVER'S KITCHEN — DESIGN SYSTEM
   Mobile: feels like a native iOS app
   Desktop: editorial, warm, modern
========================================== */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;800&family=DM+Sans:wght@400;500;600&display=swap');

/* --- ТОКЕНЫ --- */
:root {
    --bg:            #F2EDE8;
    --bg-card:       rgba(255, 252, 248, 0.85);
    --bg-soft:       rgba(255, 255, 255, 0.55);
    --surface:       #FFFFFF;

    --accent:        #D4622A;
    --accent-dark:   #B34E1F;
    --accent-light:  rgba(212, 98, 42, 0.12);
    --accent-grad:   linear-gradient(135deg, #D4622A 0%, #E8945A 100%);

    --text:          #1A1208;
    --text-muted:    #7A6E64;
    --text-faint:    #B0A89E;

    --danger:        #E53E3E;
    --danger-light:  rgba(229, 62, 62, 0.1);

    --border:        rgba(0, 0, 0, 0.07);
    --glass-border:  rgba(255, 255, 255, 0.5);

    --radius-sm:     10px;
    --radius-md:     16px;
    --radius-lg:     24px;
    --radius-xl:     32px;

    --shadow-sm:     0 2px 8px rgba(0,0,0,0.06);
    --shadow-md:     0 8px 24px rgba(0,0,0,0.08);
    --shadow-lg:     0 20px 48px rgba(0,0,0,0.12);

    --header-h:      64px;
    --safe-bottom:   env(safe-area-inset-bottom, 0px);
    --safe-top:      env(safe-area-inset-top, 0px);
}

/* --- RESET + BASE --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

* {
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

@view-transition {
    navigation: none;
}

::view-transition-old(root) {
    animation: app-page-out 0.18s ease both;
}

::view-transition-new(root) {
    animation: app-page-in 0.24s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes app-page-out {
    to { opacity: 0.86; transform: translateY(6px) scale(0.995); }
}

@keyframes app-page-in {
    from { opacity: 0; transform: translateY(10px) scale(0.995); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    padding-top: calc(var(--header-h) + var(--safe-top));
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.24s ease, color 0.24s ease;
}

body.app-leaving main,
body.app-leaving .container-ios {
    opacity: 0.82;
    transform: translateY(8px);
    transition: opacity 0.16s ease, transform 0.16s ease;
}

/* ==========================================
   HEADER
========================================== */
.ios-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: calc(var(--header-h) + var(--safe-top));
    padding-top: var(--safe-top);
    z-index: 1000;
    background: rgba(242, 237, 232, 0.82);
    backdrop-filter: saturate(200%) blur(24px);
    -webkit-backdrop-filter: saturate(200%) blur(24px);
    border-bottom: 0.5px solid var(--border);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    height: var(--header-h);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

/* Brand */
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none !important;
    color: var(--text);
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: 19px;
    flex-shrink: 0;
    letter-spacing: -0.3px;
}

.logo-img {
    height: 36px;
    width: 36px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: var(--shadow-sm);
}

/* Search */
.search-box {
    flex: 1;
    max-width: 320px;
}

.search-box input {
    width: 100%;
    background: var(--bg-soft);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 9px 14px 9px 36px;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%237A6E64' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.44 1.887a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 12px center;
}

.search-box input:focus {
    border-color: var(--accent);
    background-color: var(--surface);
    box-shadow: 0 0 0 4px var(--accent-light);
}

/* Nav actions */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    transition: background 0.2s;
    text-decoration: none;
}

.icon-btn:hover { background: var(--surface); }

.icon-btn img { height: 20px; width: 20px; object-fit: contain; }

.basket-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    text-decoration: none;
    transition: background 0.2s;
}

.basket-btn:hover { background: var(--surface); }
.basket-btn img { height: 22px; object-fit: contain; }

.badge {
    position: absolute;
    top: -5px;
    right: -6px;
    background: var(--danger);
    color: white;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
    border: 2px solid var(--bg);
}

.auth-link {
    display: inline-flex;
    align-items: center;
    padding: 8px 16px;
    background: var(--accent-grad);
    color: white !important;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none !important;
    transition: opacity 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(212,98,42,0.3);
    white-space: nowrap;
}

.auth-link:hover { opacity: 0.9; }
.auth-link:active { transform: scale(0.96); }


/* ==========================================
   MOBILE BOTTOM TAB BAR
========================================== */
.mobile-tabbar {
    display: none;
}

/* ==========================================
   LAYOUT
========================================== */
.container-ios {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px;
}

.page-margin {
    padding-top: 28px;
    padding-bottom: 80px;
}

/* ==========================================
   INDEX — RECIPE GRID
========================================== */
.page-title h1 {
    font-family: 'Playfair Display', serif;
    font-size: 38px;
    font-weight: 800;
    letter-spacing: -1px;
    color: var(--text);
    margin-bottom: 28px;
}

.recipe-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
}

/* CARD */
.recipe-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.recipe-card:hover {
    transform: translateY(-6px) scale(1.01);
    box-shadow: var(--shadow-lg);
}

.card-image {
    position: relative;
    height: 200px;
    overflow: hidden;
}

.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.5s ease;
}

.recipe-card:hover .card-image img {
    transform: scale(1.07);
}

.time-tag {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(255,255,255,0.92);
    backdrop-filter: blur(6px);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.card-info {
    padding: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-grow: 1;
    gap: 12px;
}

.card-info h3 {
    font-size: 17px;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text);
}

/* Add to cart button */
.add-to-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--accent-grad);
    color: white !important;
    border: none;
    width: 100%;
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(212,98,42,0.3);
    transition: opacity 0.2s, transform 0.15s cubic-bezier(0.34,1.56,0.64,1);
    -webkit-tap-highlight-color: transparent;
}

.add-to-cart:hover { opacity: 0.9; transform: scale(1.02); }
.add-to-cart:active { transform: scale(0.96); opacity: 0.85; }


/* ==========================================
   FOOD DETAIL PAGE
========================================== */
.recipe-detail-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 32px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(16px);
}

.recipe-header {
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.recipe-title {
    font-family: 'Playfair Display', serif;
    font-size: 36px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 12px;
    line-height: 1.15;
}

.recipe-time {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    background: var(--bg);
    padding: 6px 12px;
    border-radius: 8px;
}

/* Content grid: image + ingredients */
.recipe-content-grid {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 24px;
    margin-bottom: 24px;
}

.recipe-image-wrap img {
    width: 100%;
    height: 360px;
    object-fit: cover;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    cursor: zoom-in;
    display: block;
    transition: transform 0.2s;
}

.recipe-image-wrap img:hover { transform: scale(1.01); }

.recipe-ingredients,
.recipe-instructions {
    background: var(--bg);
    padding: 22px;
    border-radius: var(--radius-lg);
}

.recipe-instructions { margin-bottom: 24px; }

.recipe-ingredients h2,
.recipe-instructions h2 {
    font-family: 'Playfair Display', serif;
    font-size: 19px;
    font-weight: 700;
    margin-bottom: 14px;
    color: var(--text);
}

pre {
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.rich-text-content {
    font-size: 16px;
    line-height: 1.7;
    color: var(--text);
}

.rich-text-content p { margin-bottom: 14px; }
.rich-text-content img,
.rich-text-content iframe {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: 12px 0;
    display: block;
    cursor: zoom-in;
}

/* Actions */
.recipe-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.btn-ios {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 13px 22px;
    border-radius: var(--radius-md);
    font-family: 'DM Sans', sans-serif;
    font-weight: 600;
    font-size: 15px;
    text-decoration: none !important;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-ios:active { transform: scale(0.96); }

.btn-primary {
    background: var(--accent-grad);
    color: white !important;
    box-shadow: 0 6px 18px rgba(212,98,42,0.3);
}

.btn-danger {
    background: var(--danger-light);
    color: var(--danger) !important;
}

.btn-secondary {
    background: var(--bg);
    color: var(--accent) !important;
    border: 1px solid var(--border);
}

.btn-primary:hover, .btn-danger:hover, .btn-secondary:hover { opacity: 0.85; }


/* ==========================================
   FORMS (addFood / editFood)
========================================== */
.form-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 32px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

.form-title {
    font-family: 'Playfair Display', serif;
    font-size: 30px;
    font-weight: 800;
    margin-bottom: 28px;
    letter-spacing: -0.5px;
}

.form-group { margin-bottom: 20px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.ios-input {
    width: 100%;
    background: var(--bg);
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-family: 'DM Sans', sans-serif;
    font-size: 15px;
    color: var(--text);
    outline: none;
    resize: vertical;
    transition: all 0.2s ease;
}

.ios-input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 4px var(--accent-light);
}

/* File upload */
.file-group {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg);
    padding: 14px;
    border-radius: var(--radius-md);
}

.current-image-preview img {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 10px;
    box-shadow: var(--shadow-sm);
}

.upload-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.upload-preview[hidden] {
    display: none !important;
}

.upload-preview span {
    max-width: 220px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-transform: none;
    letter-spacing: 0;
}

input[type="file"] { display: none; }

.custom-file-upload {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    padding: 10px 16px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--accent) !important;
    transition: all 0.2s;
    margin: 0 !important;
}

.custom-file-upload:hover {
    background: var(--accent-light);
    border-color: var(--accent);
}

.form-actions { margin-top: 8px; }

/* TinyMCE */
.tox-tinymce {
    border: 1.5px solid transparent !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden !important;
    box-shadow: none !important;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.tox-tinymce:focus-within {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 4px var(--accent-light) !important;
}

.tox-statusbar { display: none !important; }


/* ==========================================
   CART
========================================== */
.cart-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    padding: 28px;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 16px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.cart-header h1 {
    font-family: 'Playfair Display', serif;
    font-size: 26px;
    font-weight: 800;
}

.cart-list { display: flex; flex-direction: column; }

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 0.5px solid var(--border);
    gap: 12px;
}

.cart-item:last-child { border-bottom: none; }

.cart-item-info { display: flex; align-items: center; gap: 14px; }

.cart-item-img {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    object-fit: cover;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.cart-item-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}

.cart-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--danger-light);
    color: var(--danger) !important;
    text-decoration: none;
    flex-shrink: 0;
    transition: all 0.2s;
}

.cart-delete-btn:hover {
    background: var(--danger);
    color: white !important;
}

.cart-footer {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.order-submit-btn {
    width: 100% !important;
    font-size: 17px !important;
    padding: 16px !important;
    box-shadow: 0 8px 24px rgba(212,98,42,0.3) !important;
}

.empty-cart {
    text-align: center;
    padding: 60px 0;
}

.empty-cart p {
    color: var(--text-muted);
    font-size: 18px;
    margin-bottom: 24px;
}


/* ==========================================
   AUTH MODAL
========================================== */
.form-popup {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 18, 8, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.form-popup.open {
    display: flex;
}

.form-container {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 36px 28px 28px;
    width: 90%;
    max-width: 340px;
    box-shadow: 0 32px 64px rgba(0,0,0,0.2);
    animation: modalIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.form-container h1 {
    font-family: 'Playfair Display', serif;
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 22px;
    text-align: center;
}

.auth-error-message {
    background: var(--danger-light);
    border: 1px solid rgba(229, 62, 62, 0.18);
    color: var(--danger);
    border-radius: var(--radius-md);
    padding: 11px 12px;
    margin: 0 0 14px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
}

.form-container label { display: none !important; }

.form-container input {
    width: 100%;
    background: var(--bg);
    border: 1.5px solid transparent;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    color: var(--text);
    margin-bottom: 12px;
    outline: none;
    transition: all 0.2s;
    box-sizing: border-box;
}

.form-container input:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-container .btn {
    width: 100%;
    background: var(--accent-grad);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px;
    font-family: 'DM Sans', sans-serif;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    box-shadow: 0 6px 16px rgba(212,98,42,0.3);
    transition: opacity 0.2s, transform 0.15s;
}

.form-container .btn:active { transform: scale(0.97); }

.form-container .cancel {
    background: transparent;
    color: var(--danger) !important;
    box-shadow: none;
}

.form-container .cancel:hover {
    background: var(--danger-light);
}


/* ==========================================
   LIGHTBOX / FULLSCREEN OVERLAY
========================================== */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    cursor: zoom-out;
}

.fullscreen-image {
    max-width: 90vw;
    max-height: 90vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--radius-lg);
    box-shadow: 0 32px 64px rgba(0,0,0,0.5);
    animation: imageZoomIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes imageZoomIn {
    from { opacity: 0; transform: scale(0.8); }
    to   { opacity: 1; transform: scale(1); }
}


/* ==========================================
   FOOTER
========================================== */
footer {
    text-align: center;
    padding: 24px 20px calc(24px + var(--safe-bottom));
    color: var(--text-faint);
    font-size: 13px;
    background: transparent !important;
    border-top: none !important;
}


/* ==========================================
   ████████ MOBILE ████████  ≤ 768px
========================================== */
@media (max-width: 768px) {

    body {
        padding-top: 0;
        padding-bottom: calc(100px + var(--safe-bottom));
        background: var(--bg);
        overscroll-behavior-y: none;
        -webkit-overflow-scrolling: touch;
    }

    main,
    .container-ios,
    .form-card,
    .cart-card,
    .recipe-card {
        transform: translateZ(0);
        backface-visibility: hidden;
    }

    .btn-ios,
    .icon-btn,
    .basket-btn,
    .tab-item,
    .recipe-card,
    .cart-item {
        transition:
            transform 0.18s cubic-bezier(0.34, 1.5, 0.64, 1),
            opacity 0.18s ease,
            background-color 0.18s ease,
            box-shadow 0.18s ease;
    }

    .ios-header { display: none; }

    /* ==========================================
       FLOATING TELEGRAM-STYLE TAB BAR
       Sliding pill indicator like Telegram
    ========================================== */
    .mobile-tabbar {
        display: flex;
        position: fixed;
        bottom: calc(16px + var(--safe-bottom));
        left: 50%;
        transform: translateX(-50%);
        width: auto;
        min-width: 260px;
        max-width: calc(100vw - 32px);

        background: rgba(20, 13, 6, 0.90);
        backdrop-filter: saturate(200%) blur(32px);
        -webkit-backdrop-filter: saturate(200%) blur(32px);

        border-radius: 999px;
        border: 1px solid rgba(255,255,255,0.10);
        box-shadow:
            0 16px 48px rgba(0,0,0,0.38),
            0 2px 8px rgba(0,0,0,0.22),
            inset 0 1px 0 rgba(255,255,255,0.08);

        z-index: 900;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 5px 6px;

        /* Pill CSS vars — JS manages these */
        --pill-left: 0px;
        --pill-width: 0px;
        --pill-transition: left 0.38s cubic-bezier(0.34, 1.3, 0.64, 1),
                           width 0.38s cubic-bezier(0.34, 1.3, 0.64, 1);
    }

    /* Sliding background pill */
    .mobile-tabbar::before {
        content: '';
        position: absolute;
        top: 5px;
        bottom: 5px;
        left: var(--pill-left);
        width: var(--pill-width);
        background: rgba(212, 98, 42, 0.30);
        border-radius: 999px;
        /* transition controlled by JS: instant on load, animated on tap */
        transition: var(--pill-transition);
        pointer-events: none;
        z-index: 0;
    }

    .tab-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 8px 15px;
        border-radius: 999px;
        text-decoration: none !important;
        color: rgba(255,255,255,0.42) !important;
        font-size: 10px;
        font-weight: 600;
        letter-spacing: 0.2px;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        background: none;
        border: none;
        font-family: 'DM Sans', sans-serif;
        white-space: nowrap;
        min-width: 52px;
        position: relative;
        z-index: 1;
        transition: color 0.25s ease, transform 0.18s cubic-bezier(0.34,1.5,0.64,1);
    }

    /* Active tab text color — pill handles the bg */
    .tab-item.active {
        color: #FFB080 !important;
    }

    .tab-item:active {
        transform: scale(0.84);
    }

    .tab-icon {
        font-size: 20px;
        line-height: 1;
        display: block;
        transition: transform 0.25s cubic-bezier(0.34,1.5,0.64,1);
    }

    .tab-item.active .tab-icon {
        transform: scale(1.12);
    }

    .tab-badge {
        position: absolute;
        top: 4px;
        right: 6px;
        background: var(--danger);
        color: white;
        border-radius: 10px;
        font-size: 9px;
        font-weight: 700;
        padding: 1px 5px;
        border: 1.5px solid rgba(20,13,6,0.92);
        min-width: 16px;
        text-align: center;
        line-height: 1.4;
    }

    .tab-item-wrap {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    /* --- Mobile Search Bar --- */
    .mobile-search-bar {
        display: block;
        padding: 20px 16px 0;
    }

    .mobile-search-bar input {
        width: 100%;
        background: var(--surface);
        border: 1.5px solid var(--border);
        border-radius: 16px;
        padding: 13px 16px 13px 42px;
        font-size: 16px;
        color: var(--text);
        outline: none;
        font-family: 'DM Sans', sans-serif;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%237A6E64' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.099zm-5.44 1.887a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: 14px center;
        -webkit-appearance: none;
        box-shadow: var(--shadow-sm);
    }

    /* --- Page title --- */
    .page-title h1 { font-size: 28px; margin-bottom: 16px; }

    /* --- Recipe grid 2 cols --- */
    .recipe-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
    .card-image { height: 150px; }
    .card-info { padding: 12px; gap: 10px; }
    .card-info h3 { font-size: 14px; }
    .add-to-cart { padding: 10px; font-size: 14px; }

    /* --- Food detail --- */
    .recipe-detail-card { border-radius: var(--radius-lg); padding: 20px 16px; }
    .recipe-title { font-size: 26px; }
    .recipe-content-grid { grid-template-columns: 1fr; }
    .recipe-image-wrap img { height: 240px; border-radius: var(--radius-md); cursor: default; }
    .recipe-actions .btn-ios { flex: 1; min-width: 0; }

    /* --- Forms --- */
    .form-card { border-radius: var(--radius-lg); padding: 20px 16px; }
    .form-title { font-size: 24px; }
    .file-group { flex-direction: column; align-items: flex-start; }
    .form-actions .btn-ios { flex: 1; }

    /* --- Cart --- */
    .cart-card { border-radius: var(--radius-lg); padding: 20px 16px; }
    .cart-item-title { font-size: 14px; }

    /* ==========================================
       AUTH BOTTOM SHEET — drag to close
    ========================================== */
    .form-popup { align-items: flex-end; }

    .form-container {
        width: 100%;
        max-width: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: 0 24px calc(36px + var(--safe-bottom));
        animation: sheetUp 0.38s cubic-bezier(0.34, 1.15, 0.64, 1);
        touch-action: none; /* we handle touch manually */
        will-change: transform;
        transition: transform 0.0s; /* overridden by JS during drag */
        user-select: none;
    }

    /* Drag handle area — taller hit zone, visual pill inside */
    .sheet-drag-handle {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 28px;
        cursor: grab;
        margin-bottom: 8px;
    }

    .sheet-drag-handle::after {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: rgba(0,0,0,0.15);
        border-radius: 2px;
        transition: background 0.2s, width 0.2s;
    }

    .sheet-drag-handle:active::after {
        background: rgba(0,0,0,0.28);
        width: 48px;
    }

    @keyframes sheetUp {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }

    @keyframes sheetDown {
        from { transform: translateY(0); }
        to   { transform: translateY(100%); }
    }

    .form-container.closing {
        animation: sheetDown 0.28s cubic-bezier(0.4, 0, 1, 1) forwards;
    }

    footer { display: none; }
    .page-margin { padding-top: 20px; }
}

@media (max-width: 768px) {
    .mobile-tabbar {
        min-width: min(430px, calc(100vw - 22px));
        max-width: calc(100vw - 22px);
        bottom: calc(10px + var(--safe-bottom));
        padding: 7px;
        gap: 3px;
        border-radius: 28px;
        background:
            linear-gradient(180deg, rgba(255,255,255,0.34), rgba(255,255,255,0.12)),
            color-mix(in srgb, var(--nav-bg) 72%, rgba(20,20,24,0.55) 28%) !important;
        border: 1px solid rgba(255,255,255,0.34);
        box-shadow:
            0 18px 50px rgba(0,0,0,0.28),
            0 4px 14px rgba(0,0,0,0.18),
            inset 0 1px 0 rgba(255,255,255,0.38),
            inset 0 -1px 0 rgba(0,0,0,0.10);
        backdrop-filter: saturate(180%) blur(28px);
        -webkit-backdrop-filter: saturate(180%) blur(28px);
        overflow: hidden;
        will-change: transform, opacity;
        transform: translate3d(-50%, 0, 0);
        contain: layout paint;
        --pill-transition:
            left 0.48s cubic-bezier(0.22, 1.2, 0.28, 1),
            width 0.48s cubic-bezier(0.22, 1.2, 0.28, 1),
            opacity 0.22s ease;
    }

    .mobile-tabbar::after {
        content: '';
        position: absolute;
        inset: 1px 1px auto;
        height: 46%;
        border-radius: 27px 27px 18px 18px;
        background: linear-gradient(180deg, rgba(255,255,255,0.30), rgba(255,255,255,0));
        pointer-events: none;
        z-index: 0;
    }

    .mobile-tabbar::before {
        top: 7px;
        bottom: 7px;
        border-radius: 22px;
        background:
            linear-gradient(180deg, rgba(255,255,255,0.42), rgba(255,255,255,0.16)),
            color-mix(in srgb, var(--accent) 36%, rgba(255,255,255,0.28) 64%);
        border: 1px solid rgba(255,255,255,0.38);
        box-shadow:
            0 8px 22px rgba(0,0,0,0.18),
            inset 0 1px 0 rgba(255,255,255,0.42);
        z-index: 1;
    }

    .tab-item {
        flex: 1 1 0;
        min-width: 0;
        height: 54px;
        padding: 7px 8px;
        color: color-mix(in srgb, var(--text) 70%, transparent) !important;
        border-radius: 21px;
        transform: translateZ(0);
        transition:
            color 0.24s ease,
            transform 0.2s cubic-bezier(0.34, 1.5, 0.64, 1),
            opacity 0.2s ease;
    }

    .tab-item.active {
        color: var(--text) !important;
    }

    .tab-item:active {
        transform: scale(0.91);
    }

    .tab-icon {
        width: 24px;
        height: 24px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 21px;
        filter: drop-shadow(0 1px 1px rgba(0,0,0,0.12));
    }

    .tab-item span:not(.tab-icon):not(.tab-badge):not(.cart-badge) {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    body.app-leaving .mobile-tabbar {
        transform: translate3d(-50%, 4px, 0) scale(0.99);
        opacity: 0.96;
        transition: transform 0.16s ease, opacity 0.16s ease;
    }
}

@supports not (background: color-mix(in srgb, #000 50%, #fff 50%)) {
    @media (max-width: 768px) {
        .mobile-tabbar {
            background: rgba(35, 35, 38, 0.66) !important;
        }

        .mobile-tabbar::before {
            background: rgba(255,255,255,0.22);
        }
    }
}

/* Very small phones */
@media (max-width: 380px) {
    .recipe-grid { grid-template-columns: 1fr; }
    .tab-item { padding: 8px 11px; min-width: 46px; font-size: 9px; }
}

/* Theme contrast fixes */
.btn-secondary,
.custom-file-upload,
.filter-open-btn,
.cat-chip-modal,
.filter-chip,
.exclude-chip {
    background: var(--surface, var(--bg-card)) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

.btn-secondary:hover,
.custom-file-upload:hover,
.filter-open-btn:hover {
    background: var(--input-bg, var(--bg)) !important;
}

.form-container,
.cat-modal,
.filter-modal,
.result-card,
.recipe-card,
.lab-card {
    color: var(--text);
}

.form-container input,
.search-filter-row input[type="search"],
.search-box input {
    background-color: var(--input-bg, var(--bg)) !important;
    color: var(--text) !important;
    border-color: var(--border) !important;
}

.form-container input::placeholder,
.search-filter-row input::placeholder,
.search-box input::placeholder {
    color: var(--text-muted) !important;
    opacity: 0.85;
}

.cart-item,
.dialog-row {
    border-color: var(--border) !important;
}

.cat-badge {
    background: rgba(0, 0, 0, 0.68) !important;
    color: #fff !important;
}

.time-tag {
    background: color-mix(in srgb, var(--bg-card) 88%, #fff 12%) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
}

@supports not (background: color-mix(in srgb, #000 50%, #fff 50%)) {
    .time-tag {
        background: var(--bg-card) !important;
    }
}

/* =====================================================
   2026 UI REFRESH — adaptive iOS-like interface
   ===================================================== */
:root {
  --app-max: 1180px;
  --mobile-bar-h: 72px;
  --ios-blue: #0a84ff;
  --ios-red: #ff453a;
  --ios-green: #30d158;
  --panel-blur: blur(22px) saturate(180%);
}
html, body { min-width: 0; overflow-x: clip; }
body { background-image: radial-gradient(circle at 20% -10%, rgba(255,255,255,.72), transparent 34rem); }
.container-ios { width: min(var(--app-max), calc(100% - 32px)); margin-inline: auto; }
.page-margin { padding-block: clamp(20px, 3vw, 38px) 110px; }
.form-card,.cart-card,.profile-card,.recipe-detail-card,.dialogs-card,.level-card,.orders-stat-card,.achievements,.leaderboard,.cal-card {
  border: 1px solid color-mix(in srgb, var(--border) 75%, white 25%);
  box-shadow: 0 14px 42px rgba(20,18,16,.08);
}
.btn-ios { min-height: 44px; border-radius: 14px; font-weight: 700; display:inline-flex; align-items:center; justify-content:center; gap:8px; }
.btn-primary { background: var(--accent); color:#fff; border:0; }
.btn-secondary { background: color-mix(in srgb,var(--bg-card) 86%,var(--text) 14%); color:var(--text); border:1px solid var(--border); }
.ios-input,input,textarea,select { max-width:100%; }
img,video,canvas { max-width:100%; }

/* Desktop header */
.ios-header { border-bottom: 1px solid var(--border) !important; box-shadow: 0 1px 18px rgba(0,0,0,.035); }
.header-content { width:min(var(--app-max), calc(100% - 32px)); padding-inline:0; }
.nav-actions { gap:10px; }
.icon-btn,.basket-btn,.auth-link { min-height:42px; border-radius:13px; }

/* iPhone tab bar */
.mobile-tabbar { display:none; }
.tab-item .tab-icon { width:24px; height:24px; display:grid; place-items:center; }
.tab-item .tab-icon svg { width:23px; height:23px; stroke:currentColor; fill:none; stroke-width:1.9; }

/* Cart */
.cart-card { max-width:760px; margin-inline:auto; padding:clamp(18px,3vw,30px); border-radius:28px; }
.cart-header { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom:18px; }
.cart-list { display:grid; gap:10px; }
.cart-item { display:flex; align-items:center; gap:14px; padding:12px; border-radius:18px; background:color-mix(in srgb,var(--bg-card) 80%,transparent); border:1px solid var(--border); }
.cart-item-info { min-width:0; flex:1; display:flex; align-items:center; gap:13px; }
.cart-item-img { width:68px; height:68px; border-radius:15px; object-fit:cover; flex:0 0 auto; }
.cart-item-title { min-width:0; overflow:hidden; text-overflow:ellipsis; font-size:15px; font-weight:700; }
.cart-delete-btn { width:42px; height:42px; flex:0 0 42px; border:0; border-radius:50%; display:grid; place-items:center; color:var(--ios-red); background:rgba(255,69,58,.11); }
.cart-footer { position:sticky; bottom:12px; margin-top:18px; padding:12px; border-radius:20px; background:color-mix(in srgb,var(--bg-card) 88%,transparent); backdrop-filter:var(--panel-blur); border:1px solid var(--glass-border); box-shadow:0 16px 36px rgba(0,0,0,.14); }
.order-submit-btn { width:100%; }
.empty-cart { min-height:320px; display:grid; place-items:center; align-content:center; gap:12px; text-align:center; }

@media (max-width: 900px) {
  .container-ios { width:min(100% - 24px, 720px); }
  .search-box { display:none; }
}
@media (max-width: 768px) {
  :root { --header-h: 54px; }
  body { padding-top:calc(var(--header-h) + var(--safe-top)); padding-bottom:calc(var(--mobile-bar-h) + 24px + var(--safe-bottom)); }
  .ios-header { height:calc(var(--header-h) + var(--safe-top)); }
  .header-content { height:var(--header-h); width:100%; padding:0 16px; }
  .brand { font-size:17px; }
  .logo-img { width:34px; height:34px; border-radius:10px; }
  .nav-actions .icon-btn,.nav-actions .basket-btn,.nav-actions .auth-link { display:none; }
  .mobile-tabbar {
    display:grid !important; grid-template-columns:repeat(5,1fr); position:fixed; z-index:5000;
    left:12px; right:12px; bottom:calc(10px + var(--safe-bottom));
    min-width:0 !important; max-width:none !important; width:auto !important;
    height:var(--mobile-bar-h); padding:7px 8px; gap:2px;
    background:color-mix(in srgb,var(--nav-bg) 82%,transparent) !important;
    -webkit-backdrop-filter:var(--panel-blur); backdrop-filter:var(--panel-blur);
    border:1px solid rgba(255,255,255,.38); border-radius:25px;
    box-shadow:0 18px 50px rgba(0,0,0,.22), inset 0 1px rgba(255,255,255,.34);
  }
  .mobile-tabbar::before { display:none !important; }
  .tab-item { position:relative; min-width:0; height:58px; padding:6px 2px; border:0; border-radius:18px; background:transparent; color:var(--text-muted) !important; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px; font-size:10px; font-weight:650; text-decoration:none; }
  .tab-item.active { color:var(--accent) !important; background:color-mix(in srgb,var(--accent) 12%,transparent); }
  .tab-item.active .tab-icon { transform:translateY(-1px); }
  .tab-item .tab-icon { font-size:0; }
  .chat-badge,.cart-badge { top:2px !important; right:16% !important; }
  .page-margin { padding-top:14px; padding-bottom:24px; }
  .container-ios { width:100%; padding-inline:12px; }
  .form-card,.profile-card,.recipe-detail-card,.cart-card { border-radius:22px; padding:18px 14px; }
  .cart-card { border:none; box-shadow:none; background:transparent; padding-inline:0; }
  .cart-item { padding:10px; border-radius:17px; }
  .cart-item-img { width:60px; height:60px; }
  .cart-footer { bottom:calc(var(--mobile-bar-h) + 20px + var(--safe-bottom)); }
  .recipe-grid { grid-template-columns:repeat(2,minmax(0,1fr)) !important; gap:10px !important; }
  .recipe-card { min-width:0; }
  .card-image { height:145px !important; }
  .form-title { font-size:24px; }
}
@media (max-width: 390px) {
  .mobile-tabbar { left:8px; right:8px; border-radius:23px; padding-inline:5px; }
  .tab-item { font-size:9px; }
  .recipe-grid { grid-template-columns:1fr !important; }
  .card-image { height:210px !important; }
  .cart-item-img { width:54px; height:54px; }
}
@media (min-width: 769px) and (max-width: 1100px) {
  .recipe-grid { grid-template-columns:repeat(3,minmax(0,1fr)); }
}


/* =====================================================
   MOBILE APP PERFORMANCE PATCH — no layout thrashing
   ===================================================== */
@media (max-width: 768px) {
  html { scroll-behavior: auto !important; }
  body {
    padding-top: calc(54px + var(--safe-top)) !important;
    padding-bottom: calc(74px + var(--safe-bottom)) !important;
    overscroll-behavior-y: none;
    background-image: none !important;
  }

  /* Fixed, lightweight app chrome. Blur on a large fixed layer causes
     visible jank in iOS Safari while navigating and scrolling. */
  .ios-header {
    display: block !important;
    height: calc(54px + var(--safe-top)) !important;
    background: var(--bg) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    contain: layout paint;
  }
  .header-content { height: 54px !important; }

  .mobile-tabbar {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    height: calc(64px + var(--safe-bottom)) !important;
    padding: 5px 8px calc(5px + var(--safe-bottom)) !important;
    margin: 0 !important;
    transform: none !important;
    border: 0 !important;
    border-top: 1px solid var(--border) !important;
    border-radius: 0 !important;
    background: var(--nav-bg) !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: 0 -5px 18px rgba(0,0,0,.06) !important;
    overflow: visible !important;
    contain: layout paint style;
    will-change: auto !important;
  }
  .mobile-tabbar::before,
  .mobile-tabbar::after { display: none !important; content: none !important; }

  .tab-item {
    height: 54px !important;
    min-width: 0 !important;
    padding: 5px 2px 3px !important;
    border-radius: 12px !important;
    transform: none !important;
    transition: background-color .12s linear, color .12s linear !important;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
  }
  .tab-item:active {
    transform: none !important;
    background: color-mix(in srgb, var(--accent) 10%, transparent) !important;
    opacity: .72;
  }
  .tab-item.active {
    color: var(--accent) !important;
    background: transparent !important;
  }
  .tab-item.active .tab-icon { transform: none !important; }
  .tab-icon { filter: none !important; transform: none !important; }

  /* Never animate the whole document when opening another PHP page. */
  body.app-leaving main,
  body.app-leaving .container-ios,
  body.app-leaving .mobile-tabbar {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  main, .container-ios, .form-card, .cart-card, .profile-card,
  .recipe-card, .cart-item, .tab-item {
    backface-visibility: visible !important;
    will-change: auto !important;
  }

  .form-card, .cart-card, .profile-card, .recipe-detail-card,
  .cart-footer, .cat-modal, .form-container {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }

  .page-margin { padding-bottom: 18px !important; }
  .cart-footer { bottom: calc(72px + var(--safe-bottom)) !important; }
}

@media (prefers-reduced-motion: reduce), (max-width: 768px) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none !important; }
}
