/* ==========================================================================
   MANDARINO DOCUMENT ENGINE — UI Styles
   Questo file gestisce SOLO la UI dell'editor (sidebar, preview-pane, buttons).
   NON viene passato al Previewer Paged.js — serve solo per il layout a schermo.
   I componenti print sono in print.css (caricato separatamente via Blob).
   ========================================================================== */

:root {
    /* ── Token allineati al Design System ── */
    --color-dark: #181A1B;
    --color-light: #F4F4F5;
    --color-primary: #FF3E00;
    --color-muted: #6B7280;
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

body, html {
    font-family: var(--font-sans);
    color: var(--color-dark);
    margin: 0;
    padding: 0;
    background-color: var(--color-light);
    height: 100%;
}

/* ==========================================================================
   SIDEBAR & BUILDER STYLES
   ========================================================================== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 450px;
    background: #fff;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    padding: 20px;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
    z-index: 100;
    box-sizing: border-box;
}

.preview-pane {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 450px;
    background: #e5e5e5;
    overflow-y: auto;
    padding: 40px;
    box-sizing: border-box;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.header h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; }
.header p { margin: 5px 0 0; color: var(--color-muted); font-size: 14px; }

button, .btn-outline {
    background: var(--color-dark);
    color: white;
    border: 1px solid var(--color-dark);
    padding: 10px 20px;
    font-family: var(--font-mono);
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-block;
}

.btn-outline {
    background: transparent;
    color: var(--color-dark);
}

.btn-outline:hover {
    background: var(--color-dark);
    color: white;
}

/* Builder Components */
.builder-block {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.block-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-family: var(--font-mono);
    cursor: pointer;
    user-select: none;
}

.is-active .block-header {
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 10px;
}

.block-header:hover {
    color: var(--color-primary);
}

.block-actions button {
    padding: 4px 10px;
    margin-left: 5px;
    font-size: 14px;
}

.btn-danger {
    background: #dc3545;
    border-color: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
}

/* Render Loading Overlay */
.render-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(229, 229, 229, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 50;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--color-muted);
    letter-spacing: 0.05em;
}

.render-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid #ddd;
    border-top-color: var(--color-dark);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.block-body label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    margin-top: 15px;
    color: var(--color-muted);
}

.block-body label:first-child {
    margin-top: 0;
}

.block-body input[type="text"],
.block-body input[type="number"],
.block-body textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: var(--font-sans);
    font-size: 14px;
    box-sizing: border-box;
    background: #fafafa;
}

.add-block-panel {
    background: #fff;
    padding: 30px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    text-align: center;
}

/* ==========================================================================
   PAGED.JS PREVIEW (screen only)
   ========================================================================== */
.pagedjs_pages {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
}

.pagedjs_page {
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* Elementi interattivi nell'Anteprima */
.pagedjs_pages .paged-block-wrapper {
    position: relative;
    cursor: pointer;
    transition: outline 0.2s, background-color 0.2s;
}

.pagedjs_pages .paged-block-wrapper:hover {
    outline: 2px dashed #ff9900;
    outline-offset: 4px;
    background-color: rgba(255, 153, 0, 0.02);
}

/* Layout in fase di stampa PDF nativa */
@media print {
    body, html {
        overflow: visible !important;
        height: auto !important;
    }
    .sidebar { display: none !important; }
    .preview-pane {
        left: 0 !important;
        position: relative !important;
        padding: 0 !important;
        background: transparent !important;
        overflow: visible !important;
    }
}
