/* Shared responsive layer for the admin, POS, and auth screens. */

html,
body {
  max-width: 100%;
}

img,
svg,
video,
canvas {
  max-width: 100%;
}

img,
video {
  height: auto;
}

.app-wrapper,
.app-wrapper .container,
.app-wrapper .container-fluid,
.app-wrapper .row > [class*="col-"],
.card,
.card-body,
.card-header,
.modal-body,
.modal-content {
  min-width: 0;
}

.app-page-head,
.card-header.d-flex,
.app-page-head > .d-flex {
  flex-wrap: wrap;
  row-gap: 0.5rem;
}

.app-page-title,
.card-title,
.breadcrumb-item {
  overflow-wrap: anywhere;
}

.breadcrumb {
  flex-wrap: wrap;
}

.alert,
.invalid-feedback,
.valid-feedback,
.form-text {
  max-width: 100%;
  overflow-wrap: break-word;
}

.form-control,
.form-select,
textarea,
.input-group,
.select2-container {
  max-width: 100%;
}

.input-group {
  min-width: 0;
}

.input-group > .form-control,
.input-group > .form-select {
  min-width: 0;
}

input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"] {
  min-width: 0;
  max-width: 100%;
}

.card .select2-container,
.modal .select2-container {
  width: 100% !important;
}

.flatpickr-calendar {
  max-width: calc(100vw - 1rem);
}

/* Sidebar drawer below the desktop breakpoint. Desktop mini/full stays intact. */
.app-menubar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-inline-start: auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  flex-shrink: 0;
}

.tenant-context {
  min-width: 0;
}

.tenant-context-select {
  width: auto;
  min-width: 9rem;
  max-width: 14rem;
}

.tenant-context-label {
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1199.98px) {
  .app-header {
    z-index: 1030;
  }

  .app-menubar {
    z-index: 1045;
    width: min(280px, 86vw);
    max-width: 86vw;
    right: calc(-1 * min(280px, 86vw) - 24px);
  }

  .app-menubar.open {
    right: 0;
  }

  .app-menubar .app-navbar-brand,
  .app-menubar .app-navbar {
    width: 100%;
    min-width: 0;
  }

  .app-menubar-close {
    display: inline-flex;
  }

  .app-header .vr {
    display: none;
  }

  .app-header-end {
    min-width: 0;
    gap: 0.25rem;
  }

  .tenant-context-select {
    min-width: 0;
    width: 8.5rem;
    max-width: 10rem;
  }
}

@media (max-width: 991.98px) {
  .app-header {
    height: auto;
    align-items: flex-start;
  }

  .app-header-inner {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 0.35rem;
    padding: 0.45rem 0.6rem 0.55rem;
  }

  .app-toggler {
    margin: 0.45rem 0.15rem 0;
    flex-shrink: 0;
  }

  .app-header-end {
    flex: 1 1 auto;
    width: auto;
    height: auto;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
  }

  .tenant-context {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    order: 5;
    margin: 0 !important;
  }

  .tenant-context-select {
    flex: 1 1 calc(50% - 0.5rem);
    width: auto;
    max-width: none;
  }

  .tenant-context-label {
    max-width: none;
  }

  .btn-pos-label {
    display: none;
  }

  .btn-pos-shortcut {
    margin-inline-start: 0 !important;
  }

  .app-wrapper {
    margin-top: var(--app-header-offset, 96px);
  }
}

@media (max-width: 575.98px) {
  .app-wrapper {
    padding-left: 12px;
    padding-right: 12px;
  }

  .app-page-title {
    font-size: 1.25rem;
  }

  .app-page-head {
    margin-bottom: 1rem;
  }

  .card-header,
  .card-body {
    padding-left: 0.9rem;
    padding-right: 0.9rem;
  }

  .form-control,
  .form-select,
  .select2-container .select2-selection {
    font-size: 16px;
  }

  .card-body form .text-end > .btn,
  .card-body form .text-start > .btn,
  .card-body form .d-flex.justify-content-end > .btn,
  .card-body form .d-flex.justify-content-start > .btn {
    width: 100%;
  }

  .dropdown-menu {
    max-width: calc(100vw - 1rem);
  }

  .w-225px {
    width: min(225px, calc(100vw - 1rem)) !important;
  }

  #toast-container {
    width: calc(100vw - 1rem);
    max-width: calc(100vw - 1rem);
    inset-inline: 0.5rem;
  }

  #toast-container > div,
  #toast-container > .toast {
    width: 100%;
  }

  .swal2-container {
    padding: 0.5rem;
  }

  .swal2-popup {
    width: 100% !important;
    max-width: calc(100vw - 1rem);
    font-size: 0.95rem;
  }

  [class*="fl-wrapper"] {
    max-width: calc(100vw - 1rem);
    inset-inline: 0.5rem;
  }
}

/* Tables keep every column and scroll inside the card. */
.table-responsive,
.card-body.p-0,
.card-body:has(.dataTables_wrapper),
.dataTables_wrapper,
.modal-body .table-responsive {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.dataTables_wrapper,
.table-responsive {
  width: 100%;
}

table.dataTable td .btn,
table.dataTable td .btn-group,
.table td .btn,
.table td .btn-group {
  white-space: nowrap;
}

@media (max-width: 767.98px) {
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    float: none;
    width: 100%;
    text-align: start;
    margin-bottom: 0.5rem;
  }

  .dataTables_wrapper .dataTables_filter label,
  .dataTables_wrapper .dataTables_length label {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
    width: 100%;
  }

  .dataTables_wrapper .dataTables_filter input {
    display: block;
    width: 100% !important;
    margin: 0 !important;
  }

  .dataTables_wrapper .row > [class*="col-"] {
    flex: 0 0 100%;
    max-width: 100%;
    width: 100%;
  }

  .dataTables_wrapper .pagination {
    flex-wrap: wrap;
    justify-content: center;
  }

  div.dataTables_wrapper div.dataTables_paginate {
    text-align: center;
  }
}

/* Modals stay inside the viewport and scroll when the form is long. */
.modal-content {
  max-height: calc(100vh - 1rem);
}

.modal-fullscreen .modal-content {
  max-height: 100%;
}

.modal-body {
  overflow-y: auto;
}

@media (max-width: 575.98px) {
  .modal-dialog:not(.modal-fullscreen) {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-dialog.modal-xl,
  .modal-dialog.modal-lg,
  .modal-dialog.modal-md,
  .modal-dialog.modal-sm {
    max-width: calc(100% - 1rem);
  }

  .modal-header,
  .modal-footer {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    flex: 1 1 calc(50% - 0.5rem);
  }
}

/* Charts and stat cards */
.card .h1,
.card .h2,
.card .h3,
.card .h4,
.card .h5 {
  overflow-wrap: anywhere;
}

.bg-light:has(> canvas),
.card-body:has(> canvas) {
  min-width: 0;
  overflow: hidden;
}

/* POS */
@media (max-width: 991.98px) {
  .pos-page .pos-checkout-actions {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 1020;
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--bs-border-color, #e9ecef);
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.12);
  }

  .pos-page {
    padding-bottom: calc(5.25rem + env(safe-area-inset-bottom));
  }

  body.pos-input-focused .pos-page .pos-checkout-actions {
    position: static;
    box-shadow: none;
    border-top: 0;
    padding-inline: 0;
  }

  .pos-page .pos-category-grid {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  }

  .pos-page input,
  .pos-page select,
  .pos-page textarea {
    scroll-margin-bottom: 5.5rem;
  }
}

@media (max-width: 575.98px) {
  .pos-page .pos-category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pos-page .pos-receipt-head {
    display: none;
  }

  .pos-page .pos-receipt-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .pos-page .receipt-qty-controls {
    justify-self: start;
  }

  .pos-page .payment-method-btn {
    flex-direction: column;
    min-width: 0;
    padding: 8px 4px;
    gap: 4px;
  }

  .pos-page .app-page-head .btn {
    flex: 1 1 auto;
  }
}

/* Auth frames: decorative images must not create a horizontal page scroll. */
@media (max-width: 991.98px) {
  .auth-frame-wrapper {
    height: auto;
    min-height: 100vh;
    overflow-x: clip;
  }

  .auth-imgs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin: 1.5rem 0 0;
  }

  .auth-imgs .position1,
  .auth-imgs .position2 {
    position: static;
    width: 72px;
  }
}

@media (max-width: 575.98px) {
  .auth-frame {
    padding: 1.5rem 1rem;
  }

  .auth-frame .display-6 {
    font-size: 1.45rem;
  }

  .auth-inner,
  .maxw-450px {
    max-width: 100%;
  }

  .auth-inner {
    padding: 1.25rem !important;
  }
}

.guest-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 0.75rem;
}

.guest-card {
  width: min(440px, 100%);
}

.guest-card label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.guest-card .text-red-600 {
  color: #dc3545;
}

.guest-card .text-green-600 {
  color: #198754;
}

.guest-card .text-gray-600 {
  color: #667085;
}

/*
 * One required-field marker for every screen.
 * A label shows the red asterisk when its control carries the required attribute,
 * including fields whose script toggles that attribute. Radio options stay unmarked;
 * the group legend carries the single asterisk. Labels that already include
 * .required-mark are left unchanged.
 */
label:not(:has(.required-mark)):has(+ :is(input, select, textarea)[required]:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]))::after,
label:not(:has(.required-mark)):has(+ .password-field :is(input, select, textarea)[required]:not([type="hidden"]))::after,
label:not(:has(.required-mark)):has(+ .input-group :is(input, select, textarea)[required]:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]))::after,
label:not(:has(.required-mark)):has(+ :is(div, span) > :is(input, select, textarea)[required]:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]))::after,
label:not(:has(.required-mark)):has(> :is(input, select, textarea)[required]:not([type="hidden"]):not([type="radio"]):not([type="checkbox"]))::after,
.form-floating:has(> :is(input, select, textarea)[required]:not([type="hidden"]):not([type="radio"])) > label:not(:has(.required-mark))::after,
.form-check:has(> input[required]:not([type="radio"])) > label:not(:has(.required-mark))::after,
legend:not(:has(.required-mark)):has(~ .form-check > input[type="radio"][required])::after {
  content: "*";
  margin-inline-start: 0.28rem;
  color: #dc3545;
  font-weight: 700;
  font-size: 1em;
  line-height: 1;
}

.required-mark {
  color: #dc3545;
  font-weight: 700;
  margin-inline-start: 0.28rem;
  font-size: 1em;
  line-height: 1;
  user-select: none;
}

.required-mark[hidden] {
  display: none !important;
}

@media print {
  .app-header,
  .app-menubar,
  .footer-wrapper,
  .pos-checkout-actions {
    display: none !important;
  }

  .app-wrapper,
  .pos-page {
    margin: 0 !important;
    padding: 0 !important;
  }
}
