/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #0a0a0a;
    --card: #1a1a1a;
    --card-hover: #252525;
    --accent: #ff4444;
    --accent-glow: rgba(255, 68, 68, 0.3);
    --success: #44ff88;
    --success-glow: rgba(68, 255, 136, 0.3);
    --text: #ffffff;
    --text-muted: #888888;
    --radius: 20px;
    --radius-sm: 12px;
    --radius-xs: 8px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.4;
}

/* Фиксируем страницу редактора чтобы не скроллилась ВСЯ страница */
body.page-editor {
    overflow: hidden;
    height: 100vh;
}

/* ===== MAIN PAGE ===== */
.page-main {
    padding: 20px;
    padding-bottom: 40px;
}

.main-header {
    text-align: center;
    padding: 24px 50px 32px;
    position: relative;
}

.main-header h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
}

.main-header p {
    display: none;
}

/* Кнопка истории на главной странице */
.main-history-btn {
    position: absolute;
    right: 10px;
    top: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid #333;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.main-history-btn:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.main-history-btn svg {
    width: 20px;
    height: 20px;
}

.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.template-card {
    background: var(--card);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.25s ease;
    border: 2px solid transparent;
    text-decoration: none;
    color: inherit;
    display: block;
}

.template-card:hover {
    background: var(--card-hover);
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 12px 32px var(--accent-glow);
}

.template-card:active {
    transform: scale(0.97);
}

.template-preview {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
}

.template-name {
    padding: 14px;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
}

/* ===== TEMPLATE PAGE ===== */
.page-template {
    padding: 16px;
    padding-bottom: 120px;
    position: relative;
    z-index: 1;
}

.back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 15px;
    padding: 10px 0;
    transition: color 0.2s;
}

.back-btn:hover {
    color: var(--text);
}

.back-btn svg {
    width: 18px;
    height: 18px;
}

/* Кнопка "В редактор" (после нажатия "Заменить") */
.forward-btn {
    position: absolute;
    top: 20px;
    left: 110px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text);
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    padding: 8px 14px;
    cursor: pointer;
    transition: all 0.2s;
    z-index: 10;
}

.forward-btn:hover {
    background: #ff6666;
    transform: scale(1.02);
}

.forward-btn svg {
    width: 16px;
    height: 16px;
    transform: rotate(180deg);
}

.template-header {
    text-align: center;
    margin-bottom: 20px;
}

.template-header h1 {
    font-size: 24px;
    font-weight: 800;
}

/* ===== SEARCH SECTION ===== */
.search-section {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
}

.search-section.compact {
    padding: 12px;
    margin-bottom: 12px;
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    background: var(--bg);
    border: 2px solid #333;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    min-width: 0;
}

.search-section.compact .search-input {
    padding: 10px 12px;
    font-size: 13px;
}

.search-input:focus {
    border-color: var(--accent);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-btn {
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.search-section.compact .search-btn {
    padding: 10px 14px;
}

.search-btn:hover {
    background: #ff5555;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.search-btn:active {
    transform: scale(0.95);
}

.search-btn:disabled {
    background: #333;
    cursor: not-allowed;
}

.search-btn svg {
    width: 18px;
    height: 18px;
}

.attach-btn {
    background: #333;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.attach-btn:hover {
    background: #444;
}

.attach-btn svg {
    width: 18px;
    height: 18px;
}

/* ===== STATUS ===== */
.status {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.status.has-results {
    display: none;
}

.status.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.count-badge {
    display: none;
}

/* Search box с счётчиком */
.search-box {
    position: relative;
}

.search-count {
    position: absolute;
    right: 70px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent);
    color: white;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 10px;
}

/* ===== MASONRY GALLERY ===== */
.gallery {
    column-count: 2;
    column-gap: 10px;
    margin-top: 16px;
}

.gallery-item {
    break-inside: avoid;
    margin-bottom: 10px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    border: 3px solid transparent;
    transition: all 0.2s;
}

.gallery-item:hover {
    border-color: var(--accent);
}

.gallery-item.selected {
    border-color: var(--success);
    box-shadow: 0 0 24px var(--success-glow);
}

.gallery-item img {
    width: 100%;
    height: auto;
    display: block;
}

/* 1xBet toggle on image */
.gallery-item .xbet-toggle {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 44px;
    height: 24px;
    background: rgba(0,0,0,0.6);
    border-radius: 12px;
    cursor: pointer;
    display: none;
    align-items: center;
    padding: 2px;
    backdrop-filter: blur(4px);
    transition: background 0.2s;
}

.gallery-item.selected .xbet-toggle {
    display: flex;
}

.gallery-item .xbet-toggle.on {
    background: var(--accent);
}

.gallery-item .xbet-toggle .knob {
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.gallery-item .xbet-toggle.on .knob {
    transform: translateX(20px);
}

.gallery-item .xbet-label {
    position: absolute;
    bottom: 8px;
    left: 8px;
    font-size: 10px;
    font-weight: 700;
    color: white;
    background: var(--accent);
    padding: 3px 6px;
    border-radius: 4px;
    display: none;
}

.gallery-item.selected .xbet-label {
    display: block;
}

.gallery-item .check {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    background: var(--success);
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
}

.gallery-item .check svg {
    width: 16px;
    height: 16px;
    color: white;
}

.gallery-item.selected .check {
    display: flex;
}

/* ===== ACTION BAR ===== */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, var(--bg) 30%);
    padding: 24px 16px 20px;
    z-index: 100;
}

.action-btn {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    display: flex;
    background: linear-gradient(135deg, var(--accent) 0%, #ff6666 100%);
    border: none;
    border-radius: var(--radius);
    padding: 20px;
    color: white;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.action-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px var(--accent-glow);
}

.action-btn:active {
    transform: scale(0.97);
}

.action-btn:disabled {
    background: #333;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.action-btn svg {
    width: 24px;
    height: 24px;
}

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 28px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    transform: scale(0.9);
    transition: transform 0.3s;
}

.modal-overlay.show .modal {
    transform: scale(1);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--text);
}

.modal-progress {
    height: 6px;
    background: #333;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 16px;
}

.modal-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ff6666);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.modal-current-step {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.modal-step-counter {
    font-size: 12px;
    color: #555;
    font-weight: 600;
}

/* ===== FULLSCREEN PREVIEW ===== */
.fullscreen-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s, visibility 0.25s;
}

.fullscreen-overlay.show {
    opacity: 1;
    visibility: visible;
}

.fullscreen-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2010;
    transition: background 0.2s;
}

.fullscreen-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.fullscreen-close svg {
    width: 24px;
    height: 24px;
}

.fullscreen-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    user-select: none;
}

.fullscreen-container img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.fullscreen-zoom-indicator {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    z-index: 2010;
}

.fullscreen-hint {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    text-align: center;
    pointer-events: none;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--card);
    border: 1px solid #333;
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1001;
    opacity: 0;
    transition: all 0.3s;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
}

.toast.success svg {
    color: var(--success);
}

.toast svg {
    width: 20px;
    height: 20px;
}

/* ===== EDITOR PAGE ===== */
.page-editor {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

/* Mobile: editor-content and editor-right-panel are transparent wrappers */
.editor-content {
    display: contents; /* На мобильных - не влияет на layout */
}

.editor-right-panel {
    display: contents; /* На мобильных - не влияет на layout */
}

.editor-header {
    flex-shrink: 0;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border-bottom: 1px solid #222;
}

.editor-header h2 {
    font-size: 16px;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.editor-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
}

.editor-close svg {
    width: 24px;
    height: 24px;
}

/* Editor Toolbar */
.editor-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--card);
    border-bottom: 1px solid #222;
    flex-wrap: wrap;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--card);
    border: 1px solid #333;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.toolbar-btn:hover {
    background: var(--card-hover);
    border-color: #444;
}

.toolbar-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.toolbar-btn svg {
    width: 16px;
    height: 16px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: #333;
    margin: 0 4px;
}

.toolbar-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-spacer {
    flex: 1;
    min-width: 8px;
}

.toolbar-btn-right {
    margin-left: 0;
}

.toolbar-btn-right:last-child {
    /* Кнопка "Заменить" справа */
}

.toolbar-values {
    font-size: 11px;
    color: var(--accent);
    font-family: monospace;
    background: rgba(255, 68, 68, 0.15);
    padding: 4px 8px;
    border-radius: 4px;
}

.toolbar-reset {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: transparent;
    border: 1px solid #444;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.toolbar-reset svg {
    width: 14px;
    height: 14px;
}

.toolbar-reset:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Preview Area - fixed height to prevent jitter */
.editor-preview {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    position: relative;
    height: 40vh;
    min-height: 180px;
    max-height: 50vh;
    overflow: hidden;
    z-index: 1;
    background: var(--bg);
}

/* Watermark processing indicator - маленький в углу */
.watermark-processing-indicator {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 50%;
    z-index: 10;
}

.watermark-processing-indicator svg {
    width: 16px;
    height: 16px;
    animation: spin 1s linear infinite;
    color: var(--accent);
}

.watermark-processing-indicator span {
    display: none;  /* Скрываем текст */
}

/* Успешная очистка - зелёная галочка */
.watermark-done-indicator {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: rgba(68, 255, 136, 0.2);
    border-radius: 50%;
    z-index: 10;
    animation: fade-in 0.3s ease;
    color: var(--success, #44ff88);
    font-size: 18px;
    font-weight: bold;
}

/* НОВЫЕ индикаторы внутри изображения */
.watermark-indicator {
    position: absolute;
    bottom: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    z-index: 10;
    pointer-events: none;
}

.watermark-indicator.watermark-processing {
    background: rgba(0, 0, 0, 0.7);
}

.watermark-indicator.watermark-processing svg {
    width: 14px;
    height: 14px;
    animation: spin 1s linear infinite;
    color: var(--accent);
}

.watermark-indicator.watermark-done {
    background: rgba(68, 255, 136, 0.25);
    animation: fade-in 0.3s ease;
    color: var(--success, #44ff88);
    font-size: 14px;
    font-weight: bold;
}

@keyframes fade-in {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.editor-preview.compact {
    height: 28vh;
    min-height: 140px;
    max-height: 30vh;
}

.editor-preview-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.editor-preview img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: var(--radius-sm);
    display: block;
    object-fit: contain;
}

/* Form Area - scrollable */
.editor-form-wrapper {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    background: var(--bg);
    position: relative;
    z-index: 2;
}

.editor-form-wrapper::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.editor-form {
    padding: 12px;
    padding-bottom: 70px; /* Space for action bar */
}

/* Text overlay preview */
.editor-text-overlay {
    position: absolute;
    color: white;
    font-weight: 700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    white-space: pre-line;
    text-transform: uppercase;
}

/* Action Bar - sticky bottom */
.action-bar {
    flex-shrink: 0;
    padding: 10px 12px;
    background: var(--card);
    border-top: 1px solid #222;
    display: flex;
    gap: 10px;
}

.action-btn {
    flex: 1;
    display: flex;
    background: linear-gradient(135deg, var(--accent) 0%, #cc3333 100%);
    border: none;
    border-radius: var(--radius);
    padding: 14px;
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.action-btn-secondary {
    flex: 0 0 30%;
    background: linear-gradient(135deg, #444 0%, #333 100%);
    padding: 14px 10px;
}

.action-btn-secondary:hover {
    background: linear-gradient(135deg, #555 0%, #444 100%);
}

.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.action-btn-secondary:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.action-btn:active {
    transform: scale(0.98);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.action-btn:disabled:hover {
    transform: none;
    box-shadow: none;
}

.action-btn svg {
    width: 20px;
    height: 20px;
}

/* Spinning animation for loading */
.action-btn:disabled svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--accent);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-select-compact {
    width: auto;
    min-width: 120px;
}

.form-group-compact {
    display: flex;
    align-items: center;
    gap: 12px;
}

.form-group-compact .form-label {
    margin-bottom: 0;
    white-space: nowrap;
}

.form-select option {
    background: var(--bg);
    color: var(--text);
}

.form-textarea {
    resize: none;
    min-height: 60px;
}

/* ===== STATS TABLE ===== */
.stats-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stats-row {
    display: flex;
    gap: 8px;
}

.stats-value {
    width: 60px !important;
    flex-shrink: 0;
    text-align: center;
}

.stats-label {
    flex: 1;
}

/* Compact версия для stats-table (меньше шрифт и padding) */
.stats-table-compact .form-input {
    padding: 8px 10px;
    font-size: 13px;
}

.stats-table-compact .stats-value {
    width: 50px !important;
}

/* ===== BEST PLAYER ROW ===== */
.best-player-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.best-player-month {
    flex: 0 0 85px;
    min-width: 85px;
    padding: 8px 10px !important;
    font-size: 13px !important;
}

.best-player-name {
    flex: 1;
    min-width: 0;
}

.best-player-align-btn {
    flex: 0 0 75px;
    min-width: 75px;
    padding: 8px 6px;
    font-size: 11px;
    background: var(--bg);
    border: 2px solid #333;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.best-player-align-btn:hover {
    border-color: var(--accent);
}

.best-player-align-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.form-group-full {
    margin-bottom: 12px;
}

/* ===== HISTORY SIDEBAR ===== */
.history-btn {
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: var(--card);
    border: 1px solid #333;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: all 0.2s;
}

.history-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent);
}

.history-btn svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.history-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: var(--accent);
    border-radius: 50%;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    background: var(--card);
    transform: translateX(100%);
    transition: transform 0.3s;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.history-sidebar.show {
    transform: translateX(0);
}

.history-header {
    padding: 20px;
    border-bottom: 1px solid #222;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.history-header h3 {
    font-size: 16px;
}

.history-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.history-item {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 12px;
}

.history-item:hover {
    background: #1a1a1a;
}

.history-item img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
}

.history-item-no-image {
    width: 50px;
    height: 50px;
    background: var(--card);
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

.history-item-info {
    flex: 1;
    min-width: 0;
}

.history-item-title {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.history-item-status {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    margin-top: 6px;
    display: inline-block;
}

.history-item-status.editing {
    background: rgba(255, 200, 0, 0.2);
    color: #ffc800;
}

.history-item-status.done {
    background: rgba(68, 255, 136, 0.2);
    color: var(--success);
}

.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.history-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 500px) {
    .templates-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }
    
    .main-header h1 {
        font-size: 24px;
    }
    
    .page-main {
        padding: 14px;
    }
}

@media (min-width: 500px) {
    .gallery {
        column-count: 3;
    }
}

@media (min-width: 700px) {
    .gallery {
        column-count: 4;
    }
}

@media (min-width: 900px) {
    .gallery {
        column-count: 5;
    }
}

/* ===== LINEUP TABLE ===== */
.lineup-table {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lineup-row {
    display: flex;
    gap: 8px;
}

.lineup-number {
    width: 45px;
    flex-shrink: 0;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: var(--radius-xs);
    padding: 8px 6px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.lineup-number:focus {
    border-color: var(--accent);
}

.lineup-name {
    flex: 1;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: var(--radius-xs);
    padding: 8px 10px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.lineup-name:focus {
    border-color: var(--accent);
}

.lineup-name::placeholder,
.lineup-number::placeholder {
    color: var(--text-muted);
}

/* ===== PREVIEW OVERLAY ===== */
.editor-preview-container {
    position: relative;
    max-width: 100%;
    max-height: 50vh;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.editor-preview-container img {
    max-width: 100%;
    max-height: 50vh;
    border-radius: var(--radius-sm);
    display: block;
    flex-shrink: 0;
}

.preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    font-family: 'TT Firs Neue', -apple-system, BlinkMacSystemFont, sans-serif;
}

.preview-overlay > div {
    text-shadow: 1px 1px 3px rgba(0,0,0,0.7);
    word-wrap: break-word;
}

/* ===== SERVER PREVIEW ===== */
.server-preview-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
}

.server-preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

.server-preview.adjustable {
    cursor: grab;
}

.server-preview.adjustable.dragging {
    cursor: grabbing;
}

.server-preview img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    border-radius: var(--radius-sm);
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    pointer-events: none;
    object-fit: contain;
}

/* Контейнер для изображения с индикатором */
.server-preview-image-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    overflow: hidden;
}

.server-preview-image-container img {
    pointer-events: auto;  /* Восстанавливаем для клика */
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.preview-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 16px;
    border-radius: var(--radius-xs);
    pointer-events: none;
}

/* Placeholder во время первой загрузки */
.preview-placeholder {
    aspect-ratio: 1 / 1;
    background: linear-gradient(135deg, #1a1a1a 0%, #2a2a2a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.preview-placeholder .preview-loading {
    position: static;
    transform: none;
}

.preview-hint {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    color: white;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.7);
    padding: 6px 12px;
    border-radius: var(--radius-xs);
    pointer-events: none;
    white-space: nowrap;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.server-preview:hover .preview-hint {
    opacity: 1;
}

.preview-drag-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: white;
    background: rgba(0, 0, 0, 0.8);
    padding: 16px 24px;
    border-radius: var(--radius-sm);
    pointer-events: none;
    z-index: 10;
}

.preview-drag-indicator .drag-direction {
    font-size: 32px;
    line-height: 1;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-drag-indicator .drag-values {
    font-size: 12px;
    color: var(--text-muted);
    font-family: monospace;
}

/* ===== PAGE BACKGROUND ===== */
.page-bg {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(40px) saturate(1.2);
    transform: scale(1.15);
    z-index: -1;
    opacity: 0.4;
}

/* ===== RECENT SECTION ===== */
.recent-section {
    max-width: 800px;
    margin: 0 auto 32px;
    padding: 0 20px;
}

.recent-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.recent-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.recent-item:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.recent-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recent-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    color: white;
    font-size: 11px;
    text-align: center;
}

.recent-item.done .recent-overlay {
    background: linear-gradient(transparent, rgba(68, 255, 136, 0.3));
    color: var(--success);
    font-weight: 600;
}

/* Toggle Switch */
.form-toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    cursor: pointer;
}

.form-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #333;
    border-radius: 26px;
    transition: all 0.3s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.form-toggle input:checked + .toggle-slider {
    background: var(--accent);
}

.form-toggle input:checked + .toggle-slider::before {
    transform: translateX(24px);
}

.form-toggle:hover .toggle-slider {
    background: #444;
}

.form-toggle input:checked:hover + .toggle-slider {
    background: var(--accent-hover);
}

.field-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
}

.field-toggle .field-label {
    margin-bottom: 0;
}

.toggle-label {
    font-size: 13px;
    color: var(--text-muted);
    min-width: 30px;
}

/* Editor Smooth Loading */
.editor-loading {
    opacity: 0;
    animation: fadeInEditor 0.4s ease forwards;
}

@keyframes fadeInEditor {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== TEAM SELECTOR ===== */
.team-selector {
    width: 100%;
}

.team-selector-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--card);
    border: 1px solid #333;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
}

.team-selector-btn:hover {
    background: var(--card-hover);
    border-color: var(--accent);
}

.team-selector-btn.has-value {
    border-color: var(--accent);
}

.team-selector-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 4px;
}

.team-selector-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

.team-selector-placeholder {
    font-size: 14px;
    color: var(--text-muted);
}

/* Team Modal */
.team-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.team-modal {
    width: 100%;
    max-width: 500px;
    max-height: 70vh;
    margin-bottom: 80px; /* Отступ для action-bar */
    background: var(--card);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

.team-modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid #333;
}

.team-modal-search {
    flex: 1;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid #333;
    border-radius: var(--radius-xs);
    color: var(--text);
    font-size: 15px;
}

.team-modal-search:focus {
    outline: none;
    border-color: var(--accent);
}

.team-modal-close {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.team-modal-close svg {
    width: 20px;
    height: 20px;
}

.team-modal-close:hover {
    color: var(--text);
}

.team-modal-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.team-modal-loading,
.team-modal-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}

.team-modal-loading svg {
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
}

.team-modal-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.team-modal-item:hover {
    background: var(--card-hover);
}

.team-modal-item.selected {
    background: rgba(255, 68, 68, 0.15);
}

.team-modal-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 6px;
}

.team-modal-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.team-modal-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.team-modal-league {
    font-size: 12px;
    color: var(--text-muted);
}

.team-modal-check {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border-radius: 50%;
    color: white;
}

.team-modal-check svg {
    width: 14px;
    height: 14px;
}

/* Compact form groups for team selectors */
.form-group-compact .team-selector-btn {
    padding: 10px 12px;
    min-height: 42px;
}

.form-group-compact .team-selector-logo {
    width: 26px;
    height: 26px;
}

.form-group-compact .team-selector-name {
    font-size: 13px;
}

/* ===== TRANSFER TEMPLATE STYLES ===== */
.transfer-teams {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
}

.transfer-team-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.transfer-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 20px;
    color: var(--accent);
    font-size: 20px;
    flex-shrink: 0;
}

.transfer-texts {
    display: flex;
    align-items: stretch;
    gap: 16px;
    width: 100%;
}

.transfer-text-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.form-label-mini {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.transfer-team-col .team-selector-btn {
    padding: 8px 10px;
    min-height: 38px;
}

.transfer-team-col .team-selector-logo {
    width: 24px;
    height: 24px;
}

.transfer-team-col .team-selector-name {
    font-size: 12px;
}

.transfer-text-col textarea {
    min-height: 60px;
    resize: vertical;
}

/* ===== PLAYER STAT TEMPLATE STYLES ===== */
.player-stat-row {
    display: flex;
    gap: 12px;
    width: 100%;
}

.player-stat-col {
    flex: 1;
    min-width: 0;
}

.player-stat-score {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    padding: 8px 12px !important;
}

.player-stat-textarea {
    font-size: 13px;
    min-height: 100px;
    resize: vertical;
}

.player-stat-stats-row {
    gap: 8px;
}

.player-stat-teams.compact {
    gap: 4px;
}

.player-stat-teams.compact .transfer-arrow {
    padding-top: 0;
    font-size: 16px;
}

.player-stat-teams.compact .team-selector-btn {
    padding: 6px 8px;
    min-height: 32px;
}

/* ===== DESKTOP STYLES (min-width: 1024px) ===== */
@media (min-width: 1024px) {
    /* ===== MAIN PAGE - Desktop ===== */
    .page-main {
        max-width: 1200px;
        margin: 0 auto;
        padding: 32px 40px;
    }
    
    .main-header {
        padding: 40px 0 48px;
    }
    
    .main-header h1 {
        font-size: 36px;
    }
    
    .templates-grid {
        max-width: 1000px;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 24px;
    }
    
    /* ===== TEMPLATE PAGE (Getty Search) - Desktop ===== */
    .page-template {
        max-width: 1400px;
        margin: 0 auto;
        padding: 24px 40px 120px;
    }
    
    .search-section {
        max-width: 800px;
        margin-left: auto;
        margin-right: auto;
        padding: 20px 24px;
    }
    
    .search-input {
        font-size: 15px;
        padding: 14px 16px;
    }
    
    .search-btn {
        padding: 14px 24px;
    }
    
    .template-header h1 {
        font-size: 28px;
    }
    
    /* Gallery - больше колонок на десктопе */
    .gallery {
        column-count: 5;
        column-gap: 16px;
        max-width: 1200px;
        margin: 24px auto 0;
    }
    
    .gallery-item {
        margin-bottom: 16px;
    }
    
    /* Action bar - ограниченная ширина */
    .page-template .action-bar {
        left: 50%;
        transform: translateX(-50%);
        max-width: 600px;
        border-radius: var(--radius) var(--radius) 0 0;
        background: var(--card);
    }
    
    /* ===== EDITOR PAGE - Desktop Layout with wrapper ===== */
    .page-editor {
        display: flex;
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    
    /* Header и Toolbar - всегда видимы вверху */
    .page-editor .editor-header {
        flex-shrink: 0;
    }
    
    .page-editor .editor-toolbar {
        flex-shrink: 0;
        padding: 10px 20px;
    }
    
    /* Container for preview + form side by side */
    .editor-content {
        display: flex;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        background: var(--bg);
    }
    
    /* Preview area - left side */
    .editor-preview {
        flex: 1;
        height: auto;
        max-height: none;
        min-height: unset;
        padding: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        overflow: hidden;
        background: var(--bg);
    }
    
    .editor-preview.compact {
        height: auto;
        max-height: none;
        min-height: unset;
    }
    
    .editor-preview img,
    .editor-preview-container img,
    .server-preview-image-container img {
        max-width: 100%;
        max-height: calc(100vh - 140px);
        width: auto;
        height: auto;
        border-radius: var(--radius);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
    
    /* Right panel - form + action bar */
    .editor-right-panel {
        flex: 0 0 480px;
        min-width: 400px;
        max-width: 550px;
        display: flex;
        flex-direction: column;
        height: 100%;
        overflow: hidden;
        background: var(--card);
        border-left: 1px solid #333;
    }
    
    /* Form wrapper - scrollable */
    .editor-form-wrapper {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .editor-form {
        padding: 20px 24px;
        padding-bottom: 24px;
    }
    
    /* Action bar in right panel */
    .editor-right-panel .action-bar {
        position: relative;
        left: auto;
        right: auto;
        bottom: auto;
        flex-shrink: 0;
        border-top: 1px solid #222;
        border-radius: 0;
        padding: 16px 24px;
        background: var(--card);
    }
    
    /* Field groups - more spacing */
    .field-group {
        margin-bottom: 18px;
    }
    
    .field-group label {
        font-size: 13px;
    }
    
    /* Server preview on desktop */
    .server-preview-container {
        padding: 12px;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .server-preview-image-container {
        max-height: calc(100vh - 100px);
        max-width: 100%;
    }
    
    .server-preview-image-container img {
        max-height: calc(100vh - 110px);
        max-width: 100%;
        width: auto;
        height: auto;
        object-fit: contain;
        border-radius: var(--radius);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

/* ===== EXTRA LARGE DESKTOP (min-width: 1440px) ===== */
@media (min-width: 1440px) {
    .page-main {
        max-width: 1400px;
    }
    
    .templates-grid {
        max-width: 1200px;
        grid-template-columns: repeat(5, 1fr);
    }
    
    .gallery {
        column-count: 6;
    }
    
    /* Редактор: НЕ меняем layout, просто ограничиваем ширину */
    /* Стили редактора остаются такими же как для 1024px */
}
