:root {
    --primary: #2e3fb1;
    --primary-dark: #2530b4;
    --bg-app: #f1f5f9;
    --bg-sidebar: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --sidebar-width: 400px;
}

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

body { font-family: 'Inter', sans-serif; }

.main .app-container {
    height: auto;
    min-height: 70vh;
    border-radius: 8px;
    overflow: hidden;
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
}

.main .editor-sidebar {
    height: auto;
    min-height: 70vh;
}

.editor-sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05);
}

.sidebar-header {
    flex-shrink: 0;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 { font-size: 1.25rem; font-weight: 700; color: var(--text-main); }

.scrollable-form {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.editor-section { margin-bottom: 12px; }

.editor-section label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 4px;
    color: var(--text-muted);
}

.editor-section input,
.editor-section textarea,
.editor-section select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: inherit;
}

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

.editor-section textarea { resize: vertical; min-height: 100px; }

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

.full-width { grid-column: span 2; }

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: #10b981; color: white; }

.preview-stage {
    background: #525659;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 30px;
    overflow-y: auto;
}

.preview-toolbar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(82, 86, 89, 0.9);
    padding: 10px 20px;
    border-radius: 20px;
    margin-bottom: 20px;
    display: flex;
    gap: 20px;
    align-items: center;
    backdrop-filter: blur(5px);
}

.preview-label { color: white; font-size: 0.9rem; opacity: 0.8; }

.letter-paper {
    background: white;
    width: 210mm;
    min-height: 297mm;
    padding: 20mm;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    color: var(--text-main);
}

.letter-header {
    margin-bottom: 24px;
}

.letter-date {
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.letter-header-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    align-items: start;
}

.letter-sender-block,
.letter-recipient-block {
    font-size: 0.9rem;
    line-height: 1.5;
}

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

.letter-sender,
.letter-recipient {
    white-space: pre-line;
    color: #334155;
}


.letter-subject {
    font-weight: 600;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.letter-body {
    font-size: 0.95rem;
    line-height: 1.6;
    white-space: pre-line;
    margin-bottom: 16px;
}

.letter-footer {
    margin-top: 32px;
    font-size: 0.9rem;
    white-space: pre-line;
}

.letter-rodo {
    font-size: 0.65rem;
    color: #94a3b8;
    margin-top: 24px;
    border-top: 1px solid #e2e8f0;
    padding-top: 10px;
}

.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    z-index: 9999;
}

.loader-overlay.hidden {
    display: none !important;
}

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

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

.pdf-mode { margin: 0 !important; width: 210mm !important; min-height: 297mm !important; box-shadow: none !important; }

@media (max-width: 1000px) {
    .main .app-container { grid-template-columns: 1fr; }
    .editor-sidebar { border-right: none; border-bottom: 1px solid var(--border-color); }
    .letter-paper { width: 100%; padding: 16px; }
}
