#alphabet-index a {
  transition: background 0.2s ease, color 0.2s ease;
}
#alphabet-index a.active {
  background: #2563eb;
  color: white;
  font-weight: bold;
}
.view-counter {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #d1d5db;
  border-radius: 999px;
  color: #374151;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  user-select: none;
}

.stats-box {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,0.95);
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 4px 6px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  font-size: 0.72rem;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 999px;
  white-space: nowrap;
    position: relative;
  cursor: default;
}

.stat-online {
  background: #eef6ff;
  color: #1d4ed8;
}

.stat-issue {
  background: #f0fdf4;
  color: #166534;
}

.stat-item::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  right: 50%;
  transform: translateX(50%);
  background: #111827;
  color: #f9fafb;
  padding: 6px 8px;
  font-size: 0.7rem;
  line-height: 1.2;
  border-radius: 6px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.stat-item::before {
  content: "";
  position: absolute;
  bottom: 115%;
  right: 50%;
  transform: translateX(50%);
  border-width: 5px;
  border-style: solid;
  border-color: #111827 transparent transparent transparent;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 20;
}

.stat-item:hover::after,
.stat-item:hover::before {
  opacity: 1;
}

/* Фиксируем ширину столбцов, чтобы не прыгали */
#books-table th:nth-child(2) {
  width: 120px; /* Год издания */
  min-width: 120px;
  max-width: 120px;
}

#books-table th:nth-child(3) {
  width: 200px; /* Кафедра */
  min-width: 200px;
  max-width: 200px;
}

#books-table th:nth-child(4) {
  width: 140px; /* Язык текста */
  min-width: 140px;
  max-width: 140px;
}

/* Чтобы фильтры не ломали макет */
#books-table {
  table-layout: fixed;
  width: 100%;
}

/* Фильтры располагаются поверх и не влияют на размеры ячеек */
#books-table thead th > div[id^="filter-"] {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  box-sizing: border-box;
}

/* Для красоты */
#books-table th {
  text-align: center;
  vertical-align: middle;
  background: #ebf8ff;
}

/* по умолчанию скрыто везде */
.mobile-controls {
  display: none;
}
/* ===============================
   MOBILE LAYOUT FOR CATALOG TABLES
   =============================== */

@media (max-width: 768px) {

  /* таблица становится карточками */
  #books-table {
    table-layout: auto;
  }

  #books-table thead {
    display: none;
  }

  #books-table tr {
    display: block;
    margin-bottom: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    overflow: hidden;
  }

  #books-table td {
    display: block;
    width: 100%;
    text-align: left;
    padding: 12px 14px;
  }


  /* убираем фиксированные ширины колонок */
  #books-table th:nth-child(2),
  #books-table th:nth-child(3),
  #books-table th:nth-child(4) {
    width: auto;
    min-width: unset;
    max-width: unset;
  }


  /* карточка книги становится вертикальной */
  #books-table td > div > div {
    flex-direction: column !important;
    gap: 12px !important;
  }


  /* обложка центрируется */
  #books-table img {
    max-width: 130px;
    margin: 6px auto;
    display: block;
    border-radius: 6px;
  }


  /* номер записи превращаем в бейдж сверху */
  #books-table td:first-child {
    font-weight: 600;
    font-size: 14px;
    color: #374151;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
  }


  /* статистика переносится вниз */
  .stats-box {
    position: static;
    margin-top: 10px;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
  }


  /* кнопки шаринга аккуратно переносятся */
  .stats-box + div {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }


  /* нижний блок метаданных (год / кафедра / язык) */
  #books-table td:nth-last-child(-n+3) {
    font-size: 14px;
    color: #2563eb;
    padding-top: 6px;
    padding-bottom: 10px;
  }


  /* алфавитный указатель становится компактнее */
  #alphabet-index {
    font-size: 13px;
    line-height: 1.8;
  }

  #alphabet-index a {
    display: inline-block;
    padding: 3px 5px;
    margin: 2px;
    border-radius: 6px;
  }

  #alphabet-index a.active {
    background: #2563eb;
    color: white;
  }


  /* панель поиска складывается красиво */
  #searchInput {
    min-width: 100%;
    font-size: 16px;
    padding: 10px 12px;
  }


  /* кнопки поиска становятся одной строкой */
  .search-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
  }

  .search-buttons button {
    flex: 1;
    min-width: 90px;
  }

}
@media (max-width: 768px) {

  /* старый алфавит скрываем */
  #alphabet-index.desktop-alphabet {
    display: none;
  }

}
@media (max-width: 768px) {

  .mobile-controls {
    display: block;
    margin-bottom: 12px;
  }

  .mobile-toggle {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 6px;
    font-size: 15px;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    text-align: left;
  }

  .mobile-hidden {
    display: none;
  }

  .mobile-visible {
    display: block;
  }

  .filter-item {
    margin-bottom: 10px;
  }

  .filter-item label {
    font-size: 13px;
    display: block;
    margin-bottom: 4px;
  }

  .filter-item select {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
  }

}