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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-lighter: #c7d2fe;
    --secondary: #8b5cf6;
    --accent: #ec4899;
    --background: #fafbfc;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --success: #059669;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

/* Login Card */
.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 3.5rem;
    box-shadow: var(--shadow-xl);
    max-width: 420px;
    margin: 10vh auto;
    text-align: center;
    border: 1px solid var(--border);
}

.login-card h1 {
    font-size: 2.25rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text);
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2.5rem;
    font-size: 0.9375rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.input, textarea {
    width: 100%;
    padding: 1.125rem 1.25rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 400;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    line-height: 1.5;
    appearance: none;
    -webkit-appearance: none;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
}

.input:hover, textarea:hover {
    border-color: var(--primary-lighter);
    background: var(--surface);
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.06);
}

.input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1), 0 2px 8px 0 rgba(99, 102, 241, 0.15);
    background: var(--surface);
}

.input:focus:hover, textarea:focus:hover {
    border-color: var(--primary);
}

.input::placeholder, textarea::placeholder {
    color: var(--text-muted);
    opacity: 0.6;
    font-weight: 400;
}

.textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

/* File Input */
input[type="file"] {
    padding: 1rem 1.125rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    background: var(--background);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    width: 100%;
    font-family: inherit;
    color: var(--text);
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

input[type="file"]:hover {
    border-color: var(--primary-light);
    background: var(--surface);
    border-style: solid;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.08);
}

input[type="file"]:focus {
    outline: none;
    border-color: var(--primary);
    border-style: solid;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.08);
    background: var(--surface);
}

/* Buttons */
.btn {
    padding: 0.875rem 1.75rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
    background: var(--primary);
    color: white;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

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

.btn-outline {
    background: var(--surface);
    border: 1.5px solid var(--border);
    color: var(--text);
}

.btn-outline:hover:not(:disabled) {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-sm {
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
}

.btn-full {
    width: 100%;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Error Message - УБРАН КРАСНЫЙ ФОН */
.error-message {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    min-height: 1.5rem;
    text-align: center;
}

/* Main Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1.5rem 2rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.main-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text);
    letter-spacing: -0.02em;
}

.user-code {
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-weight: 500;
}

/* Loading */
.loading {
    text-align: center;
    padding: 4rem 2rem;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1.5rem;
}

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

.loading p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Error Container - УБРАН КРАСНЫЙ */
.error-container {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    font-weight: 500;
    box-shadow: var(--shadow);
}

/* Content */
.content {
    margin-top: 2rem;
}

.hidden {
    display: none !important;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.empty-state svg {
    margin-bottom: 1.5rem;
    opacity: 0.3;
    color: var(--primary);
}

.empty-state p {
    font-size: 1rem;
}

/* Videos Container */
.videos-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}

@media (max-width: 1024px) {
    .videos-container {
        grid-template-columns: 1fr;
    }
}

/* Video Player */
.video-player-section {
    grid-column: 1;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.video-player-container {
    position: relative;
    padding-bottom: 56.25%;
    height: 0;
    margin-bottom: 1.5rem;
    background: #000;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.video-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.video-description {
    margin-bottom: 1.5rem;
    padding: 0;
    background: transparent;
    border-radius: 0;
    white-space: pre-wrap;
    border: none;
}

.video-description h3 {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.video-description p {
    color: var(--text);
    line-height: 1.8;
    font-size: 0.9375rem;
    margin: 0;
    padding: 1.5rem;
    background: var(--surface);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}

/* Videos List */
.videos-list-section {
    grid-column: 2;
}

.videos-list-section h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.videos-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.video-item {
    background: var(--surface);
    border-radius: var(--radius-sm);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow-xs);
}

.video-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--primary-light);
}

.video-item.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.03) 0%, rgba(139, 92, 246, 0.03) 100%);
}

.video-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: var(--radius-sm);
    margin-bottom: 0.75rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.video-thumbnail video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Для мобильных устройств - улучшаем отображение превью */
@media (max-width: 768px) {
    .video-thumbnail video {
        background: #000;
    }
    
    .video-thumbnail {
        min-height: 200px;
    }
}

.video-item-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.5;
}

.video-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Admin Panel */
.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

@media (max-width: 1024px) {
    .admin-grid {
        grid-template-columns: 1fr;
    }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.card-content {
    padding-top: 0;
}

/* Users List */
.users-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.user-item {
    padding: 1.25rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

.user-item:hover {
    background: var(--background);
    border-color: var(--primary-light);
    transform: translateX(4px);
    box-shadow: var(--shadow);
}

.user-item.selected {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.user-item.selected .user-item-code,
.user-item.selected .user-item-meta {
    color: white;
}

.user-item-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-item-details {
    flex: 1;
}

.user-item-code {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.375rem;
    color: var(--text);
}

.user-item-meta {
    font-size: 0.875rem;
    opacity: 0.8;
    color: var(--text-secondary);
}

.user-item-note {
    margin-top: 0.75rem;
    padding: 0.875rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    border: 1px solid var(--border-light);
    line-height: 1.5;
}

.user-item.selected .user-item-note {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.95);
}

.user-item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    padding: 0.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    transition: all 0.2s;
    border-radius: var(--radius-sm);
}

.btn-icon:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
}

.user-item.selected .btn-icon:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Create Form */
.create-form {
    padding: 1.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
}

.create-form .input {
    background: var(--surface);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Upload Form */
.upload-form {
    padding: 1.5rem;
    background: var(--background);
    border-radius: var(--radius-sm);
    margin-bottom: 1.5rem;
    border: 1.5px solid var(--border);
}

.upload-form h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text);
}

.upload-form .input,
.upload-form .textarea {
    margin-bottom: 1rem;
}

/* Admin Video Item */
.admin-video-item {
    padding: 1.5rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    background: var(--surface);
    transition: all 0.2s;
    box-shadow: var(--shadow-xs);
}

.admin-video-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
}

.admin-video-thumbnail {
    width: 100%;
    aspect-ratio: 16/9;
    background: #000;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.admin-video-thumbnail video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.admin-video-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .container {
        padding: 1.5rem 1rem;
    }

    .login-card {
        padding: 2.5rem 2rem;
        margin: 2rem auto;
        border-radius: var(--radius);
    }

    .login-card h1 {
        font-size: 1.75rem;
    }

    .main-header {
        flex-direction: row;
        gap: 1rem;
        align-items: flex-start;
        justify-content: space-between;
        padding: 1rem 0 1.5rem 0;
        margin-bottom: 2rem;
    }

    .main-header > div {
        flex: 1;
        padding-right: 1rem;
    }

    .main-header h1 {
        font-size: 1.75rem;
        margin-bottom: 0.75rem;
        padding-left: 0;
    }

    .user-code {
        font-size: 0.9375rem;
        margin: 0;
        padding-left: 0;
    }

    .videos-container {
        grid-template-columns: 1fr;
        display: grid;
        gap: 2rem;
    }

    .videos-list-section {
        grid-column: 1;
    }

    .videos-list-section h2 {
        font-size: 1.5rem;
        margin-bottom: 1.5rem;
        padding-left: 0;
    }

    .video-player-section {
        order: 1;
    }

    .videos-list-section {
        order: 2;
    }

    .video-player-section .card {
        padding: 1.5rem;
    }

    .video-player-section h2 {
        margin-bottom: 1.5rem;
        padding-left: 0;
    }

    .video-player-container {
        margin-bottom: 1.5rem;
        padding-bottom: 56.25%; /* Соотношение 16:9 */
        position: relative;
        height: 0;
        background: #000;
        border-radius: var(--radius-sm);
        overflow: hidden;
    }

    .video-player {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: var(--radius-sm);
    }

    .video-description {
        margin-top: 1.5rem;
    }

    .video-description p {
        padding: 1.25rem;
        font-size: 0.9375rem;
    }

    .video-item {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }

    .video-thumbnail {
        margin-bottom: 1rem;
    }

    .video-item-description {
        font-size: 0.875rem;
        margin-bottom: 0.75rem;
        line-height: 1.6;
    }

    .video-item-date {
        font-size: 0.75rem;
    }

    .btn {
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }

    .btn-full {
        width: 100%;
        margin-top: 1rem;
    }

    #logoutBtn {
        padding: 0.75rem 1.25rem;
    }

    /* Админ-панель */
    .admin-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .card {
        padding: 1.25rem;
    }

    .card-header h2 {
        font-size: 1.25rem;
    }

    .upload-form {
        padding: 1rem;
    }

    .upload-form h3 {
        font-size: 1.125rem;
        margin-bottom: 1rem;
    }

    .admin-video-item {
        padding: 0.75rem;
    }

    .admin-video-actions {
        flex-direction: column;
        gap: 0.5rem;
    }

    .admin-video-actions .btn {
        width: 100%;
    }

    /* Модальное окно */
    .modal-content {
        margin: 1rem;
        max-width: calc(100% - 2rem);
    }

    .modal-header {
        padding: 1.25rem;
    }

    .modal-header h3 {
        font-size: 1.125rem;
    }

    .modal-body {
        padding: 1.25rem;
    }

    .modal-footer {
        padding: 1.25rem;
        flex-direction: column-reverse;
        gap: 0.75rem;
    }

    .modal-footer .btn {
        width: 100%;
    }
}

/* Малые экраны */
@media (max-width: 480px) {
    .container {
        padding: 1rem 0.75rem;
    }

    .login-card {
        padding: 1.5rem 1rem;
    }

    .main-header {
        padding: 1rem 1.25rem;
        margin-bottom: 1.5rem;
    }

    .main-header h1 {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    .card {
        padding: 1rem;
    }

    .video-item {
        padding: 0.625rem;
    }

    .btn {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 44px; /* Минимальный размер для touch */
    }

    .btn-sm {
        min-height: 36px;
        padding: 0.5rem 0.875rem;
    }

    .input, .textarea {
        font-size: 16px; /* Предотвращает zoom на iOS */
        padding: 0.75rem;
    }

    .video-thumbnail {
        min-height: 180px;
    }

    .video-player-container {
        margin: 0 -1rem 1rem -1rem;
        padding-bottom: 56.25%; /* Соотношение 16:9 */
        position: relative;
        height: 0;
        background: #000;
        border-radius: 0;
        overflow: hidden;
    }

    .video-player {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        object-fit: contain;
        border-radius: 0;
    }
}

/* Touch устройства */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 44px;
    }

    .video-item {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    .video-item:active {
        transform: scale(0.98);
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--background);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--border-light);
    color: var(--text);
}

.modal-body {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    padding: 1.5rem;
    border-top: 1px solid var(--border-light);
}