/* =====================================================================
   DESIGN SYSTEM — shared restaurant app styles
   Base tokens, resets and shared primitives used by every screen.
   ===================================================================== */

:root {
    /* Brand */
    --brand: #b42332;
    --brand-dark: #861f2b;
    --brand-light: #d94a55;
    --brand-soft: #f8e9e8;
    --accent: #d9a441;
    --accent-dark: #b78324;

    /* Neutrals */
    --bg: #f7f4ef;
    --surface: #ffffff;
    --surface-2: #fbf9f6;
    --ink: #292522;
    --ink-2: #625b55;
    --muted: #817972;
    --line: #e9e3dc;

    /* Feedback */
    --success: #25815d;
    --success-soft: #e7f3ec;
    --danger: #b42332;

    /* Elevation */
    --shadow-sm: 0 2px 8px rgba(43, 34, 28, .05);
    --shadow-md: 0 10px 28px rgba(43, 34, 28, .09);
    --shadow-lg: 0 20px 48px rgba(43, 34, 28, .16);

    /* Radii */
    --r-sm: 10px;
    --r-md: 16px;
    --r-lg: 22px;
    --r-pill: 999px;

    /* Full-width responsive layout: no centered phone frame */
    --frame: 100%;
}

@media (min-width: 768px) {
    :root {
        --frame: min(100%, 1480px);
    }

    .app-frame {
        max-width: 100%;
        box-shadow: none;
    }

    .welcome-content,
    .loading-panel,
    .status-card,
    .notfound-screen > * {
        max-width: min(92vw, 760px);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }

#app { min-height: 100vh; min-height: 100dvh; }

/* Center the mobile frame on desktop */
.app-frame {
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
    background: var(--bg);
    position: relative;
    box-shadow: none;
}

@media (min-width: 768px) {
    .app-frame {
        border-radius: 0;
        overflow: visible;
    }
}

/* -------- Shared buttons -------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: var(--r-md);
    font-weight: 700;
    cursor: pointer;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
    line-height: 1;
}
.btn:active { transform: scale(.98); }

.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: 0 8px 18px rgba(134, 31, 43, .2);
}
.btn-primary:hover { background: var(--brand-dark); }

.btn-block { width: 100%; min-height: 54px; padding: 0 20px; }

.btn-ghost {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
}

/* -------- Toast / feedback -------- */
.toast {
    position: fixed;
    z-index: 60;
    left: 50%;
    bottom: 96px;
    transform: translateX(-50%);
    width: min(calc(100% - 32px), 440px);
    padding: 14px 18px;
    border-radius: var(--r-md);
    background: var(--ink);
    color: #fff;
    text-align: center;
    font-size: .86rem;
    font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: toast-in .22s ease both;
}

/* Shared responsive refinements */
button, a, input, select, textarea {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--brand) 35%, transparent);
    outline-offset: 3px;
}

.app-shell { background: var(--bg); }
.topbar {
    background: rgba(255, 255, 255, .9);
    border-color: var(--line);
    box-shadow: var(--shadow-sm);
}
.brand-mark {
    background: linear-gradient(135deg, var(--brand), var(--accent));
    box-shadow: 0 10px 22px rgba(134, 31, 43, .2);
}
.brand-name { color: var(--ink); }
.brand-subtitle { color: var(--muted); }
.page-message {
    background: var(--surface);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-md);
}
.page-message p { color: var(--muted); }
.status-card {
    width: min(calc(100% - 32px), 720px);
    border: 1px solid var(--line);
}
.feature-card, .hero-card {
    border-color: var(--line);
    box-shadow: var(--shadow-sm);
}

@media (min-width: 768px) {
    .welcome-content {
        width: min(100% - 48px, 680px);
        padding: 56px;
        border: 1px solid rgba(255, 255, 255, .14);
        border-radius: 32px;
        background: rgba(35, 27, 23, .28);
        backdrop-filter: blur(8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* -------- Generic app header (red top bar) -------- */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 44px 1fr 44px;
    align-items: center;
    gap: 10px;
    padding: max(16px, env(safe-area-inset-top)) 16px 14px;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
}
.app-topbar .tb-title { text-align: center; min-width: 0; }
.app-topbar .tb-title h1 { font-size: 1.02rem; font-weight: 800; letter-spacing: .01em; }
.app-topbar .tb-title p { margin-top: 2px; font-size: .68rem; opacity: .85; }

.tb-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: var(--r-pill);
    background: rgba(255, 255, 255, .16);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background .12s ease;
}
.tb-icon:hover { background: rgba(255, 255, 255, .28); }

/* -------- Loading & welcome (kept, restyled) -------- */
.loading-screen {
    position: fixed; inset: 0; z-index: 20; overflow: hidden; color: #fff;
    display: flex; align-items: center; justify-content: center;
    background: #211d1a url('../images/background_coffee.jpg') center / cover no-repeat;
}
.loading-overlay { position: absolute; inset: 0; z-index: 0; background: linear-gradient(180deg, rgba(18,15,13,.35) 0%, rgba(13,10,9,.85) 100%); }
.loading-panel {
    position: relative; z-index: 1; width: min(calc(100% - 40px), 430px);
    padding: 28px 22px 22px; border-radius: var(--r-lg);
    background: rgba(20,17,16,.92); text-align: center; box-shadow: var(--shadow-lg);
    animation: rise-in .5s ease both;
}
.loading-cup { width: 54px; height: 54px; margin: 0 auto 16px; display: grid; place-items: center; font-size: 1.8rem; background: var(--brand); border-radius: 50%; animation: loading-cup-pulse 1.4s ease-in-out infinite; }
.loading-panel p { color: rgba(255,255,255,.92); font-size: .95rem; font-weight: 700; line-height: 1.4; }
.loading-line { position: relative; width: 74%; height: 4px; margin: 22px auto 14px; overflow: hidden; border-radius: 4px; background: rgba(255,255,255,.18); }
.loading-line::after { content: ''; position: absolute; left: 0; top: 0; display: block; width: 40%; height: 100%; border-radius: 4px; background: var(--accent); animation: loading-progress 1.4s ease-in-out infinite; }
.loading-panel span { font-size: .74rem; color: rgba(255,255,255,.85); }
@keyframes loading-progress {
    0%   { left: -40%; }
    100% { left: 100%; }
}
@keyframes loading-cup-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes rise-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.welcome-screen {
    position: fixed; inset: 0; z-index: 15;
    width: 100%; min-height: 100vh; min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; color: #fff;
    background: #27231f url('../images/background_coffee.jpg') center / cover no-repeat;
}
.welcome-overlay { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(20,16,13,.15) 25%, rgba(13,10,9,.9) 100%); }
.welcome-content {
    position: relative; z-index: 1; display: grid; grid-template-rows: 1fr auto 1fr; align-items: center;
    width: min(100%, 640px); min-height: 100vh; min-height: 100dvh; box-sizing: border-box;
    padding: clamp(28px, 7vw, 64px) clamp(24px, 6vw, 56px) max(42px, calc(18px + env(safe-area-inset-bottom)));
    text-align: center; animation: welcome-fade .25s ease both;
}
.welcome-branding {
    grid-row: 1; align-self: end; padding: 0 24px 32px;
}
.welcome-mark { width: 64px; height: 64px; margin: 0 auto 22px; display: grid; place-items: center; border-radius: 50%; background: var(--brand); font-size: 1.8rem; box-shadow: 0 10px 26px rgba(134,31,43,.24); }
.welcome-kicker { margin: 0 0 12px; color: var(--accent); font-size: .7rem; font-weight: 800; letter-spacing: .18em; }
.welcome-content h1 { margin: 0 0 16px; font-size: clamp(2.5rem, 12vw, 4rem); letter-spacing: .08em; font-weight: 800; line-height: 1; }
.welcome-copy { margin: 0; color: rgba(255,255,255,.85); line-height: 1.6; }
.welcome-content > .welcome-button {
    grid-row: 2; justify-self: center; position: relative; width: min(100%, 420px); height: 58px; margin: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
    box-sizing: border-box; text-align: center;
    border: 0; border-radius: var(--r-md); background: var(--brand); color: #fff; font-weight: 800; font-size: 1rem;
    cursor: pointer; box-shadow: 0 10px 24px rgba(134,31,43,.24);
}
.welcome-button span { position: absolute; right: 20px; font-size: 1.2rem; }
.welcome-content > .welcome-button:active { filter: brightness(.92); }

@media (max-height: 620px) {
    .welcome-branding { padding-bottom: 20px; }
    .welcome-mark { width: 48px; height: 48px; margin-bottom: 12px; font-size: 1.4rem; }
    .welcome-kicker { margin-bottom: 7px; }
    .welcome-content h1 { margin-bottom: 10px; }
    .welcome-copy { font-size: .88rem; }
}

@keyframes welcome-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* -------- 404 / mesa inválida -------- */
.notfound-screen {
    position: fixed; inset: 0; z-index: 15;
    display: grid; place-items: center; text-align: center;
    padding: 32px; color: #fff;
    background:
        radial-gradient(circle at 50% 30%, rgba(225, 27, 34, .35), transparent 55%),
        linear-gradient(160deg, #2a2320 0%, #171310 100%);
}
.notfound-screen > * { position: relative; z-index: 1; }
.notfound-screen .notfound-code {
    font-size: clamp(5rem, 22vw, 9rem);
    font-weight: 900;
    line-height: 1;
    color: var(--brand);
    text-shadow: 0 8px 30px rgba(225, 27, 34, .5);
    letter-spacing: .04em;
}
.notfound-screen h1 { margin: 8px 0 14px; font-size: 1.5rem; font-weight: 800; }
.notfound-screen p {
    max-width: 340px; margin: 0 auto;
    color: rgba(255, 255, 255, .8); line-height: 1.6; font-size: .95rem;
}

/* -------- Simple status cards (mesa flow) -------- */
.status-card {
    max-width: var(--frame); margin: 40px auto; background: var(--surface);
    border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 32px 24px; text-align: center;
}
.status-card .inline-badge {
    display: inline-flex; background: var(--brand-soft); color: var(--brand-dark);
    padding: 8px 14px; border-radius: var(--r-pill); font-weight: 700; margin-bottom: 16px; font-size: .8rem;
}
.status-card h3 { font-size: 1.5rem; margin-bottom: 10px; }
.status-card p { color: var(--muted); line-height: 1.6; }
.status-card.success .inline-badge { background: var(--success-soft); color: var(--success); }
.status-card.error .inline-badge { background: var(--brand-soft); color: var(--danger); }

/* =====================================================================
   CART BUTTON (badge no header) + CART PREVIEW (drawer inferior)
   ===================================================================== */
.cart-button-wrap { position: relative; display: flex; justify-content: flex-end; }

.cart-button {
    position: relative;
    display: grid; place-items: center;
    width: 44px; height: 44px;
    border-radius: var(--r-pill);
    background: #fff; color: var(--brand);
    cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
    transition: background .12s ease, transform .12s ease;
}
.cart-button:hover { background: var(--brand-soft); }
.cart-icon { font-size: 1.25rem; line-height: 1; }
.cart-count {
    position: absolute; top: -4px; right: -4px;
    display: grid; place-items: center;
    min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: var(--r-pill); border: 2px solid var(--brand);
    background: var(--accent); color: var(--ink); font-size: .66rem; font-weight: 800;
}
.cart-count.pulse { animation: badge-pop 420ms ease; }
@keyframes badge-pop { 0% { transform: scale(.9); } 50% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* Drawer */
.cart-preview {
    position: fixed; z-index: 1002; left: 50%; bottom: 0;
    width: min(100%, var(--frame));
    max-height: min(84dvh, 700px);
    transform: translate(-50%, 100%);
    background: var(--surface);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .22);
    transition: transform .28s cubic-bezier(.22, 1, .36, 1);
    display: flex; flex-direction: column;
    overflow: hidden;
    opacity: 0; pointer-events: none;
}
.cart-preview.open { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }

.cart-preview-header {
    display: grid; grid-template-columns: 36px 1fr 36px; align-items: center;
    padding: 16px; border-bottom: 1px solid var(--line);
}
.cart-preview-header > div { text-align: center; }
.cart-preview-header strong { display: block; font-size: 1rem; font-weight: 800; }
.cart-preview-header small { color: var(--muted); font-size: .72rem; }
.cart-preview-back, .cart-preview .close {
    display: grid; place-items: center;
    width: 36px; height: 36px; border: 0; border-radius: var(--r-pill);
    background: var(--surface-2); color: var(--ink); cursor: pointer;
}
.cart-preview-back { font-size: 1.5rem; }
.cart-preview .close { font-size: .9rem; }

.cart-empty {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    padding: 48px 24px; text-align: center; color: var(--muted);
}
.cart-empty strong { color: var(--ink); font-size: 1rem; }
.cart-empty-icon {
    display: grid; place-items: center; width: 64px; height: 64px;
    border-radius: 50%; background: var(--brand-soft); font-size: 1.6rem;
}

.cart-items { flex: 1; overflow-y: auto; padding: 8px 16px; }
.cart-item {
    display: grid; grid-template-columns: 48px 1fr auto; grid-template-areas: 'thumb main side' 'thumb qty side';
    align-items: center; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--line);
}
.cart-item:last-child { border-bottom: 0; }
.cart-item-thumb {
    grid-area: thumb; display: grid; place-items: center; width: 48px; height: 48px;
    border-radius: var(--r-sm); background: var(--brand-soft); color: var(--brand); font-size: 1.3rem;
}
.cart-item-main { grid-area: main; min-width: 0; }
.cart-item-name { font-size: .9rem; font-weight: 800; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-item-main small { color: var(--muted); font-size: .74rem; }
.cart-item-qty {
    grid-area: qty; justify-self: start; display: flex; align-items: center; gap: 10px;
    padding: 4px 8px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface-2);
}
.cart-item-qty button {
    display: grid; place-items: center; width: 24px; height: 24px; border: 0; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand); font-size: 1rem; cursor: pointer;
}
.cart-item-qty button:hover { background: var(--brand); color: #fff; }
.cart-item-side { grid-area: side; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.cart-item-sub { color: var(--brand); font-size: .95rem; font-weight: 800; }
.cart-item-remove { border: 0; background: transparent; color: var(--muted); font-size: .72rem; cursor: pointer; }
.cart-item-remove:hover { color: var(--danger); }

.cart-preview-footer { padding: 16px; border-top: 1px solid var(--line); background: var(--surface); }
.cart-totals { display: grid; grid-template-columns: 1fr auto; gap: 6px; color: var(--muted); font-size: .84rem; }
.cart-totals strong { text-align: right; color: var(--ink); }
.cart-totals strong:last-child { color: var(--brand); font-size: 1.1rem; }
.cart-checkout {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    min-height: 54px; margin-top: 14px; padding: 0 20px;
    border-radius: var(--r-md); background: var(--brand); color: #fff; font-weight: 800;
    box-shadow: 0 8px 20px rgba(134, 31, 43, .22); transition: background .12s ease;
}
.cart-checkout:hover { background: var(--brand-dark); }
.cart-checkout span { font-size: 1.2rem; }

/* =====================================================================
   MODAL de produto (ProductModal)
   ===================================================================== */
.modal-backdrop { position: fixed; inset: 0; z-index: 1200; background: rgba(15, 15, 20, .55); }
.modal-sheet {
    position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
    width: min(100%, var(--frame)); background: var(--surface);
    border-radius: 22px 22px 0 0; overflow: hidden; box-shadow: var(--shadow-lg);
}
.modal-image { width: 100%; height: 220px; display: grid; place-items: center; background: var(--surface-2); }
.modal-image img { width: 100%; height: 100%; object-fit: cover; }
.modal-body { padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); }
.modal-body h3 { font-size: 1.3rem; font-weight: 800; margin-bottom: 8px; }
.modal-desc { color: var(--muted); line-height: 1.6; font-size: .9rem; }
.modal-price { color: var(--brand); font-size: 1.6rem; font-weight: 800; margin-top: 16px; }
.modal-actions { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.modal-actions .quant {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill);
}
.modal-actions .quant button {
    display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%;
    background: var(--brand-soft); color: var(--brand); font-size: 1.3rem; cursor: pointer;
}
.modal-actions .quant span { min-width: 24px; text-align: center; font-weight: 800; }
.modal-actions .btn-adicionar {
    flex: 1; min-height: 52px; border: 0; border-radius: var(--r-md);
    background: var(--brand); color: #fff; font-weight: 800; cursor: pointer;
    box-shadow: 0 8px 20px rgba(134, 31, 43, .22);
}
.modal-close { display: block; width: 100%; margin-top: 14px; border: 0; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }

@media (min-width: 768px) {
    .cart-preview {
        left: auto;
        right: max(24px, calc((100vw - 1400px) / 2));
        width: min(calc(100% - 48px), 620px);
        transform: translateY(100%);
        border-radius: var(--r-lg);
        bottom: 24px;
    }
    .cart-preview.open { transform: translateY(0); }
    .modal-sheet {
        top: 50%;
        bottom: auto;
        width: min(calc(100% - 48px), 560px);
        max-height: min(90dvh, 820px);
        transform: translate(-50%, -50%);
        border-radius: 24px;
        overflow-y: auto;
    }
    .modal-image { height: 280px; }
}

/* =====================================================================
   CATEGORIAS (lista inicial)
   ===================================================================== */
.categorias-container {
    width: 100%; max-width: var(--frame); min-height: 100vh; min-height: 100dvh;
    margin: 0 auto; padding-bottom: 40px; background: var(--bg);
}
.categorias-container .produto-card {
    max-width: var(--frame); margin: 40px auto; padding: 32px 24px; text-align: center;
    background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-md);
}
.categorias-container .titulo {
    margin: 0 -0 0; padding: max(20px, env(safe-area-inset-top)) 16px 20px;
    font-size: 1.4rem; font-weight: 800; color: #fff;
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
    border-radius: 0 0 20px 20px;
}
.categorias-list { display: flex; flex-direction: column; gap: 16px; padding: 20px 16px; }
.categoria-hero {
    position: relative; display: flex; align-items: stretch; overflow: hidden; cursor: pointer;
    min-height: 130px; border-radius: var(--r-md);
    background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
    transition: transform .12s ease, box-shadow .12s ease;
}
.categoria-hero:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.categoria-hero-image { flex: 0 0 42%; background-size: cover; background-position: center; background-color: var(--brand-soft); }
.categoria-hero-body { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 20px; }
.categoria-hero-title { font-size: 1.25rem; font-weight: 800; color: var(--ink); }
.categoria-hero-sub {
    margin-top: 8px; display: inline-flex; align-items: center; gap: 6px;
    color: var(--brand); font-weight: 700; font-size: .84rem;
}
.categoria-hero-sub::after { content: '→'; }

@media (min-width: 700px) {
    .categorias-list {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
        width: min(100%, 1200px);
        margin: 0 auto;
        padding: 28px 24px;
        gap: 20px;
    }
    .categoria-hero { min-height: 170px; }
}
