/* Shared mobile layer for the legacy AdminLTE/Angular application. */
html,
body {
  max-width: 100%;
}

.content-wrapper {
  min-width: 0;
}

.content-wrapper img,
.content-wrapper canvas,
.content-wrapper svg {
  max-width: 100%;
}

.space-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 767.98px) {
  body {
    overflow-x: hidden;
  }

  .main-header {
    min-height: 56px;
    padding: 0.35rem 0.5rem;
  }

  .main-header .nav-link {
    display: inline-flex;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
  }

  .main-header .navbar-nav.ml-auto a {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    gap: 0.35rem;
    padding: 0 0.35rem;
  }

  .content-wrapper {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }

  .content-header {
    padding: 0.85rem 0 0.45rem;
  }

  .content-header h1 {
    margin: 0;
    font-size: 1.45rem;
    line-height: 1.25;
  }

  .content > .container-fluid,
  .content-header > .container-fluid,
  .content-wrapper > .container-fluid {
    padding-right: 0.75rem;
    padding-left: 0.75rem;
  }

  .content .row {
    min-width: 0;
  }

  .content [class*="col-"],
  .content [class*="col-sm-"],
  .content [class*="col-md-"],
  .content [class*="col-lg-"] {
    min-width: 0;
  }

  .card {
    max-width: 100%;
    margin-bottom: 0.85rem;
    border-radius: 0.65rem;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: 0.85rem;
  }

  .card-header .row {
    row-gap: 0.5rem;
  }

  .card-header .form-group {
    margin-bottom: 0.5rem;
  }

  .card-header .text-right,
  .card-header .item-right {
    text-align: left !important;
  }

  .card-header .btn {
    min-height: 42px;
  }

  .form-control,
  .custom-select,
  .select2-container .select2-selection--single {
    min-height: 42px;
    font-size: 16px;
  }

  textarea.form-control {
    min-height: 90px;
  }

  .btn {
    white-space: normal;
  }

  .modal-dialog {
    width: auto;
    margin: 0.5rem;
  }

  .modal-content {
    max-height: calc(100dvh - 1rem);
    overflow-y: auto;
    border-radius: 0.75rem;
  }

  .table-responsive,
  .space-table-scroll,
  .card-body[style*="overflow-x"] {
    scrollbar-width: thin;
    overscroll-behavior-x: contain;
  }

  /* Tables that are too complex for cards remain readable by horizontal scroll. */
  .space-table-scroll > table:not(.space-mobile-table) {
    min-width: 680px;
  }

  /* Simple CRUD tables are converted to scan-friendly mobile cards by JS. */
  table.space-mobile-table,
  table.space-mobile-table tbody,
  table.space-mobile-table tr,
  table.space-mobile-table td {
    display: block;
    width: 100% !important;
  }

  table.space-mobile-table {
    min-width: 0 !important;
    margin: 0;
    border: 0 !important;
    background: transparent;
  }

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

  table.space-mobile-table tbody {
    display: grid;
    gap: 0.75rem;
  }

  table.space-mobile-table tbody tr {
    overflow: hidden;
    border: 1px solid #dee2e6;
    border-radius: 0.65rem;
    background: #fff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  }

  table.space-mobile-table tbody td {
    display: grid;
    grid-template-columns: minmax(92px, 36%) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
    min-height: 42px;
    padding: 0.65rem 0.75rem !important;
    border: 0 !important;
    border-bottom: 1px solid #edf0f3 !important;
    overflow-wrap: anywhere;
    white-space: normal !important;
    text-align: left !important;
  }

  table.space-mobile-table tbody td:last-child {
    border-bottom: 0 !important;
  }

  table.space-mobile-table tbody td::before {
    content: attr(data-mobile-label);
    color: #64748b;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.4;
    text-transform: uppercase;
  }

  table.space-mobile-table tbody td[data-mobile-label="Action"],
  table.space-mobile-table tbody td[data-mobile-label="Thao tác"] {
    align-items: center;
  }

  table.space-mobile-table tbody td .btn {
    min-width: 40px;
    min-height: 40px;
    margin: 0.1rem;
  }

  .pagination {
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .main-footer {
    padding: 0.75rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 420px) {
  .content > .container-fluid,
  .content-header > .container-fluid,
  .content-wrapper > .container-fluid {
    padding-right: 0.5rem;
    padding-left: 0.5rem;
  }

  .card-header,
  .card-body,
  .card-footer {
    padding: 0.7rem;
  }

  table.space-mobile-table tbody td {
    grid-template-columns: minmax(82px, 34%) minmax(0, 1fr);
    gap: 0.5rem;
    padding: 0.6rem !important;
  }
}
