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

:root {
  --primary: #7c5aa8;
  --primary-dark: #6a4b90;
  --bg: #faf9fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  padding: 2rem 1rem;
}

.container { 
  width: 100%; 
  max-width: 980px; 
  margin: 0 auto; 
}

.header {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem 1.5rem;
  box-shadow: var(--shadow);
  margin: 0 0 1.25rem;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header h1 { 
  font-size: 1.35rem; 
  letter-spacing: 0.2px; 
  margin-bottom: 0.25rem; 
}

.header p { 
  color: var(--text-muted); 
  font-size: 0.95rem; 
}

.form-section {
  display: grid;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.form-card h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--primary);
}

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

.field {
  display: flex;
  flex-direction: column;
}

.field.full-width {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

label input[type="checkbox"] {
  margin-right: 0.5rem;
  cursor: pointer;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.check-label input[type="checkbox"] {
  margin-right: 0;
}

input[type="text"],
input[type="number"],
input[type="date"] {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
  color: var(--text);
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 90, 168, 0.15);
}

input:disabled {
  background: #f3f4f6;
  color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.6;
}

input[readonly] {
  background: #f9fafb;
  cursor: default;
}

.preview-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.preview-section h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Mejoras visuales en la factura */
.invoice-preview {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.5rem;
  background: white;
  min-height: 400px;
  font-size: 0.9rem;
  line-height: 1.6;
}

.invoice-header-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--text);
}

/* Bloques de emisor y cliente con bordes más sutiles */
.invoice-block {
  border: 1px solid var(--text);
  padding: 1rem;
  margin-bottom: 2rem;
}

.invoice-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.invoice-meta {
  text-align: right;
  font-size: 0.9rem;
}

.invoice-meta div {
  margin-bottom: 0.25rem;
}

/* Concepto con borde más sutil y menos padding */
.invoice-concept {
  border: 1px solid var(--border);
  padding: 1.5rem;
  margin-bottom: 2.5rem;
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.95rem;
}

/* Tabla de totales mejorada */
.invoice-totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.invoice-row {
  display: grid;
  grid-template-columns: 120px 120px;
  gap: 1rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
}

.invoice-row span {
  text-align: left;
}

.invoice-row strong {
  text-align: right;
}

/* Total más prominente */
.invoice-row.total-row {
  border: 2px solid var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.5rem 0.5rem;
}

/* Instrucciones de pago */
.invoice-payment-instructions {
  display: none;
  margin-top: 1.5rem;
  padding: 1rem;
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}

.invoice-payment-instructions strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: var(--text);
}

/* Notas de IVA */
.invoice-notes {
  margin-top: 1rem;
}

.invoice-note {
  display: none;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.actions {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

.btn-secondary {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  background: white;
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-primary {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.branding-badge {
  margin: 1.5rem 0 0.75rem;
  text-align: center;
  color: var(--text);
  font-weight: 600;
}

.branding-badge a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
  transition: color 0.2s ease;
}

.branding-badge a:hover { 
  color: var(--primary-dark); 
}

.iva-exception-field {
  display: none;
}

.iva-exception-field input {
  font-size: 0.85rem;
}

/* Responsive */
@media (max-width: 768px) {
  body { 
    padding: 1rem 0.75rem; 
  }

  .header-row {
    flex-direction: column;
    align-items: flex-start;
  }
  
  .form-section {
    grid-template-columns: 1fr;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .field {
    grid-column: 1 / -1;
  }
  
  .invoice-preview {
    padding: 1.5rem;
  }
  
  .invoice-header-section {
    flex-direction: column;
    gap: 1rem;
  }
  
  .invoice-meta {
    text-align: left;
  }
  
  .invoice-row {
    grid-template-columns: 1fr 100px;
  }
}
