/* =============================================
   HOLOSPET — Comprobante de venta
   Paleta: #041b54 (oscuro) / #052ea5 (claro)

   Layout: resumen (izq) + boleta (der) en escritorio;
   apilado (boleta abajo) en pantallas chicas.

   Tipografía responsive: todos los tamaños están en rem y escalan
   con el font-size base de <html> según el dispositivo.
   ============================================= */

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

:root {
  --azul-oscuro:  #041b54;
  --azul-claro:   #052ea5;
  --azul-accent:  #1d4ed8;
  --azul-suave:   #4f6099;   /* azul apagado para títulos/íconos */
  --azul-light:   #e8edf8;
  --azul-total:   #eef2fc;

  --text-primary: #15203c;
  --text-muted:   #7a8499;
  --text-soft:    #9aa3b5;
  --border:       #edf0f5;

  --bg-page:      #eef1f6;
  --bg-card:      #ffffff;
  --bg-soft:      #f8f9fc;

  --ok:           #16a34a;
  --ok-bg:        #dcfce7;
  --warn:         #b45309;
  --warn-bg:      #fef3c7;
  --sii:          #b42318;   /* rojo SII de la boleta */
  --sii-bg:       #fdf3f2;

  --radius:       20px;
  --radius-md:    14px;
  --radius-sm:    10px;
  --shadow:       0 10px 40px -8px rgba(4,27,84,.18);
}

/* ---- Escala base de tipografía ---- */
html {
  font-size: 14px;                  /* PC */
  -webkit-text-size-adjust: 100%;
}
@media (max-width: 900px) { html { font-size: 13px; } } /* tablet */
@media (max-width: 540px) { html { font-size: 12px; } } /* móvil  */

body {
  font-family: 'Inter', -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif;
  background:
    radial-gradient(1200px 600px at 50% -200px, #dfe6f5 0%, transparent 70%),
    var(--bg-page);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 18px calc(28px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 1060px;
  margin: 0 auto;
}

/* ---- Layout dos columnas ---- */
.layout,
.skeleton-wrap {
  display: grid;
  gap: 22px;
  align-items: start;
}

@media (min-width: 880px) {
  .layout,
  .skeleton-wrap {
    grid-template-columns: 1fr 0.82fr;   /* resumen un poco más ancho */
  }
}

/* ---- card ---- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fadeUp .45s cubic-bezier(.2,.7,.3,1) both;
}

.panel-boleta { animation-delay: .06s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- header resumen ---- */
.card-header {
  position: relative;
  background: linear-gradient(135deg, #041b54 0%, #0a37b0 100%);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  overflow: hidden;
}

.card-header::after {
  content: "";
  position: absolute;
  top: -60%;
  right: -10%;
  width: 220px;
  height: 220px;
  background: radial-gradient(circle, rgba(255,255,255,.12) 0%, transparent 65%);
  pointer-events: none;
}

.logo {
  height: 30px;
  width: auto;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.venta-id {
  display: flex;
  align-items: baseline;
  gap: 7px;
  position: relative;
  z-index: 1;
}

.venta-label {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.6);
}

.venta-num {
  font-size: .9375rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: .01em;
}

/* ---- bloque de datos: dos cajitas gemelas (cliente + venta) ---- */
.doc-top {
  display: flex;
  align-items: stretch;
  gap: 14px;
}

/* Cajitas gemelas: mismo fondo, borde y radio */
.doc-cliente,
.doc-box {
  background: var(--azul-total);
  border: 1.5px solid var(--azul-light);
  border-radius: 12px;
  padding: 12px 15px;
}

.doc-cliente { flex: 1; min-width: 0; }
.doc-box { flex-shrink: 0; min-width: 178px; }

/* Título de cada cajita (mismo estilo en ambas) */
.doc-mini-label,
.doc-box-title {
  display: block;
  font-size: .625rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--azul-claro);
}

.doc-cliente-nombre {
  font-size: 1rem;
  font-weight: 800;
  color: var(--azul-oscuro);
  line-height: 1.2;
  margin: 5px 0 9px;
  text-transform: capitalize;
}

.doc-dato {
  display: flex;
  gap: 10px;
  font-size: .75rem;
  margin-top: 4px;
  line-height: 1.35;
}

.doc-dato > span:first-child {
  color: var(--text-muted);
  font-weight: 600;
  flex-shrink: 0;
  min-width: 74px;
}

.doc-dato > span:last-child {
  color: var(--text-primary);
  font-weight: 500;
  min-width: 0;
}

.doc-box-title { margin-bottom: 8px; }

.doc-box-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: .6875rem;
  padding: 2px 0;
}

.doc-box-row > span:first-child { color: var(--text-muted); font-weight: 600; }
.doc-box-row > span:last-child { color: var(--azul-oscuro); font-weight: 700; text-align: right; }

/* ---- separador entrecortado e insertado (no llega a los bordes) ---- */
.hr-dash {
  height: 0;
  border-top: 1.5px dashed #d7dce6;
  margin: 0 24px;
}

/* ---- secciones ---- */
.section { padding: 16px 24px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--azul-suave);
  margin-bottom: 14px;
}

.sec-ico {
  width: 12px;
  height: 12px;
  color: var(--azul-suave);
  flex-shrink: 0;
}

/* ---- enlace de dirección (dentro del bloque de datos) ---- */
.dir-link {
  color: var(--azul-claro);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(5,46,165,.3);
  transition: border-color .12s;
}
.dir-link:hover { border-bottom-color: var(--azul-claro); }

/* ---- productos (filas modernas con miniatura) ---- */
.prod-img {
  width: 56px; height: 56px;
  object-fit: contain;
  border-radius: 12px;
  background: #fafbfd;
  border: 1px solid var(--border);
  display: block;
  flex-shrink: 0;
}

.prod-img-placeholder {
  width: 56px; height: 56px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #eef1f6, #f6f8fb);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.prod-img-placeholder::after {
  content: "🐾";
  font-size: 18px;
  opacity: .45;
}

.badge-descuento {
  display: inline-block;
  background: var(--ok-bg);
  color: var(--ok);
  font-size: .5625rem;
  font-weight: 800;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 999px;
}

.prod-tag {
  display: inline-block;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .5625rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: 2px 7px;
  border-radius: 999px;
}

.prod-tag--sag {
  background: #fdebe9;
  color: #b42318;
}

.precio-original {
  text-decoration: line-through;
  color: var(--text-soft);
  font-size: .6875rem;
  display: block;
}

.precio-final {
  font-size: .9375rem;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
  font-variant-numeric: tabular-nums;
}

/* Lista de productos: filas alineadas en columnas (imagen | datos | precio) */
.productos-mobile { display: flex; flex-direction: column; }

.prod-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.prod-row:first-child { padding-top: 2px; }
.prod-row:last-child { border-bottom: none; padding-bottom: 2px; }

.prod-main { flex: 1; min-width: 0; }

.prod-name {
  font-size: .875rem;
  line-height: 1.35;
  color: var(--text-primary);
  font-weight: 600;
  text-transform: capitalize;
}

.prod-chips {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.prod-right {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  text-align: right;
}

.prod-qty-line {
  font-size: .6875rem;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---- totales ---- */
.totales { margin-top: 16px; }

.totales-desglose {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 0 4px 12px;
}

.desglose-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .8125rem;
}

.desglose-label { color: var(--text-muted); font-weight: 500; }

.desglose-val {
  color: var(--text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--azul-total);
  padding: 14px 18px;
  border-radius: var(--radius-md);
}

.total-label {
  font-size: .875rem;
  font-weight: 700;
  color: var(--azul-oscuro);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.total-val {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--azul-oscuro);
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

/* ---- footer ---- */
.card-footer {
  padding: 16px 24px;
  text-align: center;
  font-size: .6875rem;
  color: var(--text-soft);
  font-weight: 500;
}

/* =============================================
   PANEL BOLETA
   ============================================= */
.panel-boleta {
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 18px;
}

.boleta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px 11px 20px;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
}

.boleta-bar-title {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--azul-suave);
}

/* Botón de descarga, compacto, arriba en la barra */
.btn-descargar {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: linear-gradient(135deg, #041b54 0%, #0a37b0 100%);
  color: #fff;
  font-size: .75rem;
  font-weight: 700;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 9px;
  box-shadow: 0 3px 10px -4px rgba(4,27,84,.45);
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s;
}
.btn-descargar:hover { transform: translateY(-1px); box-shadow: 0 6px 14px -5px rgba(4,27,84,.5); }
.btn-descargar:active { transform: translateY(0); opacity: .92; }

.boleta-doc {
  padding: 16px;
  background: #f3f5f9;
  flex: 1;
}

/* Documento oficial embebido (PDF en iframe) */
.boleta-frame,
.boleta-img {
  width: 100%;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}
.boleta-frame { height: 620px; }
.boleta-img { height: auto; }

/* ---- Boleta reconstruida (estilo documento SII) ---- */
.dte {
  background: #fff;
  border: 1px solid #e2e6ee;
  border-radius: var(--radius-sm);
  padding: 18px 18px 16px;
  box-shadow: 0 2px 10px -4px rgba(4,27,84,.12);
  font-size: .75rem;
  color: var(--text-primary);
}

.dte-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px dashed #d7dce6;
}

.dte-emisor-nombre {
  font-size: .9375rem;
  font-weight: 800;
  color: var(--azul-oscuro);
  line-height: 1.2;
}

.dte-emisor-dato {
  font-size: .6875rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.35;
}

.dte-rojo {
  flex-shrink: 0;
  border: 2px solid var(--sii);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
  color: var(--sii);
  min-width: 132px;
}

.dte-rojo .rut {
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .01em;
}

.dte-rojo .tipo {
  font-size: .625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-top: 3px;
}

.dte-rojo .folio {
  font-size: .8125rem;
  font-weight: 800;
  margin-top: 3px;
}

.dte-rojo .sii-of {
  font-size: .5625rem;
  font-weight: 700;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-top: 5px;
}

.dte-fecha {
  font-size: .6875rem;
  color: var(--text-muted);
  margin: 10px 0 4px;
}

/* Detalle de items dentro de la boleta */
.dte-items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
}

.dte-items th {
  font-size: .5625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-soft);
  text-align: left;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.dte-items th.num { text-align: right; }

.dte-items td {
  font-size: .6875rem;
  padding: 6px 0;
  border-bottom: 1px solid #f1f3f8;
  vertical-align: top;
}
.dte-items td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dte-items tr:last-child td { border-bottom: none; }

.dte-desc { color: var(--text-primary); font-weight: 500; text-transform: capitalize; }

/* Totales de la boleta */
.dte-tot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #d7dce6;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.dte-tot-row {
  display: flex;
  justify-content: space-between;
  font-size: .6875rem;
  color: var(--text-muted);
}
.dte-tot-row span:last-child { font-variant-numeric: tabular-nums; color: var(--text-primary); font-weight: 600; }

.dte-tot-row.total {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: .8125rem;
}
.dte-tot-row.total span { color: var(--azul-oscuro); font-weight: 800; }

/* Timbre electrónico + QR */
.dte-timbre {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed #d7dce6;
  display: flex;
  align-items: center;
  gap: 12px;
}

.dte-qr,
.dte-qr-ph {
  width: 92px;
  height: 92px;
  flex-shrink: 0;
  border-radius: 8px;
  background: #fff;
}
.dte-qr { border: 1px solid var(--border); display: block; }
.dte-qr-ph {
  border: 1.5px dashed var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.dte-timbre-txt {
  font-size: .5625rem;
  color: var(--text-soft);
  line-height: 1.5;
}
.dte-timbre-txt strong { color: var(--text-muted); font-weight: 700; }

/* =============================================
   SKELETON
   ============================================= */
.skeleton-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sk-header { height: 62px; background: linear-gradient(135deg, #041b54, #0a37b0); }
.sk-bar { height: 44px; background: var(--bg-soft); border-bottom: 1px solid var(--border); }

.sk-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sk {
  background: linear-gradient(90deg, #eceef3 25%, #f5f6f9 50%, #eceef3 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
}

.sk-row { height: 14px; }
.sk-block { height: 56px; }

@keyframes shimmer {
  0%   { background-position: 200% 0 }
  100% { background-position: -200% 0 }
}

/* =============================================
   ERROR
   ============================================= */
.error-msg {
  text-align: center;
  padding: 48px 28px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 520px;
  margin: 0 auto;
  animation: fadeUp .4s ease both;
}

.error-icon {
  width: 56px; height: 56px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 1.875rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error-msg h2 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.error-msg p {
  font-size: .8125rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ---- utilidades ---- */
.hidden { display: none !important; }

/* =============================================
   RESPONSIVE
   ============================================= */

/* Una sola columna: la boleta queda debajo del resumen */
@media (max-width: 879px) {
  .panel-boleta { position: static; }
}

@media (max-width: 540px) {
  body { padding: 14px 12px calc(20px + env(safe-area-inset-bottom)); }
  .layout, .skeleton-wrap { gap: 16px; }
  .card-header { padding: 16px 18px; }
  .section { padding: 18px; }
  .card-footer { padding: 16px 18px; }

  /* Bloque de datos: en móvil el detalle de venta va arriba, luego el cliente */
  .doc-top { flex-direction: column-reverse; gap: 12px; }
  .doc-box { width: 100%; min-width: 0; }

  .boleta-doc { padding: 14px; }
  .dte-top { flex-direction: column; }
  .dte-rojo { align-self: flex-start; }
}

/* reduce motion */
@media (prefers-reduced-motion: reduce) {
  .card, .error-msg, .sk { animation: none !important; }
  .btn-descargar { transition: none; }
}

/* =============================================
   PRINT — solo la boleta
   ============================================= */
@media print {
  body { background: #fff; padding: 0; }
  .panel-resumen,
  .boleta-bar,
  .skeleton-wrap { display: none !important; }
  .layout { display: block; }
  .card { box-shadow: none; border-radius: 0; }
  .boleta-doc { padding: 0; background: #fff; }
  .dte { border: none; box-shadow: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
