/* CSS Variables */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #64748b;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-secondary: #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: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --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-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --transition: all 0.2s ease;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.nav-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

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

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

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

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 16px;
    flex-shrink: 0;
}

.sidebar-section {
    margin-bottom: 24px;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Template Grid */
.template-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.template-card {
    aspect-ratio: 3/4;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
    position: relative;
    background: var(--surface-secondary);
}

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

.template-card.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.template-card .template-preview {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 8px;
    font-size: 0.5rem;
}

.template-card .template-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.625rem;
    text-align: center;
}

/* Import Options */
.import-options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-upload-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface-secondary);
    color: var(--text-primary);
}

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

/* Element Buttons */
.element-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.element-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

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

.element-btn svg {
    color: var(--text-secondary);
}

.element-btn span {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Chart Type Grid */
.chart-type-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chart-type-btn {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

.chart-type-btn:hover {
    border-color: var(--primary-light);
    color: var(--primary);
}

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

/* Color Palette */
.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: var(--transition);
}

.color-swatch:hover {
    transform: scale(1.1);
}

.color-swatch.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--text-primary);
}

.custom-colors {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    align-items: center;
}

.custom-colors label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.custom-colors input[type="color"] {
    width: 100%;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-secondary);
    overflow: hidden;
}

.canvas-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.canvas-control-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

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

.zoom-level {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.canvas {
    width: 800px;
    min-height: 1000px;
    background: white;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius);
    position: relative;
    transform-origin: center center;
    transition: transform 0.2s ease;
}

/* Properties Panel */
.properties-panel {
    width: 280px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
}

.properties-panel.visible {
    display: flex;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.panel-header h3 {
    font-size: 0.875rem;
    font-weight: 600;
}

.close-panel-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.25rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

.close-panel-btn:hover {
    background: var(--surface-secondary);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.no-selection {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    padding: 40px 20px;
}

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

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

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

.footer a:hover {
    text-decoration: underline;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--surface-secondary);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.modal-hint {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.modal-body textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.875rem;
    resize: vertical;
}

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

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

/* Download Options */
.download-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.download-option {
    cursor: pointer;
}

.download-option input {
    display: none;
}

.option-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    transition: var(--transition);
}

.download-option input:checked + .option-card {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.option-card svg {
    color: var(--text-secondary);
}

.option-card strong {
    font-size: 0.875rem;
}

.option-card small {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.size-options {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.size-options select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
}

/* Image Upload */
.image-upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    transition: var(--transition);
}

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

.image-upload-area svg {
    color: var(--text-muted);
    margin-bottom: 12px;
}

.image-upload-area p {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.image-upload-area span {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 12px;
}

.image-url-input {
    margin-top: 20px;
}

.image-url-input label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.image-url-input input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}

/* Text Edit Options */
.text-edit-options .form-group {
    margin-bottom: 16px;
}

.text-edit-options label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.text-edit-options textarea {
    min-height: 100px;
}

.text-edit-options input,
.text-edit-options select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Shape Grid */
.shape-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.shape-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 16px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    color: var(--text-secondary);
}

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

.shape-option span {
    font-size: 0.75rem;
}

/* Icon Grid */
.icon-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 16px;
}

.icon-option {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

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

/* Canvas Elements */
.canvas-element {
    position: absolute;
    cursor: move;
    user-select: none;
}

.canvas-element.selected {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.canvas-element:hover:not(.selected) {
    outline: 2px dashed var(--primary-light);
    outline-offset: 2px;
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary);
    border: 2px solid white;
    border-radius: 50%;
}

.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* Chart Container */
.chart-container {
    width: 100%;
    height: 100%;
    position: relative;
}

/* Template Elements */
.infographic-title {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    padding: 20px;
    color: #1e293b;
}

.infographic-subtitle {
    font-size: 1rem;
    text-align: center;
    color: #64748b;
    margin-top: -10px;
}

.stat-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: var(--radius-lg);
    padding: 24px;
    color: white;
    text-align: center;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.875rem;
    opacity: 0.9;
}

/* Properties Form */
.property-group {
    margin-bottom: 16px;
}

.property-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.property-group input,
.property-group select,
.property-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
}

.property-group input:focus,
.property-group select:focus,
.property-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.property-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.delete-element-btn {
    width: 100%;
    padding: 10px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    margin-top: 20px;
}

.delete-element-btn:hover {
    background: #dc2626;
}

/* Data Table in Properties */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

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

.data-table th {
    background: var(--surface-secondary);
    font-weight: 500;
}

.data-table input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid transparent;
    background: transparent;
    font-size: 0.875rem;
}

.data-table input:focus {
    border-color: var(--primary);
    background: white;
}

.add-row-btn {
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    background: var(--surface-secondary);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.add-row-btn:hover {
    background: var(--border);
}

/* Responsive Design */
@media (max-width: 1200px) {
    .properties-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 200;
        width: 300px;
        box-shadow: var(--shadow-lg);
    }

    .properties-panel.visible::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 300px;
        bottom: 0;
        background: rgba(0, 0, 0, 0.3);
        z-index: -1;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        width: 240px;
    }

    .canvas {
        width: 600px;
        min-height: 750px;
    }
}

@media (max-width: 768px) {
    .header {
        padding: 10px 16px;
    }

    .logo h1 {
        display: none;
    }

    .nav-actions .btn span {
        display: none;
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        overflow-x: auto;
    }

    .sidebar-section {
        min-width: max-content;
    }

    .template-grid {
        display: flex;
        gap: 8px;
    }

    .template-card {
        width: 80px;
        min-width: 80px;
    }

    .canvas-container {
        padding: 20px;
    }

    .canvas {
        width: 100%;
        min-width: 300px;
        max-width: 100%;
        min-height: 500px;
    }

    .modal-content {
        max-width: 100%;
        margin: 10px;
    }

    .download-options {
        grid-template-columns: 1fr;
    }

    .shape-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .header {
        padding: 8px 12px;
    }

    .btn {
        padding: 8px 12px;
    }

    .element-buttons {
        grid-template-columns: repeat(4, 1fr);
    }

    .element-btn {
        padding: 8px 4px;
    }

    .element-btn span {
        display: none;
    }
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

.modal.visible .modal-content {
    animation: slideIn 0.2s ease;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    background: var(--text-primary);
    color: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.2s ease;
    max-width: 300px;
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
