/* =========================================
   Variables de Disseny i Colors
   ========================================= */
:root {
    --bg-color: #f3f4f6;
    --surface-color: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --border-color: #d1d5db;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #e5e7eb;
    --secondary-hover: #d1d5db;
    --danger-color: #dc2626;
    --focus-ring: rgba(37, 99, 235, 0.4);
    --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);
    --radius: 8px;
    --font-family: 'Inter', -apple-system, sans-serif;
}

/* =========================================
   Resets i Elements Base
   ========================================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* =========================================
   Estructura Principal (Split Screen)
   ========================================= */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.form-section {
    width: 40%;
    min-width: 450px;
    height: 100%;
    background-color: var(--surface-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    padding: 2rem;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.form-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--secondary-color);
}

.form-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

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

fieldset {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    background-color: #f9fafb;
}

legend {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--primary-color);
    background-color: var(--surface-color);
    padding: 0 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.form-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.half-width {
    flex: 1;
}

.third-width {
    flex: 1;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: var(--font-family);
    font-size: 0.95rem;
    background-color: var(--surface-color);
    transition: all 0.2s ease;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    background: var(--surface-color);
    padding-bottom: 1rem;
}

button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-family: var(--font-family);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

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

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

/* =========================================
   Secció Previsualització
   ========================================= */
.preview-section {
    flex: 1;
    background-color: var(--bg-color);
    display: flex;
    justify-content: center;
    padding: 2rem;
    overflow-y: auto;
}

.a4-document {
    background: white;
    width: 210mm;
    max-width: 210mm;
    min-height: 297mm;
    padding: 14mm 18mm;
    box-shadow: var(--shadow-lg);
    font-family: 'Times New Roman', Times, serif;
    font-size: 11.5pt;
    line-height: 1.3;
    color: #000;
    flex-shrink: 0;
    box-sizing: border-box;
}

.document-title {
    text-align: center;
    font-size: 14pt;
    font-weight: bold;
    margin-bottom: 0.8rem;
    text-transform: uppercase;
}

.a4-document h3 {
    font-size: 12pt;
    font-weight: bold;
    margin-top: 0.8rem;
    margin-bottom: 0.2rem;
}

.a4-document p {
    margin-bottom: 0.3rem;
    text-align: justify;
    display: block;
}

.a4-document ul {
    margin-left: 1.5rem;
    margin-bottom: 0.4rem;
}

.a4-document li {
    margin-bottom: 0.1rem;
}

span[class^="ph-"],
strong[class^="ph-"] {
    color: var(--primary-color);
    font-family: Helvetica, Arial, sans-serif;
    border-bottom: 1px dotted var(--primary-color);
}

.signatures {
    display: flex;
    justify-content: space-between;
    margin-top: 1.2rem;
}

.signature-box {
    width: 45%;
}

.signature-box.right {
    text-align: right;
}

/* =========================================
   Contenidors exportació PDF (Ocults)
   ========================================= */
#pdf-paper {
    display: none;
    /* S'activa només per JS durant la captura */
    position: absolute;
    top: 0;
    left: 0;
    width: 794px;
    /* Fix pixels A4 */
    background: white;
    z-index: -9999;
}

#pdf-clone {
    width: 794px;
    padding: 56px 68px;
    /* Marges exactes */
    box-sizing: border-box;
    font-family: 'Times New Roman', Times, serif;
    font-size: 11.5pt;
    line-height: 1.3;
    color: #000;
}

@media print {

    span[class^="ph-"],
    strong[class^="ph-"] {
        color: #000;
        border-bottom: none;
        font-family: inherit;
    }
}

/* Page Break Controls */
.section {
    page-break-inside: avoid;
    break-inside: avoid;
}

.avoid-break {
    page-break-inside: avoid;
    break-inside: avoid;
}

.force-page-break {
    page-break-before: always;
    break-before: page;
}