/* Глобальные стили для адаптивных таблиц */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
}

/* Стили для всех таблиц на сайте */
table {
  width: 100% !important;
  max-width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
  table-layout: fixed !important;
}

/* Синхронизация ширины заголовков и столбцов */
table thead th,
table tbody td {
  box-sizing: border-box;
}

/* Исправление переноса текста в заголовках */
table thead th {
  white-space: normal !important;
  word-wrap: break-word !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  hyphens: auto !important;
  line-height: 1.4 !important;
  vertical-align: top !important;
  padding: 0.75rem 0.5rem !important;
}

/* Автоматическая адаптивность для ВСЕХ таблиц - принудительный горизонтальный скролл */
@media (max-width: 1200px) {
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  
  table tbody,
  table thead,
  table tfoot {
    display: table;
    width: 100%;
    min-width: 100%;
  }
  
  table tr {
    display: table-row;
  }
  
  table th,
  table td {
    display: table-cell;
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
}

/* Адаптивность для мобильных устройств */
@media (max-width: 768px) {
  table {
    font-size: 1.4rem;
  }
  
  table th, table td {
    padding: 1.2rem 0.8rem;
    word-wrap: break-word;
    overflow-wrap: break-word;
  }
  
  /* Убираем фиксированные ширины на мобильных */
  table th[width], table td[width] {
    width: auto !important;
  }
  
  /* Убираем nowrap на мобильных для лучшего переноса */
  table th[nowrap], table td[nowrap] {
    white-space: normal !important;
  }
}

@media (max-width: 576px) {
  table {
    font-size: 1.25rem;
  }
  
  table th, table td {
    padding: 1rem 0.6rem;
  }
}

/* Специальные стили для таблиц с фиксированными ширинами */
table[width] {
  width: 100% !important;
}

/* Стили для ячеек таблиц */
th, td {
  border: 1px solid #dee2e6;
  padding: 0.75rem;
  vertical-align: top;
}

/* Адаптивные стили для мобильных */
@media (max-width: 768px) {
  th, td {
    padding: 1.2rem 0.8rem;
    font-size: 1.4rem;
  }
}

@media (max-width: 576px) {
  th, td {
    padding: 1rem 0.6rem;
    font-size: 1.25rem;
  }
}

/* Стили для заголовков таблиц */
th {
  background-color: #f8f9fa;
  font-weight: 600;
  text-align: center;
}

@media (max-width: 768px) {
  th {
    font-weight: 500;
  }
}

/* Стили для строк таблиц */
tr:nth-child(even) {
  background-color: #f8f9fa;
}

tr:hover {
  background-color: #e9ecef;
}

/* Стили для таблиц с классом Bootstrap */
.table {
  width: 100% !important;
  margin-bottom: 1rem;
}

@media (max-width: 768px) {
  .table {
    font-size: 1.4rem;
  }
}

/* Дополнительные стили для контейнеров таблиц */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}

.table-container table {
  min-width: 100%;
}

/* Принудительная адаптивность для всех таблиц без исключения */
@media (max-width: 1200px) {
  /* Принудительный горизонтальный скролл для всех таблиц */
  table {
    overflow-x: auto !important;
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    -webkit-overflow-scrolling: touch;
  }
  
  /* Восстанавливаем табличную структуру */
  table tbody,
  table thead,
  table tfoot {
    display: table !important;
    width: 100% !important;
    min-width: max-content !important;
  }
  
  table tr {
    display: table-row !important;
  }
  
  table th,
  table td {
    display: table-cell !important;
    white-space: nowrap !important;
    min-width: auto !important;
  }
}

/* Дополнительные стили для очень широких таблиц на мобильных */
@media (max-width: 768px) {
  table {
    /* Принудительный скролл */
    overflow-x: auto !important;
    display: block !important;
  }
  
  table tbody,
  table thead,
  table tfoot {
    display: table !important;
    min-width: max-content !important;
  }
  
  table th,
  table td {
    white-space: nowrap !important;
    min-width: 120px !important;
  }
}

/* Специальные стили для таблиц в админке */
.tbl-typical {
  width: 100% !important;
}

@media (max-width: 768px) {
  .tbl-typical th,
  .tbl-typical td {
    padding: 18px 14px;
    font-size: 1.4rem;
  }
}

@media (max-width: 576px) {
  .tbl-typical th,
  .tbl-typical td {
    padding: 14px 12px;
    font-size: 1.25rem;
  }
}

/* Стили для таблиц с фиксированными ячейками */
table td[nowrap] {
  white-space: nowrap;
}

@media (max-width: 768px) {
  table td[nowrap] {
    white-space: normal;
  }
}

/* Улучшенные стили для горизонтального скролла */
.table-responsive::-webkit-scrollbar {
  height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
  background: #555;
}
