:root {
    --primary: #e85d04;
    --primary-dark: #d00000;
    --primary-light: #ffba08;
    --bg: #faf8f5;
    --bg-card: #ffffff;
    --text: #1a1a2e;
    --text-muted: #6c757d;
    --border: #e9ecef;
    --success: #2d6a4f;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --radius: 16px;
    --header-height: 64px;
    --cart-width: 380px;
}

[data-theme="dark"] {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --text: #f8f9fa;
    --text-muted: #adb5bd;
    --border: #2d2d44;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
    padding-bottom: 100px;
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    color: white;
    padding: 0.75rem 1rem;
    box-shadow: 0 2px 12px rgba(208, 0, 0, 0.3);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.header-start {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    flex: 1;
}

.btn-back-header {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: white;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.45rem 0.75rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    transition: background 0.2s;
}

.btn-back-header:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon {
    width: 42px;
    height: 42px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.brand h1 {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
}

.brand small {
    font-size: 0.75rem;
    opacity: 0.85;
}

.mesa-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.4rem 1rem;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.9rem;
    backdrop-filter: blur(4px);
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Search & Filters */
.search-section {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 1rem;
}

.search-box {
    position: relative;
    margin-bottom: 1rem;
}

.search-box input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.75rem;
    border: 2px solid var(--border);
    border-radius: 50px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-box i {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.categories-scroll {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
}

.categories-scroll::-webkit-scrollbar {
    display: none;
}

.category-chip {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    border: 2px solid var(--border);
    border-radius: 50px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.category-chip:hover,
.category-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.category-chip i {
    margin-right: 0.35rem;
}

/* Main content */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 1.5rem 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title i {
    color: var(--primary);
}

/* Products grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.product-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.product-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--border);
}

.product-badges {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    display: flex;
    gap: 0.35rem;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-destaque {
    background: var(--primary-light);
    color: #1a1a2e;
}

.badge-promo {
    background: var(--primary-dark);
    color: white;
}

.product-body {
    padding: 1rem;
}

.product-category {
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.product-name {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0.25rem 0;
}

.product-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.product-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.product-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.product-price {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--primary);
}

.product-price-old {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: line-through;
    margin-left: 0.35rem;
}

.btn-add {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-add:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(232, 93, 4, 0.4);
}

/* Cart FAB */
.cart-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    border-radius: 50px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(208, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    z-index: 900;
    transition: transform 0.2s;
}

.cart-fab:hover {
    transform: scale(1.05);
}

.cart-fab.hidden {
    display: none;
}

.cart-count {
    background: white;
    color: var(--primary-dark);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 800;
}

/* Cart drawer */
.cart-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1100;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.cart-overlay.open {
    opacity: 1;
    visibility: visible;
}

.cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    max-width: var(--cart-width);
    height: 100%;
    background: var(--bg-card);
    z-index: 1200;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.cart-drawer.open {
    transform: translateX(0);
}

.cart-header {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cart-header h2 {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.cart-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--bg);
    border-radius: 12px;
    margin-bottom: 0.75rem;
}

.cart-item-img {
    width: 70px;
    height: 70px;
    border-radius: 10px;
    object-fit: cover;
}

.cart-item-info {
    flex: 1;
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.cart-item-price {
    color: var(--primary);
    font-weight: 700;
    font-size: 0.9rem;
}

.cart-item-obs {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-style: italic;
}

.qty-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    color: var(--text);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qty-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.qty-value {
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}

.cart-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.cart-empty i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.cart-footer {
    padding: 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.cart-total {
    display: flex;
    justify-content: space-between;
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 1rem;
}

.cart-total span:last-child {
    color: var(--primary);
}

.observacoes-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.9rem;
    margin-bottom: 1rem;
    resize: none;
}

.observacoes-input:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-primary:hover {
    transform: scale(1.02);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    max-width: 420px;
    width: 100%;
    padding: 2rem;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.open .modal-content {
    transform: scale(1);
}

.modal-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #2d6a4f, #40916c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 2.5rem;
    color: white;
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* Loading */
.loading {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast */
.toast-container {
    position: fixed;
    top: 80px;
    right: 1rem;
    z-index: 3000;
}

.toast {
    background: var(--bg-card);
    border-left: 4px solid var(--primary);
    padding: 1rem 1.25rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin-bottom: 0.5rem;
    animation: slideIn 0.3s ease;
    max-width: 320px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--primary-dark); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive — todos os dispositivos */
@media (max-width: 479px) {
    body {
        padding-bottom: max(100px, calc(80px + env(safe-area-inset-bottom)));
    }

    .app-header {
        padding: max(0.65rem, env(safe-area-inset-top)) 0.85rem 0.65rem;
    }

    .header-content {
        flex-wrap: wrap;
        gap: 0.65rem;
    }

    .header-start {
        flex: 1 1 auto;
        min-width: 0;
    }

    .btn-back-text { display: none; }

    .brand h1 { font-size: 0.9rem; }
    .brand-icon { width: 38px; height: 38px; font-size: 1.2rem; }
    .brand small { font-size: 0.68rem; }

    .mesa-badge {
        font-size: 0.8rem;
        padding: 0.35rem 0.75rem;
        order: 3;
        margin-left: auto;
    }

    .header-actions {
        order: 2;
    }

    .btn-icon {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    .search-section { padding: 0 0.85rem; }

    .search-box input {
        font-size: 16px; /* evita zoom no iOS */
        padding: 0.8rem 1rem 0.8rem 2.5rem;
        min-height: 48px;
    }

    .category-chip {
        padding: 0.55rem 0.9rem;
        min-height: 44px;
        font-size: 0.8rem;
    }

    .main-content { padding: 0 0.85rem 1.5rem; }

    .section-title { font-size: 1.1rem; margin: 1.25rem 0 0.85rem; }

    .products-grid {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .product-image { height: 160px; }

    .product-footer {
        flex-wrap: wrap;
        gap: 0.65rem;
    }

    .btn-add {
        min-height: 44px;
        padding: 0.65rem 1.1rem;
        flex: 1;
        justify-content: center;
    }

    .cart-fab {
        bottom: max(1rem, env(safe-area-inset-bottom));
        right: 1rem;
        left: 1rem;
        justify-content: center;
        min-height: 52px;
        padding: 0.85rem 1.25rem;
    }

    .cart-drawer {
        max-width: 100%;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .qty-btn {
        width: 44px;
        height: 44px;
    }

    .toast-container {
        top: auto;
        bottom: max(5.5rem, calc(4.5rem + env(safe-area-inset-bottom)));
        right: 0.85rem;
        left: 0.85rem;
    }

    .toast {
        max-width: 100%;
    }
}

@media (min-width: 480px) and (max-width: 767px) {
    .products-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cart-fab {
        bottom: max(1.25rem, env(safe-area-inset-bottom));
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .products-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    }
}

@media (max-height: 500px) and (orientation: landscape) {
    .cart-drawer {
        max-width: min(420px, 85vw);
    }

    .product-image { height: 130px; }
}

@media (hover: none) and (pointer: coarse) {
    .product-card:hover { transform: none; }
    .product-card:active { transform: scale(0.98); }
    .btn-add:hover { transform: none; }
    .cart-fab:hover { transform: none; }

    .btn-add,
    .cart-fab,
    .category-chip,
    .qty-btn,
    .btn-back-header {
        -webkit-tap-highlight-color: transparent;
    }
}

@supports (padding: max(0px)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}
