:root {
    --primary: #8b2d3a;
    --primary-dark: #5c1c26;
    --primary-light: #c4a574;
    --bg: #f7f3ec;
    --bg-card: #ffffff;
    --text: #1c1210;
    --text-muted: #6b5e55;
    --border: #e8e0d4;
    --success: #2d6a4f;
    --shadow: 0 8px 30px rgba(28, 18, 16, 0.06);
    --radius: 12px;
    --header-height: 64px;
    --cart-width: 400px;
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'Outfit', system-ui, sans-serif;
}

[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: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background 0.3s, color 0.3s;
    padding-bottom: 100px;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: #1c1210;
    color: #f4efe6;
    padding: 0.85rem 1.15rem;
    border-bottom: 1px solid rgba(196, 165, 116, 0.28);
}

.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: #f4efe6;
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    padding: 0.45rem 0.75rem;
    border-radius: 2px;
    background: rgba(244, 239, 230, 0.08);
    border: 1px solid rgba(196, 165, 116, 0.2);
    flex-shrink: 0;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    transition: background 0.2s;
}

.btn-back-header:hover {
    background: rgba(244, 239, 230, 0.14);
    color: #f4efe6;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: transparent;
    border: 1px solid var(--primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--primary-light);
}

.brand h1 {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    line-height: 1.15;
}

.brand small {
    font-size: 0.68rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0.7;
    color: var(--primary-light);
}

.mesa-badge {
    background: transparent;
    border: 1px solid rgba(196, 165, 116, 0.4);
    color: var(--primary-light);
    padding: 0.35rem 0.95rem;
    border-radius: 2px;
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid rgba(196, 165, 116, 0.2);
    background: rgba(244, 239, 230, 0.08);
    color: #f4efe6;
    border-radius: 2px;
    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: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.search-box input[type="search"]::-webkit-search-decoration,
.search-box input[type="search"]::-webkit-search-cancel-button,
.search-box input[type="search"]::-webkit-search-results-button,
.search-box input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-light);
}

.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: 1px solid var(--border);
    border-radius: 2px;
    background: var(--bg-card);
    color: var(--text);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.category-chip:hover,
.category-chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #f4efe6;
}

.category-chip i {
    margin-right: 0.35rem;
}

/* Main content */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem 2rem;
}

.section-title {
    font-family: var(--font-display);
    font-size: 1.55rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-title i {
    color: var(--primary-light);
}

/* 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);
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
}

.product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 36px rgba(28, 18, 16, 0.1);
}

.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.22rem 0.55rem;
    border-radius: 2px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.badge-destaque {
    background: var(--primary-light);
    color: #1c1210;
}

.badge-promo {
    background: var(--primary);
    color: #f4efe6;
}

.product-body {
    padding: 1rem;
}

.product-category {
    font-size: 0.68rem;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.product-name {
    font-family: var(--font-display);
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0.2rem 0 0.35rem;
    line-height: 1.25;
}

.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.1rem;
    font-weight: 700;
    color: var(--text);
}

.product-price-old {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-decoration: line-through;
    margin-left: 0.35rem;
}

.btn-add {
    background: var(--primary);
    color: #f4efe6;
    border: none;
    padding: 0.55rem 1.05rem;
    border-radius: 2px;
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: transform 0.2s, background 0.2s;
}

.btn-add:hover {
    transform: translateY(-1px);
    background: var(--primary-dark);
}

/* Cart FAB */
.cart-fab {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: #1c1210;
    color: #f4efe6;
    border: 1px solid var(--primary-light);
    padding: 1rem 1.5rem;
    border-radius: 2px;
    font-weight: 600;
    font-size: 0.85rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(28, 18, 16, 0.28);
    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: var(--primary-light);
    color: #1c1210;
    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-family: var(--font-display);
    font-size: 1.35rem;
    font-weight: 600;
    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: var(--primary);
    color: #f4efe6;
    border: none;
    border-radius: 2px;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.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: 72px;
    height: 72px;
    background: #2d6a4f;
    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-family: var(--font-display);
    font-size: 1.7rem;
    font-weight: 600;
    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);
    }
}

@media (max-width: 359px) {
    .brand h1 { font-size: 0.82rem; max-width: 38vw; }
    .brand small { display: none; }
    .products-grid { grid-template-columns: 1fr; }
    .product-name { font-size: 1.05rem; }
    .cart-fab { font-size: 0.75rem; gap: 0.35rem; padding: 0.75rem 0.9rem; }
}

@media (max-width: 767px) {
    .brand h1,
    .brand small {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .brand div { min-width: 0; }
    .mesa-info-inner { width: 100%; }
    .cart-drawer { max-width: 100%; }
    .modal-content { max-width: 100%; padding: 1.5rem 1.15rem; }
    .search-box input { font-size: 16px; }
}

@media (min-width: 1280px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    }
}
