/* ============================================================
   MOBILE OPTIMIZATION - AdminLTE 3 / Bootstrap 4
   ============================================================
   Objetivo:
   - reduzir recuos e espacos desperdicados
   - deixar cards, tabelas e formularios mais compactos
   - melhorar leitura e toque em telas pequenas
   - manter compatibilidade com as telas atuais
   ============================================================ */

@media (max-width: 991.98px) {
  .content-wrapper,
  .content-header,
  .content {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .content-header .container-fluid,
  .content > .container-fluid,
  .content-wrapper > .content > .container-fluid,
  .content-wrapper > .content-header > .container-fluid {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  .row {
    margin-left: -4px !important;
    margin-right: -4px !important;
  }

  [class^="col-"],
  [class*=" col-"] {
    padding-left: 4px !important;
    padding-right: 4px !important;
  }
}

@media (max-width: 768px) {
  html {
    scroll-behavior: smooth;
  }

  body {
    font-size: 13px;
    line-height: 1.35;
    -webkit-text-size-adjust: 100%;
  }

  * {
    -webkit-tap-highlight-color: transparent;
  }

  h1,
  .h1 {
    font-size: 1.2rem;
  }

  h2,
  .h2 {
    font-size: 1.1rem;
  }

  h3,
  .h3 {
    font-size: 1rem;
  }

  h4,
  h5,
  h6,
  .h4,
  .h5,
  .h6 {
    font-size: 0.95rem;
  }

  small,
  .small {
    font-size: 0.76rem;
  }

  p,
  li,
  dt,
  dd,
  label,
  .form-text {
    margin-bottom: 0.35rem;
  }

  .content-header {
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
  }

  .content-header h1,
  .content-header .m-0 {
    font-size: 1.08rem;
    line-height: 1.2;
  }

  .breadcrumb,
  .content-header .breadcrumb,
  .breadcrumb.float-sm-right {
    display: none !important;
  }

  .card {
    margin-bottom: 0.55rem;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  }

  .card-header {
    padding: 0.45rem 0.6rem;
    min-height: auto;
  }

  .card-header .card-title,
  .card-header h3.card-title,
  .card-header h5,
  .card-header h6 {
    font-size: 0.92rem;
    line-height: 1.2;
    margin-bottom: 0;
  }

  .card-body {
    padding: 0.6rem;
  }

  .card-footer {
    padding: 0.45rem 0.6rem;
  }

  .btn {
    font-size: 0.84rem;
    padding: 0.42rem 0.68rem;
    border-radius: 8px;
    white-space: nowrap;
  }

  .btn-sm,
  .btn-xs {
    font-size: 0.76rem;
    padding: 0.32rem 0.5rem;
  }

  .btn-lg {
    font-size: 0.95rem;
    padding: 0.6rem 0.9rem;
  }

  .btn-block + .btn-block {
    margin-top: 0.4rem;
  }

  .btn i {
    margin-right: 4px;
  }

  .form-group {
    margin-bottom: 0.55rem;
  }

  label {
    font-size: 0.8rem;
    margin-bottom: 0.2rem;
  }

  .form-control,
  .custom-select,
  .input-group-text {
    height: auto;
    min-height: 36px;
    font-size: 0.84rem;
    padding: 0.4rem 0.55rem;
    border-radius: 8px;
  }

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

  input,
  select,
  textarea,
  button {
    touch-action: manipulation;
  }

  .main-header .navbar {
    min-height: 52px;
    padding-left: 0.25rem;
    padding-right: 0.25rem;
  }

  .main-header .navbar-nav .nav-link {
    padding: 0.35rem 0.5rem;
    font-size: 0.86rem;
  }

  .main-sidebar {
    width: 230px;
  }

  .nav-sidebar .nav-item > .nav-link {
    padding: 0.42rem 0.56rem;
    font-size: 0.86rem;
  }

  .nav-sidebar .nav-icon {
    margin-right: 6px;
    font-size: 0.88rem;
  }

  .nav-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .nav-tabs .nav-link {
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
  }

  .table-responsive {
    border: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    font-size: 0.76rem;
    margin-bottom: 0;
  }

  .table th,
  .table td {
    padding: 0.34rem 0.38rem;
    vertical-align: middle;
  }

  .table thead th {
    font-size: 0.72rem;
    line-height: 1.15;
    white-space: nowrap;
  }

  .table td {
    line-height: 1.2;
  }

  .table-sm th,
  .table-sm td {
    padding: 0.26rem 0.3rem;
  }

  .table td.text-right,
  .table th.text-right {
    min-width: 64px;
  }

  .table td .btn,
  .table th .btn {
    margin-bottom: 2px;
  }

  .table-hover tbody tr:hover {
    background-color: inherit;
  }

  table.dataTable thead th,
  table.dataTable tbody td {
    white-space: nowrap;
  }

  .dataTables_wrapper {
    font-size: 0.76rem;
  }

  .dataTables_wrapper .row {
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .dataTables_wrapper .col-sm-12,
  .dataTables_wrapper .col-md-6,
  .dataTables_wrapper .col-md-5,
  .dataTables_wrapper .col-md-7 {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .dataTables_wrapper .dataTables_filter,
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_info,
  .dataTables_wrapper .dataTables_paginate {
    text-align: left !important;
    margin-bottom: 0.35rem;
  }

  .dataTables_wrapper .dataTables_filter label,
  .dataTables_wrapper .dataTables_length label {
    width: 100%;
    margin-bottom: 0.2rem;
  }

  .dataTables_wrapper .dataTables_filter input,
  .dataTables_wrapper .dataTables_length select {
    width: 100%;
    margin-left: 0 !important;
    font-size: 0.8rem;
  }

  .dataTables_wrapper .pagination {
    flex-wrap: wrap;
    gap: 4px;
  }

  .dataTables_wrapper .page-link {
    padding: 0.28rem 0.5rem;
    font-size: 0.76rem;
  }

  /* Tabelas comuns: esconde colunas finais quando houver muitas colunas */
  .table-mobile-hide-last-1 th:last-child,
  .table-mobile-hide-last-1 td:last-child {
    display: none;
  }

  .table-mobile-hide-last-2 th:nth-last-child(-n + 2),
  .table-mobile-hide-last-2 td:nth-last-child(-n + 2) {
    display: none;
  }

  .table-mobile-hide-last-3 th:nth-last-child(-n + 3),
  .table-mobile-hide-last-3 td:nth-last-child(-n + 3) {
    display: none;
  }

  .table-mobile-hide-col-3 th:nth-child(3),
  .table-mobile-hide-col-3 td:nth-child(3),
  .table-mobile-hide-col-4 th:nth-child(4),
  .table-mobile-hide-col-4 td:nth-child(4),
  .table-mobile-hide-col-5 th:nth-child(5),
  .table-mobile-hide-col-5 td:nth-child(5),
  .table-mobile-hide-col-6 th:nth-child(6),
  .table-mobile-hide-col-6 td:nth-child(6),
  .table-mobile-hide-col-7 th:nth-child(7),
  .table-mobile-hide-col-7 td:nth-child(7),
  .table-mobile-hide-col-8 th:nth-child(8),
  .table-mobile-hide-col-8 td:nth-child(8) {
    display: none;
  }

  .modal-dialog {
    margin: 0.35rem;
  }

  .modal-content {
    border-radius: 12px;
  }

  .modal-header,
  .modal-footer {
    padding: 0.5rem 0.65rem;
  }

  .modal-title {
    font-size: 0.94rem;
    line-height: 1.2;
  }

  .modal-body {
    padding: 0.65rem;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .timeline {
    padding: 0.5rem !important;
  }

  .timeline > div > .timeline-item {
    margin-left: 42px;
  }

  .timeline > div > .fas,
  .timeline > div > .far,
  .timeline > div > .fa,
  .timeline > div > .fab,
  .timeline > div > .glyphicon,
  .timeline > div > .ion {
    width: 24px;
    height: 24px;
    line-height: 24px;
    left: 8px;
    font-size: 11px;
  }

  .timeline .time-label > span {
    font-size: 0.7rem;
    padding: 0.25rem 0.45rem;
  }

  .swal2-popup {
    width: calc(100% - 18px) !important;
    padding: 1rem 0.8rem;
    border-radius: 14px;
    font-size: 0.88rem;
  }

  .swal2-title {
    font-size: 1rem;
  }

  .swal2-html-container,
  .swal2-content {
    font-size: 0.84rem;
  }

  .dropdown-menu {
    font-size: 0.82rem;
  }

  .badge {
    font-size: 0.68rem;
    padding: 0.3em 0.48em;
  }

  .alert {
    padding: 0.55rem 0.65rem;
    margin-bottom: 0.55rem;
    font-size: 0.8rem;
  }

  .login-page,
  .register-page {
    padding: 0.75rem;
  }

  .login-box,
  .register-box {
    width: 100%;
    margin: 0;
  }

  .login-logo,
  .register-logo {
    font-size: 1.15rem;
    margin-bottom: 0.45rem;
  }

  .mt-1,
  .my-1 {
    margin-top: 0.2rem !important;
  }

  .mb-1,
  .my-1 {
    margin-bottom: 0.2rem !important;
  }

  .mt-2,
  .my-2 {
    margin-top: 0.35rem !important;
  }

  .mb-2,
  .my-2 {
    margin-bottom: 0.35rem !important;
  }

  .mt-3,
  .my-3 {
    margin-top: 0.55rem !important;
  }

  .mb-3,
  .my-3 {
    margin-bottom: 0.55rem !important;
  }

  .mt-4,
  .my-4 {
    margin-top: 0.75rem !important;
  }

  .mb-4,
  .my-4 {
    margin-bottom: 0.75rem !important;
  }

  .pt-2,
  .py-2 {
    padding-top: 0.35rem !important;
  }

  .pb-2,
  .py-2 {
    padding-bottom: 0.35rem !important;
  }

  .pt-3,
  .py-3 {
    padding-top: 0.55rem !important;
  }

  .pb-3,
  .py-3 {
    padding-bottom: 0.55rem !important;
  }

  .pt-4,
  .py-4 {
    padding-top: 0.75rem !important;
  }

  .pb-4,
  .py-4 {
    padding-bottom: 0.75rem !important;
  }

  .px-3 {
    padding-left: 0.55rem !important;
    padding-right: 0.55rem !important;
  }

  .px-4 {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  .text-truncate-mobile {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

@media (max-width: 575.98px) {
  .content-header .btn,
  .card-header .btn,
  .card-footer .btn,
  .btn-group > .btn {
    margin-bottom: 4px;
  }

  .card-header.d-flex,
  .card-footer.d-flex,
  .d-flex.justify-content-between,
  .d-flex.justify-content-end,
  .d-flex.align-items-center {
    flex-wrap: wrap;
    gap: 6px;
  }

  .table {
    font-size: 0.72rem;
  }

  .table th,
  .table td {
    padding: 0.26rem 0.28rem;
  }

  .hide-mobile,
  .d-none-mobile {
    display: none !important;
  }

  .mobile-stack > * {
    width: 100%;
  }

  .mobile-stack .btn,
  .mobile-stack .form-control,
  .mobile-stack .custom-select {
    width: 100%;
  }
}
