/* Modern CSS Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* CSS Variables for consistent theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #5855eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

/* Dark theme variables */
[data-theme="dark"] {
    --primary-color: #818cf8;
    --primary-hover: #6366f1;
    --secondary-color: #94a3b8;
    --success-color: #34d399;
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Header */
.app-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
    color: var(--text-primary);
}

/* Main Layout */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 300px 1fr 300px;
    gap: 2rem;
    min-height: calc(100vh - 100px);
}

/* Sidebars */
.sidebar {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    height: fit-content;
    position: sticky;
    top: 120px;
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.panel-header i {
    color: var(--primary-color);
    font-size: 1.125rem;
}

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Upload Section */
.upload-section {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.file-upload {
    position: relative;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.upload-label:hover {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

.upload-label i {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.upload-label span {
    font-weight: 500;
    color: var(--text-primary);
}

.upload-label small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Field Selection */
.field-selection {
    border-top: 1px solid var(--border);
}

.field-select {
    margin: 1.5rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    width: calc(100% - 3rem);
    background: var(--surface);
    color: var(--text-primary);
}

.field-checkboxes {
    padding: 0 1.5rem 1.5rem;
    max-height: 200px;
    overflow-y: auto;
}

.field-checkboxes label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.field-checkboxes input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary-color);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
}

.canvas-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    height: fit-content;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.canvas-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.canvas-wrapper {
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 400px;
    position: relative;
}

#preview {
    max-width: 100%;
    max-height: 600px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    cursor: grab;
}

#preview:active {
    cursor: grabbing;
}

.canvas-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    color: var(--text-muted);
    text-align: center;
}

.canvas-placeholder i {
    font-size: 3rem;
    opacity: 0.5;
}

/* Style Controls */
.style-controls {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.control-group label i {
    color: var(--primary-color);
    width: 1rem;
}

/* Font Controls */
.font-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.font-search, .font-select {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
}

.font-search:focus, .font-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgb(99 102 241 / 0.1);
}

.font-search::placeholder {
    color: var(--text-muted);
}

/* Size Control */
.size-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.size-slider {
    flex: 1;
    height: 0.5rem;
    border-radius: 0.25rem;
    background: var(--border);
    outline: none;
    accent-color: var(--primary-color);
}

.size-input {
    width: 4rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
}

/* Alignment Buttons */
.align-buttons {
    display: flex;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.align-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    border-right: 1px solid var(--border);
}

.align-btn:last-child {
    border-right: none;
}

.align-btn:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.align-btn.active {
    background: var(--primary-color);
    color: white;
}

/* Color Control */
.color-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-picker {
    width: 3rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    background: none;
}

.color-value {
    font-family: 'Courier New', monospace;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Position Controls */
.position-controls {
    border-top: 1px solid var(--border);
    padding: 1.5rem;
}

.movement-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 1rem;
    max-width: 150px;
    margin-left: auto;
    margin-right: auto;
}

.move-btn, .reset-btn {
    width: 2.5rem;
    height: 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.move-btn:hover, .reset-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.move-btn:nth-child(1) { grid-column: 2; grid-row: 1; }
.move-center { grid-column: 1 / -1; grid-row: 2; display: flex; gap: 0.5rem; }
.move-btn:nth-child(4) { grid-column: 2; grid-row: 3; }

.reset-btn {
    background: var(--warning-color);
    color: white;
    border-color: var(--warning-color);
}

.reset-btn:hover {
    background: #d97706;
    border-color: #d97706;
}

.precision-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.precision-controls label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.step-select {
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .app-container {
        grid-template-columns: 280px 1fr 280px;
        gap: 1.5rem;
        padding: 1.5rem;
    }
}

@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .sidebar {
        position: static;
    }
    
    .header-content {
        padding: 0 1.5rem;
    }
    
    .logo h1 {
        font-size: 1.25rem;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
    }
    
    .header-content {
        padding: 0 1rem;
        flex-direction: column;
        gap: 1rem;
    }
    
    .header-actions {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .canvas-wrapper {
        padding: 1rem;
    }
    
    .movement-grid {
        max-width: 120px;
    }
    
    .move-btn, .reset-btn {
        width: 2rem;
        height: 2rem;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }
    
    .theme-dropdown {
        right: auto;
        left: 50%;
        transform: translateX(-50%) translateY(-10px);
    }
    
    .theme-dropdown.show {
        transform: translateX(-50%) translateY(0);
    }
}

/* Loading and Success States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.success {
    border-color: var(--success-color) !important;
    background: rgb(16 185 129 / 0.05) !important;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* Patch Notes Modal */
.patch-notes-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.patch-notes-overlay.show {
    opacity: 1;
    visibility: visible;
}

.patch-notes-modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.patch-notes-overlay.show .patch-notes-modal {
    transform: translateY(0) scale(1);
}

.patch-notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
}

.patch-notes-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.patch-notes-title i {
    font-size: 1.5rem;
    color: #fbbf24;
}

.patch-notes-title h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.version-badge {
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 500;
    backdrop-filter: blur(10px);
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius);
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.patch-notes-content {
    padding: 2rem;
    max-height: 50vh;
    overflow-y: auto;
}

.update-section {
    margin-bottom: 2rem;
}

.update-section:last-child {
    margin-bottom: 0;
}

.update-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.update-header i {
    color: var(--primary-color);
    font-size: 1.125rem;
}

.update-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.update-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.update-list li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
    color: var(--text-secondary);
    line-height: 1.5;
    font-size: 0.875rem;
}

.update-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
    font-size: 1.2rem;
}

.update-list li strong {
    color: var(--text-primary);
    font-weight: 600;
}

.patch-notes-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border);
    background: var(--surface-hover);
}

.dont-show-again {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.dont-show-again input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary-color);
}

.patch-notes-btn {
    position: relative;
}

.patch-notes-btn::after {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 8px;
    height: 8px;
    background: var(--warning-color);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.patch-notes-btn.seen::after {
    display: none;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7);
    }
    
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(245, 158, 11, 0);
    }
    
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
    }
}

/* Mobile responsiveness for patch notes */
@media (max-width: 768px) {
    .patch-notes-modal {
        width: 95%;
        max-height: 90vh;
    }
    
    .patch-notes-header {
        padding: 1rem 1.5rem;
    }
    
    .patch-notes-title h2 {
        font-size: 1.125rem;
    }
    
    .patch-notes-content {
        padding: 1.5rem;
        max-height: 60vh;
    }
    
    .patch-notes-footer {
        padding: 1rem 1.5rem;
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .patch-notes-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Theme Switcher */
.theme-switcher {
    position: relative;
}

.theme-btn {
    background: var(--surface-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
}

.theme-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.theme-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 0.5rem;
    min-width: 120px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.theme-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.875rem;
    transition: all 0.2s ease;
}

.theme-option:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.theme-option.active {
    background: var(--primary-color);
    color: white;
}

.theme-option i {
    width: 1rem;
    text-align: center;
}

/* Footer */
.app-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 4rem;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-left p,
.footer-right p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer-right a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.footer-right a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Form Elements Dark Mode Fix */
input, select, textarea, option {
    color: var(--text-primary) !important;
    background: var(--surface) !important;
}

input::placeholder {
    color: var(--text-muted) !important;
}

/* Ensure select options have proper colors */
select option {
    background: var(--surface) !important;
    color: var(--text-primary) !important;
}

/* Canvas placeholder text */
.canvas-placeholder p {
    color: var(--text-muted);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--surface-hover);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}