/* Phones and tablets.
   Up to 1100px wide (tablets, small laptops): the menu slides in from the left (☰ button).
   Up to 760px wide (phones): one column, the order is a bottom bar that opens full screen,
   forms open as full-width sheets, wide tables scroll sideways inside their box. */

.menu-toggle, .cart-fab, .cart-close, .menu-extra, #menuScrim { display: none; }

@media (max-width: 1100px) {
  .app { grid-template-columns: minmax(0, 1fr) !important; }
  .app > *, #view-sales > *, .view { min-width: 0; }
  header { grid-column: 1 / -1 !important; }
  .view, #view-sales { grid-column: 1 !important; }
  .menu-toggle {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    width: 40px; height: 40px; border: none; border-radius: 10px; margin-right: 2px;
    background: rgba(255,255,255,.1); color: #fff; font-size: 20px; cursor: pointer;
  }
  .tabbar {
    position: fixed !important; top: 0; left: 0; bottom: 0; z-index: 65;
    width: min(300px, 86vw); padding: 12px 10px calc(16px + env(safe-area-inset-bottom)) !important;
    transform: translateX(-105%); transition: transform .22s ease; box-shadow: 8px 0 30px rgba(0,0,0,.25);
    -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  }
  body.menu-open .tabbar { transform: none; }
  body.menu-open #menuScrim { display: block; position: fixed; inset: 0; background: rgba(20,28,32,.5); z-index: 64; }
  body.menu-open { overflow: hidden; }
  .tabbar button { padding: 12px 14px !important; font-size: 14px !important; }
  .menu-extra { display: flex; align-items: center; gap: 8px; padding: 6px 8px 12px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 6px; color: #e3e8ea; font-size: 13px; }
  .menu-extra .me-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-extra .me-name small { display: block; color: #9fd0ec; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }
  .menu-extra button { width: auto !important; padding: 8px 10px !important; font-size: 13px !important; border-radius: 8px; background: rgba(255,255,255,.1) !important; color: #fff !important; border-left: 0 !important; }
  header .brand, header .till-pill, header .userbox, header .clock { white-space: nowrap; }
  /* Till on a tablet: categories as a strip across the top, products and the order side by side */
  #view-sales { grid-template-columns: minmax(0, 1fr) 320px !important; grid-template-rows: auto minmax(0, 1fr); }
  nav.catnav { grid-column: 1 !important; grid-row: 1; display: flex !important; flex-direction: row; gap: 6px; overflow-x: auto; overflow-y: hidden;
    padding: 8px 12px !important; border-right: 0 !important; border-bottom: 1px solid var(--line); -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav.catnav::-webkit-scrollbar { display: none; }
  nav.catnav .cat-label { display: none; }
  nav.catnav button { width: auto !important; flex: 0 0 auto; white-space: nowrap; margin: 0 !important; padding: 8px 12px !important; border: 1px solid var(--line) !important; border-radius: 20px !important; }
  nav.catnav button .count { margin-left: 4px; }
  main.salesmain { grid-column: 1 !important; grid-row: 2; }
  aside.cartcol { grid-column: 2 !important; grid-row: 1 / 3; }
}
@media (max-width: 1100px) {
  /* Wide tables scroll sideways inside their own box, so the page itself never does */
  .view table, .modal table, .report-panel table, .erp-detail table, #erpHelpDrawer table {
    display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
}
@media (max-width: 900px) {
  header .clock, header .brand small { display: none !important; }
}

@media (max-width: 760px) {
  /* Top bar */
  header { padding: 0 8px !important; gap: 6px !important; height: 56px; border-bottom-width: 2px; }
  .app { grid-template-rows: 56px 1fr !important; }
  header .brand-mark { width: 24px; height: 24px; }
  header .brand { font-size: 14px; line-height: 1.15; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  header .brand small { display: none !important; }
  header .clock, #themeToggle, header .userbox #userName, header .userbox .role { display: none !important; }
  header .userbox { padding: 4px !important; background: none !important; }
  header .userbox button { width: 34px; height: 34px; }
  header .till-pill { padding: 8px !important; }
  header .till-pill #tillPillText { display: none; }
  #branchSelector { max-width: 110px; }
  #bellBtn, #helpBubble { width: 36px !important; height: 36px !important; }
  .bell-menu { position: fixed !important; top: 60px !important; left: 8px; right: 8px !important; width: auto !important; max-width: none !important; max-height: 70dvh; overflow-y: auto; }
  #helpPanel { top: 60px !important; left: 8px; right: 8px !important; width: auto !important; max-width: none !important; height: calc(100dvh - 72px) !important; max-height: none !important; }

  /* Till: products full width, categories as a sideways strip, the order opens from a bottom bar */
  #view-sales.active { display: flex !important; flex-direction: column; height: 100%; min-width: 0; width: 100%; }
  #view-sales > * { min-width: 0; max-width: 100%; }
  nav.catnav { display: flex !important; flex-direction: row; gap: 6px; overflow-x: auto; overflow-y: hidden; padding: 8px 10px !important;
    border-right: 0 !important; border-bottom: 1px solid var(--line); flex: 0 0 auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav.catnav::-webkit-scrollbar { display: none; }
  nav.catnav .cat-label { display: none; }
  nav.catnav button { width: auto !important; flex: 0 0 auto; white-space: nowrap; margin: 0 !important; padding: 8px 12px !important; border: 1px solid var(--line) !important; border-radius: 20px !important; font-size: 13px !important; }
  nav.catnav button .count { margin-left: 4px; }
  main.salesmain { flex: 1; min-height: 0; padding: 10px 10px 90px !important; }
  .toolbar { gap: 8px; }
  .toolbar .search { flex: 1 1 100%; }
  .toolbar .hold-btn { flex: 1 1 0; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; gap: 8px !important; }
  .card { padding: 12px; }
  .card:hover { transform: none; }
  aside.cartcol {
    position: fixed !important; inset: 0; z-index: 50; height: 100% !important; height: 100dvh !important;
    transform: translateY(105%); transition: transform .22s ease; border-left: 0 !important;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.cart-open aside.cartcol { transform: none; }
  body.cart-open { overflow: hidden; }
  .cart-close {
    display: flex; align-items: center; gap: 6px; width: 100%; margin: 0 0 10px; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer;
  }
  .pay-row { gap: 8px !important; }
  .pay-btn { padding: 14px 6px !important; font-size: 14px !important; }
  .cart-fab {
    position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 40;
    align-items: center; gap: 10px; padding: 14px 16px; border: none; border-radius: 14px; cursor: pointer;
    background: var(--chrome); color: #fff; font-size: 15px; font-weight: 700; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  }
  body.on-sales:not(.cart-open):not(.menu-open) .cart-fab { display: flex; }
  .cart-fab .cf-count { background: var(--orange); color: #1f2a30; border-radius: 20px; padding: 2px 9px; font-size: 13px; }
  .cart-fab .cf-total { margin-left: auto; font-family: 'Space Grotesk', sans-serif; font-size: 17px; }
  .cart-fab.empty { background: var(--surface); color: var(--muted); border: 1px solid var(--line); box-shadow: none; }

  /* Screens */
  .admin { padding: 12px 12px 28px !important; }
  .admin-toolbar { gap: 8px !important; }
  .admin-toolbar h2 { flex: 1 1 100%; margin-right: 0 !important; }
  .admin-toolbar input, .admin-toolbar select, .toolbar-search { flex: 1 1 140px; min-width: 0 !important; width: auto !important; max-width: 100% !important; }
  .admin-toolbar .primary-btn, .admin-toolbar .ghost-btn, .admin-toolbar button { flex: 0 1 auto; }
  .erp-help-btn { margin-left: 0 !important; }
  .stat-row > * { flex: 1 1 140px; min-width: 0; }
  .report-grid, .erp-split, .erp-form-grid, .erp-c360 { grid-template-columns: minmax(0, 1fr) !important; }
  .report-grid > *, .erp-split > *, .erp-form-grid > *, .erp-c360 > *, .erp-cards > *, .erp-dgrid > * { min-width: 0; }
  /* Rows laid out inline on a screen wrap onto the next line instead of running off the edge */
  .view [style*="display:flex"], .view [style*="display: flex"] { flex-wrap: wrap; }
  .view [style*="display:flex"] > *, .view [style*="display: flex"] > * { min-width: 0; }
  .erp-dgrid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important; }
  .erp-cards { grid-template-columns: minmax(0, 1fr) !important; }
  .field-row { flex-direction: column; gap: 0 !important; }
  /* Wide tables scroll sideways inside their own box, so the page itself never does */
  .view table, .modal table, .report-panel table, .erp-detail table, #erpHelpDrawer table {
    display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .view table td, .view table th { white-space: nowrap; }
  .view table td.name-cell, .view table td .wrap { white-space: normal; min-width: 140px; }
  .view pre, .view img, .view canvas, .view svg, .view iframe, .view input[type=file], .modal input[type=file] { max-width: 100%; }

  /* Forms and details open as sheets from the bottom */
  .overlay { align-items: flex-end !important; z-index: 80 !important; }
  .modal {
    width: 100% !important; max-width: 100% !important; max-height: 94dvh !important;
    border-radius: 16px 16px 0 0 !important; padding: 18px 14px calc(18px + env(safe-area-inset-bottom)) !important;
  }
  .modal-actions { flex-wrap: wrap; position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--surface);
    padding: 10px 0 calc(6px + env(safe-area-inset-bottom)); margin-bottom: calc(-18px - env(safe-area-inset-bottom)); }
  .modal-actions button { min-width: 40%; padding: 13px !important; font-size: 14px !important; }
  .erp-actions { display: flex; flex-wrap: wrap; gap: 6px; }
  .erp-actions .erp-btn { flex: 1 1 45%; }
  .toast { left: 10px !important; right: 10px; transform: none !important; bottom: calc(84px + env(safe-area-inset-bottom)) !important; z-index: 90 !important; text-align: center; }
  @keyframes toastin { from { opacity: 0; } to { opacity: 1; } }

  /* No zoom-in when tapping a field on iPhone (iOS zooms anything under 16px) */
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; }

  /* Sign-in and sign-up */
  .login-card { width: 100% !important; max-width: 420px; margin: 12px; padding: 24px 18px !important; }
}

/* Fingers, not a mouse: bigger tap targets */
@media (pointer: coarse) {
  .tabbar button, .ghost-btn, .primary-btn, .hold-btn, .erp-btn, .cart-tools button, .qty-ctrl button { min-height: 40px; }
  .qty-ctrl button { min-width: 38px; }
  .icon-btn, .li-remove { min-width: 36px; min-height: 36px; }
}
