/* VisionEzy responsive layout: phones + tablets (23 Oct 2026)
 * This stylesheet comes AFTER the existing module styles. Only presentation
 * changes; data access, tenant routing, permission checks and transactions are
 * deliberately unchanged.
 */
.mobile-nav-backdrop[hidden] { display:none!important; }
.mobile-nav-backdrop { display:none; }
.mobile-nav-close { display:none; }

@media screen and (max-width:1024px) {
  html,body { max-width:100%; overflow-x:clip; }
  .app-shell { width:100%; min-height:100dvh; }
  .app-shell .main {
    margin-left:0!important;
    width:100%!important;
    min-width:0!important;
    max-width:100%!important;
  }
  .topbar {
    display:flex!important;
    position:sticky;
    top:0;
    z-index:100!important;
    height:auto!important;
    min-height:62px;
    padding:8px 15px!important;
    gap:10px;
  }
  .topbar #mobileMenu {
    display:flex!important;
    flex:0 0 44px;
    justify-content:center;
    align-items:center;
    width:44px;
    height:44px;
    border-radius:11px;
    border:1px solid var(--ui-border,#dbe3eb);
    background:var(--ui-surface,#fff);
    color:var(--ui-text,#202c39);
    font-size:23px;
  }
  .topbar .top-search { flex:1 1 240px; width:auto!important; max-width:520px; min-width:0!important; }
  .topbar .top-search input { width:100%; min-width:0; }
  .topbar .topbar-right { flex:0 1 auto; margin-left:auto!important; min-width:0; gap:8px!important; }
  .topbar .profile-mini { max-width:48px; overflow:hidden; }
  .topbar .profile-mini > div:not(.avatar),.topbar .profile-mini > span { display:none!important; }
  .topbar .clock-wrap { display:none; }
  .topbar .theme-btn,.topbar .notification-btn { flex:0 0 42px; width:42px; height:42px; }
  .app-shell .content { width:100%; max-width:100%; min-width:0; padding:18px 16px 38px; }
  .content > *, .content .panel, .shop-module, .tea-module { min-width:0; max-width:100%; }

  /* Single permission-aware menu, including tenant-specific injected modules. */
  .app-shell #sidebar {
    position:fixed!important;
    inset:0 auto 0 0!important;
    width:min(85vw,340px)!important;
    max-width:340px!important;
    height:100dvh!important;
    max-height:100dvh!important;
    padding:58px 12px 12px!important;
    z-index:7200!important;
    display:flex!important;
    flex-direction:column!important;
    visibility:visible!important;
    opacity:1!important;
    transform:translateX(-105%)!important;
    transition:transform .2s ease!important;
    overflow:hidden!important;
    box-shadow:14px 0 45px rgba(13,21,32,.24);
    background:var(--ui-surface,#fff);
    color:var(--ui-text,#253344);
  }
  .app-shell #sidebar.open { transform:translateX(0)!important; }
  .app-shell #sidebar .mobile-nav-close {
    display:flex!important;
    align-items:center;
    justify-content:center;
    position:absolute;
    top:10px;
    right:12px;
    width:40px;
    height:40px;
    border:1px solid var(--ui-border,#dbe3eb);
    border-radius:10px;
    background:var(--ui-surface-soft,#f6f8fa);
    color:inherit;
    font-size:18px;
    z-index:1;
  }
  .app-shell #sidebar .logo { flex:0 0 auto; padding:0 10px 10px!important; }
  .app-shell #sidebar .restaurant { flex:0 0 auto; margin-bottom:10px; }
  .app-shell #sidebar nav {
    display:flex!important;
    flex:1 1 auto!important;
    min-height:0!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    flex-direction:column!important;
    align-items:stretch!important;
    gap:4px;
    overscroll-behavior:contain;
    -webkit-overflow-scrolling:touch;
    padding:4px 2px 8px;
  }
  .app-shell #sidebar nav > .nav,
  .app-shell #sidebar nav > .nav-group,
  .app-shell #sidebar .sidebar-bottom .nav { flex:0 0 auto; min-height:44px; width:100%; }
  .app-shell #sidebar nav .nav { min-height:44px; }
  .app-shell #sidebar nav .nav.hidden,
  .app-shell #sidebar .nav.hidden { display:none!important; }
  .app-shell #sidebar .nav-submenu button { min-height:42px; }
  .app-shell #sidebar .sidebar-bottom {
    flex:0 0 auto!important;
    margin-top:0!important;
    border-top:1px solid var(--ui-border,#dbe3eb);
    padding-top:8px;
    max-height:38dvh;
    overflow-y:auto;
  }
  .mobile-nav-backdrop:not([hidden]) {
    display:block!important;
    position:fixed;
    inset:0;
    background:rgba(12,23,38,.53);
    z-index:7100;
  }
  body.mobile-nav-open { overflow:hidden!important; }
  /* Ensure session/login screens are never obscured by the drawer. */
  #loginScreen:not(:empty) { position:relative; z-index:8000; }

  /* Do not let cards, toolbars, grids, tables or long labels push the page wide. */
  .dashboard-main-grid,.dashboard-bottom-grid,.grid-2,.grid-3,
  .reports-payment-row,.pos-layout,.order-access-layout,
  .shop-bill-layout,.tea-bill-layout { grid-template-columns:minmax(0,1fr)!important; }
  .kpis,.hero-kpis,.shop-kpis { grid-template-columns:repeat(2,minmax(0,1fr))!important; }
  .kitchen-grid,.recipe-grid { grid-template-columns:repeat(2,minmax(0,1fr))!important; }
  .toolbar,.panel-head,.report-toolbar,.menu-toolbar,
  .shop-tools,.tea-form,.warehouse-report-filters,
  .customer-directory-toolbar { flex-wrap:wrap; max-width:100%; }
  .toolbar > *, .panel-head > *, .shop-tools > *, .tea-form > * { min-width:0; }
  .table-panel,.table-responsive,.table-wrap,.report-table-wrap,
  .ops-report-scroll,.shop-table-wrap,.tea-scroll,
  .admin-permission-table-wrap,.admin-bulk-table,
  .warehouse-report-scroll,.payment-chart-scroll {
    max-width:100%; overflow-x:auto!important; -webkit-overflow-scrolling:touch;
    overscroll-behavior-x:contain;
  }
  .table-panel table,.table-responsive table,.table-wrap table,
  .report-table-wrap table,.shop-table-wrap table,
  .tea-scroll table,.ops-report-scroll table,
  .warehouse-report-table { width:max-content; min-width:100%; }
  .shop-table-wrap table { min-width:820px; }
  .tea-core-inventory table { min-width:850px; }
  .warehouse-report-table { min-width:1220px; }
  .admin-permission-table { min-width:980px; }
  .admin-bulk-manager { min-width:0!important; width:100%!important; max-width:100%!important; }
  .admin-bulk-manager .admin-bulk-table table { min-width:630px; }
  .content table th { white-space:nowrap; }

  /* Staff can complete their forms without narrow overlapping fields. */
  .modal-backdrop { z-index:7600!important; }
  .modal,.modal.modal-wide {
    width:min(96vw,800px)!important;
    max-width:96vw!important;
    min-width:0!important;
    max-height:calc(100dvh - 32px)!important;
    overflow-y:auto;
    overscroll-behavior:contain;
  }
  .modal .form-grid,.modal .permission-grid,
  .admin-ui-settings-grid,.supplier-master-form .form-grid { grid-template-columns:minmax(0,1fr)!important; }
  .modal .form-grid > *, .modal .permission-matrix,
  .modal .role-permission-box { min-width:0; }
  #modalRoot .modal-actions { display:flex; flex-wrap:wrap; gap:8px; }
  #modalRoot .modal-actions button { min-height:44px; }

  .shop-module .shop-tabs,.tea-module .tea-tabs {
    display:flex; flex-wrap:nowrap; overflow-x:auto; max-width:100%;
    -webkit-overflow-scrolling:touch; scrollbar-width:thin;
    padding-bottom:7px;
  }
  .shop-tabs button,.tea-tabs button { flex:0 0 auto; min-height:44px; }
  .shop-bill-layout .shop-panel,.tea-bill-layout .panel { width:100%; min-width:0; }
  .shop-product-grid,.tea-products { grid-template-columns:repeat(auto-fill,minmax(135px,1fr)); }
  .shop-dialog,.tea-dialog { max-width:100%; max-height:calc(100dvh - 24px); overflow-y:auto; }
  .shop-overlay,.tea-overlay { padding:12px; }
  .shop-cart-row { grid-template-columns:minmax(60px,1fr) 30px 24px 30px minmax(42px,auto) 30px; }
  .shop-edit-line { grid-template-columns:minmax(0,1fr) 64px 75px; }
  .tea-module .panel { overflow:visible; }
  .tea-module .tea-scroll,.tea-module .admin-permission-table-wrap { overflow-x:auto; }
  .shop-form-grid,.tea-master-form { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .pfb-shell .pfb-toolbar { overflow-x:auto; }
  .pfb-workspace { min-width:0; overflow:auto; }
  .pfb-canvas-stage { min-width:0; }
}

@media screen and (max-width:600px) {
  .app-shell .content { padding:12px 9px 28px!important; }
  .topbar { padding:8px 9px!important; gap:6px!important; }
  .topbar #mobileMenu { width:44px; height:44px; flex-basis:44px; }
  .topbar .top-search { flex-basis:0; }
  .topbar .top-search input { font-size:16px!important; }
  .topbar .top-search input::placeholder { color:transparent!important; }
  .topbar .profile-mini,.topbar .theme-btn { display:none!important; }
  .topbar .notification-btn { width:42px; flex-basis:42px; }
  .panel,.shop-panel,.tea-bill-layout>.panel { padding:12px; }
  .kpis,.hero-kpis,.shop-kpis { grid-template-columns:repeat(2,minmax(0,1fr))!important; gap:8px; }
  .kitchen-grid,.recipe-grid { grid-template-columns:minmax(0,1fr)!important; }
  .product-grid,.tables-grid { grid-template-columns:repeat(2,minmax(0,1fr))!important; }
  .shop-product-grid,.tea-products { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .shop-form-grid,.tea-master-form,.tea-pay-cols { grid-template-columns:minmax(0,1fr)!important; }
  .shop-tools > input,.shop-tools > select,.shop-tools > button { flex:1 1 100%; width:100%; }
  .shop-cart-row { font-size:11px; gap:2px; }
  .shop-cart-row button { min-width:30px; min-height:36px; }
  .shop-edit-line { grid-template-columns:minmax(0,1fr) 65px; }
  .shop-edit-line > button { grid-column:1/-1; width:100%; }
  .modal,.modal.modal-wide { width:100%!important; max-width:100%!important; max-height:94dvh!important; }
  .modal-backdrop { align-items:flex-end; padding:0!important; }
  .modal { border-radius:18px 18px 0 0; }
  .purchase-totals-grid { grid-template-columns:minmax(0,1fr)!important; }
  .payment-allocation-row { grid-template-columns:22px minmax(0,1fr)!important; }
  .warehouse-report-filters label { flex:1 1 100%; }
  .warehouse-report-filters button { flex:1 1 135px; }
  .panel-head > button,.report-export-actions > button { min-height:44px; }
  .pfb-workspace { display:flex!important; flex-direction:column; }
  .pfb-components,.pfb-properties { max-height:220px; }
  .pfb-toolbar { min-width:0!important; width:max-content; }
}

@media screen and (max-width:360px) {
  .topbar .top-search { display:none!important; }
  .topbar .topbar-right { margin-left:auto!important; }
  .shop-kpis,.hero-kpis,.kpis { grid-template-columns:minmax(0,1fr)!important; }
  .product-grid,.tables-grid,.shop-product-grid,.tea-products { grid-template-columns:minmax(0,1fr)!important; }
}
@media (prefers-reduced-motion:reduce) {
  .app-shell #sidebar { transition:none!important; }
}

/* Hidden navigation entries collapse without stretching the remaining rows. */
@media(max-width:800px){
  .app-shell #sidebar nav{
    align-content:flex-start!important;
    justify-content:flex-start!important;
    gap:4px!important;
  }
  .app-shell #sidebar nav > .nav,
  .app-shell #sidebar nav > .nav-group{
    align-self:flex-start!important;
    flex:0 0 auto!important;
  }
}
