:root {
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --success-color: #10b981;
    --success-hover: #059669;
    --danger-color: #ef4444;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --transition-fast: 0.2s ease;
}

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

body {
    font-family: 'Alexandria', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    background: linear-gradient(135deg, var(--primary-color), #3b82f6);
    padding: 1.2rem 2rem;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: baseline;
    gap: 1rem;
    z-index: 10;
}

.logo {
    font-size: 1.75rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 300;
}

/* Main Container */
.app-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 350px;
    background-color: var(--surface-color);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: opacity var(--transition-fast);
    z-index: 5;
}

.sidebar[aria-disabled="true"] {
    opacity: 0.5;
    pointer-events: none;
}

.sidebar-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-section h2 {
    font-size: 1.125rem;
    margin-bottom: 1rem;
    color: var(--text-main);
}

.fields-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--surface-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.75rem 1rem;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

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

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

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

.btn.success:not(:disabled):hover {
    background-color: var(--success-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn.outline {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.btn.outline:not(:disabled):hover {
    background-color: var(--border-color);
    color: var(--text-main);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    padding: 0.25rem;
}

.btn-icon:hover {
    color: var(--danger-color);
    background-color: rgba(239, 68, 68, 0.1);
}

/* Numbering Cards */
.numbering-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1rem;
    box-shadow: var(--shadow-sm);
    animation: slideIn 0.3s ease-out;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px dashed var(--border-color);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.form-row {
    display: flex;
    gap: 0.75rem;
}

.form-row .form-group {
    flex: 1;
}

label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color var(--transition-fast);
    background-color: var(--surface-color);
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.checkbox-group input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

.checkbox-group label {
    cursor: pointer;
}

/* Alignment Group */
.alignment-group {
    display: flex;
    gap: 0.25rem;
    background-color: var(--bg-color);
    padding: 0.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.align-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

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

.align-btn.active {
    background-color: var(--surface-color);
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

/* Settings Divider */
.divider {
    border: 0;
    border-top: 1px dashed var(--border-color);
    margin: 1rem 0 0.5rem;
}

.settings-title {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

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

input[type="color"] {
    -webkit-appearance: none;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
    background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Workspace */
.workspace {
    flex: 1;
    background-color: var(--bg-color);
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Dropzone */
.dropzone {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.dropzone-content {
    border: 2px dashed var(--primary-color);
    border-radius: var(--radius-lg);
    background-color: rgba(99, 102, 241, 0.02);
    width: 100%;
    max-width: 600px;
    height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.dropzone-content:hover, .dropzone.drag-over .dropzone-content {
    background-color: rgba(99, 102, 241, 0.08);
    border-color: var(--primary-hover);
    transform: scale(1.02);
}

.dropzone-content svg {
    color: var(--primary-color);
}

/* Preview Area */
.preview-area {
    flex: 1;
    overflow: auto;
    padding: 2rem;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background-color: #cbd5e1; /* darker background for canvas area */
}

.preview-area.hidden {
    display: none;
}

.canvas-wrapper {
    position: relative;
    box-shadow: var(--shadow-lg);
    background-color: white;
}

canvas {
    display: block;
}

.overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through except on elements */
}

/* Draggable Elements */
.draggable-number {
    position: absolute;
    border: 2px solid var(--primary-color);
    border-radius: 4px;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.5rem;
    font-family: 'Cairo', sans-serif;
    cursor: grab;
    user-select: none;
    pointer-events: auto;
    transform: translate(-50%, -50%); /* Center on click */
    min-width: max-content;
    direction: ltr; /* numbers look better ltr usually */
}

.draggable-number:active {
    cursor: grabbing;
    background: white;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Loading Overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

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

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

/* Footer */
.app-footer {
    text-align: center;
    padding: 0.75rem;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    z-index: 10;
}

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

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

/* Advanced Settings Accordion */
.advanced-settings {
    margin-top: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.advanced-settings summary {
    background-color: var(--bg-color);
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    outline: none;
    color: var(--text-muted);
}

.advanced-settings summary:hover {
    background-color: #e2e8f0;
}

.advanced-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--surface-color);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal-content {
    background-color: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.2s ease-out;
}

.modal-title {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.25rem;
    color: var(--text-main);
}

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

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    background-color: var(--bg-color);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

.info-box {
    background-color: rgba(99, 102, 241, 0.05);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 1rem;
    border-radius: var(--radius-md);
    color: var(--primary-color);
    font-size: 0.95rem;
}

.radio-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.radio-group input[type="radio"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.hint {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}
