:root {
    --bg-color: #f3f4f6;
    --paper-color: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #059669;
    --success-hover: #047857;
    --danger: #ef4444;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
}

.app-container {
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

/* Controls section (Left Sidebar) */
.controls {
    flex: 0 0 300px;
    background: var(--paper-color);
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 2rem;
}

.controls h2 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    font-weight: 600;
}

.search-section {
    margin-bottom: 2rem;
}

.search-section label {
    display: block;
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
}

.search-input-group {
    display: flex;
    gap: 0.5rem;
}

.search-input-group input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
}

.btn-primary, .btn-success, .btn-secondary {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
}

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

.btn-success { background: var(--success); color: white; width: 100%; padding: 0.75rem; font-size: 1rem;}
.btn-success:hover { background: var(--success-hover); }

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

.search-results {
    margin-top: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
}

.search-results.hidden {
    display: none;
}

.result-item {
    padding: 0.5rem;
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}
.result-item:last-child { border-bottom: none; }
.result-item:hover { background-color: var(--bg-color); }
.result-name { font-weight: 500; }
.result-doc { color: var(--text-muted); font-size: 0.75rem; }

/* Document section (Paper) */
.oc-document {
    flex: 1;
    background: var(--paper-color);
    padding: 3rem 4rem;
    border-radius: 2px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    min-height: 1056px; /* A4 aspect ratio approx */
}

.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 3rem;
    border-bottom: 2px solid var(--text-main);
    padding-bottom: 1rem;
}

.Company-info h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}
.company-info p { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 0.1rem;}
.buyer-attention { margin-top: 0.5rem; color: var(--text-main) !important; font-size: 0.85rem !important;}

.doc-title-box h2 {
    font-size: 1.25rem;
    font-weight: 700;
    text-align: right;
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.doc-meta { display: flex; flex-direction: column; gap: 0.25rem; align-items: flex-end;}
.meta-item { display: flex; gap: 1rem; font-size: 0.8rem; }
.meta-item span:first-child { font-weight: 600; color: var(--text-muted); }

.provider-info { margin-bottom: 2.5rem; }
.provider-info h3 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem; }

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.info-item { display: flex; flex-direction: column; gap: 0.25rem; }
.info-item label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;}

.items-section { margin-bottom: 2.5rem; }

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.col-qty { width: 10%; }
.col-desc { width: 48%; }
.col-price { width: 17%; text-align: right; }
.col-total { width: 17%; text-align: right; }
.col-action { width: 8%; }

/* Ocultar las flechitas de los inputs numéricos para que no estorben el texto */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

.items-table th {
    text-align: left;
    padding: 0.75rem 0.5rem;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    color: var(--text-muted);
}
.items-table td {
    padding: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.text-center { text-align: center !important; }
.text-right { text-align: right !important; }

.clean-input, .clean-textarea {
    width: 100%;
    border: 1px solid transparent;
    font-family: inherit;
    font-size: 0.875rem;
    padding: 0.25rem;
    background: transparent;
    color: var(--text-main);
}
.clean-input:focus, .clean-textarea:focus {
    outline: none;
    border-bottom-color: var(--primary);
}
.clean-textarea { resize: vertical; }

.item-desc[contenteditable="true"] {
    min-height: 1.5em;
    word-wrap: break-word;
    white-space: pre-wrap;
    padding: 0.25rem;
    outline: none;
}
.item-desc:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
}

.editable {
    outline: none;
    border-bottom: 1px dashed transparent;
    min-width: 50px;
    display: inline-block;
}
.editable:focus { border-bottom-color: var(--primary); }
.editable:empty:before { content: attr(data-placeholder); color: #9ca3af; }

.item-qty, .item-price { text-align: right; }
.item-total { text-align: right; font-weight: 500; font-size: 0.875rem; }

.btn-delete-row {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
}
.btn-delete-row:hover { opacity: 1; }

.totals-section { display: flex; justify-content: flex-end; margin-bottom: 3rem; }
.totals-box { width: 300px; }
.total-row { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border-color); font-size: 0.875rem;}
.total-row span:first-child { font-weight: 600; color: var(--text-muted); }
.grand-total { border-bottom: none; border-top: 2px solid var(--text-main); font-size: 1.125rem; font-weight: 700; margin-top: 0.5rem; padding-top: 1rem;}
.grand-total span:first-child { color: var(--text-main); }

.doc-footer { margin-top: 2rem; display: flex; justify-content: space-between; gap: 4rem;}
.notes { flex: 1; }
.notes label { display: block; font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.5rem; text-transform: uppercase;}
.signatures { display: flex; justify-content: space-around; margin-top: 4rem; width: 100%; }
.signature-box { width: 220px; text-align: center; }
.signature-line { border-top: 1px solid var(--text-main); padding-top: 0.5rem; font-size: 0.85rem; font-weight: 500;}

/* Estilos aplicados dinámicamente cuando se genera el PDF (.printing) */
.oc-document.printing {
    padding: 0 1rem !important; /* Quitar padding vertical extra */
    min-height: auto !important;
    box-shadow: none !important;
    font-size: 0.8rem;
}
.oc-document.printing .doc-header { margin-bottom: 1.5rem; }
.oc-document.printing .provider-info { margin-bottom: 1.5rem; }
.oc-document.printing .items-section { margin-bottom: 1.5rem; }
.oc-document.printing .totals-section { margin-bottom: 1.5rem; }
.oc-document.printing .doc-footer { margin-top: 1.5rem; }
.oc-document.printing .signatures { margin-top: 2.5rem; }
.oc-document.printing .clean-input { border: none !important; }
.oc-document.printing .editable { border: none !important; }
.oc-document.printing th { color: black; border-bottom: 2px solid black; }
.oc-document.printing td { border-bottom: 1px solid #ccc; }
