:root {
    --primary-color: #d0112b;
    /* Red from ITA logo */
    --primary-hover: #b00d23;
    --bg-main: #f1f5f9;
    --bg-sidebar: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --input-bg: #f8fafc;
    --table-header-bg: #e2e8f0;
    --table-border: #cbd5e1;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --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 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text-main);
    background-color: var(--bg-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Sidebar Form */
.sidebar-form {
    width: 450px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    z-index: 10;
}

.form-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
    background: #ffffff;
}

.form-header h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-header h1::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background-color: var(--primary-color);
    border-radius: 50%;
}

.form-header p {
    font-size: 13px;
    color: var(--text-muted);
}

#reportForm {
    flex-grow: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 36px;
}

#reportForm::-webkit-scrollbar {
    width: 6px;
}

#reportForm::-webkit-scrollbar-track {
    background: transparent;
}

#reportForm::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.form-section h2 {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary-color);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--input-bg);
}

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

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

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background-color: var(--input-bg);
    transition: all 0.2s;
    color: var(--text-main);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: #94a3b8;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(208, 17, 43, 0.1);
}

.repuestos-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.repuesto-row {
    display: flex;
    gap: 8px;
    align-items: center;
    background: #ffffff;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: box-shadow 0.2s;
}

.repuesto-row:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(208, 17, 43, 0.1);
}

.repuesto-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    background-color: var(--input-bg);
    transition: all 0.2s;
}

.repuesto-row input:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #ffffff;
}

.btn-icon {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: #fee2e2;
}

.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px;
    background-color: white;
    border: 1px dashed #94a3b8;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--text-main);
    color: var(--text-main);
    background-color: var(--input-bg);
}

.totals-summary {
    background-color: var(--input-bg);
    border-radius: 8px;
    padding: 16px;
    margin-top: 16px;
    border: 1px solid var(--border-color);
}

.summary-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.summary-line:last-child {
    margin-bottom: 0;
}

.total-bold {
    font-weight: 700;
    font-size: 18px;
    padding-top: 12px;
    margin-top: 4px;
    border-top: 1px dashed var(--border-color);
    color: var(--text-main);
}

.form-actions {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    background-color: #ffffff;
    z-index: 10;
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(208, 17, 43, 0.2), 0 2px 4px -1px rgba(208, 17, 43, 0.1);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(208, 17, 43, 0.3), 0 4px 6px -2px rgba(208, 17, 43, 0.1);
}

.btn-primary:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(208, 17, 43, 0.2);
}

/* Preview Area */
.preview-area {
    flex-grow: 1;
    position: relative;
    background-color: var(--bg-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 40px;
    background-image: radial-gradient(#cbd5e1 1px, transparent 0);
    background-size: 20px 20px;
}

.zoom-controls {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    padding: 10px 20px;
    border-radius: 30px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 24px;
    transition: box-shadow 0.2s;
}

.zoom-controls:hover {
    box-shadow: var(--shadow-md);
}

.zoom-controls button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.1s;
}

.zoom-controls button:hover {
    color: var(--primary-color);
    transform: scale(1.1);
}

.zoom-controls span {
    font-size: 14px;
    font-weight: 600;
    min-width: 48px;
    text-align: center;
    color: var(--text-main);
}

.a4-container {
    transform-origin: top center;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* A4 Document Styling */
.a4-document {
    width: 794px;
    /* A4 width at 96 DPI */
    height: 1121px;
    /* Rigid A4 height (minus fractionals) to strictly prevent blank page */
    max-height: 1121px; 
    background: white;
    box-shadow: var(--shadow-lg);
    padding: 25px 35px;
    /* Reducido de 35px 45px para ganar área útil */
    font-family: 'Arial', sans-serif;
    color: #000;
    box-sizing: border-box;
    position: relative;
    /* For absolutely positioned pseudo-element */
    z-index: 1;
    /* Keep content above background */
    overflow: hidden;
}

.a4-document::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('../assets/fondo.jpg');
    /* Update with actual path if needed */
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.12;
    /* High transparency effect */
    filter: blur(1px);
    /* Efecto difuminado */
    z-index: -1;
    /* Place behind PDF content */
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 3px solid var(--primary-color);
    padding-bottom: 8px;
    /* Reducido */
    margin-bottom: 15px;
    /* Reducido de 24px */
}

.doc-title h2 {
    font-size: 24px;
    /* Reducido de 26px */
    font-weight: 800;
    margin: 0;
    text-transform: uppercase;
    color: #1e293b;
    letter-spacing: 1px;
}

.real-logo {
    max-height: 70px;
    /* Reducido de 80px */
    object-fit: contain;
}

.doc-section {
    margin-bottom: 12px;
    /* Reducido de 20px */
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px 14px;
    /* Reducido de 16px */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.split-row {
    display: flex;
    gap: 15px;
    width: 100%;
}

.half-section {
    flex: 1;
    width: 50%;
}

.section-title {
    text-align: left;
    font-weight: 700;
    font-size: 12px;
    /* Reducido de 13px */
    color: #0f172a;
    padding: 0 0 4px 0;
    /* Reducido */
    margin-bottom: 8px;
    /* Reducido de 12px */
    border-bottom: 2px solid #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-title-val {
    margin-bottom: 6px;
    font-size: 11px;
}

.doc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 8px;
}

.doc-table th,
.doc-table td {
    padding: 5px 8px;
    /* Reducido padding de celdas */
    vertical-align: middle;
    border-bottom: 1px solid #e2e8f0;
}

.doc-table th {
    color: #64748b;
    text-transform: uppercase;
    text-align: left;
    font-weight: 600;
    font-size: 9px;
    /* Reducido de 10px */
    letter-spacing: 0.5px;
}

/* Override center aligns for cleaner list */
.center-th,
.center-td {
    text-align: left !important;
}

/* specific right align for values */
#table_repuestos th:nth-child(3),
#table_repuestos td:nth-child(3),
.table-valorization td {
    text-align: right !important;
}

.doc-table td {
    background-color: transparent;
    color: #0f172a;
}

.textarea-cell {
    min-height: 30px;
    /* Reducido */
    white-space: pre-wrap;
    vertical-align: top !important;
    text-align: left !important;
    padding-top: 6px;
    /* Reducido */
    color: #334155;
    border-bottom: none;
}

.min-height-cell {
    height: 50px;
    /* Reducido */
}

.doc-table-striped th {
    text-align: left;
    border-bottom: 2px solid #cbd5e1;
}

.doc-table-striped td {
    text-align: left;
}

.observation-section {
    margin-bottom: 15px;
    /* Reducido */
}

.observation-box {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background-color: transparent;
    padding: 8px 8px 0 8px;
    /* Reducido */
    font-size: 11px;
    /* Reducido de 12px */
    min-height: 60px;
    /* Reducido de 100px */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    color: #334155;
    border: none;
}

.nota-final {
    text-align: center;
    font-weight: 600;
    margin-top: 10px;
    /* Reducido de 16px */
    color: #1e293b;
    font-style: italic;
    font-size: 10px;
    /* Reducido */
}

.doc-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: auto;
    /* Empuja el footer al final si hay espacio */
    gap: 20px;
}

.valorization-section {
    flex: 1;
    max-width: 380px;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 12px 16px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.table-valorization {
    margin-bottom: 0;
}

.table-valorization th {
    text-align: right !important;
    padding-right: 15px;
    padding-top: 5px;
    padding-bottom: 5px;
}

.table-valorization td {
    font-weight: 600;
    padding-top: 5px;
    padding-bottom: 5px;
}

.total-row {
    font-size: 15px;
    color: #0f172a !important;
    /* Neutral dark instead of red */
}

.total-row th,
.total-row td {
    border-top: 2px solid #64748b;
    border-bottom: none;
    padding-top: 8px;
}

.signature-section {
    flex: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    padding-bottom: 10px;
}

.signature-line {
    width: 220px;
    border-bottom: 1px solid #000;
    margin-bottom: 8px;
    position: relative;
    z-index: 1;
    /* Para que la línea pase por encima de los bordes blancos del timbre si se solapan */
}

.signature-stamp {
    width: 200px;
    margin-bottom: 1px;
    /* Aumentar margen negativo para subir más la imagen */
    margin-top: -15px;
    /* Subirla ligeramente respecto a los elementos de arriba si es necesario */
    position: relative;
    z-index: 0;
    opacity: 0.95;
}

.signature-name {
    font-weight: 700;
    font-size: 14px;
    color: #0f172a;
    min-height: 18px;
    /* Maintain height if empty */
}

.signature-role {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
}

/* Print Specific overrides when exporting to PDF */
@media print {
    body {
        background: white;
    }

    .sidebar-form,
    .zoom-controls {
        display: none !important;
    }

    .preview-area {
        padding: 0;
        margin: 0;
        overflow: visible;
        background: none;
    }

    .a4-document {
        box-shadow: none;
        padding: 0;
        width: 100%;
        min-height: 100vh;
    }
}