/* CSS Reset & Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --success-hover: #059669;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --border-color: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --radius: 12px;
    --radius-sm: 8px;
    --transition: 0.2s ease;
}

html {
    font-size: 16px;
}

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

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--surface) 0%, var(--background) 100%);
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-icon {
    width: 2.5rem;
    height: 2.5rem;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

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

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* Upload Section */
.upload-section {
    max-width: 600px;
    margin: 2rem auto;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--surface);
}

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

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.upload-icon {
    width: 4rem;
    height: 4rem;
    color: var(--primary-color);
}

.upload-content h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.upload-content p {
    color: var(--text-secondary);
}

.supported-formats {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--background);
    padding: 0.5rem 1rem;
    border-radius: 2rem;
    margin-top: 0.5rem;
}

/* Editor Section */
.editor-section {
    display: grid;
    grid-template-columns: 280px 1fr 200px;
    gap: 1.5rem;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Panels */
.controls-panel,
.actions-panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.controls-panel h3,
.actions-panel h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Control Groups */
.control-group {
    margin-bottom: 1.25rem;
}

.control-group label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.control-group label span {
    color: var(--primary-color);
    font-weight: 600;
}

.control-group select,
.control-group input[type="range"] {
    width: 100%;
}

select {
    padding: 0.625rem 0.875rem;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color var(--transition);
}

select:hover,
select:focus {
    border-color: var(--primary-color);
    outline: none;
}

input[type="range"] {
    -webkit-appearance: none;
    height: 6px;
    background: var(--background);
    border-radius: 3px;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.button-group.vertical {
    flex-direction: column;
    margin-top: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.btn svg {
    width: 1.125rem;
    height: 1.125rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--surface-hover);
    color: var(--text-primary);
}

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

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

.btn-success:hover {
    background: var(--success-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    background: var(--surface-hover);
    border-color: var(--text-muted);
}

/* Preview Container */
.preview-container {
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.preview-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.625rem 1.25rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.tab-btn.active {
    color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
}

.preview-area {
    flex: 1;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    position: relative;
    overflow: hidden;
}

.preview-pane {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.preview-pane canvas,
.preview-pane #svgContainer {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#svgContainer svg,
#compareSvgContainer svg {
    max-width: 100%;
    max-height: 100%;
    background: white;
    border-radius: var(--radius-sm);
}

/* Compare View */
.compare-view {
    padding: 0;
}

.compare-slider {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.compare-original,
.compare-vector {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.compare-original {
    z-index: 1;
    clip-path: inset(0 50% 0 0);
}

.compare-vector {
    z-index: 0;
}

.compare-original canvas,
.compare-vector > div {
    max-width: 100%;
    max-height: 100%;
}

.slider-handle {
    position: absolute;
    top: 0;
    left: 50%;
    width: 4px;
    height: 100%;
    background: var(--primary-color);
    cursor: ew-resize;
    z-index: 10;
    transform: translateX(-50%);
}

.handle-line {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
}

.handle-line::before,
.handle-line::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border: 5px solid transparent;
}

.handle-line::before {
    left: 4px;
    border-right-color: white;
}

.handle-line::after {
    right: 4px;
    border-left-color: white;
}

.preview-info {
    display: flex;
    justify-content: center;
    gap: 2rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    text-align: center;
}

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

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

.loading-spinner p {
    color: var(--text-secondary);
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--surface);
}

.footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: color var(--transition);
}

.footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .editor-section {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        order: 1;
    }

    .preview-container {
        order: 0;
    }

    .actions-panel {
        order: 2;
    }

    .button-group.vertical {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .button-group.vertical .btn {
        flex: 1;
        min-width: 140px;
    }
}

@media (max-width: 640px) {
    html {
        font-size: 14px;
    }

    .header {
        padding: 1.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    .main-content {
        padding: 1rem;
    }

    .upload-area {
        padding: 2rem 1rem;
    }

    .upload-icon {
        width: 3rem;
        height: 3rem;
    }

    .preview-area {
        min-height: 300px;
    }

    .preview-info {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group.vertical .btn {
        min-width: 100%;
    }

    .controls-panel,
    .actions-panel {
        padding: 1rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles */
button:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Utility classes */
[hidden] {
    display: none !important;
}
