:root {
  --bg: #f1f4f8;
  --card: #ffffff;
  --primary: #1f5fa8;
  --primary-dark: #123b6b;
  --primary-soft: #eaf2fb;
  --text: #17202a;
  --muted: #667085;
  --border: #d7dee8;
  --success: #e8f7ee;
  --success-text: #176b35;
  --warning: #fff4d6;
  --warning-text: #795200;
  --danger: #ffe8e8;
  --danger-text: #a40000;
  --whatsapp: #25d366;
  --whatsapp-dark: #146c37;
  --cart: #7357d8;
  --cart-dark: #4b349f;
  --shadow: 0 14px 34px rgba(18, 59, 107, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
body.modal-open { overflow: hidden; }
button, input, select, textarea { font: inherit; }
button { border: 0; }

.main-header {
  color: #fff;
  background: radial-gradient(circle at top right, rgba(255,255,255,.16), transparent 33%), linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 34px 18px;
}
.header-content { width: min(1240px, 100%); margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.eyebrow, .section-kicker { display: block; margin: 0 0 7px; font-size: 12px; font-weight: 800; letter-spacing: .14em; color: var(--primary); }
.main-header .eyebrow { color: rgba(255,255,255,.78); }
.main-header h1 { margin: 0; font-size: clamp(30px, 5vw, 46px); line-height: 1.05; }
.main-header p:last-child { max-width: 760px; margin: 12px 0 0; line-height: 1.55; color: rgba(255,255,255,.88); }
.header-cart { display: inline-flex; align-items: center; gap: 10px; padding: 12px 15px; border-radius: 12px; color: #fff; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); font-weight: 900; cursor: pointer; white-space: nowrap; }
.header-cart span, .cart-tab span { display: inline-grid; place-items: center; min-width: 25px; height: 25px; padding: 0 7px; border-radius: 999px; background: #fff; color: var(--cart-dark); font-size: 12px; }

.container { width: min(1240px, calc(100% - 32px)); margin: 24px auto 52px; }
.service-tabs { display: flex; gap: 10px; margin-bottom: 22px; padding: 7px; overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.service-tab { flex: 1; min-width: 180px; padding: 13px 18px; border-radius: 10px; color: var(--primary-dark); background: transparent; font-weight: 800; cursor: pointer; transition: .18s ease; }
.service-tab:hover { background: var(--primary-soft); }
.service-tab.active { color: #fff; background: var(--primary); }
.cart-tab { display: inline-flex; justify-content: center; align-items: center; gap: 9px; }
.service-panel.hidden, .hidden-block { display: none !important; }

.section-heading, .card-heading-inline { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.section-heading { margin: 25px 0 15px; }
.section-heading h2, .card h3 { margin: 0; color: var(--primary-dark); }
.section-heading h2 { font-size: clamp(25px, 4vw, 34px); }
.card h3 { margin-bottom: 18px; font-size: 21px; }
.card-heading-inline h3 { margin-bottom: 0; }
.status-pill { flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; color: var(--primary-dark); background: var(--primary-soft); font-size: 13px; font-weight: 800; }
.status-pill-green { color: var(--success-text); background: var(--success); }
.grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.card { padding: 22px; background: var(--card); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.field { margin-bottom: 15px; }
.field label, .field legend, .message-mode label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 800; }
.fieldset-reset { margin-inline: 0; padding: 0; border: 0; }
input, select, textarea { width: 100%; padding: 12px 13px; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 10px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(31,95,168,.14); border-color: var(--primary); }
textarea { resize: vertical; }
.radio-row { display: flex; gap: 11px; }
.radio-card, .check-card { display: flex; align-items: flex-start; gap: 10px; padding: 13px; color: var(--primary-dark); background: #f8fbff; border: 1px solid var(--border); border-radius: 11px; cursor: pointer; }
.radio-card { flex: 1; }
.radio-card input, .check-card input { width: auto; margin: 3px 0 0; accent-color: var(--primary); }
.radio-card span, .check-card span { display: grid; gap: 3px; }
.radio-card small, .check-card small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.check-card { margin: 2px 0 15px; }
.compact-check { margin-top: 14px; }
.dimensions-grid { display: grid; grid-template-columns: 1fr 1fr .8fr; gap: 10px; }
.result-box { padding: 18px; background: #f8fbff; border: 1px solid var(--border); border-radius: 13px; }
.price-row, .summary-row { display: flex; justify-content: space-between; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.price-row strong, .summary-row strong { max-width: 58%; text-align: right; }
.total-label { margin-top: 18px; color: var(--muted); font-size: 13px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.price-big { margin: 4px 0 10px; color: var(--primary-dark); font-size: clamp(32px, 6vw, 44px); font-weight: 900; letter-spacing: -.04em; }
.grand-total { margin-top: 10px; padding: 16px 0 4px; border-top: 2px solid var(--primary-dark); border-bottom: 0; color: var(--primary-dark); font-size: 19px; }
.badge { display: inline-block; margin-top: 8px; padding: 8px 10px; border-radius: 9px; font-size: 13px; font-weight: 800; line-height: 1.4; }
.badge.success { color: var(--success-text); background: var(--success); }
.badge.warning { color: var(--warning-text); background: var(--warning); }
.badge.danger { color: var(--danger-text); background: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions button, .file-button { min-height: 43px; padding: 11px 16px; border-radius: 10px; font-size: 14px; font-weight: 900; cursor: pointer; transition: transform .15s ease, filter .15s ease; }
.actions button:hover, .file-button:hover { filter: brightness(.97); transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--primary); }
.btn-secondary { color: var(--primary-dark); background: var(--primary-soft); }
.btn-cart { color: #fff; background: var(--cart); }
.btn-print { color: #fff; background: #1c7c54; }
.btn-whatsapp { color: #fff; background: var(--whatsapp); }
.btn-whatsapp-secondary { color: var(--whatsapp-dark); background: var(--success); }
.btn-text-danger { padding: 8px 10px; border-radius: 8px; color: var(--danger-text); background: var(--danger); font-weight: 800; cursor: pointer; }
.note { margin: 12px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.whatsapp-box, .table-card, .cart-card, .manual-item-card, .ot-actions-card, .history-card { margin-top: 18px; }
.whatsapp-box { background: #f8fff9; border-color: #bfe7c9; }
.whatsapp-kicker { color: var(--whatsapp-dark); }
.whatsapp-preview { min-height: 320px; margin-top: 17px; resize: vertical; color: #18211b; background: #fff; border-color: #bfe7c9; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.message-mode { width: min(245px, 100%); }
.message-mode label { color: var(--muted); font-size: 12px; }
.table-wrapper { margin-top: 18px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; min-width: 850px; border-collapse: collapse; background: #fff; }
.wide-table { min-width: 1180px; }
th, td { padding: 11px; border-bottom: 1px solid var(--border); font-size: 13px; text-align: left; vertical-align: top; }
th { color: #fff; background: var(--primary); font-weight: 800; white-space: nowrap; }
tbody tr:nth-child(even) td { background: #f7faff; }
tbody tr:hover td { background: #eef5fd; }
.compact-field { width: min(300px, 100%); }
.muted { color: var(--muted); }
.process-label, .custom-label { display: inline-flex; margin-left: 6px; padding: 3px 7px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.process-label { color: var(--warning-text); background: var(--warning); }
.custom-label { color: var(--primary-dark); background: var(--primary-soft); }
.table-actions { display: flex; gap: 6px; white-space: nowrap; }
.btn-edit-small, .btn-delete-small { padding: 7px 9px; border-radius: 8px; font-size: 12px; font-weight: 900; cursor: pointer; }
.btn-edit-small { color: var(--primary-dark); background: var(--primary-soft); }
.btn-delete-small { color: var(--danger-text); background: var(--danger); }

.material-manager { margin-top: 18px; padding: 0; overflow: hidden; }
.material-manager > summary, .history-card > summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 20px 22px; color: var(--primary-dark); background: #fff; cursor: pointer; list-style: none; }
.material-manager > summary::-webkit-details-marker, .history-card > summary::-webkit-details-marker { display: none; }
.material-manager > summary span:first-child, .history-card > summary span:first-child { display: grid; gap: 4px; }
.material-manager > summary small, .history-card > summary small { color: var(--muted); font-weight: 400; line-height: 1.4; }
.summary-action { flex: 0 0 auto; padding: 8px 11px; border-radius: 999px; color: var(--primary-dark); background: var(--primary-soft); font-size: 12px; font-weight: 900; }
.material-manager[open] > summary, .history-card[open] > summary { border-bottom: 1px solid var(--border); }
.material-form, .history-content { padding: 22px; background: #fbfcfe; }
.form-grid { display: grid; grid-template-columns: .8fr 1fr 1.5fr; gap: 12px; }
.two-columns { grid-template-columns: 1fr 1fr; }
.price-input-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.subsection-heading { margin: 8px 0 12px; }
.subsection-heading h4 { margin: 0 0 4px; color: var(--primary-dark); font-size: 16px; }
.subsection-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.hidden-field { display: none; }
.hidden-field.visible { display: block; }
.file-button { display: inline-flex; align-items: center; justify-content: center; color: var(--primary-dark); background: var(--primary-soft); }

.order-top-grid { align-items: start; }
.totals-card { position: sticky; top: 18px; }
.discount-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.manual-item-grid { display: grid; grid-template-columns: 1.6fr 1.2fr .55fr .6fr .8fr auto; gap: 10px; align-items: end; }
.manual-item-grid .field { margin-bottom: 0; }
.manual-submit { padding-bottom: 1px; }
.manual-submit button { min-height: 43px; padding: 11px 14px; border-radius: 10px; font-weight: 900; cursor: pointer; white-space: nowrap; }
.empty-state { padding: 24px; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); background: #fafbfd; text-align: center; line-height: 1.5; }
.cart-table { min-width: 1000px; }
.cart-table td:first-child { min-width: 320px; }
.cart-item-title { display: block; color: var(--primary-dark); font-weight: 900; }
.cart-item-detail { display: block; margin-top: 4px; color: var(--muted); line-height: 1.4; }
.cart-warning { display: block; margin-top: 5px; color: var(--warning-text); font-size: 11px; font-weight: 800; }
.cart-input { min-width: 95px; padding: 8px 9px; }
.cart-total-cell { white-space: nowrap; font-weight: 900; }
.ot-actions-card { display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.ot-actions-card h3 { margin-bottom: 4px; }
.history-card { padding: 0; overflow: hidden; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(13,28,45,.58); backdrop-filter: blur(3px); }
.modal-card { position: relative; width: min(980px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: 24px; background: #fff; border-radius: 17px; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.modal-header h2 { margin: 0; color: var(--primary-dark); }
.modal-close { width: 40px; height: 40px; border-radius: 10px; color: var(--primary-dark); background: var(--primary-soft); font-size: 25px; cursor: pointer; }
.editor-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.editor-section { padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: #fafcff; }
.editor-section h4 { margin: 0 0 13px; color: var(--primary-dark); }
.editor-price-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.editor-price-grid .field { margin-bottom: 0; }
.modal-actions { padding-top: 8px; border-top: 1px solid var(--border); }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 120; max-width: min(360px, calc(100% - 36px)); padding: 12px 15px; color: #fff; background: #17202a; border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
.print-sheet { display: none; }

@media (max-width: 1050px) {
  .manual-item-grid { grid-template-columns: 1fr 1fr 1fr; }
  .manual-description { grid-column: 1 / 3; }
  .manual-submit { grid-column: 3; }
}

@media (max-width: 860px) {
  .header-content { align-items: flex-start; flex-direction: column; }
  .grid { grid-template-columns: 1fr; }
  .dimensions-grid, .form-grid, .price-input-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .field:last-child { grid-column: 1 / -1; }
  .responsive-heading { align-items: flex-start; flex-direction: column; }
  .totals-card { position: static; }
  .ot-actions-card { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 620px) {
  .container { width: min(100% - 20px, 1240px); }
  .card { padding: 17px; border-radius: 13px; }
  .section-heading, .card-heading-inline { align-items: flex-start; flex-direction: column; }
  .radio-row { flex-direction: column; }
  .radio-card { width: 100%; }
  .dimensions-grid, .form-grid, .price-input-grid, .two-columns, .discount-grid, .manual-item-grid, .editor-columns, .editor-price-grid { grid-template-columns: 1fr; }
  .form-grid .field:last-child, .manual-description, .manual-submit { grid-column: auto; }
  .compact-field, .message-mode { width: 100%; }
  .actions button, .file-button { width: 100%; }
  .price-row strong, .summary-row strong { max-width: 54%; }
  .material-manager > summary, .history-card > summary, .material-form, .history-content { padding: 17px; }
  .modal { padding: 8px; }
  .modal-card { padding: 17px; max-height: calc(100vh - 16px); }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  body > *:not(#otPrintSheet) { display: none !important; }
  #otPrintSheet { display: block !important; color: #000; font-family: Arial, Helvetica, sans-serif; }
  .print-header { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 12px; border-bottom: 2px solid #000; }
  .print-header h1 { margin: 0; font-size: 24px; }
  .print-header p { margin: 5px 0 0; font-size: 12px; }
  .print-number { text-align: right; font-weight: 800; }
  .print-client { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 22px; margin: 15px 0; padding: 12px; border: 1px solid #999; }
  .print-client div { font-size: 12px; }
  .print-client strong { display: block; margin-bottom: 2px; }
  .print-table { width: 100%; min-width: 0; border-collapse: collapse; }
  .print-table th, .print-table td { padding: 7px; border: 1px solid #999; font-size: 11px; color: #000; background: #fff !important; }
  .print-table th { font-weight: 800; }
  .print-totals { width: 310px; margin: 14px 0 0 auto; }
  .print-total-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #ccc; font-size: 12px; }
  .print-total-row.final { padding-top: 8px; border-top: 2px solid #000; border-bottom: 0; font-size: 16px; font-weight: 900; }
  .print-notes { margin-top: 16px; min-height: 60px; padding: 10px; border: 1px solid #999; font-size: 11px; white-space: pre-wrap; }
  .print-signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; margin-top: 42px; }
  .print-signature { padding-top: 8px; border-top: 1px solid #000; text-align: center; font-size: 11px; }
}


/* =========================================================
   PRODUCTOS FINALES
========================================================= */

.final-products-pill {
  color: var(--cart-dark);
  background: #eee9ff;
}

.final-products-toolbar {
  margin-bottom: 18px;
}

.catalog-toolbar-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, .55fr) auto;
  gap: 14px;
  align-items: end;
}

.catalog-toolbar-grid .field {
  margin-bottom: 0;
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.toolbar-actions button,
.toolbar-actions .file-button {
  min-height: 43px;
}

.final-products-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.final-product-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0;
}

.final-product-media {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  overflow: hidden;
  color: var(--muted);
  background: linear-gradient(135deg, #eef3f9, #f8fbff);
  border-bottom: 1px solid var(--border);
}

.final-product-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.final-product-placeholder {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border-radius: 22px;
  color: var(--primary-dark);
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 24px;
  font-weight: 900;
  text-transform: uppercase;
}

.final-product-category {
  position: absolute;
  top: 12px;
  left: 12px;
  max-width: calc(100% - 24px);
  padding: 6px 9px;
  overflow: hidden;
  color: var(--primary-dark);
  background: rgba(255, 255, 255, .92);
  border: 1px solid rgba(215, 222, 232, .85);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.final-product-content {
  display: flex;
  flex: 1;
  flex-direction: column;
  padding: 19px;
}

.final-product-content h3 {
  margin: 0 0 7px;
  font-size: 20px;
  line-height: 1.2;
}

.final-product-description {
  min-height: 40px;
  margin: 0 0 15px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.final-product-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.final-product-selectors .field {
  margin-bottom: 0;
}

.final-product-price-box {
  margin-top: 15px;
  padding: 13px;
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.final-product-price-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.final-product-price {
  margin-top: 3px;
  color: var(--primary-dark);
  font-size: 27px;
  font-weight: 900;
  letter-spacing: -.03em;
}

.final-product-card .actions {
  margin-top: auto;
  padding-top: 16px;
}

.final-product-card .actions button {
  flex: 1;
}

.final-products-empty {
  margin: 18px 0;
}

.final-product-manager {
  margin-top: 20px;
}

.final-product-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.75fr) minmax(230px, .65fr);
  gap: 22px;
}

.final-product-image-editor {
  padding: 16px;
  background: #f7f9fc;
  border: 1px solid var(--border);
  border-radius: 13px;
}

.final-image-preview {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  overflow: hidden;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 12px;
  font-size: 13px;
  font-weight: 800;
}

.final-image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.full-width {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  font-weight: 900;
  cursor: pointer;
}

.final-price-table-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.final-price-table-head,
.final-price-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.45fr) minmax(90px, .55fr) minmax(120px, .7fr) 42px;
  gap: 9px;
  align-items: center;
}

.final-price-table-head {
  padding: 10px 12px;
  color: #fff;
  background: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.final-price-row {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.final-price-row:first-child {
  border-top: 0;
}

.final-price-row input {
  padding: 9px 10px;
}

.final-price-remove {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--danger-text);
  background: var(--danger);
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.compact-actions {
  margin-top: 10px;
}

@media (max-width: 1050px) {
  .final-products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .catalog-toolbar-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .final-product-form-grid,
  .catalog-toolbar-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-actions {
    grid-column: auto;
  }

  .final-products-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .final-product-selectors,
  .final-price-table-head,
  .final-price-row {
    grid-template-columns: 1fr;
  }

  .final-price-table-head {
    display: none;
  }

  .final-price-row {
    gap: 7px;
  }

  .final-price-remove {
    width: 100%;
  }
}
