/* ==========================================================================
   responsive.css: loaded last. Phones and tablets behave like an app.
     >= 992px   desktop: floating side menu + top bar
     < 992px    tablet / phone: bottom tab bar, side menu becomes a drawer (More, or swipe from the edge)
     < 768px    tables become cards, filters stack, page chrome tightens
     < 576px    dialogs become bottom sheets
   Safe areas (notch, home bar) are respected; touch targets are 44px; hover lifts never stick on touch.
   ========================================================================== */

[hidden] { display: none !important; }
html { -webkit-tap-highlight-color: transparent; }
a, button, .btn, input, select, textarea, label, summary, .chip, .product, .stepper button, .tabbar__item { touch-action: manipulation; }
body.app, body.pos-app { padding-inline: env(safe-area-inset-left) env(safe-area-inset-right); }
@media (display-mode: standalone) { html, body { overscroll-behavior-y: none; } }   /* installed app: no pull to refresh surprises mid sale */

/* nothing may push the page sideways: wide content scrolls inside its own box, the page itself never does */
html, body { max-width: 100%; }
html { overflow-x: hidden; overscroll-behavior-x: none; }                 /* the page itself can never scroll sideways, whatever is inside it */
body.app, body.pos-app { overflow-x: clip; }
.app-shell__main, .app-content, .card, .card-body, .row > *, .modal-body { min-width: 0; }
img, svg, video, canvas, iframe { max-width: 100%; }
.app-content :is(pre, code, .text-break) { overflow-wrap: anywhere; }

/* ---------- bottom tab bar (hidden on desktop) ---------- */
.tabbar { display: none; }

/* ---------- < 992px: tablet and phone ---------- */
@media (max-width: 991.98px) {
  #btnSidenav { display: none; }                       /* the More tab opens the menu */
  .topbar { top: max(var(--sp-100), env(safe-area-inset-top)); margin-inline: var(--sp-100); }
  .topbar__chip--static { display: none; }             /* branch is in the drawer */

  .tabbar {
    --n: 5; --i: 0;
    position: fixed; z-index: var(--pos-z-topbar); inset-inline: var(--sp-100); bottom: calc(var(--sp-100) + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: repeat(var(--n), minmax(0, 1fr)); padding: var(--sp-50); max-width: 36rem; margin-inline: auto;
    background: var(--pos-panel-solid); border: 1px solid var(--pos-panel-edge); border-radius: var(--pos-radius-xl);
    box-shadow: var(--pos-shadow-lg), inset 0 1px 0 var(--pos-edge-hi);
    view-transition-name: pos-tabbar;
    transition: transform var(--pos-dur-slow) var(--pos-ease), opacity var(--pos-dur) var(--pos-ease);
  }
  body.kb-open .tabbar, body.sidenav-open .tabbar { transform: translateY(160%); opacity: 0; pointer-events: none; }   /* out of the way of the keyboard and the drawer */
  /* the highlight is one pill that slides to the active tab (position comes from --i, set by the server and moved at once on tap) */
  .tabbar__pill {
    position: absolute; inset-block: var(--sp-50); inset-inline-start: var(--sp-50); z-index: 0; pointer-events: none;
    width: calc((100% - var(--sp-50) * 2) / var(--n)); border-radius: var(--pos-radius-lg); background: var(--pos-primary-soft-strong);
    transform: translateX(calc(var(--i) * 100% * var(--pos-dir)));
    transition: transform var(--pos-dur-slow) var(--pos-ease);
    view-transition-name: pos-tab-pill;
  }
  .tabbar__item {
    position: relative; z-index: 1; min-width: 0; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-25);
    border: 0; border-radius: var(--pos-radius-lg); background: transparent; color: var(--pos-text-muted);
    font: var(--caption-4); text-decoration: none; padding-inline: 0;
    transition: color var(--pos-dur) var(--pos-ease), transform var(--pos-dur) var(--pos-ease);
  }
  .tabbar__item > span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar__item .ico { font-size: 1.5rem; transition: transform var(--pos-dur-slow) var(--pos-ease); }
  .tabbar__item:active { transform: scale(0.94); }
  .tabbar__item.is-active { color: var(--pos-primary-text); }
  .tabbar__item.is-active .ico { transform: scale(1.1); animation: pos-tab-pop 560ms var(--pos-ease); }
  html.intro .tabbar { animation: pos-rise 600ms var(--pos-ease) 350ms backwards; }
  .app-footer { padding-bottom: calc(var(--sp-900) + env(safe-area-inset-bottom)); justify-content: center; text-align: center; }

  /* the side menu is a drawer: wide enough to read, never wider than the screen */
  .sidenav {
    width: min(88vw, 22rem); top: max(var(--sp-100), env(safe-area-inset-top)); bottom: max(var(--sp-100), env(safe-area-inset-bottom));
    inset-inline-start: var(--sp-100);
  }
  .sidenav .nav-link { min-height: 48px; }
  .topbar__heading { display: flex; flex-direction: column; min-width: 0; }
  .topbar__sub { display: block; font: var(--caption-5); color: var(--pos-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar__title { line-height: 1.5rem; }
  .topbar.is-hidden { transform: translateY(calc(-100% - var(--sp-300))); }
  .sidenav #iconSidenav { inset-block-start: var(--sp-200); }
  .app-content { padding-top: var(--sp-200); }
}

/* ---------- small laptops and tablets landscape (side menu visible, 992 to 1279px): top bar controls shrink to icons ---------- */
@media (min-width: 992px) and (max-width: 1279.98px) {
  .topbar .net-status__text { display: none; }
  .topbar__actions .topbar__chip > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .topbar__actions { flex-shrink: 0; }
}

/* ---------- < 768px: phone and small tablet ---------- */
@media (max-width: 767.98px) {
  .app-content { padding-inline: var(--sp-100); }
  .card { --bs-card-spacer-x: var(--sp-200); --bs-card-spacer-y: var(--sp-200); }
  .page-header__title { font: var(--heading-6); }
  .page-actions { justify-content: stretch; }
  .page-actions .page-actions__lead { flex: 1 1 100%; margin-bottom: var(--sp-25); }
  .page-actions .btn, .page-header__actions .btn { flex: 1 1 auto; }
  .chart-box { height: 220px; }
  .invoice__head { flex-direction: column; }
  .invoice__totals { max-width: none; }

  /* filters stack: one control per row, full width */
  .filter-bar { gap: var(--sp-100); }
  .filter-bar > * { flex: 1 1 100%; min-width: 0; }
  .filter-bar .form-select, .filter-bar .form-control, .filter-bar .select2-container { min-width: 0; width: 100% !important; }
  .filter-bar .btn { width: 100%; }

  /* DataTables controls */
  .dt-container .dt-layout-row { flex-direction: column; align-items: stretch !important; gap: var(--sp-100); }
  .dt-container .dt-layout-cell { width: 100%; justify-content: space-between; }
  .dt-container .dt-search, .dt-container .dt-search input { width: 100%; min-width: 0; margin: 0; }
  .dt-container .dt-paging { align-self: center; }
  .dt-container .dt-paging .page-item:not(.active):not(.previous):not(.next):not(.first):not(.last) { display: none; }
  .dt-container .dt-info { text-align: center; }
  .dt-buttons { display: flex; flex-wrap: wrap; gap: var(--sp-75); }

  /* tables become cards: label on the left, value on the right (labels are set from the column headers by js/spatial.js) */
  .table-responsive { overflow: visible; }
  table.table-stack { display: block; width: 100% !important; border: 0; }
  table.table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  table.table-stack tbody, table.table-stack tfoot { display: block; }
  table.table-stack tr {
    display: block; margin-bottom: var(--sp-100); padding: var(--sp-100) var(--sp-200);
    background: var(--pos-surface); border: 1px solid var(--pos-border); border-radius: var(--pos-radius-lg); box-shadow: var(--pos-shadow-xs);
  }
  table.table-stack :is(td, tbody th, tfoot th) {
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-200); width: auto !important; min-height: 32px;
    padding: var(--sp-50) 0 !important; border: 0 !important; text-align: end; background: transparent; white-space: normal;
  }
  table.table-stack :is(td, tbody th, tfoot th)::before {
    content: attr(data-label); flex: 0 0 auto; max-width: 45%; text-align: start; font: var(--caption-3); color: var(--pos-text-muted);
  }
  table.table-stack :is(td, tbody th, tfoot th)[data-label=""]::before, table.table-stack :is(td, tbody th, tfoot th):not([data-label])::before { display: none; }
  table.table-stack :is(td, tbody th, tfoot th).sr-col { display: none; }
  table.table-stack :is(td, tbody th, tfoot th):empty { display: none; }
  table.table-stack :is(td, tbody th, tfoot th).dt-empty { display: block; text-align: center; }
  table.table-stack tfoot th[colspan]:not([colspan="1"]), table.table-stack tbody th[colspan]:not([colspan="1"]), table.table-stack tfoot th[data-title] { display: block; text-align: start; font: var(--title-3); padding: 0 0 var(--sp-75) !important; margin-bottom: var(--sp-50); border-bottom: 1px solid var(--pos-border) !important; }
  table.table-stack td[colspan]:not([colspan="1"]) { display: block; text-align: center; }
  table.table-stack :is(td, tbody th, tfoot th):last-child:has(.btn) { justify-content: flex-end; flex-wrap: wrap; margin-top: var(--sp-75); padding-top: var(--sp-100) !important; border-top: 1px dashed var(--pos-border) !important; }
  table.table-stack :is(td, tbody th, tfoot th):last-child:has(.btn) .btn { min-height: var(--pos-tap); min-width: var(--pos-tap); }
  table.table-stack tfoot tr { background: var(--pos-surface-2); }
  table.table-stack .dt-column-footer, table.table-stack .dt-column-header { display: contents; }
  table.table-stack tr:hover > td { background: transparent; }

  .credit-summary > div { flex: 1 1 calc(50% - var(--sp-200)); }
  .setup-grid { gap: var(--sp-200); }
}

/* ---------- < 576px: small phones ---------- */
@media (max-width: 575.98px) {
  .topbar [data-fullscreen-toggle], .topbar .net-status { display: none; }
  .app-footer { font: var(--caption-5); }
  .auth__panel { padding-inline: var(--sp-100); padding-top: max(var(--sp-100), env(safe-area-inset-top)); }
  .auth__card { padding: var(--sp-300) var(--sp-200); }

  /* dialogs are bottom sheets: slide up, grab handle, buttons stay in reach */
  .modal-dialog, .modal-dialog-centered, .modal-dialog-scrollable { margin: 0; max-width: none; width: 100%; height: 100%; min-height: 0; display: flex; align-items: flex-end; }
  .modal.fade .modal-dialog { transform: translateY(100%); }
  .modal.show .modal-dialog { transform: none; }
  .modal-content {
    width: 100%; max-height: calc(100dvh - var(--sp-600)); border-radius: var(--pos-radius-xl) var(--pos-radius-xl) 0 0; border-bottom-width: 0;
    padding-bottom: env(safe-area-inset-bottom); overflow: hidden;
  }
  .modal-content::before { content: ""; display: block; flex-shrink: 0; width: 40px; height: 4px; margin: var(--sp-75) auto 0; border-radius: var(--pos-radius-xs); background: var(--pos-border-strong); }
  .modal-header { padding: var(--sp-100) var(--sp-200); }
  .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--sp-100) var(--sp-200); }
  .modal-footer { padding: var(--sp-100) var(--sp-200) var(--sp-200); flex-wrap: nowrap; }
  .modal-footer .btn { flex: 1 1 0; }
  .modal-title { font: var(--title-1); }

  .swal2-popup { width: calc(100vw - var(--sp-400)) !important; padding: var(--sp-200); }
  .swal2-actions { width: 100%; flex-direction: column-reverse; gap: var(--sp-75); margin-top: var(--sp-200); }
  .swal2-actions .swal2-styled { width: 100%; margin: 0 !important; }
  .select2-search--dropdown .select2-search__field { font-size: 1rem; }

  .stat-card__value { font: var(--heading-6); }
  .kpi-deck > :first-child .stat-card__value { font: var(--heading-4); }
  .error-page__code { font: var(--heading-3); }
}

/* ---------- phones turned sideways: every pixel of height counts ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .topbar { height: 48px; top: var(--sp-75); margin-top: var(--sp-75); }
  .tabbar { padding: var(--sp-50); }
  .tabbar__item { min-height: 44px; flex-direction: row; justify-content: center; gap: var(--sp-75); }
  .app-content { padding-top: var(--sp-100); }
  .auth__main { padding: var(--sp-100) 0; }
  .modal-content { max-height: calc(100dvh - var(--sp-200)); }
}

/* ---------- touch screens: 44px targets, no hover that sticks after a tap ---------- */
@media (pointer: coarse) {
  .chip, .stepper button, .dropdown-item, .sidenav .nav-link, .page-link { min-height: var(--pos-tap); }
  .stepper button { width: var(--pos-tap); height: var(--pos-tap); }
  .form-check-input { width: 1.375em; height: 1.375em; }
  .line__disc input { height: var(--pos-tap); }
}
@media (hover: none) {
  .btn:hover:not(:disabled):not(.disabled), .btn-icon:hover, .auth__tools .btn-icon:hover, .topbar__chip:hover, .topbar__user:hover .avatar, .chip:hover,
  .pos-header .btn-icon:hover, .pos-header .topbar__chip:hover, .cart__pay:not(:disabled):hover { transform: none; }
  .product:hover:not(:disabled) { --lift: 0px; }
  .product:hover:not(:disabled)::after { opacity: 0; }
  .sidenav .nav-link:hover .icon-shape, .sidenav .nav-link:hover > .ico { transform: none; }
  .topbar [data-tools] .btn-icon:hover .ico, .auth__tools .btn-icon:hover .ico, .topbar [data-fullscreen-toggle]:hover .ico, .topbar__chip:hover .ico { transform: none; }
  .stat-card:hover::after { opacity: 0; }
  .pos-header__brand:hover img { transform: none; }
}

@media print { .tabbar, .nav-progress { display: none !important; } }

/* ---------- top bar: elevation when content scrolls under it, status dot on the avatar ---------- */
.topbar { transition: transform var(--pos-dur-slow) var(--pos-ease); }
.topbar::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; box-shadow: var(--pos-shadow-lg); opacity: 0; pointer-events: none; transition: opacity var(--pos-dur) var(--pos-ease); }
.topbar.is-scrolled::after { opacity: 1; }
.topbar__heading { display: flex; flex-direction: column; min-width: 0; }
@media (min-width: 992px) { .topbar__sub { display: none; } }   /* desktop shows the branch chip instead */
.topbar__user .avatar { position: relative; }
.topbar__user .avatar::after {
  content: ""; position: absolute; inset-block-end: -2px; inset-inline-end: -2px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--pos-success); border: 2px solid var(--pos-panel-solid); transition: background-color var(--pos-dur) var(--pos-ease);
}
.topbar:has([data-network-status][data-state="offline"]) .topbar__user .avatar::after { background: var(--pos-danger); animation: pos-breathe 1.6s ease-in-out infinite; }
@keyframes pos-tab-pop { 0% { transform: translateY(6px) scale(0.8); } 55% { transform: translateY(-3px) scale(1.2); } 100% { transform: scale(1.1); } }

/* ---------- drawer footer: currency, language and theme live here on phones (the top bar has no room) ---------- */
.sidenav__prefs { display: none; }
@media (max-width: 575.98px) {
  .topbar [data-tools] { display: none !important; }
  .sidenav__prefs { display: block; flex-shrink: 0; margin-top: var(--sp-75); padding: var(--sp-100) var(--sp-50) var(--sp-25); border-top: 1px solid rgba(255, 255, 255, 0.12); }
  .sidenav__prefs-label { display: block; margin-bottom: var(--sp-75); padding-inline: var(--sp-75); font: var(--caption-3); color: var(--sn-text); }
  .sidenav__prefs-row { display: flex; flex-wrap: wrap; gap: var(--sp-75); padding-inline: var(--sp-50); }
  .sidenav .topbar__chip, .sidenav .btn-icon { background: rgba(255, 255, 255, 0.07); border: 1px solid rgba(255, 255, 255, 0.12); color: var(--sn-strong); height: 44px; }
  .sidenav .topbar__chip > span, .sidenav .topbar__chip > span.d-none { display: inline !important; }
  .sidenav .btn-icon { width: 44px; }
  .sidenav .topbar__chip:hover, .sidenav .btn-icon:hover { background: rgba(255, 255, 255, 0.14); }

  /* The currency, language and theme menus open as one panel above the chips, as wide as the drawer.
     (Anchored to the small chip they were wider than it and ran off the screen edge, cutting the text.) */
  .sidenav__prefs-row { position: relative; }
  .sidenav__prefs-row > .dropup, .sidenav__prefs-row > .dropdown { position: static; }
  .sidenav__prefs-row .dropdown-menu {
    position: absolute !important; inset-inline: 0 !important; inset-block: auto calc(100% + var(--sp-75)) !important;
    width: auto; min-width: 0; margin: 0 !important; transform: none !important;
    max-height: min(60vh, 22rem); overflow-y: auto; overscroll-behavior: contain;
    padding: var(--sp-50); text-align: start;
  }
  .sidenav__prefs-row .dropdown-header { padding-inline: var(--sp-100); text-align: start; }
  .sidenav__prefs-row .dropdown-item { width: 100%; justify-content: flex-start; text-align: start; white-space: nowrap; }
  .sidenav__prefs-row .dropdown-item__code { min-width: 3.25rem; }                 /* currency codes line up in a column */
  .sidenav__prefs-row .dropdown-item__hint { overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- login password eye on touch screens: behave exactly like the mouse version ----------
   The (hover: none) rule above resets transform on .btn-icon:hover, and a tapped button keeps :hover, so the eye lost its
   translateY(-50%) and stayed low. Keep the centring while hovered, and keep the same press motion as the desktop. */
@media (hover: none) {
  .auth__input-wrap .auth__toggle:hover { transform: translateY(-50%); }
  .auth__input-wrap .auth__toggle:active { transform: scale(0.98); }
}

/* ---------- dashboard KPI tiles on phones: a last tile left alone in its row stretches across both columns ---------- */
@media (max-width: 767.98px) {
  .kpi-deck > :last-child:nth-child(even) { grid-column: 1 / -1; }                              /* hero is tile 1, so an even last tile would sit alone */
  .kpi-deck > :last-child:nth-child(even) .stat-card { padding-block: var(--sp-300); row-gap: var(--sp-100); }
  .kpi-deck > :last-child:nth-child(even) .stat-card__value { font: var(--heading-5); }         /* the extra width carries a larger figure */
}

/* ---------- top bar buttons: one size, one gap (40px with a mouse, 44px on touch screens) ---------- */
.topbar { --tb-btn: 40px; }
@media (pointer: coarse) { .topbar { --tb-btn: 44px; } }
.topbar__actions { gap: var(--sp-75); }
.topbar .btn-icon, .topbar .btn-icon-solid, .topbar__user .avatar { width: var(--tb-btn); height: var(--tb-btn); min-width: var(--tb-btn); min-height: var(--tb-btn); padding: 0; }
.topbar__chip { height: var(--tb-btn); min-height: var(--tb-btn); }
.topbar .dropdown { display: flex; }
.topbar__user { display: grid; place-items: center; }
