/* boletas.tyan.cl — estilos propios, sin CDN ni fuentes externas (CSP style-src 'self'). Móvil primero. */
:root {
  --fondo: #f4f5f7;
  --superficie: #ffffff;
  --superficie-suave: #eef1f5;
  --texto: #1b2330;
  --texto-suave: #556070;
  --borde: #d5dbe3;
  --marca: #14365c;
  --marca-texto: #ffffff;
  --acento: #1f5fa8;
  --sii-rojo: #c8102e;
  --ok: #1d7a46;
  --ok-fondo: #e7f5ec;
  --mal: #b3261e;
  --mal-fondo: #fdecea;
  --foco: #f2b705;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #10151c;
    --superficie: #18202a;
    --superficie-suave: #1f2935;
    --texto: #e7ecf2;
    --texto-suave: #a3afbe;
    --borde: #324152;
    --marca: #0d2540;
    --acento: #7fb2ee;
    --sii-rojo: #ff6b7f;
    --ok: #6fd39b;
    --ok-fondo: #12301f;
    --mal: #ff8a80;
    --mal-fondo: #3a1715;
    --sombra: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--acento); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; }
h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
p { margin: 0 0 .75rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.saltar { position: absolute; left: -999px; top: 0; background: var(--superficie); padding: .5rem 1rem; z-index: 10; }
.saltar:focus { left: 1rem; }

.envoltura { width: 100%; max-width: 44rem; margin: 0 auto; padding: 0 16px; }
main.envoltura { flex: 1; padding-top: 1.25rem; padding-bottom: 2rem; }

/* ---------- cabecera y pie ---------- */
.cabecera { background: var(--marca); color: var(--marca-texto); }
.cabecera .envoltura { padding-top: .75rem; padding-bottom: .75rem; }
.marca { display: inline-flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; }
.marca strong { display: block; letter-spacing: .06em; font-size: 1.05rem; }
.marca small { display: block; opacity: .85; font-size: .85rem; }
.marca-logo {
  display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 8px;
  background: var(--marca-texto); color: var(--marca); font-weight: 800; font-size: 1.15rem;
}
.pie { border-top: 1px solid var(--borde); color: var(--texto-suave); font-size: .875rem; }
.pie .envoltura { padding-top: 1rem; padding-bottom: 1.25rem; }
.pie p { margin: 0 0 .35rem; }

/* ---------- tarjetas ---------- */
.tarjeta {
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 1.25rem 1rem; margin-bottom: 1rem;
}
.tarjeta-suave { background: var(--superficie-suave); box-shadow: none; font-size: .95rem; }
.tarjeta-suave p:last-child { margin-bottom: 0; }
.intro { color: var(--texto-suave); }

/* ---------- formulario ---------- */
.formulario { display: grid; gap: 1rem; margin-top: 1rem; }
.campo label { display: block; font-weight: 600; margin-bottom: .3rem; }
.campo input, .campo select {
  width: 100%; font: inherit; font-size: 1rem; color: var(--texto); background: var(--superficie);
  border: 1px solid var(--borde); border-radius: 8px; padding: .65rem .75rem; min-height: 2.9rem;
}
.campo input[aria-invalid="true"], .campo select[aria-invalid="true"] { border-color: var(--mal); border-width: 2px; }
.ayuda { color: var(--texto-suave); font-size: .85rem; margin: .3rem 0 0; }
.error { color: var(--mal); font-size: .9rem; font-weight: 600; margin: .3rem 0 0; }

.aviso { border-radius: 8px; padding: .75rem 1rem; margin: 1rem 0 0; border: 1px solid; }
.aviso p { margin: 0; }
.aviso-error { background: var(--mal-fondo); border-color: var(--mal); color: var(--texto); }

.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: .7rem 1.1rem; min-height: 2.9rem; border-radius: 8px;
  border: 1px solid var(--acento); background: transparent; color: var(--acento);
}
.boton-primario { background: var(--acento); color: var(--superficie); }
.boton:hover { filter: brightness(1.08); }

/* ---------- boleta ---------- */
.volver { margin-bottom: .75rem; }
.boleta-cabecera { display: grid; gap: 1rem; margin-bottom: 1rem; }
.boleta-emisor p { margin: 0; color: var(--texto-suave); font-size: .9rem; }
.boleta-emisor .emisor-nombre { color: var(--texto); font-weight: 700; font-size: 1.05rem; }
.boleta-recuadro {
  border: 2px solid var(--sii-rojo); color: var(--sii-rojo); border-radius: 4px;
  padding: .75rem; text-align: center; font-weight: 700;
}
.boleta-recuadro p, .boleta-recuadro h1 { margin: 0; color: inherit; }
.boleta-recuadro h1 { font-size: 1rem; margin: .2rem 0; }
.boleta-recuadro .folio { font-size: 1.15rem; }

.datos { display: grid; gap: .5rem; margin: 0 0 1rem; }
.datos div { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px dashed var(--borde); padding-bottom: .35rem; }
.datos dt { color: var(--texto-suave); }
.datos dd { margin: 0; font-weight: 600; text-align: right; }

.tabla-envoltura { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.detalle th, .detalle td { padding: .5rem 0; border-bottom: 1px solid var(--borde); vertical-align: top; text-align: left; }
.detalle th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-suave); }
.item-nombre { display: block; }
.item-detalle { display: block; font-size: .85rem; color: var(--texto-suave); }
.num { text-align: right !important; white-space: nowrap; padding-left: 1rem; font-variant-numeric: tabular-nums; }
.totales { margin: .75rem 0 .5rem auto; max-width: 20rem; }
.totales th { text-align: left; font-weight: 500; color: var(--texto-suave); padding: .2rem 0; }
.totales td { padding: .2rem 0; }
.totales .total th, .totales .total td { color: var(--texto); font-weight: 800; font-size: 1.15rem; border-top: 2px solid var(--texto); padding-top: .45rem; }
.leyenda { font-size: .85rem; color: var(--texto-suave); text-align: right; }

.validacion { border-radius: 8px; padding: .9rem 1rem; margin: 1rem 0; border: 1px solid; }
.validacion h2 { font-size: 1rem; }
.validacion ul { list-style: none; margin: 0 0 .5rem; padding: 0; }
.validacion li { font-weight: 600; }
.validacion li.ok { color: var(--ok); }
.validacion li.mal { color: var(--mal); }
.validacion .ayuda { margin: 0; }
.validacion-ok { background: var(--ok-fondo); border-color: var(--ok); }
.validacion-mal { background: var(--mal-fondo); border-color: var(--mal); }

.acciones { display: grid; gap: .6rem; }

@media (min-width: 640px) {
  h1 { font-size: 1.6rem; }
  .tarjeta { padding: 1.5rem; }
  .formulario { grid-template-columns: 1fr 1fr; }
  .formulario .campo:first-child, .formulario .boton { grid-column: 1 / -1; }
  .formulario .boton { justify-self: start; }
  .boleta-cabecera { grid-template-columns: 1fr 15rem; align-items: start; }
  .acciones { grid-template-columns: repeat(3, auto); justify-content: start; }
}

@media print {
  .cabecera, .pie, .volver, .acciones, .tarjeta-suave { display: none; }
  body { background: #fff; color: #000; }
  .tarjeta { border: 0; box-shadow: none; }
}
