/* Crossover Smart Restaurant System — shared styles across all 4 apps */

:root {
    --color-bg: #faf9f7;
    --color-surface: #ffffff;
    --color-text: #1c1917;
    --color-text-muted: #78716c;
    --color-border: #e7e5e4;
    --color-primary: #145DA0;
    --color-primary-dark: #0d4172;
    --color-success: #15803d;
    --color-success-bg: #dcfce7;
    --color-warning: #b45309;
    --color-warning-bg: #fef3c7;
    --color-danger: #b91c1c;
    --color-danger-bg: #fee2e2;
    --color-info: #051D40;
    --color-info-bg: #dbeafe;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #1c1917;
        --color-surface: #292524;
        --color-text: #f5f5f4;
        --color-text-muted: #a8a29e;
        --color-border: #44403c;
        --color-success-bg: #052e16;
        --color-warning-bg: #451a03;
        --color-danger-bg: #450a0a;
        --color-info-bg: #172554;
    }
}
:root[data-theme="dark"] {
    --color-bg: #1c1917;
    --color-surface: #292524;
    --color-text: #f5f5f4;
    --color-text-muted: #a8a29e;
    --color-border: #44403c;
    --color-success-bg: #052e16;
    --color-warning-bg: #451a03;
    --color-danger-bg: #450a0a;
    --color-info-bg: #172554;
}

* { box-sizing: border-box; }

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

body {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

img { max-width: 100%; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 16px;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 600;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    background: var(--color-primary);
    color: #fff;
    min-height: 48px;
    touch-action: manipulation;
}
.btn:active { background: var(--color-primary-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.btn-block { width: 100%; }
.btn.btn-secondary { background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-border); }
.btn.btn-success { background: var(--color-success); }
.btn.btn-danger { background: var(--color-danger); }
.btn.btn-lg { min-height: 64px; font-size: 20px; padding: 16px 24px; }

input, select, textarea {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    min-height: 44px;
}

label { font-size: 14px; font-weight: 600; color: var(--color-text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 14px; }

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-new, .badge-pending_payment { background: var(--color-info-bg); color: var(--color-info); }
.badge-paid, .badge-accepted { background: var(--color-info-bg); color: var(--color-info); }
.badge-preparing { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-ready { background: var(--color-success-bg); color: var(--color-success); }
.badge-served, .badge-completed { background: var(--color-border); color: var(--color-text-muted); }
.badge-cancelled, .badge-payment_failed { background: var(--color-danger-bg); color: var(--color-danger); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--color-text-muted); }
.center { text-align: center; }
.hidden { display: none !important; }

.top-bar {
    position: sticky;
    top: 0;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    z-index: 10;
}
.top-bar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.top-bar h1 { font-size: 18px; margin: 0; }

.brand-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-logo img { height: 28px; width: 28px; display: block; }
.brand-logo .brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-logo .brand-sub { font-size: 11px; color: var(--color-text-muted); font-weight: 500; }

.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px; right: 16px;
    max-width: 480px;
    margin: 0 auto;
    background: var(--color-text);
    color: var(--color-bg);
    padding: 14px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 100;
    text-align: center;
}
.toast.toast-error { background: var(--color-danger); color: #fff; }

.grid-cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid-cols-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 480px) {
    .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
}

.auth-screen {
    min-height: 100vh;
    min-height: 100svh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}
.auth-screen::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: linear-gradient(180deg, rgba(5,15,35,0.6) 0%, rgba(5,15,35,0.82) 100%), url('landing/hero-hall.jpg');
    background-size: cover;
    background-position: center;
    z-index: -1;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: 0 24px 64px rgba(0,0,0,0.35);
}
.auth-logo { width: 60px; height: 60px; margin: 0 auto 14px; display: block; border-radius: 14px; }
.auth-title { color: #fff; text-align: center; font-size: 26px; font-weight: 800; margin-bottom: 6px; text-shadow: 0 2px 12px rgba(0,0,0,0.4); }
.auth-subtitle { color: rgba(255,255,255,0.82); text-align: center; font-size: 14px; margin-bottom: 24px; text-shadow: 0 1px 8px rgba(0,0,0,0.4); }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 50;
}
.modal {
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    border-radius: var(--radius) var(--radius) 0 0;
    margin-bottom: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 600px) {
    .modal-backdrop { align-items: center; }
    .modal { border-radius: var(--radius); margin-bottom: 16px; }
}


/* =====================================================================
   RESPONSIVE LAYER (v2) — appended last so it refines the rules above.
   Mobile-first: phones (320px+) → large phones → tablets → laptops → TV/kitchen screens.
   ===================================================================== */

:root {
    --gutter: clamp(12px, 3.5vw, 28px);
    --container: 960px;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-padding-top: 76px; /* sticky top bar never covers anchored content */
}
body {
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;       /* nothing is ever allowed to scroll the page sideways */
    line-height: 1.45;
    -webkit-tap-highlight-color: transparent;
}
img, svg, video, canvas { max-width: 100%; }

h1 { font-size: clamp(20px, 4.2vw, 28px); }
h2 { font-size: clamp(17px, 3.2vw, 22px); }
h3 { font-size: clamp(15px, 2.6vw, 18px); }

/* ---------- containers (respect notches in landscape) ---------- */
.container {
    max-width: var(--container);
    padding: var(--gutter);
    padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
    padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
}
.container.wide { --container: 1280px; }
.container.full { --container: 1800px; }

/* ---------- top bar ---------- */
.top-bar-inner {
    max-width: 960px;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px var(--gutter);
    padding-left: max(var(--gutter), env(safe-area-inset-left, 0px));
    padding-right: max(var(--gutter), env(safe-area-inset-right, 0px));
    min-height: 56px;
}
.top-bar-inner.wide { max-width: 1280px; }
.top-bar-inner.full { max-width: 1800px; }
.top-bar-inner > .row { flex-wrap: wrap; justify-content: flex-end; }

.brand-logo { min-width: 0; flex: 1 1 auto; }
.brand-logo > div { min-width: 0; }
.brand-logo .brand-name,
.brand-logo .brand-sub {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}
.brand-logo img { flex: 0 0 auto; }

/* ---------- flexible rows / cards ---------- */
.row { flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.row > * { min-width: 0; }
.row > input:not([type="color"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
.row > select { flex: 1 1 140px; width: auto; }
.card { min-width: 0; overflow-wrap: break-word; }
.note { font-size: 13px; color: var(--color-text-muted); }

/* ---------- scrollable tab strip (admin dashboard) ---------- */
.tabs {
    display: flex;
    gap: 6px;
    margin: 0 calc(-1 * var(--gutter)) 16px;
    padding: 2px var(--gutter);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs > .btn { flex: 0 0 auto; scroll-snap-align: start; }
@media (min-width: 900px) {
    .tabs { margin: 0 0 16px; padding: 2px 0; flex-wrap: wrap; overflow: visible; }
}

/* ---------- fluid grids (columns appear as space allows) ---------- */
.grid-cols-2 > *, .grid-cols-3 > * { min-width: 0; }
.grid-cols-3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 130px), 1fr)); }
@media (max-width: 340px) { .grid-cols-2 { grid-template-columns: 1fr; } }

.grid-stats,
.grid-cards,
.grid-list,
.grid-menu,
.grid-products { display: grid; gap: 12px; align-items: start; }
.grid-stats    { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 8px; margin-bottom: 12px; }
.grid-cards    { grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr)); }
.grid-list     { grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); }
.grid-menu     { grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 10px; }
.grid-products { grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)); gap: 8px; }
.grid-stats > .card, .grid-cards > .card, .grid-list > .card, .grid-menu > .card { margin-bottom: 0; }
.grid-products > .btn { width: 100%; }

/* ---------- POS: menu + order side by side on tablets / laptops ---------- */
.pos-layout { display: block; }
.pos-cart:empty { display: none; }
@media (min-width: 900px) {
    .pos-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(320px, 380px);
        gap: 20px;
        align-items: start;
    }
    .pos-cart { position: sticky; top: 76px; max-height: calc(100vh - 96px); max-height: calc(100dvh - 96px); overflow-y: auto; }
    .pos-cart > .card { margin-top: 0 !important; }
}

/* ---------- auth screens ---------- */
.auth-screen { min-height: 100dvh; }
.auth-card { padding: clamp(20px, 6vw, 32px) clamp(16px, 6vw, 28px); }
@media (max-height: 560px) { .auth-screen { align-items: flex-start; } } /* landscape phones */

/* ---------- modals / drawers ---------- */
.modal { max-height: 90vh; max-height: 90dvh; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@media (min-width: 600px) { .modal { max-width: 520px; } }

/* ---------- inputs & touch ---------- */
input, select, textarea { max-width: 100%; }
textarea { min-height: 88px; resize: vertical; }
:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; }
@media (hover: hover) { .btn:not(:disabled):hover { filter: brightness(1.08); } }
@media (pointer: coarse) { .btn, input, select { min-height: 48px; } .top-bar .btn { min-height: 40px; } }

/* ---------- small phones ---------- */
@media (max-width: 400px) {
    .btn { padding: 10px 14px; font-size: 15px; }
    .btn.btn-lg { min-height: 56px; font-size: 18px; }
    .brand-logo .brand-sub { display: none; }
    .badge { font-size: 11px; padding: 3px 8px; }
}

/* ---------- big screens (kitchen displays on TVs) ---------- */
@media (min-width: 1600px) {
    .grid-cards { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
}

@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
