.flash-messages {
    margin-bottom: 20px;
}

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.flash-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.flash-info {
    background-color: #e8f4f8;
    color: #2c5f7d;
    border: 1px solid #bee5eb;
}

.flash-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.flash-error {
    background-color: #fee;
    color: #c33;
    border: 1px solid #fcc;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
}

h1 {
    color: #333;
    margin-bottom: 10px;
    font-size: 2.5em;
}

.version {
    color: #666;
    margin-bottom: 30px;
    font-size: 0.9em;
}

.upload-section {
    border: 3px dashed #667eea;
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    margin-bottom: 30px;
    transition: all 0.3s ease;
    background: #f8f9ff;
}

.upload-section:hover {
    border-color: #764ba2;
    background: #f0f2ff;
}

.upload-section.dragover {
    border-color: #764ba2;
    background: #e8ebff;
    transform: scale(1.02);
}

.upload-icon {
    font-size: 4em;
    color: #667eea;
    margin-bottom: 20px;
}

input[type="file"] {
    display: none;
}

.file-input-label {
    display: inline-block;
    padding: 15px 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1em;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.file-input-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.file-input-label:active {
    transform: translateY(0);
}

.file-list {
    margin-top: 20px;
    text-align: left;
}

.file-item {
    padding: 10px;
    background: #f5f5f5;
    border-radius: 5px;
    margin: 5px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.process-btn {
    padding: 15px 40px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1.2em;
    cursor: pointer;
    margin-top: 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 15px rgba(17, 153, 142, 0.4);
}

.process-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(17, 153, 142, 0.6);
}

.process-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.tasks-section {
    margin-top: 40px;
}

.task-card {
    background: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin: 15px 0;
    border-left: 4px solid #667eea;
}

.task-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.task-filename {
    font-weight: bold;
    color: #333;
    font-size: 1.1em;
}

.task-status {
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 0.9em;
    font-weight: bold;
}

.status-queued {
    background: #ffc107;
    color: #856404;
}

.status-processing {
    background: #17a2b8;
    color: white;
}

.status-completed {
    background: #28a745;
    color: white;
}

.status-error {
    background: #dc3545;
    color: white;
}

.progress-bar-container {
    width: 100%;
    height: 25px;
    background: #e9ecef;
    border-radius: 15px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.8em;
    font-weight: bold;
}

.task-message {
    color: #666;
    margin-top: 10px;
    font-style: italic;
}

.download-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    margin-top: 10px;
    margin-right: 10px;
    transition: transform 0.2s ease;
}

.download-btn:hover {
    transform: translateY(-2px);
}

.task-info {
    margin-top: 10px;
    color: #666;
    font-size: 0.9em;
}

/* Стили для результатов */
.results-section {
    margin-top: 20px;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    border: 2px solid #667eea;
}

.classes-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.class-item {
    padding: 12px;
    background: #f0f0f0;
    border-radius: 8px;
    border-left: 4px solid #667eea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.class-item:hover {
    background: #e0e0e0;
    transform: translateX(5px);
}

.class-name {
    font-weight: bold;
    color: #333;
}

.class-stats {
    font-size: 0.9em;
    color: #666;
}

/* Фильтры */
.filters-section {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.filter-group label {
    font-weight: bold;
    color: #333;
}

.filter-group input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    width: 100px;
}

.filter-btn {
    padding: 8px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

.filter-btn:hover {
    background: #764ba2;
}

/* Таймлайн */
.timeline-section {
    margin-top: 20px;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    border: 2px solid #667eea;
}

.timeline-container {
    width: 100%;
    height: 200px;
    background: #f0f0f0;
    border-radius: 8px;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    margin-top: 15px;
}

.timeline-track {
    height: 100%;
    position: relative;
    min-width: 100%;
}

.timeline-ruler {
    height: 30px;
    border-bottom: 2px solid #333;
    position: relative;
}

.timeline-ruler-tick {
    position: absolute;
    bottom: 0;
    border-left: 1px solid #333;
    height: 10px;
}

.timeline-ruler-label {
    position: absolute;
    bottom: -20px;
    font-size: 10px;
    transform: translateX(-50%);
}

.timeline-bars {
    height: calc(100% - 30px);
    position: relative;
}

.timeline-bar {
    position: absolute;
    height: 20px;
    border-radius: 3px;
    opacity: 0.7;
    cursor: pointer;
    transition: opacity 0.2s;
}

.timeline-bar:hover {
    opacity: 1;
}

.timeline-legend {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: #f0f0f0;
    border-radius: 5px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 3px;
}

/* Извлечение видео */
.extract-section {
    margin-top: 20px;
    padding: 20px;
    background: #fff;
    border-radius: 10px;
    border: 2px solid #28a745;
}

.class-checkbox {
    margin: 5px;
}

.extract-btn {
    padding: 10px 20px;
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 15px;
    font-size: 1em;
}

.extract-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(40, 167, 69, 0.4);
}

.extract-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Подсказка */
.help-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    text-align: center;
    line-height: 20px;
    font-size: 14px;
    cursor: help;
    margin-left: 10px;
    position: relative;
}

.help-icon:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 30px;
    top: -5px;
    background: #333;
    color: white;
    padding: 10px 15px;
    border-radius: 5px;
    white-space: normal;
    max-width: 400px;
    width: max-content;
    z-index: 1000;
    font-size: 13px;
    line-height: 1.4;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.help-icon:hover::before {
    content: '';
    position: absolute;
    left: 25px;
    top: 5px;
    border: 5px solid transparent;
    border-right-color: #333;
    z-index: 1001;
}

/* Модальное окно для изображений */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    overflow: auto;
}

.modal-overlay.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    max-width: 95%;
    max-height: 90vh;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #667eea;
}

.modal-title {
    font-size: 1.5em;
    font-weight: bold;
    color: #333;
}

.modal-close {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    background: #dc3545;
    color: white;
    border: none;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: #c82333;
    transform: rotate(90deg);
}

.modal-images-container {
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 15px;
    padding: 10px;
    max-height: 37vh;
    scrollbar-width: thin;
    scrollbar-color: #667eea #f0f0f0;
}

.modal-images-container::-webkit-scrollbar {
    height: 8px;
}

.modal-images-container::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 10px;
}

.modal-images-container::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.modal-image-item {
    flex-shrink: 0;
    text-align: center;
    background: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
}

.modal-image-item img {
    max-height: 30vh;
    max-width: auto;
    border-radius: 5px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.modal-image-info {
    margin-top: 8px;
    font-size: 0.85em;
    color: #666;
}

.modal-loading {
    text-align: center;
    padding: 40px;
    color: #667eea;
    font-size: 1.2em;
}

/* Иконка Telegram */
.telegram-icon {
    display: inline-block;
    width: 40px;
    height: 40px;
    margin-left: 15px;
    cursor: pointer;
    transition: transform 0.2s ease;
    color: #0088cc;
}

.telegram-icon:hover {
    transform: scale(1.1);
    color: #006699;
}

.telegram-icon svg {
    width: 100%;
    height: 100%;
}

.shop-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: 12px;
    cursor: pointer;
    transition: transform 0.2s ease;
    text-decoration: none;
}

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

.shop-icon-link img {
    width: 100%;
    height: 100%;
}

.btnRefresh {
    margin-left: 10px;
}

.bthClass {
    width: 18px;
}


/* Адаптивные стили для мобильных устройств */
@media screen and (max-width: 768px) {
    body {
        padding: 10px;
    }

    .btnRefresh {
        margin-left: 0;
    }

    .bthClass {
        width: auto
    }

    .container {
        padding: 20px;
        border-radius: 10px;
    }

    h1 {
        font-size: 1.8em;
        flex-wrap: wrap;
    }

    h2 {
        font-size: 1em;
    }

    .version {
        font-size: 0.8em;
    }

    .upload-section {
        padding: 20px;
    }

    .upload-icon {
        font-size: 3em;
        margin-bottom: 15px;
    }

    .file-input-label {
        padding: 12px 20px;
        font-size: 1em;
        width: 100%;
        text-align: center;
    }

    .process-btn {
        padding: 15px 30px;
        font-size: 1.1em;
        width: 100%;
        margin-top: 15px;
    }

    .task-card {
        padding: 15px;
    }

    .task-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .task-filename {
        font-size: 1em;
        word-break: break-word;
    }

    .classes-list {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .filters-section {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .filter-group input {
        width: 100%;
        padding: 10px;
    }

    .filter-btn {
        width: 100%;
        padding: 12px;
        font-size: 1em;
    }

    .timeline-container {
        height: 150px;
    }

    .timeline-legend {
        flex-direction: column;
    }

    .download-btn {
        width: 100%;
        margin-right: 0;
        margin-top: 10px;
        text-align: center;
        padding: 12px;
    }

    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 10px auto;
        padding: 15px;
    }

    .modal-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .modal-close {
        position: absolute;
        top: 10px;
        right: 10px;
        font-size: 24px;
        padding: 5px 10px;
    }

    .modal-images-container {
        max-height: 50vh;
    }

    .modal-image-item img {
        max-height: 40vh;
    }

    /* Камера */
    #cameraSection {
        padding: 20px;
    }

    #localCameraSelect,
    #cameraUrlInput,
    #classSelect {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        /* Предотвращает зум на iOS */
        margin-bottom: 10px;
    }

    #browserCameraVideo {
        max-width: 100%;
        max-height: 250px;
    }

    #cameraStreamImg {
        max-width: 100%;
        max-height: 300px;
    }

    /* Радио кнопки и кнопки камеры */
    input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 8px;
    }

    label {
        font-size: 16px;
        /* Предотвращает зум на iOS */
    }

    button {
        min-height: 44px;
        /* Минимальный размер для удобного нажатия */
        font-size: 16px;
        /* Предотвращает зум на iOS */
    }

    .telegram-icon {
        margin-left: 40%;
    }

    /* Заголовок с Telegram */
    .user-info {
        margin-left: 0 !important;
        margin-top: 15px;
        text-align: left !important;
        display: flex;
        gap: 10px;
    }

    /* Заголовок контейнер - адаптивность */
    .container>div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
    }

    h1 {
        flex-wrap: wrap;
        word-break: break-word;
    }

    /* Выбранные классы */
    #selectedClassesList {
        flex-direction: column;
        align-items: end;
    }

    .selected-class-item {
        width: 100%;
        margin-bottom: 8px;
    }

    /* Переопределение inline стилей для мобильных */
    .container>div:first-child>div:first-child {
        flex: 1 1 100% !important;
    }

    /* Адаптивность для выбора классов */
    #classSelect {
        min-width: 100% !important;
    }

    /* Кнопки в строках */
    button[onclick="addSelectedClass()"],
    button[onclick="refreshCameras()"] {
        width: 100%;
        margin-top: 10px;
    }

    /* Радио кнопки - вертикальное расположение */
    input[type="radio"]+label {
        display: block;
        margin-bottom: 10px;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 5px;
    }
}

@media screen and (max-width: 480px) {
    body {
        padding: 5px;
    }

    .radio-list {
        display: flex;
        flex-direction: column;
    }

    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.5em;
    }

    h2 {
        font-size: 0.9em;
    }

    .upload-section {
        padding: 15px;
    }

    .upload-icon {
        font-size: 2.5em;
    }

    .file-input-label {
        padding: 12px 15px;
        font-size: 0.95em;
    }

    .process-btn {
        padding: 12px 20px;
        font-size: 1em;
    }

    .task-card {
        padding: 12px;
    }

    .task-filename {
        font-size: 0.95em;
    }

    .task-status {
        font-size: 0.8em;
        padding: 4px 10px;
    }

    .progress-bar-container {
        height: 20px;
    }

    .timeline-container {
        height: 120px;
    }

    .modal-content {
        width: 98%;
        max-width: 98%;
        padding: 10px;
    }

    .modal-image-item img {
        max-height: 35vh;
    }

    #browserCameraVideo {
        max-height: 200px;
    }

    #cameraStreamImg {
        max-height: 250px;
    }

    /* Улучшаем отображение форм на маленьких экранах */
    select,
    input[type="text"],
    input[type="number"] {
        font-size: 16px;
        /* Предотвращает зум на iOS */
        padding: 12px;
    }

    /* Компактные кнопки */
    button {
        padding: 10px 15px;
        font-size: 14px;
    }
}

/* Дополнительные улучшения для сенсорных устройств */
@media (hover: none) and (pointer: coarse) {

    /* Убираем hover эффекты на устройствах без мыши */
    .file-input-label:hover {
        transform: none;
    }

    .process-btn:hover:not(:disabled) {
        transform: none;
    }

    .download-btn:hover {
        transform: none;
    }

    .class-item:hover {
        transform: none;
    }

    /* Увеличиваем область нажатия */
    .file-input-label,
    .process-btn,
    .download-btn,
    .filter-btn,
    .extract-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Улучшаем видимость активных элементов */
    .file-input-label:active,
    .process-btn:active,
    .download-btn:active {
        opacity: 0.8;
    }
}

/* Портретная ориентация на мобильных */
@media screen and (max-width: 768px) and (orientation: portrait) {
    .container {
        padding: 15px;
    }

    .upload-section {
        padding: 15px;
    }
}

/* Ландшафтная ориентация на мобильных */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-images-container {
        max-height: 60vh;
    }
}
