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

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #141824;
    --bg-tertiary: #1e2433;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: rgba(148, 163, 184, 0.1);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: linear-gradient(135deg, #0a0e1a 0%, #1a1f35 100%);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 2rem;
}

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

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.main-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 2rem;
    align-items: start;
}

.controls-section {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg-tertiary);
    margin-bottom: 2rem;
    position: relative;
    overflow: hidden;
}

.upload-area:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.05);
}

.upload-area.dragover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.upload-content svg {
    color: var(--accent-primary);
    margin-bottom: 1rem;
}

.upload-text {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.upload-hint {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.preview-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    object-fit: contain;
}

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 2rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.input-group label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.input-group input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    transition: all 0.2s ease;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.preset-section {
    margin-bottom: 2rem;
}

.preset-section label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.preset-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.btn-preset {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn-preset:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

.palette-save-section {
    margin-bottom: 2rem;
}

.palette-save-section label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.palette-save-controls,
.palette-load-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.palette-name-input,
.palette-select {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.palette-name-input:focus,
.palette-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.btn-save-palette,
.btn-delete-palette {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn-save-palette:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

.btn-delete-palette:hover:not(:disabled) {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
    transform: translateY(-2px);
}

.btn-delete-palette:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.palette-section {
    margin-bottom: 2rem;
}

.palette-source-section {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.palette-source-section label:first-child {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.palette-source-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.radio-option {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.radio-option:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.05);
}

.radio-option input[type="radio"] {
    cursor: pointer;
}

.radio-option input[type="radio"]:checked+span {
    color: var(--accent-primary);
    font-weight: 600;
}

.radio-option:has(input[type="radio"]:checked) {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

.palette-size-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.palette-size-control label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.palette-size-control input[type="number"] {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.palette-section.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.palette-save-section.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* AI Generation Section */
.ai-generation-section {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ai-header {
    margin-bottom: 10px;
    font-weight: 600;
    color: #333;
}

.ai-controls {
    display: flex;
    gap: 10px;
}

.ai-prompt-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.btn-generate-ai {
    padding: 8px 16px;
    background-color: #8e44ad;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn-generate-ai:hover {
    background-color: #732d91;
}

.btn-generate-ai:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

.palette-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.palette-header label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.btn-add-color {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--accent-primary);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.btn-add-color:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

.palette-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.color-item {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.color-item input[type="color"] {
    width: 100%;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    background: var(--bg-tertiary);
    transition: all 0.2s ease;
}

.color-item input[type="color"]:hover {
    border-color: var(--accent-primary);
    transform: scale(1.05);
}

.btn-remove-color {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 700;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.btn-remove-color:hover:not(:disabled) {
    background: #ef4444;
    color: white;
    transform: scale(1.1);
}

.btn-remove-color:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-generate {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border: none;
    color: white;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.3);
}

.btn-generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(99, 102, 241, 0.4);
}

.btn-generate:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.result-section {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-lg);
}

.editor-header {
    text-align: center;
    margin-bottom: 2rem;
}

.editor-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.editor-header p {
    color: var(--text-secondary);
}

.editor-content {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 2rem;
    margin-bottom: 2rem;
}

.canvas-container {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    max-height: 600px;
}

#gridCanvas {
    cursor: crosshair;
    image-rendering: pixelated;
}

.editor-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.color-selector h3,
.preview-images h4 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.color-palette {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.palette-color {
    width: 100%;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.palette-color:hover {
    transform: scale(1.05);
    border-color: var(--accent-primary);
}

.palette-color.selected {
    border-color: var(--accent-primary);
    border-width: 3px;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.preview-item {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1rem;
    border: 1px solid var(--border-color);
}

.preview-item img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
}

.btn-download {
    width: 100%;
    background: linear-gradient(135deg, #10b981, #059669);
    border: none;
    color: white;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 10px 30px rgba(16, 185, 129, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-download:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(16, 185, 129, 0.4);
}

.loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 14, 26, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 64px;
    height: 64px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loader p {
    margin-top: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

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

    .comparison-view {
        grid-template-columns: 1fr;
    }
}

/* Notifications */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.notification-toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    animation: slideIn 0.3s ease forwards;
    pointer-events: auto;
    backdrop-filter: blur(10px);
}

.notification-toast.success {
    border-left: 4px solid #10b981;
}

.notification-toast.error {
    border-left: 4px solid #ef4444;
}

.notification-toast.info {
    border-left: 4px solid #3b82f6;
}

.notification-icon {
    font-size: 1.25rem;
}

.notification-message {
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

/* Admin Panel Styles */
.admin-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
}

.create-user-form {
    margin-bottom: 2rem;
    padding-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 1rem;
    margin-top: 1rem;
}

.input-field {
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

.input-field:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
}

.data-table td {
    color: var(--text-primary);
}

.role-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.role-badge.role-admin {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.role-badge.role-user {
    background: rgba(59, 130, 246, 0.1);
    color: #3b82f6;
}

.btn-delete {
    padding: 0.5rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid #ef4444;
    border-radius: 6px;
    color: #ef4444;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: #ef4444;
    color: white;
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-block;
}

.btn-secondary:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-primary);
}

/* Project Management Styles */
.projects-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.projects-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.projects-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.project-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
}

.project-card:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.project-card h4 {
    margin: 0 0 0.5rem 0;
    color: var(--text-primary);
}

.project-card .project-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.project-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-load:hover {
    background: var(--accent-secondary);
}

/* Top Menu Styles */
.top-menu {
    display: flex;
    gap: 0;
    align-items: center;
}

.menu-item {
    position: relative;
}

.menu-button {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s;
    border-radius: 0;
}

.menu-button:hover {
    background: var(--bg-tertiary);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 1000;
    margin-top: 0.25rem;
    padding-top: 0.25rem;
}

.dropdown-menu::before {
    content: '';
    position: absolute;
    top: -0.5rem;
    left: 0;
    right: 0;
    height: 0.5rem;
}

.dropdown-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: background 0.2s;
}

.dropdown-menu a:hover {
    background: var(--bg-tertiary);
}

.dropdown-menu a:first-child {
    border-radius: 8px 8px 0 0;
}

.dropdown-menu a:last-child {
    border-radius: 0 0 8px 8px;
}

.dropdown-menu a.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.menu-item:hover .dropdown-menu,
.dropdown-menu:hover {
    display: block;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    margin: 0 0 1.5rem 0;
    color: var(--text-primary);
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.modal-projects-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.modal-project-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-project-item:hover {
    border-color: var(--accent-primary);
    transform: translateX(4px);
}

.modal-project-info h4 {
    margin: 0 0 0.25rem 0;
    color: var(--text-primary);
}

.modal-project-info .project-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}