.app-shell,
body {
  color: #111827;
}

:root {
  --ui-radius-sm: 0.35rem;
  --ui-radius-md: 0.5rem;
  --ui-radius-lg: 0.7rem;
  --ui-border: #dbe1ea;
  --ui-border-strong: #c9d2df;
  --ui-surface: #ffffff;
  --ui-surface-muted: #f7f9fc;
  --ui-text-muted: #607089;
  --ui-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --ui-shadow-md: 0 8px 22px rgba(16, 24, 40, 0.08);
}

main {
  max-width: 100%;
}

.global-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: rgba(15, 23, 42, 0.26);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
}

.global-loading-overlay.is-visible {
  display: flex;
}

.global-loading-panel {
  min-width: 200px;
  text-align: center;
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid #dbe1ea;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 14px 36px rgba(2, 6, 23, 0.18);
}

.global-loading-spinner {
  width: 2rem;
  height: 2rem;
  margin: 0 auto 0.45rem auto;
  border-radius: 999px;
  border: 3px solid #dbe3ef;
  border-top-color: var(--app-primary, #0d6efd);
  animation: global-spin 0.9s linear infinite;
}

.global-loading-text {
  color: #1f2937;
  font-size: 0.9rem;
  font-weight: 600;
}

@keyframes global-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.poster-accordion-toggle {
  border: 0;
  border-radius: 0;
  text-decoration: none;
  padding: 0.6rem 0.9rem;
}

.poster-accordion-chevron {
  display: inline-block;
  transition: transform 0.2s ease;
  color: #475569;
  font-weight: 700;
}

.poster-accordion-toggle[aria-expanded='true'] .poster-accordion-chevron {
  transform: rotate(180deg);
}

.poster-back-top {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1200;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: rgba(255, 255, 255, 0.95);
  color: #0f172a;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(2, 6, 23, 0.22);
}

.poster-back-top.is-visible {
  display: inline-flex;
}

.poster-back-top:hover {
  background: #f8fafc;
}

.card,
.modal-content,
dialog .card,
.list-group-item,
.table,
.dropdown-menu {
  border-color: var(--ui-border);
}

.card,
dialog .card {
  background: var(--ui-surface);
  border-radius: var(--ui-radius-lg);
  box-shadow: var(--ui-shadow-sm);
}

.card .card-header {
  background: var(--ui-surface-muted);
  border-bottom: 1px solid var(--ui-border);
  font-weight: 600;
}

.btn,
.form-control,
.form-select {
  border-radius: var(--ui-radius-md);
}

.btn {
  font-weight: 600;
  border-width: 1px;
}

.btn-outline-secondary {
  border-color: var(--ui-border-strong);
  color: #334155;
}

.btn-outline-secondary:hover {
  background: #edf2f7;
  border-color: #b7c4d7;
  color: #1f2937;
}

.form-control,
.form-select {
  border-color: var(--ui-border-strong);
  background: #fff;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--app-primary);
  box-shadow: 0 0 0 0.18rem rgba(13, 110, 253, 0.14);
}

.table {
  border-radius: var(--ui-radius-md);
  overflow: hidden;
}

.table thead th {
  background: #f4f7fb;
  color: #334155;
  font-weight: 600;
  border-bottom-color: var(--ui-border-strong);
}

.table > :not(caption) > * > * {
  border-bottom-color: #e9eef5;
}

.table-sort-controls .table-sort-select {
  max-width: 260px;
}

.table-sortable .table-sort-header {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 1.2rem;
}

.table-sortable .table-sort-header::after {
  content: "↕";
  position: absolute;
  right: 0.35rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.72rem;
  opacity: 0.35;
}

.table-sortable .table-sort-header.table-sort-active::after {
  opacity: 0.85;
}

.table-sortable .table-sort-header.table-sort-asc::after {
  content: "↑";
}

.table-sortable .table-sort-header.table-sort-desc::after {
  content: "↓";
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
  --bs-table-bg-type: #fbfdff;
}

.navbar-branding {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 24px rgba(0, 0, 0, 0.2);
}

.dropdown-menu {
  border-radius: var(--ui-radius-md);
  box-shadow: var(--ui-shadow-md);
}

.badge {
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.touch-btn {
  min-height: 44px;
}

.mobile-scroll {
  overflow-x: auto;
}

.mobile-scroll table {
  min-width: 680px;
}

.pos-card {
  border-radius: var(--ui-radius-lg);
  border: 1px solid var(--ui-border);
  box-shadow: var(--ui-shadow-sm);
}

.pos-card .card-header {
  font-weight: 600;
}

.pos-terminal h2 {
  font-size: 1.2rem;
}

.pos-compact-muted {
  font-size: 0.85rem;
  color: #6c757d;
}

.pos-terminal .product-tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.6rem;
}

.pos-terminal .pos-multiples-quick {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.pos-terminal .qty-shortcut {
  min-height: 34px;
  min-width: 54px;
  padding: 0.25rem 0.55rem;
  font-weight: 600;
}

.pos-terminal .qty-shortcut.active {
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.18);
}

.pos-terminal .pos-top-controls {
  align-items: stretch;
}

.pos-terminal .pos-top-controls .pos-scan-form .input-group {
  min-height: 44px;
}

.qty-pad-modal {
  border: 0;
  border-radius: 12px;
  padding: 0;
  max-width: 420px;
  width: 95%;
}

.qty-pad-modal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}

.qty-pad-modal-grid .btn,
#qty-pad-set {
  min-height: 40px;
  font-weight: 600;
}

@media (max-width: 991.98px) {
  .qty-pad-modal[open] {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100vw;
    max-width: 100vw;
    margin: 0;
    border-radius: 14px 14px 0 0;
  }
}

.pos-terminal .product-tile {
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 0.75rem;
  padding: 0.55rem;
  background: #fff;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 0.35rem;
  position: relative;
  cursor: pointer;
  overflow: hidden;
}

.pos-terminal .product-tile-low {
  border-color: #f0ad4e;
  background: #fffaf1;
}

.pos-terminal .product-tile-out {
  border-color: #dc3545;
  background: #fff1f3;
}

.pos-terminal .product-tile .min-w-0 {
  min-width: 0;
}

.pos-terminal .product-tile .product-qty-input {
  width: 92px;
  flex: 0 0 92px;
}

.pos-terminal .product-tile-submit {
  position: absolute;
  inset: 0;
  border: 0;
  background: transparent;
  color: transparent;
}

.pos-terminal .product-tile-image-wrap {
  display: flex;
  justify-content: center;
}

.pos-terminal .product-tile-image {
  height: 64px;
  width: 64px;
  border-radius: 0.6rem;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.1);
  background: #fff;
}

.pos-terminal .product-tile-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6c757d;
  font-size: 0.78rem;
  background: #f6f7f9;
}

.pos-terminal .product-tile .fw-semibold {
  line-height: 1.15;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pos-terminal .category-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.55rem;
}

.pos-terminal .category-tile {
  border: 1px solid rgba(13, 110, 253, 0.25);
  border-radius: 0.75rem;
  background: #fff;
  color: var(--app-primary);
  text-decoration: none;
  padding: 0.75rem 0.8rem;
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.pos-terminal .category-tile:hover {
  border-color: var(--app-primary);
}

.pos-terminal .category-tile-muted {
  color: #495057;
  border-color: rgba(108, 117, 125, 0.28);
}

.pos-terminal .pos-pagination {
  display: flex;
  justify-content: center;
}

.pos-terminal.terminal-mode {
  height: calc(100vh - 165px);
  overflow: hidden;
}

.pos-terminal.terminal-mode > .row {
  height: 100%;
}

.pos-terminal.terminal-mode .order-1,
.pos-terminal.terminal-mode .order-2 {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pos-terminal.terminal-mode .product-tile-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.pos-terminal.terminal-mode .product-tile {
  padding: 0.45rem;
}

.pos-terminal.terminal-mode .pos-pagination-bottom {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--app-bg);
  padding-top: 0.25rem;
  padding-bottom: 0.1rem;
}

.pos-terminal.terminal-mode .pos-pagination-top {
  display: flex;
}

.pos-terminal.terminal-mode .checkout-wrap {
  position: sticky;
  bottom: 0;
  z-index: 1000;
  background: var(--app-bg);
  padding-top: 0.45rem;
}

.pos-terminal.terminal-mode .pos-card .card-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fff;
}

.pos-terminal.terminal-mode .touch-btn {
  min-height: 46px;
}

.pos-terminal.terminal-mode .product-browser {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding-right: 0.2rem;
}

.pos-terminal.terminal-mode .pos-sidebar {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding-right: 0.2rem;
}

.pos-terminal.terminal-mode .product-tile-image {
  width: 48px;
  height: 48px;
}

.pos-terminal.terminal-mode > h2,
.pos-terminal.terminal-mode > .pos-compact-muted {
  display: none;
}

.pos-terminal .pos-cart-mobile-scroll {
  max-height: 38vh;
  overflow: auto;
}

.pos-terminal .pos-cart-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pos-terminal .pos-cart-desktop-scroll {
  flex: 1;
  min-height: 0;
  max-height: min(46vh, 460px);
  overflow: auto;
}

.pos-terminal .pos-line-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pos-terminal .pos-line-actions form {
  margin: 0;
}

.pos-terminal .pos-line-actions .btn {
  min-height: 42px;
  min-width: 76px;
  padding: 0.45rem 0.55rem;
  font-size: 0.85rem;
}

.pos-terminal .touch-action-btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  line-height: 1.05;
}

.pos-terminal .touch-action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid currentColor;
}

.pos-terminal .touch-action-label {
  font-size: 0.72rem;
  font-weight: 600;
}

.pos-terminal .table td,
.pos-terminal .table th {
  vertical-align: middle;
}

.pos-terminal tr.cas-line-highlight > td {
  background-color: #fff3bf;
}

.pos-terminal .mobile-cart-card.cas-line-highlight {
  background-color: #fff3bf;
  border-color: #e0c66b;
}

@media (min-width: 992px) {
  .pos-terminal {
    height: calc(100vh - 165px);
    overflow: hidden;
  }

  .pos-terminal > .row {
    height: 100%;
  }

  .pos-terminal .order-1,
  .pos-terminal .order-2 {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .pos-terminal .product-browser {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding-right: 0.2rem;
  }

  .pos-terminal .pos-sidebar {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding-right: 0.2rem;
  }

  .pos-terminal .pos-pagination-bottom {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: var(--app-bg);
    padding-top: 0.35rem;
    padding-bottom: 0.15rem;
  }

  .pos-terminal .table td:last-child {
    min-width: 250px;
  }

  .pos-terminal .pos-cart-desktop-scroll {
    max-height: min(48vh, 520px);
  }
}

/* Targeted tuning for 1024x768 class terminals */
@media (min-width: 992px) and (max-width: 1100px) and (max-height: 800px) {
  .pos-terminal {
    height: calc(100vh - 148px);
    overflow: hidden;
  }

  .pos-terminal .product-browser {
    overflow: auto;
  }

  .pos-terminal .product-tile-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .pos-terminal .product-tile {
    padding: 0.42rem;
  }

  .pos-terminal .product-tile-image {
    width: 38px;
    height: 38px;
  }

  .pos-terminal .product-tile .fw-semibold {
    font-size: 0.82rem;
  }

  .pos-terminal .pos-card .card-header {
    font-size: 0.92rem;
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
  }

  .pos-terminal .pos-cart-mobile-scroll {
    max-height: min(34vh, 380px);
  }

  .pos-terminal .mobile-cart-card {
    padding: 0.55rem;
  }

  .pos-terminal .mobile-cart-card .fw-semibold {
    font-size: 0.9rem;
  }

  .pos-terminal .mobile-cart-card .pos-compact-muted {
    font-size: 0.75rem;
  }

  .pos-terminal .checkout-wrap {
    position: sticky;
    bottom: 0;
    z-index: 1000;
    background: var(--app-bg);
    padding-top: 0.35rem;
  }

  .pos-terminal .pos-line-actions {
    gap: 0.3rem;
  }

  .pos-terminal .pos-line-actions .btn {
    min-height: 36px;
    font-size: 0.73rem;
    padding: 0.3rem 0.3rem;
  }

  .pos-terminal .touch-action-icon {
    width: 1.05rem;
    height: 1.05rem;
    font-size: 0.58rem;
  }

  .pos-terminal .touch-action-label {
    font-size: 0.56rem;
  }
}

@media (min-width: 992px) and (max-height: 900px) {
  .pos-terminal .product-tile-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .pos-terminal .product-tile {
    padding: 0.48rem;
  }
}

@media (max-width: 1199.98px) {
  .pos-terminal .product-tile-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.pos-status-modal::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.pos-status-modal .card {
  border-radius: 1rem;
  box-shadow: 0 18px 40px rgba(2, 6, 23, 0.25);
}

.pos-status-icon {
  width: 3.2rem;
  height: 3.2rem;
  border-radius: 999px;
  margin: 0 auto;
  font-size: 1.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pos-status-success {
  background: #e9f9ef;
  color: #1d8a49;
}

.pos-status-error {
  background: #feecef;
  color: #c9344d;
}

.pos-status-warning {
  background: #fff8e7;
  color: #b7791f;
}

.pos-status-info {
  background: #e8f1ff;
  color: #1d4ed8;
}

@media (max-width: 991.98px) {
  .pos-terminal .pos-top-controls {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .pos-terminal .pos-top-controls .pos-scan-form {
    flex: 1 1 100%;
    width: 100%;
  }

  .pos-terminal .mobile-cart-card > .d-flex {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .pos-terminal .mobile-cart-card .text-end {
    text-align: left !important;
  }

  .pos-terminal .pos-line-actions {
    justify-content: stretch;
    gap: 0.35rem;
    width: 100%;
  }

  .pos-terminal .pos-line-actions form {
    flex: 1 1 0;
    min-width: 0;
  }

  .pos-terminal .pos-line-actions .btn {
    min-width: 0;
    width: 100%;
    padding: 0.35rem 0.4rem;
    font-size: 0.78rem;
  }

  .pos-terminal .touch-action-label {
    font-size: 0.62rem;
  }

  .pos-terminal .touch-action-icon {
    width: 1.2rem;
    height: 1.2rem;
    font-size: 0.64rem;
  }
}

@media (max-width: 767.98px) {
  main .table:not(.table-mobile-cards) {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  main .table:not(.table-mobile-cards) > :not(caption) > * > * {
    white-space: nowrap;
  }

  .navbar .btn {
    min-height: 40px;
  }

  .pos-terminal .section-spacer {
    margin-top: 0.75rem;
  }

  .pos-terminal .pos-top-controls {
    margin-bottom: 0.55rem !important;
  }

  .pos-terminal .pos-top-controls .pos-scan-form .input-group {
    min-height: 48px;
  }

  .pos-terminal #scan-input {
    font-size: 0.98rem;
  }

  .pos-terminal #scan-qty-input {
    max-width: 74px !important;
    text-align: center;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }

  .pos-terminal .pos-multiples-quick {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.2rem;
    margin-bottom: 0.55rem !important;
  }

  .pos-terminal .pos-multiples-quick .qty-shortcut,
  .pos-terminal .pos-multiples-quick form {
    flex: 0 0 auto;
  }

  .pos-terminal .pos-multiples-quick form {
    margin-left: 0.2rem;
  }

  .pos-terminal .mobile-product-card,
  .pos-terminal .mobile-cart-card {
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 0.75rem;
    padding: 0.75rem;
    background: #fff;
  }

  .pos-terminal .mobile-product-card + .mobile-product-card,
  .pos-terminal .mobile-cart-card + .mobile-cart-card {
    margin-top: 0.5rem;
  }

  .pos-terminal .product-tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.45rem;
  }

  .pos-terminal .product-tile {
    padding: 0.55rem;
  }

  .pos-terminal .product-tile-image {
    height: 46px;
    width: 46px;
  }

  .pos-terminal .product-tile .fw-semibold {
    font-size: 0.84rem;
    line-height: 1.15;
  }

  .pos-terminal .category-tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pos-terminal .checkout-wrap {
    position: sticky;
    bottom: 0;
    z-index: 1000;
    background: var(--app-bg);
    padding-top: 0.5rem;
    margin-top: 0.5rem;
  }

  .pos-terminal .pos-line-actions {
    justify-content: flex-end;
  }

  .pos-terminal .pos-line-actions .btn {
    min-width: 72px;
    padding: 0.4rem 0.45rem;
    font-size: 0.8rem;
  }

  .pos-terminal .touch-action-label {
    font-size: 0.68rem;
  }

  .table-mobile-cards thead {
    display: none;
  }

  .table-mobile-cards,
  .table-mobile-cards tbody,
  .table-mobile-cards tr,
  .table-mobile-cards td {
    display: block;
    width: 100%;
  }

  .table-mobile-cards tr {
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 0.75rem;
    padding: 0.5rem;
    margin-bottom: 0.6rem;
    background: #fff;
  }

  .table-mobile-cards td {
    border: 0;
    padding: 0.2rem 0;
  }
}
