/* ===================================================================
   mobile.css — makes the panel behave like an app on a phone.

   Loaded AFTER style.css (and after theme-online.css), so it only has
   to override, never restate. Nothing here changes behaviour, colours
   or wording: it is layout only. The desktop bar and the phone drawer
   are rendered from the same $PAGES data in inc/navbar_admin.php.

   Breakpoint: 820px. Above it the panel looks exactly as it did.
=================================================================== */

:root {
  --qa-topbar-h: 56px;
  --qa-safe-top: env(safe-area-inset-top, 0px);
  --qa-safe-bottom: env(safe-area-inset-bottom, 0px);
  --qa-safe-right: env(safe-area-inset-right, 0px);
  --qa-safe-left: env(safe-area-inset-left, 0px);
}

/* Nothing may push the page sideways. */
html, body { max-width: 100%; overflow-x: hidden; }
img, video, canvas { max-width: 100%; height: auto; }

/* The phone chrome is built always but only shown small; the desktop
   bar is hidden small. One source of markup, two presentations. */
.qa-topbar, .qa-drawer, .qa-overlay { display: none; }

@media (max-width: 820px) {

  /* ---------- top bar ---------- */
  .navbar { display: none !important; }

  .qa-topbar {
    display: flex; align-items: center; gap: 10px;
    position: fixed; inset-block-start: 0; inset-inline: 0; z-index: 1000;
    height: calc(var(--qa-topbar-h) + var(--qa-safe-top));
    padding: var(--qa-safe-top) calc(12px + var(--qa-safe-right)) 0 calc(12px + var(--qa-safe-left));
    background: var(--surface, #fff);
    border-bottom: 1px solid var(--line, #e7e5e4);
    box-shadow: 0 2px 10px rgba(0,0,0,.05);
  }
  .qa-topbar .qa-logo { height: 32px; width: auto; flex: 0 0 auto; }
  .qa-topbar .qa-title {
    font-weight: 800; font-size: 16px; color: var(--ink, #1c1917);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto;
  }
  .qa-topbar .qa-badge {
    flex: 0 0 auto; font-size: 12px; font-weight: 700; border-radius: 999px;
    padding: 4px 10px; border: 1px solid;
    background: var(--amber-soft, #fef3c7); border-color: var(--amber, #d97706); color: var(--amber-dark, #b45309);
  }
  .qa-topbar .qa-badge.online {
    background: #e0e7ff; border-color: #4f46e5; color: #3730a3;
  }
  /* 44px touch target, as required. */
  .qa-burger {
    flex: 0 0 auto; width: 44px; height: 44px; border: 0; background: transparent;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 22px; color: var(--ink, #1c1917); cursor: pointer; border-radius: 10px;
  }
  .qa-burger:active { background: rgba(0,0,0,.06); }

  /* Push the page below the fixed bar. */
  body { padding-top: calc(var(--qa-topbar-h) + var(--qa-safe-top)); }

  /* ---------- drawer (slides from the RIGHT: the layout is RTL) ---------- */
  .qa-overlay {
    display: block; position: fixed; inset: 0; z-index: 1001;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .qa-overlay.open { opacity: 1; pointer-events: auto; }

  .qa-drawer {
    display: flex; flex-direction: column;
    position: fixed; z-index: 1002; inset-block: 0; inset-inline-end: 0;
    width: min(84vw, 320px);
    padding: calc(14px + var(--qa-safe-top)) 14px calc(14px + var(--qa-safe-bottom));
    background: var(--surface, #fff);
    border-inline-start: 1px solid var(--line, #e7e5e4);
    box-shadow: -14px 0 34px rgba(0,0,0,.18);
    transform: translateX(100%);          /* off to the right, RTL-correct */
    transition: transform .22s ease;
    overflow-y: auto; overscroll-behavior: contain;
  }
  [dir="rtl"] .qa-drawer, html[lang="ku"] .qa-drawer { transform: translateX(-100%); }
  .qa-drawer.open { transform: translateX(0) !important; }

  body.qa-locked { overflow: hidden; }
}

/* The drawer's own furniture — same at every width, so a wide screen can
   show it permanently later without restyling. */
.qa-drawer .qa-drawer-head {
  display: flex; align-items: center; gap: 10px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line, #e7e5e4); margin-bottom: 10px;
}
.qa-drawer .qa-drawer-head img { height: 36px; }
.qa-drawer .qa-who { font-size: 13px; color: var(--muted, #78716c); }
.qa-drawer .qa-sec-label {
  font-size: 12px; font-weight: 700; color: var(--muted, #78716c);
  margin: 14px 4px 6px;
}
.qa-drawer .qa-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;                      /* comfortably over the 44px floor */
  padding: 10px 12px; border-radius: 12px;
  color: var(--charcoal, #44403c); text-decoration: none;
  font-weight: 700; font-size: 15px;
}
.qa-drawer .qa-link:active { background: rgba(0,0,0,.05); }
.qa-drawer .qa-link.active {
  background: var(--amber-soft, #fef3c7); color: var(--amber-dark, #b45309);
}
.qa-drawer .qa-link.logout { color: #b91c1c; }
.qa-drawer .qa-switch { display: flex; gap: 8px; margin-bottom: 4px; }
.qa-drawer .qa-switch a {
  flex: 1; text-align: center; padding: 10px 8px; border-radius: 10px;
  border: 1px solid var(--line-2, #d6d3d1); text-decoration: none;
  font-weight: 700; font-size: 13px; color: var(--charcoal, #44403c);
  min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.qa-drawer .qa-switch a.on {
  background: var(--amber, #d97706); border-color: transparent; color: #fff;
}
.qa-drawer .qa-switch a.online.on { background: #4f46e5; }
.qa-drawer .qa-spacer { flex: 1 1 auto; }

/* ===================================================================
   Page content at phone widths
=================================================================== */
@media (max-width: 820px) {

  /* Wide tables scroll inside themselves rather than stretching the page.
     .table in style.css sets overflow:hidden at class specificity, which an
     element selector here cannot beat — hence the class and the !important. */
  table, .table {
    display: block !important;
    width: 100% !important; max-width: 100% !important;
    overflow-x: auto !important; overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
  }
  table thead, table tbody, table tfoot,
  .table thead, .table tbody, .table tfoot { width: max-content; min-width: 100%; }
  /* The sticky header trick does not survive display:block. */
  .table thead th { position: static !important; }

  /* The panel-wide two-column grid becomes one column. */
  .container { grid-template-columns: 1fr !important; padding: 16px 14px !important; gap: 16px !important; }

  /* Side-by-side field groups stack. .row is used outside <form> too
     (the till is not a form), so it must not be scoped to one.
     min-width:0 lets a flex child shrink below its content width — without
     it the four till fields refuse to narrow and push the page sideways. */
  .row, .form-row, .grid-2, .grid-3 {
    display: flex !important; flex-direction: column !important; gap: 10px !important;
  }
  .row > *, .form-row > *, .actions > * { min-width: 0; }
  .actions { flex-wrap: wrap !important; }

  /* 16px or larger, so iOS does not zoom the page when a field is focused. */
  input, select, textarea {
    font-size: 16px !important;
    max-width: 100%;
  }
  input, select, textarea, button, .btn, a.btn {
    min-height: 44px;                    /* the touch-target floor */
  }
  button, .btn, a.btn { padding-inline: 16px; }

  /* Generic containers stop fighting the viewport. */
  .wrap, .container, .card, .panel {
    width: 100% !important; max-width: 100% !important;
    padding-inline: 14px; box-sizing: border-box;
  }

  /* Give the thumb somewhere to rest under the till's totals. */
  body { padding-bottom: calc(10px + var(--qa-safe-bottom)); }
}

/* The receipt page prints; never let app chrome near it. */
@media print {
  .qa-topbar, .qa-drawer, .qa-overlay, .navbar { display: none !important; }
  body { padding-top: 0 !important; }
}
