/**
 * Golden Lotus POS — Complete Mobile CSS  (v2 — menu-button overflow fix)
 *
 * WHAT CHANGED IN THIS VERSION:
 *   Owner phone bug: the ☰ menu button (.sidebar-toggle) was pushed off the
 *   RIGHT edge of the screen on the owner dashboard. Cause: the topbar title /
 *   meta in the owner view would not shrink, so the flex row overflowed and
 *   shoved the button out of view.
 *   Fix (Section 3 below): topbar is clamped to the viewport, the button is
 *   forced leftmost (order:-1) and static, and the title is allowed to shrink
 *   (flex:1 1 auto; min-width:0) so it truncates instead of pushing the button
 *   off screen.
 *
 * ROOT CAUSE OF ORIGINAL LAYOUT (already fixed in head.php inline <style>):
 *   .pos-main had margin-left:260px !important inline — beat every external
 *   stylesheet. head.php now drops it to 0 at <=1024px. This file handles all
 *   per-component mobile adjustments and loads AFTER that inline block.
 *
 * REPLACE the whole file at: assets/css/mobile.css
 */

/* ═══════════════════════════════════════════════
   1. GLOBAL
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;            /* kill any horizontal drift / off-screen */
}

img, video, canvas, iframe, svg {
  max-width: 100%;
  height: auto;
}

/* Sidebar backdrop (mobile drawer) */
#sidebar-overlay {
  position: fixed !important;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
  display: block !important;
}
#sidebar-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* Hamburger hidden on desktop */
.sidebar-toggle { display: none !important; }

/* Remove blue tap flash */
a, button, [onclick], [role=button] {
  -webkit-tap-highlight-color: transparent;
}

/* Any wide table should scroll inside its box, not stretch the page */
.table-scroll,
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ═══════════════════════════════════════════════
   2. TABLET  ≤ 992px
   ═══════════════════════════════════════════════ */
@media (max-width: 992px) {
  .stats-grid, .sg  { grid-template-columns: repeat(3, 1fr) !important; gap: .75rem; }
  .quick-grid       { grid-template-columns: repeat(3, 1fr) !important; }
  .pos-content      { padding: 1.25rem; }
}

/* ═══════════════════════════════════════════════
   3. ANY NON-DESKTOP  ≤ 1024px
   (sidebar drawer + the MENU BUTTON FIX)
   ═══════════════════════════════════════════════ */
@media (max-width: 1024px) {

  /* ---- TOPBAR: clamp to screen so nothing escapes right ---- */
  .pos-topbar {
    display: flex !important;
    align-items: center;
    flex-wrap: nowrap;
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden;              /* clip any last-resort overflow */
    box-sizing: border-box;
    padding: .75rem 1rem;
    gap: .5rem;
  }

  /* ---- MENU BUTTON: force visible + leftmost + inside screen ---- */
  .sidebar-toggle {
    display: flex !important;
    order: -1 !important;          /* always first item, never right side */
    position: static !important;   /* don't anchor to an off-screen edge */
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin: 0 8px 0 0 !important;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius);
    flex: 0 0 auto !important;     /* fixed size, never shrinks away */
  }
  .sidebar-toggle:hover { background: var(--surface-2); }

  /* ---- TITLE: allow shrink so it truncates instead of pushing button out --- */
  .topbar-title {
    flex: 1 1 auto;
    min-width: 0;                  /* THE key line: lets flex child shrink */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Right-side topbar group must also be allowed to shrink, not overflow */
  .topbar-right,
  .topbar-actions,
  .topbar-meta {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
  }

  /* ---- Sidebar becomes overlay drawer ---- */
  .pos-sidebar {
    z-index: 100;
    box-shadow: 6px 0 30px rgba(0,0,0,.5);
  }

  /* ---- Main panel fills the screen (head.php also drops the 260px) ---- */
  .pos-main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .pos-content { padding: 1rem; }

  .stats-grid, .sg { grid-template-columns: repeat(3, 1fr) !important; gap: .75rem; }
  .quick-grid      { grid-template-columns: repeat(3, 1fr) !important; }
}

/* ═══════════════════════════════════════════════
   4. MOBILE  ≤ 768px
   ═══════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ---- Topbar tightens, drops non-essential meta to free space ---- */
  .pos-topbar {
    padding: .6rem .875rem;
  }
  .topbar-title {
    font-size: .95rem;
    max-width: 60vw;               /* hard cap so it can't crowd the button */
  }
  .topbar-meta,
  .topbar-time,
  #pos-clock,
  #topbar-date,
  #ws-label {
    display: none !important;      /* owner topbar extras hidden on phone */
  }

  /* ---- Content ---- */
  .pos-content { padding: .75rem !important; }

  /* ---- Stats / quick tiles collapse ---- */
  .stats-grid, .sg { grid-template-columns: repeat(2, 1fr) !important; }
  .quick-grid      { grid-template-columns: repeat(2, 1fr) !important; }

  /* ---- Order editor: menu + cart stack vertically ---- */
  .order-layout,
  .edit-layout,
  .order-split,
  .two-col {
    display: block !important;
  }
  .menu-panel,
  .cart-panel,
  .order-panel {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* ---- Billing stacks ---- */
  .billing-layout { display: block !important; }
  .billing-left,
  .billing-right { width: 100% !important; }

  /* ---- KDS / floor view: single column ---- */
  .kds-grid,
  .floor-grid,
  .table-grid {
    grid-template-columns: 1fr !important;
    gap: .75rem !important;
  }

  /* ---- Settings / owner advanced tabs scroll horizontally ---- */
  .settings-tabs,
  .owner-tabs,
  .tab-bar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    flex-wrap: nowrap !important;
  }

  /* ---- Tables become scrollable instead of stretching the page ---- */
  table { min-width: 100%; }
  .gl-table,
  table.data-table { display: block; overflow-x: auto; white-space: nowrap; }

  /* ---- Bigger touch targets ---- */
  button,
  .btn,
  .nav-link,
  [role=button] { min-height: 42px; }

  /* ---- Modals fit the screen ---- */
  .modal,
  .modal-box,
  .dialog {
    width: 94vw !important;
    max-width: 94vw !important;
    margin: 0 auto;
  }
}

/* ═══════════════════════════════════════════════
   5. SMALL PHONE  ≤ 480px
   ═══════════════════════════════════════════════ */
@media (max-width: 480px) {
  .stats-grid, .sg { grid-template-columns: 1fr !important; }
  .quick-grid      { grid-template-columns: repeat(2, 1fr) !important; }

  .topbar-title { max-width: 50vw; font-size: .9rem; }

  .pos-content { padding: .6rem !important; }

  /* Stack any remaining two-button rows */
  .btn-row,
  .action-row { flex-direction: column; }
  .btn-row > *,
  .action-row > * { width: 100%; }
}

/* ════════════════════════════════════════════════════════════════
   RUSH-TIME ITEM FINDER  (order screen item picker)
   Faster search + denser phone grid + sticky search/categories.
   Added: rush-time UX pass.
   ════════════════════════════════════════════════════════════════ */

/* Clear (✕) button + live result count inside the search box */
.picker-search { position: relative; }
.picker-search input { padding-right: 5.6rem; }

.picker-search-clear {
  position: absolute;
  right: .55rem;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-muted);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.picker-search-clear:hover { color: var(--gold); }
body.searching .picker-search-clear { display: flex; }

.picker-count {
  position: absolute;
  right: 2.4rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-muted);
  pointer-events: none;
  background: var(--surface);
  padding-left: .35rem;
}
body.searching .picker-count { right: 2.5rem; }

/* No-match empty state in the grid */
.picker-items.is-empty::after {
  content: "No items match — try fewer letters";
  grid-column: 1 / -1;
  display: block;
  text-align: center;
  color: var(--text-muted);
  font-size: .9rem;
  padding: 2.5rem 1rem;
}

/* Card layout: grow with the name, keep price pinned to the bottom,
   never let the price spill outside the card (fixes multi-line names).
   NOTE: display must NOT be !important — the search/category filter hides
   cards via inline display:none, which !important would override. */
.picker-item-card {
  display: flex;
  flex-direction: column !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0;
  overflow: visible !important;
}
.picker-item-card > div:last-child {
  margin-top: auto;            /* push the price row to the bottom */
}
.pi-name {
  overflow-wrap: anywhere;
  word-break: break-word;
}
.picker-items {
  align-items: stretch;        /* same-row cards share the tallest height */
  grid-auto-rows: max-content; /* row height follows the tallest card's content */
}

/* ── Phone: bigger search, denser grid, pinned controls = less scroll ── */
@media (max-width: 900px) {
  .item-picker {
    height: 72vh !important;
    min-height: 430px !important;
  }
  .picker-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--surface);
  }
  .picker-search input {
    font-size: 1rem;
    padding-top: .72rem;
    padding-bottom: .72rem;
  }
  /* Larger touch targets on category chips */
  .picker-cat-btn {
    padding: .45rem .95rem;
    font-size: .82rem;
  }
  /* Two compact columns — more items visible per screen */
  .picker-items {
    grid-template-columns: repeat(2, 1fr);
    gap: .5rem;
    padding: .7rem;
  }
  .picker-item-card {
    padding: .65rem .6rem;
    min-height: 62px;
  }
  .pi-name { font-size: .9rem; }
}

@media (max-width: 480px) {
  .item-picker { height: 70vh !important; }
  .picker-count { font-size: .65rem; }
}

/* ── Order screen: two-step flow on phone (Items → Review → Fire) ── */
.mobile-step-bar { display: none; }   /* hidden on desktop */

@media (max-width: 900px) {
  /* STEP 1 — ITEMS: show picker + the "Review" bar; hide the panel */
  .order-editor[data-step="items"] .order-panel { display: none !important; }
  .order-editor[data-step="items"] .item-picker {
    height: auto !important;
    min-height: calc(100dvh - 230px) !important;
  }
  .order-editor[data-step="items"] .picker-items { padding-bottom: 5rem; }
  .order-editor[data-step="items"] .to-review { display: flex; }

  /* STEP 2 — REVIEW: show panel + "Add more items" bar; hide picker */
  .order-editor[data-step="review"] .item-picker { display: none !important; }
  .order-editor[data-step="review"] .to-review   { display: none !important; }
  .order-editor[data-step="review"] .order-panel {
    display: flex !important;
    height: auto !important;
    min-height: calc(100dvh - 200px) !important;
  }
  .order-editor[data-step="review"] .to-items { display: flex; }

  .mobile-step-bar {
    width: 100%; align-items: center; gap: .5rem;
    border: none; cursor: pointer; font-family: inherit;
  }
  /* Sticky "Review order" call-to-action at the bottom of the items step */
  .to-review {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    justify-content: space-between;
    background: var(--gold, #C6A84B); color: #1c1300;
    font-weight: 800; font-size: 1rem; padding: 1.05rem 1.25rem;
    box-shadow: 0 -8px 22px rgba(0,0,0,.18);
  }
  .to-review .msb-count { font-weight: 700; font-size: .92rem; opacity: .92; }
  /* Back bar at the top of the review step */
  .to-items {
    justify-content: flex-start; gap: .45rem;
    background: var(--surface-2, #f6f4ef); color: var(--ink, #2a2a2a);
    font-weight: 700; font-size: .9rem; padding: .85rem 1rem;
    border-bottom: 1px solid var(--border-soft, #e3ddd0);
  }
}

/* ── Menu page: kitchen/barista/cashier toggle rows as clean cards on phone ── */
@media (max-width: 640px) {
  /* Hide the column header — rows become self-labelled cards */
  .menu-table-head.kitchen-mode { display: none; }

  .menu-item-row.kitchen-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "name  name"
      "price gst"
      "avail oos";
    gap: .55rem .9rem;
    padding: .95rem 1rem;
    align-items: center;
  }
  .menu-item-row.kitchen-mode > :nth-child(1) { grid-area: name; min-width: 0; }
  .menu-item-row.kitchen-mode > :nth-child(2) { grid-area: price; }
  .menu-item-row.kitchen-mode > :nth-child(3) { grid-area: gst; }
  .menu-item-row.kitchen-mode > :nth-child(4) { grid-area: avail; }
  .menu-item-row.kitchen-mode > :nth-child(5) { grid-area: oos; }

  /* Label the two toggles (header is hidden on phone) */
  .menu-item-row.kitchen-mode > :nth-child(4),
  .menu-item-row.kitchen-mode > :nth-child(5) {
    display: flex; flex-direction: column; gap: .3rem; align-items: flex-start;
  }
  .menu-item-row.kitchen-mode > :nth-child(4)::before { content: "Available"; }
  .menu-item-row.kitchen-mode > :nth-child(5)::before { content: "Out of stock"; }
  .menu-item-row.kitchen-mode > :nth-child(4)::before,
  .menu-item-row.kitchen-mode > :nth-child(5)::before {
    font-size: .68rem; font-weight: 600; letter-spacing: .03em;
    text-transform: uppercase; color: var(--text-muted);
  }

  /* Price line a touch bolder so the card reads top-down */
  .menu-item-row.kitchen-mode .item-name { font-size: 1rem; font-weight: 700; }
}
