:root {
  --brand-red: #c8102e;
  --brand-dark: #3b3b3b;
  --brand-gray-bg: #e6e7e9;
  --brand-light-bg: #f4f5f7;
  --ui-primary: #1e293b;
  --ui-accent: #c8102e;
  --ui-border: #cbd5e1;
}

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

body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: #0f172a;
  color: #1e293b;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* BARRA SUPERIOR DE LA APP */
.app-topbar {
  background: #1e293b;
  color: #fff;
  height: 58px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #334155;
  flex-shrink: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 16px;
}

.app-brand-badge {
  background: var(--brand-red);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  letter-spacing: 0.5px;
}

.app-nav {
  display: flex;
  gap: 6px;
}

.nav-tab {
  background: transparent;
  color: #cbd5e1;
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.nav-tab:hover {
  background: #334155;
  color: #fff;
}

.nav-tab.active {
  background: #fff;
  color: #0f172a;
}

.app-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.storage-status {
  font-size: 12px;
  color: #94a3b8;
  background: #0f172a;
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

/* BOTONES */
.btn {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.btn-primary {
  background: var(--brand-red);
  color: #fff;
}

.btn-primary:hover {
  background: #a50d26;
}

.btn-success {
  background: #16a34a;
  color: #fff;
}

.btn-success:hover {
  background: #15803d;
}

.btn-secondary {
  background: #334155;
  color: #f8fafc;
  border-color: #475569;
}

.btn-secondary:hover {
  background: #475569;
}

.btn-outline {
  background: #fff;
  color: #334155;
  border-color: #cbd5e1;
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-danger:hover {
  background: #fecaca;
}

/* CONTENEDOR PRINCIPAL */
.app-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.tab-panel {
  display: none;
  width: 100%;
  height: 100%;
}

.tab-panel.active {
  display: flex;
}

/* VISTA EDITOR + PREVIEW */
.editor-pane {
  width: 470px;
  background: #f8fafc;
  border-right: 1px solid #cbd5e1;
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  flex-shrink: 0;
}

.preview-pane {
  flex: 1;
  background: #334155;
  height: 100%;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* TARJETAS DE FORMULARIO */
.form-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.form-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #f1f5f9;
}

.form-card-title {
  font-size: 13px;
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

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

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

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

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
}

.form-control {
  padding: 7px 9px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  color: #0f172a;
  background: #fff;
}

.form-control:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 2px rgba(200, 16, 46, 0.12);
}

textarea.form-control {
  resize: vertical;
  min-height: 54px;
}

/* ITEMS DEL PRESUPUESTO EN EL EDITOR */
.item-editor-box {
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 10px;
  margin-bottom: 10px;
  position: relative;
}

.item-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

/* VISTAS DE GESTIÓN */
.management-container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  overflow-y: auto;
  background: #f8fafc;
}

.panel-wrapper {
  width: 100%;
  height: 100%;
  background: #f1f5f9;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 13px;
}

.data-table th {
  background: #f8fafc;
  font-weight: 700;
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
}

.data-table tr:hover td {
  background: #f8fafc;
}

/* ==========================================================
   HOJA DE PRESUPUESTO (TAMAÑO CARTA: 215.9mm x 279.4mm)
   ========================================================== */
.pdf-page {
  width: 215.9mm;
  min-height: 279.4mm;
  background: #ffffff;
  padding: 9mm 12mm 9mm 12mm;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  color: #111;
  font-family: 'Arial Narrow', Arial, Helvetica, sans-serif;
  position: relative;
}

/* ENCABEZADO SUPERIOR */
.doc-top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 12px;
}

/* ESQUINA SUPERIOR IZQUIERDA: DATOS + MARCAS LIMPIAS */
.company-info-block {
  width: 53%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.company-name {
  font-size: 19px;
  font-weight: 900;
  letter-spacing: 0.4px;
  color: #000;
  text-transform: uppercase;
  line-height: 1.15;
  font-family: Arial, Helvetica, sans-serif;
}

.company-subtitle {
  font-size: 12px;
  font-weight: 700;
  color: #333;
  margin-top: 2px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

/* GRILLA SUTIL DE LAS 6 MARCAS (SIN RECUADRO DE FONDO) */
.company-brands-grid {
  display: grid;
  grid-template-columns: repeat(3, auto);
  justify-content: center;
  align-items: center;
  column-gap: 12px;
  row-gap: 6px;
  margin: 6px 0 7px 0;
  padding: 2px 0;
  background: transparent;
  border: none;
}

.brand-badge-img {
  height: 18px;
  width: auto;
  max-width: 78px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.company-details {
  font-size: 11.8px;
  line-height: 1.32;
  color: #222;
}

/* ESQUINA SUPERIOR DERECHA: BANCO DE PRUEBA + LOGO INYECCIÓN DIESEL CURICÓ */
.company-logo-block {
  width: 45%;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.bench-logo-composite {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}

.bench-logo-img {
  width: 122px;
  height: 112px;
  object-fit: contain;
  flex-shrink: 0;
}

.bench-logo-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  font-family: Arial, Helvetica, sans-serif;
}

.bench-title-top {
  font-size: 18px;
  font-weight: 900;
  font-style: italic;
  color: #111;
  line-height: 1;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.bench-title-mid {
  font-size: 27px;
  font-weight: 900;
  font-style: italic;
  color: var(--brand-red);
  line-height: 0.98;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.bench-title-bot {
  font-size: 21px;
  font-weight: 900;
  color: #fff;
  background: #111;
  padding: 2px 10px;
  border-radius: 4px;
  margin-top: 3px;
  line-height: 1.05;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.company-logo-img {
  max-width: 260px;
  max-height: 115px;
  object-fit: contain;
}

/* BLOQUES DE METADATOS (DOCUMENTO / CLIENTE / ORDEN) */
.doc-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  align-items: stretch;
}

.meta-left-col {
  width: 58%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-right-col {
  width: 40%;
  display: flex;
  flex-direction: column;
}

.pill-header-bar {
  background: var(--brand-dark);
  color: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  display: grid;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 3px;
}

.pill-values-bar {
  background: var(--brand-gray-bg);
  border-radius: 7px;
  padding: 5px 10px;
  display: grid;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  align-items: center;
  min-height: 28px;
}

.grid-doc {
  grid-template-columns: 1.3fr 1.1fr 0.7fr 1.2fr;
}

.grid-client {
  grid-template-columns: 1fr 2.1fr 1.2fr;
}

.order-header-box {
  background: var(--brand-dark);
  color: #fff;
  padding: 7px 10px;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.order-body-box {
  background: var(--brand-gray-bg);
  flex: 1;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.order-num-line {
  font-size: 13.5px;
  font-weight: 800;
  color: #111;
}

.order-desc-line {
  font-size: 13.5px;
  font-weight: 400;
  color: #222;
  text-transform: uppercase;
}

/* TABLA CENTRAL DE ARTÍCULOS */
.items-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 10px;
}

.items-red-header {
  background: var(--brand-red);
  color: #fff;
  border-radius: 7px;
  padding: 6px 8px;
  display: grid;
  grid-template-columns: 13% 37% 10% 13% 13% 5% 9%;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.items-columns-container {
  flex: 1;
  min-height: 112mm;
  border: 1.4px solid #bcbec0;
  border-radius: 14px;
  display: grid;
  grid-template-columns: 13% 37% 10% 13% 13% 5% 9%;
  background: var(--brand-light-bg);
  overflow: hidden;
  position: relative;
}

.items-col-bg {
  border-right: 1px solid #d1d3d4;
  height: 100%;
}

.items-col-bg:last-child {
  border-right: none;
}

.items-rows-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.doc-item-row {
  display: grid;
  grid-template-columns: 13% 37% 10% 13% 13% 5% 9%;
  font-size: 12px;
  line-height: 1.35;
  color: #111;
}

.doc-item-cell {
  padding: 0 8px;
  word-break: break-word;
}

.cell-center {
  text-align: center;
}

.cell-right {
  text-align: right;
}

.item-main-title {
  font-weight: 600;
  text-transform: uppercase;
}

.item-diag-text {
  margin-top: 10px;
  white-space: pre-line;
  text-transform: uppercase;
  color: #222;
}

/* SECCIÓN DE IMPUESTOS E IMPORTES */
.taxes-box {
  margin-bottom: 8px;
}

.taxes-header {
  background: var(--brand-dark);
  color: #fff;
  border-radius: 6px;
  padding: 5px 6px;
  display: grid;
  grid-template-columns: 7% 13% 12% 13% 11% 14% 12% 10% 8%;
  font-size: 10.5px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 3px;
}

.taxes-body {
  border: 1.4px solid #bcbec0;
  border-radius: 8px;
  background: var(--brand-light-bg);
  display: grid;
  grid-template-columns: 7% 13% 12% 13% 11% 14% 12% 10% 8%;
  min-height: 44px;
}

.tax-cell {
  border-right: 1px solid #d1d3d4;
  padding: 6px 6px;
  font-size: 11.5px;
  text-align: right;
  color: #111;
}

.tax-cell.center {
  text-align: center;
}

.tax-cell:last-child {
  border-right: none;
}

/* OBSERVACIONES Y TOTAL ROJO */
.obs-total-bars {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.obs-bar {
  flex: 1;
  background: var(--brand-dark);
  color: #fff;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.total-red-bar {
  width: 32%;
  background: var(--brand-red);
  color: #fff;
  border-radius: 6px;
  padding: 5px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  font-weight: 800;
}

.obs-content-box {
  border: 1.4px solid #bcbec0;
  border-radius: 7px;
  min-height: 26px;
  padding: 4px 10px;
  font-size: 11.5px;
  margin-bottom: 6px;
  background: #fff;
}

/* DATOS DE TRANSFERENCIA Y PIE DE PÁGINA */
.payment-box {
  border: 1.4px solid #bcbec0;
  border-radius: 14px;
  background: var(--brand-light-bg);
  padding: 8px 16px;
  margin-bottom: 4px;
}

.payment-title {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 4px;
  font-family: Arial, sans-serif;
}

.payment-details-grid {
  display: flex;
  gap: 8px;
  font-size: 12px;
  line-height: 1.28;
}

.payment-label {
  font-weight: 800;
  white-space: nowrap;
}

.payment-lines {
  white-space: pre-line;
}

.footer-legal-note {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  padding-left: 4px;
  color: #111;
}

/* PANTALLA DE BLOQUEO CON PIN (PC + IPAD) */
.pin-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.pin-card {
  background: #ffffff;
  width: 100%;
  max-width: 390px;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.pin-logo-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.pin-logo-preview img {
  width: 78px;
  height: 72px;
  object-fit: contain;
}

.pin-title {
  font-size: 17px;
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
}

.pin-subtitle {
  font-size: 12.5px;
  color: #64748b;
  margin-bottom: 16px;
}

.pin-input-display {
  width: 100%;
  font-size: 26px;
  letter-spacing: 10px;
  text-align: center;
  padding: 10px;
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  margin-bottom: 14px;
  font-weight: 800;
  color: #0f172a;
  background: #f8fafc;
}

.pin-input-display:focus {
  outline: none;
  border-color: var(--brand-red);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.pin-key {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 13px 0;
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  cursor: pointer;
  user-select: none;
  transition: all 0.12s;
}

.pin-key:active,
.pin-key:hover {
  background: #e2e8f0;
}

.pin-error-msg {
  color: #dc2626;
  font-size: 12.5px;
  font-weight: 600;
  min-height: 18px;
  margin-bottom: 8px;
}

/* CONMUTADOR DE VISTA PARA IPAD / TABLET */
.ipad-view-switcher {
  display: none;
  background: #0f172a;
  padding: 8px 16px;
  gap: 8px;
  justify-content: center;
  border-bottom: 1px solid #334155;
}

.ipad-switch-btn {
  flex: 1;
  max-width: 240px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #1e293b;
  color: #cbd5e1;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.ipad-switch-btn.active {
  background: var(--brand-red);
  color: #fff;
  border-color: var(--brand-red);
}

@media (max-width: 1100px) {
  .app-topbar {
    height: auto;
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  .app-nav {
    order: 3;
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .ipad-view-switcher {
    display: flex;
  }

  #tab-editor.ipad-show-form .preview-pane {
    display: none;
  }

  #tab-editor.ipad-show-Form .editor-pane,
  #tab-editor.ipad-show-form .editor-pane {
    width: 100%;
    border-right: none;
  }

  #tab-editor.ipad-show-preview .editor-pane {
    display: none;
  }

  #tab-editor.ipad-show-preview .preview-pane {
    width: 100%;
    padding: 12px;
  }
}

/* IMPRESIÓN / GENERACIÓN DE PDF NATIVA (SOLO 1 PÁGINA TAMAÑO CARTA) */
@media print {
  @page {
    size: letter portrait;
    margin: 0;
  }

  html,
  body {
    width: 215.9mm !important;
    height: 279.4mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: hidden !important;
  }

  .pin-overlay,
  .ipad-view-switcher,
  .app-topbar,
  .editor-pane,
  .no-print,
  #tab-clientes,
  #tab-catalogo,
  #tab-historial,
  #tab-config {
    display: none !important;
  }

  .app-main,
  #tab-editor,
  .preview-pane {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
    overflow: hidden !important;
    width: 215.9mm !important;
    height: 279.4mm !important;
  }

  .pdf-page {
    box-shadow: none !important;
    margin: 0 !important;
    width: 215.9mm !important;
    height: 279.4mm !important;
    max-height: 279.4mm !important;
    min-height: 0 !important;
    padding: 8.5mm 12mm !important;
    overflow: hidden !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .items-columns-container {
    min-height: 108mm !important;
  }
}
