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

/* 1. БАЗОВЫЕ СТИЛИ для всех устройств */
* {
  box-sizing: border-box;
}

/* iOS полноэкранный режим */
@supports (-webkit-touch-callout: none) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}

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;
}

/* 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;
}

.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. ШАПКА */
.page-header {
  padding: 8px 15px;
  margin-bottom: 20px;
  border-bottom: 2px solid #28a745;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
  background: #f8f9fa;
  color: #212529;
  flex-wrap: nowrap;
  position: relative;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-title {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex-shrink: 1;
  min-width: 0;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: transform 0.3s;
}

.logo-icon:hover {
  transform: scale(1.1);
}

.page-header h1 {
  margin: 0;
  padding: 0;
  display: inline;
  font-size: 16px;
  line-height: 1.2;
}

.page-header p {
  margin: 2px 0 0 0;
  padding: 0;
  font-size: 11px;
  line-height: 1.2;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: auto;
}

.user-greeting {
  font-size: 14px;
  color: #2c3e50;
}

.user-name {
  font-weight: bold;
  color: #3498db;
}

.user-role-badge {
  padding: 3px 8px;
  background: #3498db;
  color: white;
  border-radius: 12px;
  font-size: 12px;
}

.user-role-badge.admin {
  background: #e74c3c;
}

.login-btn {
  background: #95a5a6;
  color: white;
  padding: 4px 8px;
  border-radius: 3px;
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  transition: background 0.3s;
  white-space: nowrap;
}

.login-btn:hover {
  background: #7f8c8d;
}

.logout-btn {
  background: #95a5a6;
  color: white;
  padding: 4px 8px;
  border-radius: 3px;
  border: none;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  transition: background 0.3s;
  white-space: nowrap;
}

.logout-btn:hover {
  background: #7f8c8d;
}

.header-btn {
  background: #757575;
  color: white;
  padding: 6px 12px;
  text-decoration: none;
  border-radius: 4px;
  font-weight: 400;
  font-size: 0.9em;
  white-space: nowrap;
  opacity: 0.8;
}

/* 4. КНОПКИ МОБИЛЬНОГО МЕНЮ */
.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;
}

/* Кнопка выбора тем (для десктопа) */
.desktop-topic-btn {
  display: none;
}

/* Панель управления (десктоп) */
.desktop-control-panel {
  display: none;
  align-items: center;
  gap: 16px;
  background: white;
  padding: 12px 20px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  margin-bottom: 20px;
}

.desktop-control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #28a745;
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.desktop-control-btn:hover {
  background: #218838;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(40,167,69,0.3);
}

.desktop-control-btn:active {
  transform: translateY(0);
}

.desktop-control-btn .btn-icon {
  font-size: 20px;
}

.desktop-sort-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.desktop-sort-controls .sort-select {
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: white;
  cursor: pointer;
  transition: border-color 0.2s;
  font-family: inherit;
  min-width: 160px;
}

.desktop-sort-controls .sort-select:hover {
  border-color: #4a90e2;
}

.desktop-sort-controls .sort-select:focus {
  outline: none;
  border-color: #4a90e2;
}

.desktop-sort-controls .sort-order-toggle {
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}

.desktop-sort-controls .sort-order-toggle:hover {
  border-color: #4a90e2;
  background: #e3f2fd;
}

.desktop-sort-controls .sort-order-toggle:active {
  transform: scale(0.95);
}

.desktop-sort-controls .sort-order-icon {
  font-size: 18px;
  font-weight: bold;
  color: #4a90e2;
  transition: transform 0.3s;
}

/* Поиск в десктопной панели */
.desktop-search-placeholder {
  margin-left: auto;
  display: flex;
  align-items: center;
}

#desktopSearchInput {
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  width: 200px;
  transition: all 0.2s;
}

#desktopSearchInput:focus {
  outline: none;
  border-color: #4a90e2;
  width: 250px;
}

/* 5. ОСНОВНОЙ КОНТЕЙНЕР */
.container {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 6. БОКОВАЯ ПАНЕЛЬ */
.sidebar {
  width: 100%;
  background: rgba(240, 247, 255, 0.98);
  padding: 20px;
  border-radius: 0;
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 99;
  overflow-y: auto;
  padding-top: 80px;
  backdrop-filter: blur(5px);
}

.sidebar.visible {
  display: block;
}

/* Затемнение фона */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 98;
}

.sidebar-overlay.visible {
  display: block;
}

/* Контролы сортировки */
.sort-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 15px;
  align-items: center;
}

.sort-select {
  flex: 1;
  padding: 10px 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: white;
  cursor: pointer;
  transition: border-color 0.3s;
  font-family: inherit;
}

.sort-select:hover {
  border-color: #4a90e2;
}

.sort-select:focus {
  outline: none;
  border-color: #4a90e2;
}

.sort-order-toggle {
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
}

.sort-order-toggle:hover {
  border-color: #4a90e2;
  background: #e3f2fd;
}

.sort-order-toggle:active {
  transform: scale(0.95);
}

.sort-order-icon {
  font-size: 18px;
  font-weight: bold;
  color: #4a90e2;
  transition: transform 0.3s;
}

/* 7. ЭЛЕМЕНТЫ АУДИО */
.audio-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  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;
}

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

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

.audio-item-hidden {
  background: #f5f5f5;
  opacity: 0.7;
}

.audio-item-hidden:hover {
  background: #e8e8e8;
  opacity: 1;
}

.audio-hidden-badge {
  background: #ff9800;
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}

.audio-item-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-width: 0;
}

.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);
}

.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.active .audio-duration {
  background: #4a6fa5;
  color: white;
  border-color: #3a5f95;
  box-shadow: 0 2px 4px rgba(74, 111, 165, 0.3);
}

/* Кнопка редактирования аудио */
.audio-edit-btn {
  background: transparent;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  margin-left: auto;
}

.audio-edit-btn:hover {
  background: #e0e0e0;
  transform: scale(1.1);
}

.audio-edit-btn:active {
  transform: scale(1);
}

/* Кнопка загрузки */
.download-btn {
  display: none;
}

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

/* 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;
  font-weight: 600;
  color: #2c3e50;
  margin-right: 10px;
  font-size: 14px;
  display: inline-block;
  margin-bottom: 5px;
}

/* Непроверенный сегмент */
.segment.unreviewed {
  background: white;
  border-left: 4px solid #ffc107;
}

/* Проверенный сегмент */
.segment.reviewed {
  background: #e8f5e9;
  border-left: 4px solid #28a745;
}

/* Сегмент для редакторов */
.segment.editable {
  background: white;
  border: 2px dashed #3498db;
}

.segment.editable:hover {
  border: 2px dashed #2980b9;
}

.segment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}

.segment-timestamp {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.segment-text {
  display: inline;
}

.segment-text[contenteditable="true"] {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0 2px;
  outline: none;
  cursor: text;
  display: inline;
  transition: all 0.2s;
}

.segment-text[contenteditable="true"]:hover {
  background: rgba(52, 152, 219, 0.1);
}

.segment-text[contenteditable="true"]:focus {
  background: #fff;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.segment-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.review-checkbox {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
}

.review-checkbox input {
  cursor: pointer;
}

.edit-segment-btn {
  background: #3498db;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.3s;
}

.edit-segment-btn:hover {
  background: #2980b9;
}

/* Кнопка удаления сегмента */
.segment-delete-btn {
  background: #e74c3c;
  color: white;
  border: none;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.3s;
  opacity: 0.7;
}

.segment-delete-btn:hover {
  background: #c0392b;
  opacity: 1;
}

.save-indicator {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  display: none;
}

.save-indicator.saving {
  display: block;
  background: #ffc107;
  color: #000;
}

.save-indicator.saved {
  display: block;
  background: #28a745;
  color: white;
}

.save-indicator.error {
  display: block;
  background: #dc3545;
  color: white;
}

/* 11. СТАТУС ТРАНСКРИПТА */
.transcript-status-bar {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 16px;
  border: 1px solid #e9ecef;
}

.transcript-status-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}

.version-badge {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(245, 87, 108, 0.3);
}

.version-badge.polished {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.status-text {
  font-weight: 600;
  color: #2c3e50;
  font-size: 14px;
}

.btn-create-polished {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-create-polished:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-create-polished:active {
  transform: translateY(0);
}

.status-progress-bar {
  height: 8px;
  background: #e9ecef;
  border-radius: 4px;
  overflow: hidden;
}

.status-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transition: width 0.3s ease;
  border-radius: 4px;
}

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

/* 13. ИНДИКАТОР ЗАГРУЗКИ */
.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);
  }
}

/* 14. КНОПКИ УПРАВЛЕНИЯ КЭШЕМ */
.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;
}

/* 15. КОММЕНТАРИИ */
.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;
}

.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-content {
  max-height: none;
  overflow: visible;
  background: transparent;
}

.comments-accordion-content.expanded {
  max-height: none;
  padding: 0;
  border: none;
}

.comments-accordion-toggle {
  display: none;
}

.comments-list {
  max-height: 400px;
  overflow-y: auto;
}

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

/* 16. НИЖНЯЯ ПАНЕЛЬ ДЛЯ МОБИЛЬНЫХ */
.mobile-bottom-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e0e0e0;
  padding: 5px 10px;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  z-index: 101;
  min-height: 60px;
}

.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: transparent;
  border: none;
  padding: 5px 8px;
  cursor: pointer;
  color: #2c3e50;
  border-radius: 6px;
  transition: all 0.2s ease;
  min-width: 50px;
}

.mobile-nav-btn:active {
  background: #f0f0f0;
  transform: scale(0.95);
}

.mobile-nav-btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.mobile-nav-btn[disabled]:active {
  background: transparent;
  transform: none;
}

.btn-icon {
  font-size: 20px;
  line-height: 1;
}

.btn-label {
  font-size: 9px;
  font-weight: 500;
  white-space: nowrap;
}

/* 17. МОБИЛЬНЫЙ ПЛЕЕР */
#mobile-player {
  display: none !important;
  position: fixed;
  bottom: 70px;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #e0e0e0;
  border-bottom: 1px solid #e0e0e0;
  padding: 8px 12px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  z-index: 1000 !important;
}

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

/* 18. МОДАЛЬНЫЕ ОКНА */
.modal {
  display: none !important;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  overflow-y: auto;
}

.modal.show {
  display: flex !important;
}

.modal-content {
  background: white;
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-width: 500px;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
  margin: 0 auto;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-content-wide {
  max-width: 600px;
}

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

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: #2c3e50;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: #666;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.modal-close:hover {
  background: #f0f0f0;
  color: #333;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Опции фильтра по темам */
.topic-filter-options,
.sort-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.topic-option,
.sort-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.topic-option:hover,
.sort-option:hover {
  background: #e9ecef;
}

.topic-option input,
.sort-option input {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.topic-option span,
.sort-option span {
  font-size: 16px;
  color: #2c3e50;
}

/* Кнопка порядка сортировки */
.sort-order-toggle {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e0e0e0;
}

.sort-order-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px;
  background: #2c3e50;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.sort-order-btn:hover {
  background: #1a252f;
}

/* Статистика редакторов */
.stats-table {
  width: 100%;
  border-collapse: collapse;
}

.stats-table th,
.stats-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

.stats-table th {
  background: #f8f9fa;
  font-weight: 600;
  color: #2c3e50;
}

.stats-table tr:hover {
  background: #f8f9fa;
}

.stats-editor-name {
  font-weight: 500;
}

.stats-count {
  font-weight: 600;
  color: #2c3e50;
}

.loading {
  text-align: center;
  color: #666;
  padding: 20px;
}

/* 19. ФОРМА РЕДАКТИРОВАНИЯ АУДИО */
.edit-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-weight: 600;
  color: #2c3e50;
  font-size: 14px;
}

.form-group input[type="text"],
.form-group select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 15px;
  background: white;
  transition: border-color 0.2s;
}

.form-group input[type="text"]:focus,
.form-group select:focus {
  outline: none;
  border-color: #4caf50;
}

.form-readonly {
  padding: 10px 12px;
  background: #f8f9fa;
  border-radius: 6px;
  color: #666;
  font-size: 14px;
  margin: 0;
}

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  background: #45a049;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: #e0e0e0;
  color: #333;
}

.btn-secondary:hover {
  background: #d0d0d0;
}

.form-message {
  padding: 12px;
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
  display: none;
}

.form-message.success {
  background: #e8f5e9;
  color: #2e7d32;
  display: block;
}

.form-message.error {
  background: #ffebee;
  color: #c62828;
  display: block;
}

/* 20. ССЫЛКА НА ФОРУМ */
.footer-links {
  text-align: center;
  padding: 20px;
  margin-top: 30px;
  border-top: 1px solid #e0e0e0;
}

.footer-link {
  color: #999;
  text-decoration: none;
  font-size: 14px;
  transition: color 0.2s;
}

.footer-link:hover {
  color: #666;
  text-decoration: underline;
}

/* 21. АНИМАЦИИ */
.audio-item,
.segment,
button {
  -webkit-tap-highlight-color: transparent;
}

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

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

  #mobile-player:not(.hidden) {
    display: block !important;
  }

  .mobile-bottom-bar {
    display: flex;
  }

  body {
    padding-bottom: 140px;
  }

  .cache-controls {
    margin-bottom: 140px;
  }

  .mobile-menu-toggle {
    display: none;
  }

  .sidebar .sort-controls {
    display: none;
  }

  /* Скрываем поле поиска на мобильных (заглушка в нижней панели) */
  .search-container {
    display: none;
  }

  .modal.show {
    align-items: flex-end;
    justify-content: center;
  }

  .modal-content {
    border-radius: 12px 12px 0 0;
    width: 100%;
    max-height: 80vh;
  }

  .page-header {
    flex-wrap: wrap;
    padding-right: 70px;
  }

  .header-user {
    position: absolute;
    right: 8px;
    top: 8px;
    gap: 4px;
  }

  .user-greeting {
    display: none;
  }

  .login-btn,
  .logout-btn {
    padding: 3px 6px;
    font-size: 10px;
  }

  .user-role-badge {
    padding: 2px 4px;
    font-size: 9px;
  }
  
  .header-title h1 {
    font-size: 14px;
  }
  
  .header-title p {
    font-size: 10px;
  }

  .audio-duration {
    font-size: 0.8em;
    padding: 1px 6px;
    min-width: 65px;
  }

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

  .download-btn {
    display: inline-block;
    padding: 12px 15px;
    font-size: 1.3em;
  }
  
  .audio-item-content {
    padding: 8px 4px;
  }
}

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

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

  h2 {
    font-size: 20px;
  }

  h3 {
    font-size: 18px;
  }

  .mobile-menu-toggle {
    display: none;
  }

  .desktop-topic-btn {
    display: none;
  }

  .desktop-control-panel {
    display: flex;
  }

  .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;
    background: rgba(240, 247, 255, 0.98);
    padding: 20px;
  }

  .main {
    flex: 1;
    min-width: 0;
  }

  .main-content-wrapper {
    display: flex;
    gap: 30px;
    flex: 1;
    min-width: 0;
  }

  .transcript-container {
    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;
    border: 1px solid #e0e0e0;
    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;
  }

  .mobile-bottom-bar {
    display: none !important;
  }

  #mobile-player {
    display: none !important;
  }

  .cache-controls {
    margin-top: 30px;
    margin-bottom: 20px;
    justify-content: flex-start;
  }

  .footer-links {
    margin-top: 40px;
    margin-bottom: 20px;
    text-align: left;
    padding-left: 0;
  }

  .logo-icon {
    width: 40px;
    height: 40px;
    max-width: none;
  }

  .modal.show {
    align-items: center;
    justify-content: center;
  }

  .modal-content {
    max-width: 500px;
    width: 90%;
    border-radius: 12px;
    margin: 20px auto;
  }
}

/* === ПЛАНШЕТЫ (768-1023px) === */
@media (min-width: 768px) and (max-width: 1023px) {
  .comments-desktop {
    display: none;
  }

  .comments-mobile {
    display: block;
  }

  .main-content-wrapper {
    flex-direction: column;
  }
  
  .sidebar {
    width: 300px;
  }
}

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

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

/* === ТЁМНАЯ ТЕМА (prefers-color-scheme) === */
@media (prefers-color-scheme: dark) {
  body {
    background: #121212;
    color: #e0e0e0;
  }

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

  .header-btn {
    background: #555;
    color: #ccc;
    opacity: 0.7;
  }

  .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;
  }

  .sort-select {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }

  .sort-select:hover,
  .sort-select:focus {
    border-color: #4a90e2;
  }

  .sort-order-toggle {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #444;
  }

  .sort-order-toggle:hover {
    background: #3d3d3d;
    border-color: #4a90e2;
  }

  .sort-order-icon {
    color: #4a90e2;
  }

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

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

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

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

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

  .mobile-bottom-bar {
    background: #1e1e1e;
    border-top-color: #333;
  }

  .mobile-nav-btn {
    color: #e0e0e0;
  }
  
  .mobile-nav-btn:active {
    background: #2d2d2d;
  }

  #mobile-player {
    background: #1e1e1e;
    border-top-color: #333;
    border-bottom-color: #333;
  }

  #mobile-player audio {
    filter: invert(1) hue-rotate(180deg);
  }

  .modal-content {
    background: #1e1e1e;
  }

  .modal-header {
    border-bottom-color: #333;
  }

  .modal-header h3 {
    color: #e0e0e0;
  }

  .modal-close {
    color: #999;
  }

  .modal-close:hover {
    background: #2d2d2d;
    color: #fff;
  }

  .topic-option,
  .sort-option {
    background: #2d2d2d;
  }

  .topic-option:hover,
  .sort-option:hover {
    background: #3d3d3d;
  }

  .topic-option span,
  .sort-option span {
    color: #e0e0e0;
  }

  .sort-order-btn {
    background: #4caf50;
  }

  .stats-table th {
    background: #2d2d2d;
    color: #e0e0e0;
  }

  .stats-table td {
    border-bottom-color: #333;
    color: #e0e0e0;
  }

  .stats-table tr:hover {
    background: #2d2d2d;
  }

  .stats-count {
    color: #4caf50;
  }

  .form-group label {
    color: #e0e0e0;
  }

  .form-group input[type="text"],
  .form-group select {
    background: #2d2d2d;
    border-color: #444;
    color: #e0e0e0;
  }

  .form-group input[type="text"]:focus,
  .form-group select:focus {
    border-color: #4caf50;
  }

  .form-readonly {
    background: #2d2d2d;
    color: #999;
  }

  .btn-secondary {
    background: #3d3d3d;
    color: #e0e0e0;
  }

  .btn-secondary:hover {
    background: #4d4d4d;
  }

  .form-message.success {
    background: #1b5e20;
    color: #a5d6a7;
  }

  .form-message.error {
    background: #b71c1c;
    color: #ffcdd2;
  }

  .footer-links {
    border-top-color: #444;
  }

  .footer-link {
    color: #666;
  }

  .footer-link:hover {
    color: #999;
  }

  .logo-icon {
    box-shadow: 0 2px 8px rgba(255,255,255,0.1);
  }

  .download-btn {
    color: #fff;
  }
  
  .download-btn:hover,
  .download-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
  }

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

  .segment-delete-btn {
    background: #c62828;
    color: #ffcdd2;
  }

  .segment-delete-btn:hover {
    background: #b71c1c;
  }
}
