/* === MOBILE FIRST: Начинаем с мобильных стилей === */

/* 1. БАЗОВЫЕ СТИЛИ для всех устройств */
* {
  box-sizing: border-box; /* Чтобы padding не ломал ширину */
}

body {
  margin: 0;
  padding: 15px; /* ← если хочешь отступы вокруг всего контента */
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #fafafa;
  color: #333;
  line-height: 1.5;
  font-size: 16px;
}

h1 {
  margin: 0 0 20px 0;
  font-size: 24px;
  color: #2c3e50;
}

h2 {
  margin: 0 0 15px 0;
  font-size: 18px;
  color: #34495e;
}

h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: #34495e;
}

/* Стили для элемента аудио с кнопкой скачивания */
.audio-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  margin-bottom: 4px;
  border-radius: 4px;
  background-color: var(--surface-color);
  border: 1px solid var(--border-color);
  transition: all 0.2s ease;
}

.audio-item-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-width: 0; /* Для корректного обрезания текста */
}

/* Кнопка загрузки - по умолчанию скрыта на десктопе */
.download-btn:hover,
.download-btn:active {
  opacity: 1;
  background-color: rgba(0, 123, 255, 0.1);
  transform: scale(1.1);
}

.download-btn:hover,
.download-btn:active {
  opacity: 1;
  background-color: rgba(0, 123, 255, 0.1);
  transform: scale(1.1);
}

.download-btn:focus {
  outline: none;
}

/* Показываем кнопку загрузки ТОЛЬКО на мобильных устройствах */
@media (max-width: 768px) {
  .download-btn {
    display: inline-block; /* или block, в зависимости от контекста */
    padding: 12px 15px;
    font-size: 1.3em;
  }
  
  .audio-item-content {
    padding: 8px 4px;
  }
}

/* Темная тема для кнопки */
@media (prefers-color-scheme: dark) {
  .download-btn {
    color: #fff;
  }
  
  .download-btn:hover,
  .download-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
  }
}

/* 2. ПОИСК (для всех устройств) */
.search-container {
  position: relative;
  margin: 0 0 20px 0;
}

#searchInput {
  width: 100%;
  padding: 12px 40px 12px 15px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s;
}

#searchInput:focus {
  outline: none;
  border-color: #4a90e2;
}

/* Стили для отображения длительности аудио */
.audio-item-content {
  display: flex;
  align-items: center;
  width: 100%;
  /* Убираем justify-content: space-between отсюда, так как он конфликтует */
}

.audio-name {
  flex-grow: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 10px;
}

.audio-duration {
  font-size: 0.85em;
  color: #555;
  background: #e8f0f8;
  padding: 4px 10px;
  border-radius: 12px;
  font-family: "Courier New", monospace;
  font-weight: 600;
  min-width: 70px;
  text-align: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  border: 1px solid #d0d8e0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  /* Убираем margin, который может ломать layout */
}

.audio-duration.unknown {
  opacity: 0.5;
}

.audio-item:hover .audio-duration {
  background: #d0e0f0;
  color: #2c3e50;
  border-color: #b0c8d8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.audio-item:hover .audio-duration {
  background: #d0e0f0;
  color: #2c3e50;
  border-color: #b0c8d8;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.audio-item.active .audio-duration {
  background: #4a6fa5;
  color: white;
  border-color: #3a5f95;
  box-shadow: 0 2px 4px rgba(74, 111, 165, 0.3);
}

/* Стили для мобильных */
@media (max-width: 768px) {
  .audio-duration {
    font-size: 0.8em;
    padding: 1px 6px;
    min-width: 65px;
  }

  .audio-name {
    margin-right: 5px;
  }
}

/* Дополнительно: если хотите совсем спрятать на десктопе, но оставить место */
@media (min-width: 769px) {
  /* Опционально: можно добавить небольшой отступ, если кнопка исчезла и верстка "просела" */
  .audio-item-content {
    /* Ничего не меняем, gap: 8px остается, но кнопка скрыта, поэтому отступ не создается */
  }
}

.clear-search {
  position: absolute;
  right: 15px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 3. КНОПКИ МОБИЛЬНОГО МЕНЮ */
.mobile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: #4a90e2;
  color: white;
  border: none;
  padding: 14px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 15px;
  transition: background-color 0.3s;
}

.mobile-menu-toggle:hover {
  background: #357abd;
}

.mobile-menu-toggle span {
  margin-right: 10px;
  font-size: 18px;
}

/* 4. ОСНОВНОЙ КОНТЕЙНЕР (вертикальный на мобильных) */
.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 5. БОКОВАЯ ПАНЕЛЬ (скрыта на мобильных по умолчанию) */
.sidebar {
  width: 100%;
  background: #f0f7ff;
  padding: 20px;
  border-radius: 12px;
  display: none; /* Скрываем на мобильных */
}

.sidebar.visible {
  display: block; /* Показываем при активации */
}

/* 6. ОСНОВНАЯ ОБЛАСТЬ */
.main {
  width: 100%;
}

/* 7. ЭЛЕМЕНТЫ СПИСКА АУДИО */
.audio-item {
  padding: 14px 16px;
  margin: 8px 0;
  background: white;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  font-size: 16px;
  min-height: 52px; /* Для удобного касания */
  display: flex;
  align-items: center;
}

.audio-item:hover {
  background: #e3f2fd;
  border-color: #bbdefb;
}

.audio-item.active {
  background: #bbdefb;
  border-color: #4a90e2;
  font-weight: 600;
}

/* 8. АУДИОПЛЕЕР */
#player {
  margin-bottom: 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fafafa;
  padding: 10px 0;
  margin-top: -10px;
  padding-top: 10px;
}

#player audio {
  width: 100%;
  border-radius: 8px;
}

/* 9. СТАТУС */
#status {
  margin: 0 0 20px 0;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 15px;
}

.success {
  background: #e8f5e9;
  color: #2e7d32;
  border-left: 4px solid #4caf50;
}

.warn {
  background: #fff8e1;
  color: #5d4037;
  border-left: 4px solid #ff9800;
}

.error {
  background: #ffebee;
  color: #c62828;
  border-left: 4px solid #f44336;
}

/* 10. СЕГМЕНТЫ ТРАНСКРИПТА */
.segment {
  padding: 16px;
  margin: 12px 0;
  background: white;
  border-left: 4px solid #4a90e2;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 60px; /* Для удобного касания */
}

.segment:hover {
  background: #f8fcff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.segment.active {
  background: #e6f2ff;
  border-left-color: #e74c3c;
}

.timestamp {
  font-family: "Roboto Mono", monospace, monospace;
  font-weight: 600;
  color: #2c3e50;
  margin-right: 10px;
  font-size: 14px;
  display: inline-block;
  margin-bottom: 5px;
}

/* 11. ПОДСВЕТКА ПОИСКА */
mark {
  background-color: #ffeb3b;
  padding: 0 2px;
  border-radius: 2px;
}

/* 12. ИНДИКАТОР ЗАГРУЗКИ */
.loading-indicator {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(74, 144, 226, 0.2);
  border-top-color: #4a90e2;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 10px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* 13. КНОПКИ УПРАВЛЕНИЯ КЭШЕМ */
.cache-controls {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: center;
  flex-wrap: wrap;
}

.cache-controls button {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  background: #f0f0f0;
  color: #555;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.cache-controls button:hover {
  background: #e0e0e0;
}

/* 14. КОММЕНТАРИИ - ОБЩИЕ СТИЛИ */
.comments-section {
  margin-top: 30px;
}

.comment-form {
  background: #f5f5f5;
  padding: 20px;
  border-radius: 10px;
  margin: 20px 0;
}

.comment-form input,
.comment-form textarea {
  width: 100%;
  padding: 10px;
  margin: 5px 0;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

.comment-form textarea {
  min-height: 100px;
  resize: vertical;
}

.comment-form button {
  background: #4a90e2;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: background-color 0.3s;
  width: 100%;
}

.comment-form button:hover {
  background: #357abd;
}

.comment {
  border: 1px solid #eee;
  padding: 15px;
  margin: 10px 0;
  border-radius: 5px;
  background: white;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.comment-author {
  font-weight: bold;
  color: #333;
}

.comment-date {
  color: #666;
  font-size: 0.9em;
}

.comment-text {
  line-height: 1.5;
}

.success-message {
  background: #d4edda;
  color: #155724;
  padding: 10px;
  border-radius: 5px;
  margin: 10px 0;
  display: none;
}

.error-message {
  background: #f8d7da;
  color: #721c24;
  padding: 10px;
  border-radius: 5px;
  margin: 10px 0;
  display: none;
}

/* 15. АККОРДЕОН ДЛЯ КОММЕНТАРИЕВ НА МОБИЛЬНЫХ */
.comments-accordion-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #f0f7ff;
  color: #2c3e50;
  border: none;
  padding: 16px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin: 20px 0 0 0;
  transition: background-color 0.3s;
}

.comments-accordion-toggle:hover {
  background: #e3f2fd;
}

.comments-accordion-toggle span {
  font-size: 18px;
  transition: transform 0.3s;
}

.comments-accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.comments-accordion-content.expanded {
  max-height: 2000px; /* Достаточно для комментариев */
}

.comments-accordion-toggle .icon-expanded {
  transform: rotate(180deg);
}

/* === ДЕСКТОПНАЯ ВЕРСИЯ (от 768px) === */
@media (min-width: 768px) {
  body {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 30px;
  }

  h1 {
    font-size: 32px;
    margin-bottom: 30px;
  }

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  .mobile-menu-toggle {
    display: none; /* Скрываем на десктопе */
  }

  .container {
    flex-direction: row; /* Горизонтальное расположение */
    gap: 30px;
  }

  .sidebar {
    display: block; /* Всегда показываем */
    width: 350px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
    align-self: flex-start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .main {
    flex: 1;
    min-width: 0; /* Для корректного переноса */
  }

  .audio-item {
    font-size: 15px;
    min-height: 46px;
    padding: 12px 16px;
  }

  .segment {
    min-height: auto;
    padding: 14px;
  }

  /* КОММЕНТАРИИ НА ДЕСКТОПЕ - БОКОВАЯ ПАНЕЛЬ СПРАВА */
  .comments-desktop {
    display: block;
    width: 300px;
    flex-shrink: 0;
    background: #f9f9f9;
    padding: 20px;
    border-radius: 12px;
    position: sticky;
    top: 20px;
    align-self: flex-start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .comments-mobile {
    display: none;
  }

  .comment-form button {
    width: auto;
  }

  /* Обновляем основной контейнер для трех колонок */
  .main-content-wrapper {
    display: flex;
    gap: 30px;
    flex: 1;
    min-width: 0;
  }

  .transcript-container {
    flex: 1;
    min-width: 0;
  }
}

/* === ПЛАНШЕТЫ (от 1024px) === */
@media (min-width: 1024px) {
  .sidebar {
    width: 400px;
  }

  .comments-desktop {
    width: 350px;
  }
}

/* === ПЛАНШЕТЫ (768-1023px) - комментарии под транскриптом === */
@media (min-width: 768px) and (max-width: 1023px) {
  .comments-desktop {
    display: none;
  }

  .comments-mobile {
    display: block;
  }

  .main-content-wrapper {
    flex-direction: column;
  }
}

/* === МОБИЛЬНЫЕ (<768px) === */
@media (max-width: 767px) {
  .comments-desktop {
    display: none;
  }

  .comments-mobile {
    display: block;
  }

  .comments-accordion-toggle {
    margin-top: 20px;
  }
}

/* === ТЕМНАЯ ТЕМА (если система в темном режиме) === */
@media (prefers-color-scheme: dark) {
  body {
    background: #121212;
    color: #e0e0e0;
  }
  /* Добавь эти строки ↓ */
  .page-header {
    background: #1e1e1e;       /* тёмный фон шапки */
    color: #e0e0e0;           /* светлый текст */
    border-bottom-color: #4caf50; /* чуть мягче зелёный */
  }

  .header-btn {
    background: #4caf50;
    color: white;
  }
  .sidebar {
    background: #1e1e1e;
  }

  .audio-item {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .audio-item:hover {
    background: #3d3d3d;
  }

  .audio-item.active {
    background: #2c5282;
    color: white;
  }

  .audio-duration {
    background: #2d3d4d;
    color: #b0c4de;
    border-color: #3d4d5d;
  }

  .audio-item:hover .audio-duration {
    background: #3d4d5d;
    color: #c0d4ee;
    border-color: #4d5d6d;
  }

  .audio-item.active .audio-duration {
    background: #4a6fa5;
    color: white;
    border-color: #3a5f95;
  }

  .segment {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .segment:hover {
    background: #3d3d3d;
  }

  #player {
    background: #121212;
  }

  #searchInput {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }

  .cache-controls button {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .cache-controls button:hover {
    background: #3d3d3d;
  }

  .comment-form {
    background: #2d2d2d;
  }

  .comment {
    background: #2d2d2d;
    border-color: #444;
  }

  .comments-desktop {
    background: #1e1e1e;
  }

  .comments-accordion-toggle {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .comments-accordion-toggle:hover {
    background: #3d3d3d;
  }
}
/* СТИЛИ ДЛЯ КОММЕНТАРИЕВ (ДОБАВИТЬ В КОНЕЦ style.css) */

/* Комментарии на десктопе (правая панель) */
.comments-desktop {
  background: #f9f9f9;
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #e0e0e0;
}

.comments-desktop h3 {
  margin-top: 0;
}

/* Мобильный аккордеон для комментариев */
.comments-mobile {
  margin-top: 20px;
}

.comments-accordion-toggle {
  width: 100%;
  padding: 15px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.comments-accordion-toggle:hover {
  background: #357abd;
}

.comments-accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
  background: #f9f9f9;
  border-radius: 0 0 8px 8px;
}

.comments-accordion-content.expanded {
  max-height: 500px;
  padding: 15px;
  border: 1px solid #e0e0e0;
  border-top: none;
}

/* Форма комментариев */
.comment-form {
  margin-bottom: 20px;
}

.comment-form h4 {
  margin: 0 0 15px 0;
  color: #2c3e50;
}

.comment-form input,
.comment-form textarea {
  width: 100%;
  padding: 10px;
  margin: 5px 0;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

.comment-form textarea {
  min-height: 80px;
  resize: vertical;
}

.comment-form button {
  background: #4a90e2;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  margin-top: 10px;
  width: 100%;
}

.comment-form button:hover {
  background: #357abd;
}

/* Список комментариев */
.comments-list {
  max-height: 400px;
  overflow-y: auto;
}

.comment {
  border: 1px solid #eee;
  padding: 12px;
  margin: 10px 0;
  border-radius: 5px;
  background: white;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 14px;
}

.comment-author {
  font-weight: bold;
  color: #333;
}

.comment-date {
  color: #666;
}

.comment-text {
  line-height: 1.5;
  font-size: 15px;
}

.no-comments {
  text-align: center;
  color: #666;
  font-style: italic;
  padding: 20px;
}

/* Для десктопа */
@media (min-width: 768px) {
  .comments-desktop {
    display: block;
    width: 300px;
    flex-shrink: 0;
    position: sticky;
    top: 20px;
    align-self: flex-start;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .comments-mobile {
    display: none;
  }
}

/* Для мобильных */
@media (max-width: 767px) {
  .comments-desktop {
    display: none;
  }

  .comments-mobile {
    display: block;
  }
}

/* Темная тема для комментариев */
@media (prefers-color-scheme: dark) {
  .comments-desktop,
  .comments-accordion-content {
    background: #2d2d2d;
    border-color: #444;
  }

  .comment {
    background: #3d3d3d;
    border-color: #444;
  }

  .comment-form input,
  .comment-form textarea {
    background: #3d3d3d;
    color: #e0e0e0;
    border-color: #555;
  }

  .comments-accordion-toggle {
    background: #2c5282;
  }

  .comments-accordion-toggle:hover {
    background: #1a3d6b;
  }
}

/* === АНИМАЦИИ И МИКРОИНТЕРАКЦИИ === */
.audio-item,
.segment,
button {
  -webkit-tap-highlight-color: transparent; /* Убираем синий highlight на мобильных */
}

.audio-item:active,
.segment:active {
  transform: scale(0.98);
}


/* Шапка — светлая тема по умолчанию */
.page-header {
  padding: 10px 20px;
  margin-bottom: 20px;
  border-bottom: 2px solid #28a745;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa; /* светлый фон */
  color: #212529;
}

.page-header h1 {
  margin: 0;
  padding: 0;
  display: inline;
}

.page-header p {
  margin: 5px 0 0 0;
  padding: 0;
}

.header-btn {
  background: #28a745;
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 500;
  white-space: nowrap;
}

/* 🌙 Тёмная тема — срабатывает автоматически */
@media (prefers-color-scheme: dark) {
  .page-header {
    background: #121212; /* тёмно-серый, как в системе */
    color: #e0e0e0;
    border-bottom-color: #4caf50;
  }

  .header-btn {
    background: #4caf50;
    color: white;
  }
}

/* Мобильные устройства */
@media (max-width: 480px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
}
body {
  margin: 0;
  padding: 15px;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #fafafa; /* светлый фон */
  color: #333;
  line-height: 1.5;
  font-size: 16px;
}

/* Тёмная тема — для всего тела страницы */
@media (prefers-color-scheme: dark) {
  body {
    background: #121212; /* тёмный фон */
    color: #e0e0e0;     /* светлый текст */
  }

  .page-header {
    background: #1e1e1e;
    color: #e0e0e0;
    border-bottom-color: #4caf50;
  }

  .header-btn {
    background: #4caf50;
    color: white;
  }
}