/* style.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  -webkit-tap-highlight-color: transparent; /* убирает синюю подсветку при тапе на iOS/Android */
}

body {
  background: #f4f7fb;
  min-height: 100vh;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden; /* защита от горизонтального скролла */
}

.container {
  max-width: 1300px;
  width: 100%;
}

/* ===== Верхняя навигация ===== */
.top-nav {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.nav-btn {
  background: #ffffff;
  border: 2px solid #eef2f6;
  color: #0b1a33;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  white-space: nowrap;
}

.nav-btn:hover {
  border-color: #3b82f6;
  background: #f8faff;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.15);
}

.nav-btn:active {
  transform: scale(0.97);
}

.nav-btn-tg {
  color: #1f8ac0;
  border-color: #d5ebf7;
}

.nav-btn-tg:hover {
  border-color: #29a9e0;
  background: #f0faff;
  box-shadow: 0 6px 16px rgba(41, 169, 224, 0.18);
}

h1 {
  font-size: 2.2rem;
  font-weight: 600;
  color: #0b1a33;
  letter-spacing: -0.02em;
  margin-bottom: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.2;
}

.subhead {
  color: #4a5b6e;
  font-size: 1rem;
  border-left: 3px solid #3b82f6;
  padding-left: 0.8rem;
  margin-bottom: 1.5rem;
  font-weight: 400;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.subhead span {
  background: #e9edf2;
  padding: 0.2rem 0.8rem;
  border-radius: 20px;
  font-size: 0.85rem;
  color: #1f2a3a;
}

/* ===== Поиск ===== */
.search-container {
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: #ffffff;
  border-radius: 50px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  border: 2px solid #eef2f6;
  transition: border-color 0.3s, box-shadow 0.3s;
}

.search-box:focus-within {
  border-color: #3b82f6;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.15);
}

.search-icon {
  padding: 0 0 0 1.2rem;
  font-size: 1.1rem;
  color: #8b9aad;
  user-select: none;
}

.search-box input {
  flex: 1;
  padding: 0.9rem 1rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  color: #0b1a33;
  outline: none;
  min-width: 0;
}

.search-box input::placeholder {
  color: #a8b6c7;
}

.search-clear {
  background: none;
  border: none;
  color: #8b9aad;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 1.2rem 0 0.5rem;
  transition: color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear:hover {
  color: #0b1a33;
  transform: scale(1.1);
}

.search-stats {
  font-size: 0.85rem;
  color: #6d7e91;
  padding-left: 0.5rem;
  min-height: 1.5rem;
}

.search-stats.highlight {
  color: #3b82f6;
  font-weight: 500;
}

/* ===== Сетка ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.8rem;
  margin-top: 0.5rem;
}

/* Карточка */
.tile {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 8px 20px rgba(0, 20, 40, 0.06), 0 2px 6px rgba(0, 0, 0, 0.02);
  padding: 2.5rem 1.2rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid #eef2f6;
  cursor: pointer;
  min-height: 160px;
}

.tile:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 16px 32px rgba(0, 30, 60, 0.08), 0 4px 12px rgba(0, 0, 0, 0.02);
  border-color: #3b82f6;
  background: #f8faff;
}

.tile:active {
  transform: scale(0.97);
}

.tile.hidden {
  display: none;
}

.tile.highlight {
  border-color: #3b82f6;
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.record-number {
  font-size: 2.8rem;
  font-weight: 700;
  color: #0b1a33;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-align: center;
}

.tile-hint {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: #8b9aad;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.tile:hover .tile-hint {
  opacity: 1;
}

/* ===== Нижний колонтитул ===== */
.footer-meta {
  margin-top: 2.5rem;
  border-top: 1px solid #dce3ec;
  padding-top: 1.5rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: #4a5b6e;
}

.badge-json {
  background: #e9edf2;
  padding: 0.2rem 0.8rem;
  border-radius: 30px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.75rem;
  color: #2d3e54;
  word-break: break-word;
}

/* ===== Состояния загрузки/ошибки ===== */
.loading-tile {
  text-align: center;
  padding: 2rem;
  background: #ffffffdd;
  border-radius: 30px;
  grid-column: 1 / -1;
}

.error-message {
  color: #b91c1c;
  background: #fee9e9;
  padding: 1rem 1.5rem;
  border-radius: 40px;
  border: 1px solid #fecaca;
  grid-column: 1 / -1;
}

/* ===== Модальное окно ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  animation: fadeIn 0.3s ease;
}

.modal-overlay.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content {
  background: #ffffff;
  border-radius: 28px;
  max-width: 700px;
  width: 100%;
  max-height: 90vh;
  padding: 2rem 2rem 1.8rem;
  position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: slideUp 0.3s ease;
  display: flex;
  flex-direction: column;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 0.6rem;
  right: 0.8rem;
  font-size: 2rem;
  background: none;
  border: none;
  color: #6b7a8e;
  cursor: pointer;
  transition: color 0.15s, transform 0.15s;
  line-height: 1;
  padding: 0.2rem 0.6rem;
  z-index: 2;
}

.modal-close:hover {
  color: #0b1a33;
  transform: rotate(90deg);
}

.modal-header {
  margin-bottom: 1.5rem;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.8rem;
  padding-right: 2rem;
}

.modal-header h2 {
  font-size: 1.8rem;
  font-weight: 650;
  color: #0b1a33;
  line-height: 1.2;
}

.modal-badge {
  background: #eef4ff;
  border-radius: 40px;
  padding: 0.3rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: #1f4f8a;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-audio {
  background: #f1f5f9;
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  justify-content: center;
}

.modal-audio audio {
  width: 100%;
  max-width: 500px;
  height: 50px;
}

.modal-audio audio::-webkit-media-controls-panel {
  background: #e8edf4;
}

.modal-transcript h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #4a5b6e;
  margin-bottom: 0.5rem;
}

.modal-transcript-text {
  background: #f9fafc;
  border-radius: 14px;
  padding: 1.2rem 1.5rem;
  font-size: 1rem;
  line-height: 1.7;
  color: #1a293b;
  border-left: 3px solid #3b82f6;
  max-height: 300px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f1f4f9;
}

.modal-transcript-ru {
  border-left-color: #10b981;
  background: #f6fefb;
}

.modal-transcript-text::-webkit-scrollbar { width: 4px; }
.modal-transcript-text::-webkit-scrollbar-track { background: #f1f4f9; border-radius: 10px; }
.modal-transcript-text::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }

.modal-transcript-placeholder {
  color: #8b9aad;
  font-style: italic;
}

/* ============================================================ */
/* ===================== МОБИЛЬНАЯ ВЕРСИЯ ===================== */
/* ============================================================ */

/* Планшеты и узкие ноутбуки */
@media (max-width: 900px) {
  h1 {
    font-size: 1.9rem;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1.2rem;
  }
}

/* Телефоны */
@media (max-width: 600px) {
  body {
    padding: 1rem 0.8rem 2rem;
  }

  /* --- Верхние кнопки: во всю ширину, в столбик --- */
  .top-nav {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-bottom: 1.2rem;
  }

  .nav-btn {
    width: 100%;
    text-align: center;
    padding: 0.85rem 1rem;
    font-size: 0.95rem;
    border-radius: 14px;
  }

  /* --- Заголовок --- */
  h1 {
    font-size: 1.35rem;
    line-height: 1.3;
    gap: 0.4rem;
    flex-wrap: wrap;
  }

  .subhead {
    font-size: 0.85rem;
    padding-left: 0.6rem;
    margin-bottom: 1.2rem;
    gap: 0.4rem;
  }

  .subhead span {
    font-size: 0.75rem;
    padding: 0.15rem 0.6rem;
  }

  /* --- Поиск --- */
  .search-container {
    margin-bottom: 1.2rem;
  }

  .search-box {
    border-radius: 14px;
  }

  .search-box input {
    font-size: 0.95rem;
    padding: 0.75rem 0.8rem;
  }

  .search-icon {
    padding-left: 0.8rem;
    font-size: 0.95rem;
  }

  .search-clear {
    padding: 0 0.9rem 0 0.4rem;
    font-size: 1.05rem;
  }

  .search-stats {
    font-size: 0.8rem;
    padding-left: 0.4rem;
  }

  /* --- Сетка: 2 колонки --- */
  .grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.7rem;
  }

  .tile {
    padding: 1.4rem 0.6rem;
    min-height: 100px;
    border-radius: 14px;
  }

  .tile:hover {
    /* на тач-устройствах hover не нужен */
    transform: none;
    box-shadow: 0 8px 20px rgba(0, 20, 40, 0.06), 0 2px 6px rgba(0, 0, 0, 0.02);
    border-color: #eef2f6;
    background: #ffffff;
  }

  .tile:active {
    transform: scale(0.96);
    background: #f8faff;
  }

  .record-number {
    font-size: 1.8rem;
  }

  .tile-hint {
    display: none; /* на мобильных подсказка не нужна */
  }

  /* --- Футер --- */
  .footer-meta {
    margin-top: 1.5rem;
    padding-top: 1rem;
    font-size: 0.8rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .badge-json {
    font-size: 0.7rem;
    padding: 0.15rem 0.6rem;
  }

  /* --- Модальное окно: снизу на весь экран --- */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    border-radius: 22px 22px 0 0;
    max-height: 92vh;
    padding: 1.2rem 1rem 1rem;
    animation: slideUpMobile 0.3s ease;
  }

  @keyframes slideUpMobile {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
  }

  .modal-close {
    top: 0.4rem;
    right: 0.6rem;
    font-size: 1.8rem;
  }

  .modal-header {
    margin-bottom: 1rem;
    padding-right: 2.2rem;
    gap: 0.4rem;
  }

  .modal-header h2 {
    font-size: 1.2rem;
  }

  .modal-badge {
    font-size: 0.72rem;
    padding: 0.25rem 0.7rem;
    max-width: 100%;
  }

  .modal-body {
    gap: 1rem;
  }

  .modal-audio {
    padding: 0.6rem;
    border-radius: 12px;
  }

  .modal-audio audio {
    height: 44px;
  }

  .modal-transcript h3 {
    font-size: 0.9rem;
    margin-bottom: 0.35rem;
  }

  .modal-transcript-text {
    padding: 0.9rem 1rem;
    font-size: 0.92rem;
    line-height: 1.6;
    max-height: 220px;
    border-radius: 12px;
  }
}

/* Очень маленькие телефоны (≤ 380px) */
@media (max-width: 380px) {
  h1 {
    font-size: 1.15rem;
  }

  .nav-btn {
    font-size: 0.88rem;
    padding: 0.75rem 0.8rem;
  }

  .record-number {
    font-size: 1.5rem;
  }

  .tile {
    min-height: 88px;
    padding: 1.1rem 0.5rem;
  }

  .modal-transcript-text {
    font-size: 0.88rem;
  }
}

/* Ландшафтная ориентация на телефоне — чтобы модалка влезала */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .modal-content {
    max-height: 96vh;
    border-radius: 18px;
  }
  .modal-transcript-text {
    max-height: 140px;
  }
}