/* === VARIABLES === */
:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

/* === RESET === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    overscroll-behavior: none;
}

/* === SCREENS === */
.screen {
    display: none;
    min-height: 100vh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* === LOGIN SCREEN === */
#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-container {
    background: var(--bg-card);
    padding: 40px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-logo {
    width: 60px;
    height: 60px;
    margin: 0 auto 16px;
    color: var(--primary);
}

.login-logo svg {
    width: 100%;
    height: 100%;
}

.login-container h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text);
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
}

.input-group {
    margin-bottom: 16px;
    text-align: left;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    transition: var(--transition);
    outline: none;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.error-message {
    color: var(--danger);
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    text-decoration: none;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-outline:hover {
    background: var(--bg);
    border-color: var(--text-muted);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-full {
    width: 100%;
}

.btn-small {
    padding: 8px 12px;
    font-size: 13px;
}

.btn-small svg {
    width: 16px;
    height: 16px;
}

/* === HEADER === */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
}

.header-logo svg {
    width: 28px;
    height: 28px;
    color: var(--primary);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

#header-username {
    font-size: 13px;
    color: var(--text-muted);
}

/* === NAV TABS === */
.nav-tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    flex: 1;
    min-width: 80px;
    position: relative;
}

.nav-tab svg {
    width: 22px;
    height: 22px;
}

.nav-tab.active {
    color: var(--primary);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 3px;
    background: var(--primary);
    border-radius: 3px 3px 0 0;
}

.nav-tab:hover:not(.active) {
    color: var(--text);
    background: var(--bg);
}

/* Hide admin tabs for non-admins */
body:not(.is-admin) .admin-only {
    display: none !important;
}

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.tab-content {
    display: none;
    animation: fadeIn 0.2s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* === EDITOR === */
.editor-container {
    max-width: 100%;
}

.upload-zone {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 60px 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    color: var(--text-muted);
}

.upload-icon svg {
    width: 100%;
    height: 100%;
}

.upload-zone h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.upload-zone p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Editor Workspace */
.editor-workspace {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.editor-workspace.hidden {
    display: none;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    transition: var(--transition);
}

.tool-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.tool-btn.active {
    background: var(--primary);
    color: white;
}

.tool-btn svg {
    width: 20px;
    height: 20px;
}

.toolbar-spacer {
    flex: 1;
}

.editor-main {
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    background: #1a1a2e;
}

.canvas-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 60vh;
    /* Шахматный паттерн для отображения прозрачности */
    background-image: 
        linear-gradient(45deg, #808080 25%, transparent 25%),
        linear-gradient(-45deg, #808080 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #808080 75%),
        linear-gradient(-45deg, transparent 75%, #808080 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #a0a0a0;
    border-radius: 4px;
}

#editor-canvas {
    max-width: 100%;
    max-height: 60vh;
    display: block;
    border-radius: 4px;
    /* Убираем фон canvas чтобы видеть шахматный паттерн под прозрачными областями */
}

/* Stickers Panel */
.stickers-panel {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.stickers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.stickers-header h4 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.stickers-list {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.sticker-item {
    position: relative;
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
    /* Шахматный паттерн для прозрачности */
    background-image: 
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    background-color: #fff;
}

.sticker-item:hover {
    border-color: var(--primary);
    transform: scale(1.05);
}

.sticker-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sticker-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--danger);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
}

body.is-admin .sticker-delete {
    display: flex;
}

/* Canvas Stickers */
.canvas-sticker {
    position: absolute;
    cursor: move;
    user-select: none;
    touch-action: none;
    background: transparent;
}

.canvas-sticker img {
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: transparent;
}

.canvas-sticker .resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: se-resize;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.canvas-sticker .delete-handle {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: var(--danger);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid white;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* === USERS LIST === */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.users-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-avatar svg {
    width: 24px;
    height: 24px;
}

.user-info {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

.user-meta {
    font-size: 13px;
    color: var(--text-muted);
}

.user-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--primary);
    color: white;
    font-weight: 500;
}

.user-badge.admin {
    background: var(--warning);
}

.user-actions {
    display: flex;
    gap: 8px;
}

/* === STATS === */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 16px;
    padding: 12px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
}

.stat-icon svg {
    width: 100%;
    height: 100%;
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-muted);
}

/* === PROFILE === */
.profile-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    max-width: 400px;
    margin: 0 auto;
    box-shadow: var(--shadow);
}

.profile-avatar {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    padding: 20px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
}

.profile-avatar svg {
    width: 100%;
    height: 100%;
}

.profile-card h2 {
    font-size: 24px;
    margin-bottom: 8px;
}

.profile-role {
    display: inline-block;
    padding: 4px 16px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary);
    margin-bottom: 24px;
}

.profile-role.admin {
    background: #fef3c7;
    color: #d97706;
}

.profile-stats {
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.profile-stat-value {
    display: block;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

.profile-stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* === MODAL === */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg);
    color: var(--text);
}

.modal-content form {
    padding: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* === TOAST === */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: white;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

@keyframes slideIn {
    from { 
        opacity: 0; 
        transform: translateX(100%);
    }
    to { 
        opacity: 1; 
        transform: translateX(0);
    }
}

/* === CROP OVERLAY === */
.crop-overlay {
    position: absolute;
    border: 2px dashed white;
    background: rgba(255,255,255,0.1);
    cursor: move;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
}

.crop-overlay.hidden {
    display: none;
}

.crop-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: white;
    border: 2px solid var(--primary);
    border-radius: 50%;
}

.crop-handle.nw { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle.ne { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle.sw { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle.se { bottom: -6px; right: -6px; cursor: se-resize; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .login-container {
        padding: 30px 24px;
    }
    
    .header {
        padding: 10px 16px;
    }
    
    .header-logo span {
        display: none;
    }
    
    #header-username {
        display: none;
    }
    
    .nav-tab {
        padding: 10px 12px;
    }
    
    .nav-tab span {
        font-size: 10px;
    }
    
    .main-content {
        padding: 16px;
    }
    
    .upload-zone {
        padding: 40px 20px;
    }
    
    .upload-icon {
        width: 48px;
        height: 48px;
    }
    
    .editor-main {
        padding: 12px;
        min-height: 300px;
    }
    
    .stickers-panel {
        padding: 12px;
    }
    
    .sticker-item {
        width: 50px;
        height: 50px;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .user-card {
        flex-wrap: wrap;
    }
    
    .user-actions {
        width: 100%;
        margin-top: 8px;
    }
    
    .user-actions .btn {
        flex: 1;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .profile-card {
        padding: 24px;
    }
    
    #toast-container {
        left: 20px;
        right: 20px;
        bottom: 80px;
    }
    
    .toast {
        text-align: center;
    }
}

@media (max-width: 480px) {
    .btn {
        padding: 10px 16px;
        font-size: 13px;
    }
    
    .editor-toolbar {
        flex-wrap: wrap;
        gap: 6px;
    }
    
    .tool-btn {
        width: 36px;
        height: 36px;
    }
    
    .toolbar-spacer {
        order: 99;
        flex-basis: 100%;
        height: 0;
    }
    
    #btn-save {
        flex: 1;
    }
}

/* === UTILITY === */
.hidden {
    display: none !important;
}

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
