/* Facturación de carpintería · «Plano de taller»
   Papel de dibujo con grano, líneas finas de delineante, rótulos en mono,
   titulares de grotesca en mayúsculas y un único acento rojo de marcador. */

:root {
  --paper: #efeee9;
  --paper-2: #f6f5f1;
  --sheet: #fdfdfb;
  --ink: #262624;
  --ink-2: #4b4b48;
  --muted: #72726f;
  --line: #b5b5af;
  --line-soft: #d9d8d1;
  --accent: #fa3600;
  --accent-ink: #c42a00;
  --accent-soft: #fde3d9;
  --ok: #2c6a45;
  --ok-soft: #dfeadf;
  --warn: #85590e;

  --sans: "Geist", "Helvetica Neue", Arial, system-ui, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --side: 264px;
  --gap: 8px;
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .15 0 0 0 0 .15 0 0 0 0 .13 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --ease: cubic-bezier(.2, .7, .1, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--sans);
  color: var(--ink);
  background: var(--paper) var(--grain);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent); color: #fff; }
h1, h2, h3 { font-family: var(--sans); color: var(--ink); margin: 0 0 .6em; }
h1 { font-size: clamp(2rem, 3.4vw, 2.9rem); font-weight: 700; line-height: .95; letter-spacing: -.035em; text-transform: uppercase; }
h2 { font-size: 1.15rem; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .9em; }
a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-ink); }
code { font-family: var(--mono); font-size: .86em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 99; background: var(--ink); color: #fff; padding: .6rem 1rem; font-family: var(--mono); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .84rem; color: var(--muted); }
.mt { margin-top: 1rem; }
.strong { font-weight: 600; }
.num { text-align: right; white-space: nowrap; font-family: var(--mono); font-size: .92em; letter-spacing: -.02em; }

/* Rótulo técnico reutilizable */
.eyebrow, .nav-group, .form-label, .fig-label, .table th, label, legend, .badge, .btn, .inv-label,
.kv dt, .totals dt, .bar-label, .tag, .me-role, .sheet-tag, .cajetin dt {
  font-family: var(--mono);
}

/* ---------- Marco de la lámina ---------- */

.frame { position: fixed; inset: var(--gap); border: 1px solid var(--line); pointer-events: none; z-index: 60; }
.frame i { position: absolute; width: 13px; height: 13px; }
.frame i::before, .frame i::after { content: ""; position: absolute; background: var(--ink); }
.frame i::before { left: 6px; top: 0; width: 1px; height: 13px; }
.frame i::after { top: 6px; left: 0; height: 1px; width: 13px; }
.frame i:nth-child(1) { top: -7px; left: -7px; }
.frame i:nth-child(2) { top: -7px; right: -7px; }
.frame i:nth-child(3) { bottom: -7px; left: -7px; }
.frame i:nth-child(4) { bottom: -7px; right: -7px; }

.coords {
  position: fixed; left: calc(50% + var(--side) / 2); bottom: calc(var(--gap) - 8px); transform: translateX(-50%); z-index: 61;
  font: 10.5px/1 var(--mono); color: var(--muted); letter-spacing: .04em; pointer-events: none;
  background: var(--paper); padding: 3px 6px; border: 1px solid var(--line-soft);
}
.coords b { color: var(--accent-ink); font-weight: 500; }

/* ---------- Estructura ---------- */

.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; padding: var(--gap); }
.side {
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: var(--gap); height: calc(100vh - var(--gap) * 2); overflow-y: auto;
  background: transparent;
}
.brand { display: flex; align-items: stretch; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--line); min-height: 72px; }
.brand-mark { display: grid; place-items: center; width: 72px; border-right: 1px solid var(--line); flex: none; }
.brand-mark .mark { width: 30px; height: 30px; color: var(--ink); transition: transform .5s var(--ease); }
.brand:hover .brand-mark .mark { transform: rotate(-8deg) scale(1.08); }
.brand-text { display: flex; flex-direction: column; justify-content: center; padding: .7rem 1rem; min-width: 0; }
.brand-text strong { font-weight: 700; font-size: 1.15rem; line-height: 1; letter-spacing: -.03em; text-transform: uppercase; }
.brand-text span { font: 10.5px/1.3 var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: .35rem; }
.mark { width: 30px; height: 30px; flex: none; }

.nav-group {
  margin: 0; padding: 1.1rem 1.25rem .45rem; font-size: 10.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em; display: flex; align-items: center; gap: .6rem;
}
.nav-group::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.side nav ul { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line-soft); }
.side nav a {
  position: relative; display: flex; justify-content: space-between; align-items: center; gap: .75rem;
  padding: .62rem 1.25rem; color: var(--ink); text-decoration: none; font-weight: 500; font-size: .94rem;
  border-bottom: 1px solid var(--line-soft); transition: background .18s, color .18s, padding .25s var(--ease);
}
.nav-n { font: 10.5px var(--mono); color: var(--muted); letter-spacing: .02em; }
.side nav a::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 7px; height: 7px; margin-top: -3.5px;
  background: var(--accent); transform: scale(0); transition: transform .25s var(--ease);
}
.side nav a:hover { background: rgba(38, 38, 36, .045); padding-left: 1.6rem; }
.side nav a:hover::before { transform: scale(1); }
.side nav a[aria-current="page"] { background: var(--ink); color: #fff; padding-left: 1.6rem; }
.side nav a[aria-current="page"]::before { transform: scale(1); }
.side nav a[aria-current="page"] .nav-n { color: var(--accent); }

.me { margin-top: auto; border-top: 1px solid var(--line); padding-bottom: .9rem; }
.me .nav-group { padding-top: .8rem; }
.me a { display: block; text-decoration: none; color: var(--ink); padding: .2rem 1.25rem .4rem; }
.me-name { display: block; font-weight: 600; }
.me-role { display: block; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.me a:hover .me-name, .me a[aria-current="page"] .me-name { color: var(--accent-ink); }
.me form { padding: 0 1.25rem; margin: 0; }
.me .linkish { font: 11px var(--mono); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.me .linkish:hover { color: var(--accent-ink); }

.topbar { display: none; }
.main { padding: 0 clamp(1.25rem, 3vw, 3rem) 5rem; min-width: 0; width: 100%; max-width: 1320px; }

/* Cabecera con regla graduada */
.page-head {
  position: relative; display: flex; justify-content: space-between; align-items: flex-end; gap: 1.25rem;
  flex-wrap: wrap; padding: 2.2rem 0 1.6rem; margin-bottom: 2rem;
}
.page-head::after {
  content: ""; position: absolute; left: calc(clamp(1.25rem, 3vw, 3rem) * -1); right: calc(clamp(1.25rem, 3vw, 3rem) * -1); bottom: 0; height: 10px;
  border-bottom: 1px solid var(--line);
  background:
    repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 50px) bottom / 100% 10px no-repeat,
    repeating-linear-gradient(90deg, var(--line-soft) 0 1px, transparent 1px 10px) bottom / 100% 5px no-repeat;
}
.ph-title { min-width: 0; }
.eyebrow {
  display: flex; flex-wrap: wrap; align-items: center; gap: .55rem; margin: 0 0 .95rem;
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
}
.eb-n { color: var(--accent-ink); }
.eb-date::before { content: "/ "; color: var(--line); }
.page-head h1 { margin: 0; animation: rise .7s var(--ease) both; }
.page-head .sub { margin: .8rem 0 0; color: var(--ink-2); max-width: 64ch; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- Paneles (celdas del plano) ---------- */

.main { counter-reset: panel; }
.panel {
  position: relative; background: rgba(253, 253, 251, .55); border: 1px solid var(--line);
  padding: 1.5rem; margin-bottom: 1.5rem; counter-increment: panel;
  animation: rise .6s var(--ease) both;
}
.panel > h2:first-child, .panel > .lines-head:first-child > h2 {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  margin: -1.5rem -1.5rem 1.4rem; padding: .7rem 1.5rem;
  font: 500 11px/1.4 var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.panel > h2:first-child::after { content: "[" counter(panel, decimal-leading-zero) "]"; color: var(--muted); }
.panel > .lines-head:first-child { margin: -1.5rem -1.5rem 1.2rem; padding: .55rem 1.5rem; border-bottom: 1px solid var(--line); align-items: center; }
.panel > .lines-head:first-child > h2 { margin: 0; padding: 0; border: 0; }
.panel h2:not(:first-child) { margin-top: 1.75rem; }
.panel.narrow { max-width: 860px; }
.panel-accent { border-color: var(--ink); box-shadow: 6px 6px 0 var(--accent); background: var(--sheet); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 0 1.5rem; }
.grid-2 > .panel { min-width: 0; }
.main > :nth-child(3) { animation-delay: .05s; }
.main > :nth-child(4) { animation-delay: .1s; }
.main > :nth-child(5), .grid-2 > :nth-child(2) { animation-delay: .15s; }

/* Cifras del inicio */
.figures {
  display: grid; grid-template-columns: repeat(3, 1fr); counter-reset: fig;
  border: 1px solid var(--line); margin-bottom: 1.5rem; background: rgba(253, 253, 251, .55);
}
.figure { position: relative; padding: 1.25rem 1.5rem 1.4rem; counter-increment: fig; animation: rise .6s var(--ease) both; }
.figure:nth-child(2) { animation-delay: .06s; }
.figure:nth-child(3) { animation-delay: .12s; }
.figure + .figure { border-left: 1px solid var(--line); }
.figure::after { content: "[" counter(fig, decimal-leading-zero) "]"; position: absolute; top: 1.25rem; right: 1.5rem; font: 11px var(--mono); color: var(--muted); }
.fig-label { margin: 0 0 1.6rem; color: var(--ink); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.fig-value { margin: 0 0 .35rem; font-weight: 700; font-size: clamp(1.9rem, 3vw, 2.6rem); line-height: 1; letter-spacing: -.045em; }
.fig-note { margin: 0; font-size: .82rem; color: var(--muted); }
.figure.is-alert .fig-value { color: var(--accent-ink); }
.figure.is-alert .fig-note { color: var(--accent-ink); }

/* Gráfico de barras con rayado de sección */
.bars {
  display: grid; grid-template-columns: repeat(12, 1fr); gap: .6rem; height: 200px; align-items: end;
  padding-top: .5rem;
  background: repeating-linear-gradient(0deg, transparent 0 calc(25% - 1px), var(--line-soft) calc(25% - 1px) 25%) 0 0 / 100% calc(100% - 1.6rem) no-repeat;
}
.bar { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; gap: .45rem; }
.bar-fill {
  display: block; min-height: 2px; border: 1px solid var(--ink); border-bottom: 0;
  background: repeating-linear-gradient(-45deg, var(--ink) 0 1px, transparent 1px 6px);
  transform-origin: bottom; animation: grow 1s var(--ease) both;
}
.bar:nth-child(2) .bar-fill { animation-delay: .04s; } .bar:nth-child(3) .bar-fill { animation-delay: .08s; }
.bar:nth-child(4) .bar-fill { animation-delay: .12s; } .bar:nth-child(5) .bar-fill { animation-delay: .16s; }
.bar:nth-child(6) .bar-fill { animation-delay: .2s; } .bar:nth-child(7) .bar-fill { animation-delay: .24s; }
.bar:nth-child(8) .bar-fill { animation-delay: .28s; } .bar:nth-child(9) .bar-fill { animation-delay: .32s; }
.bar:nth-child(10) .bar-fill { animation-delay: .36s; } .bar:nth-child(11) .bar-fill { animation-delay: .4s; }
.bar:nth-child(12) .bar-fill { animation-delay: .44s; }
.bar:hover .bar-fill { background: var(--ink); }
.bar.is-now .bar-fill { background: var(--accent); border-color: var(--accent); }
.bar-label { text-align: center; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-top: 1px solid var(--ink); padding-top: .4rem; }
.bar.is-now .bar-label { color: var(--accent-ink); }

/* ---------- Tablas ---------- */

.table-wrap { overflow-x: auto; background: rgba(253, 253, 251, .55); border: 1px solid var(--line); margin-bottom: 1.5rem; animation: rise .6s var(--ease) both; }
.panel .table-wrap { border: 0; margin-bottom: 1rem; background: transparent; animation: none; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-weight: 500; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); padding: .75rem 1rem; border-bottom: 1px solid var(--ink); white-space: nowrap;
}
.table td { padding: .78rem 1rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover td { background: rgba(250, 54, 0, .045); }
.table tbody tr:hover td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table tfoot td { border-top: 1px solid var(--ink); padding: .85rem 1rem; color: var(--ink); font-weight: 600; }
.table th.num { text-align: right; }
.table.compact td, .table.compact th { padding: .58rem .6rem; }
.table.compact td:first-child, .table.compact th:first-child { padding-left: 0; }
.table.compact tbody tr:hover td:first-child { box-shadow: none; }
.table td a { text-decoration: none; font-weight: 600; }
.table.compact td:first-child, .table td:first-child > a:only-child { white-space: nowrap; }
.table td a:hover { text-decoration: underline; text-decoration-color: var(--accent); }
tr.is-off td { color: var(--muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center; }
.row-actions form { margin: 0; }

.badge {
  display: inline-flex; align-items: center; gap: .4rem; padding: .22rem .5rem .2rem;
  font-size: 10.5px; line-height: 1.2; font-weight: 500; text-transform: uppercase; letter-spacing: .06em;
  border: 1px solid currentColor; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; background: currentColor; flex: none; }
.b-draft { color: var(--muted); border-style: dashed; }
.b-draft::before { background: transparent; border: 1px solid currentColor; }
.b-open { color: var(--ink); }
.b-open::before { background: transparent; border: 1px solid currentColor; }
.b-paid { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.b-late { color: #fff; background: var(--accent-ink); border-color: var(--accent-ink); }
.b-late::before { background: #fff; }
.b-void { color: var(--muted); text-decoration: line-through; }
.tag { font-size: 10.5px; color: var(--muted); border: 1px solid var(--line); padding: .05rem .4rem; margin-left: .35rem; text-transform: uppercase; letter-spacing: .04em; }
.hash { font: .78rem var(--mono); color: var(--ink-2); word-break: break-all; }

/* ---------- Formularios ---------- */

label {
  display: flex; flex-direction: column; gap: .4rem; font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .07em; color: var(--ink-2);
}
input, select, textarea {
  font: 400 15px/1.4 var(--sans); color: var(--ink); text-transform: none; letter-spacing: 0;
  padding: .62rem .75rem; border: 1px solid var(--line); border-radius: 0; background: var(--sheet); width: 100%;
  font-variant-numeric: tabular-nums; transition: border-color .15s, box-shadow .15s;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 2rem;
  background: var(--sheet) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6' fill='none' stroke='%23262624'/%3E%3C/svg%3E") no-repeat right .8rem center;
}
textarea { resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--ink-2); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 3px 3px 0 var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--accent); box-shadow: none; }
.hint { font-family: var(--sans); font-weight: 400; font-size: 12.5px; line-height: 1.4; color: var(--muted); text-transform: none; letter-spacing: 0; }
.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.1rem 1.25rem; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.75rem; padding-top: 1.25rem; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.stack { display: grid; gap: 1rem; max-width: 440px; }
.inline-form { display: flex; gap: .6rem; align-items: flex-end; flex-wrap: wrap; margin: 0; }
.inline-form input { width: auto; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 10.5px; font-weight: 500; color: var(--ink-2); margin-bottom: .45rem; text-transform: uppercase; letter-spacing: .07em; }
.radio-row { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.radio-row legend { width: 100%; }
label.radio, label.check {
  flex-direction: row; align-items: center; gap: .55rem; font: 400 .94rem var(--sans);
  text-transform: none; letter-spacing: 0; color: var(--ink);
}
label.radio input, label.check input { width: 16px; height: 16px; }
label.check { align-self: end; padding-bottom: .65rem; }
.code-input { font: 500 1.5rem var(--mono); letter-spacing: .3em; text-align: center; max-width: 12rem; }

.filters {
  display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1.25rem;
  padding: 1rem; border: 1px solid var(--line); border-bottom-style: dashed; background: rgba(253, 253, 251, .35);
}
.filters + .table-wrap, .filters + .empty { margin-top: -1.25rem; border-top: 0; }
.filters label { min-width: 140px; }
.filters .grow { flex: 1; min-width: 220px; }

/* ---------- Botones ---------- */

.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 42px; padding: 0 1.05rem;
  font-size: 11.5px; font-weight: 500; line-height: 1; text-transform: uppercase; letter-spacing: .07em;
  border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink);
  text-decoration: none; cursor: pointer; white-space: nowrap; overflow: hidden; isolation: isolate;
  transition: color .2s, border-color .2s;
}
.btn::before {
  content: ""; position: absolute; inset: 0; z-index: -1; background: var(--ink);
  transform: scaleY(0); transform-origin: bottom; transition: transform .3s var(--ease);
}
.btn:hover { color: #fff; }
.btn:hover::before { transform: scaleY(1); }
.btn-primary { background: var(--ink); color: #fff; padding-right: 0; }
.btn-primary::before { background: var(--accent-ink); }
.btn-primary::after {
  content: "→"; align-self: stretch; display: grid; place-items: center; width: 42px; margin-left: .6rem;
  background: var(--accent); color: #fff; font: 15px var(--sans); transition: background .2s;
}
.btn-primary:hover::after { background: var(--ink); }
.btn-ghost { border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); }
.btn-ghost::before { background: rgba(38, 38, 36, .08); }
.btn-danger { border-color: var(--accent-ink); color: var(--accent-ink); }
.btn-danger::before { background: var(--accent-ink); }
.btn-block { width: 100%; justify-content: space-between; min-height: 50px; padding-left: 1.2rem; }
.btn-block.btn-primary::after { width: 50px; }
button:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.linkish {
  background: none; border: 0; padding: 0; font: inherit; color: var(--ink); cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px;
}
.linkish:hover { color: var(--accent-ink); }
.icon-btn { background: none; border: 1px solid transparent; font-size: 1.25rem; line-height: 1; padding: .3rem .5rem; color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--accent-ink); border-color: var(--accent-ink); }

/* ---------- Avisos ---------- */

.flash {
  display: flex; gap: .9rem; align-items: baseline; padding: .8rem 1rem; margin: 1.25rem 0 0;
  border: 1px solid; background: var(--sheet); animation: rise .5s var(--ease) both;
}
.main > .flash + .flash { margin-top: .5rem; }
.flash::before { font: 500 10.5px var(--mono); text-transform: uppercase; letter-spacing: .08em; padding: .15rem .45rem; color: #fff; flex: none; }
.flash-ok { border-color: var(--ok); color: var(--ink); }
.flash-ok::before { content: "Hecho"; background: var(--ok); }
.flash-error { border-color: var(--accent-ink); color: var(--ink); }
.flash-error::before { content: "Error"; background: var(--accent-ink); }
.flash-info { border-color: var(--ink); color: var(--ink); }
.flash-info::before { content: "Aviso"; background: var(--ink); }
.empty {
  text-align: center; padding: 3rem 1rem 3.25rem; border: 1px dashed var(--line); background: rgba(253, 253, 251, .35);
  animation: rise .6s var(--ease) both;
}
.empty::before {
  content: ""; display: block; width: 132px; height: 96px; margin: 0 auto 1.25rem;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 132 96' fill='none' stroke='%23262624' stroke-width='1'%3E%3Cpath d='M66 8l46 22-46 22-46-22z'/%3E%3Cpath d='M20 30v36l46 22V52M112 30v36L66 88'/%3E%3Cpath d='M43 41l46-22' stroke-dasharray='3 3' stroke='%2372726f'/%3E%3Cpath d='M58 48l8-4 8 4-8 4z' fill='%23fa3600' stroke='none'/%3E%3Cpath d='M4 92h124' stroke='%23b5b5af'/%3E%3C/svg%3E") center / contain no-repeat;
}
.empty p { color: var(--muted); }

details summary { cursor: pointer; color: var(--ink); }
.inline-details summary { color: var(--ink); text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; list-style: none; }
.inline-details summary::-webkit-details-marker { display: none; }
.inline-details[open] { flex-basis: 100%; }
.inline-details form { margin-top: .5rem; }

.kv { margin: 0 0 .5rem; }
.kv div { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; padding: .55rem 0; border-bottom: 1px dashed var(--line); }
.kv dt { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; }
.kv dd { margin: 0; text-align: right; }

.steps { padding-left: 0; margin: 0; list-style: none; counter-reset: step; }
.steps li { position: relative; margin-bottom: 1.25rem; padding-left: 3rem; counter-increment: step; }
.steps li::before { content: counter(step, decimal-leading-zero); position: absolute; left: 0; top: .1rem; font: 500 11px var(--mono); padding: .2rem .4rem; background: var(--ink); color: #fff; }
.qr { width: 200px; margin: .75rem 0; background: #fff; border: 1px solid var(--ink); box-shadow: 5px 5px 0 var(--accent); }
.qr svg { display: block; width: 100%; height: auto; }
.qr-sm { width: 120px; margin: 0; border: 0; box-shadow: none; }
.secret { display: inline-block; margin-top: .3rem; font: 1rem var(--mono); letter-spacing: .08em; background: var(--sheet); border: 1px dashed var(--line); padding: .35rem .6rem; color: var(--ink); }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, max-content); gap: .5rem 1.75rem; font: 1.05rem var(--mono); }

/* ---------- Editor de factura ---------- */

.lines-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.lines-head h2 { margin: 0; }
.catalog-pick { min-width: min(100%, 420px); }
.table.lines th, .table.lines td { padding: .45rem .35rem; border-bottom: 1px solid var(--line-soft); }
.table.lines tbody tr:hover td { background: transparent; box-shadow: none; }
.table.lines textarea { min-height: 2.6rem; }
.c-desc { min-width: 260px; width: 44%; }
.c-num input { text-align: right; min-width: 80px; font-family: var(--mono); font-size: 14px; }
.c-dto input { text-align: right; min-width: 60px; font-family: var(--mono); font-size: 14px; }
.c-ud select, .c-iva select { min-width: 76px; }
.c-imp { padding-top: 1rem !important; font: 500 .92rem var(--mono); text-align: right; white-space: nowrap; }
.lines + .btn, .table-wrap + .btn { margin-top: .25rem; }
.totals-wrap { display: grid; grid-template-columns: 1fr minmax(280px, 360px); gap: 2rem; margin-top: 1.75rem; align-items: start; }
.totals { margin: 0; border: 1px solid var(--ink); padding: .4rem 1rem 1rem; background: var(--sheet); }
.totals div { display: flex; justify-content: space-between; align-items: baseline; padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.totals dt { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; }
.totals dd { margin: 0; font-family: var(--mono); }
.totals [data-t-ivas] { display: block; padding: 0; border: 0; }
.totals .grand { border-bottom: 0; border-top: 1px solid var(--ink); margin-top: .35rem; padding-top: .8rem; }
.totals .grand dt { color: var(--ink); font-weight: 500; }
.totals .grand dd { font: 700 1.75rem/1 var(--sans); letter-spacing: -.04em; }

/* ---------- Documento de factura ---------- */

.doc-toolbar { padding-top: 1.75rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.invoice {
  background-color: var(--sheet); max-width: 880px; margin: 0 0 1.75rem;
  padding: clamp(1.5rem, 5vw, 3.5rem); border: 1px solid var(--line);
  position: relative; font-size: 14px; box-shadow: 10px 10px 0 rgba(38, 38, 36, .07);
  animation: rise .7s var(--ease) both;
  /* marcas de corte */
  background-image:
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink)),
    linear-gradient(var(--ink), var(--ink)), linear-gradient(var(--ink), var(--ink));
  background-size: 14px 1px, 1px 14px, 14px 1px, 1px 14px, 14px 1px, 1px 14px, 14px 1px, 1px 14px;
  background-position: 10px 10px, 10px 10px, right 10px top 10px, right 10px top 10px,
    left 10px bottom 10px, left 10px bottom 10px, right 10px bottom 10px, right 10px bottom 10px;
  background-repeat: no-repeat;
}
.invoice.is-draft::after, .invoice.is-void::after {
  content: "Borrador"; position: absolute; top: 38%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg);
  font: 800 7rem/1 var(--sans); text-transform: uppercase; letter-spacing: -.05em;
  color: transparent; -webkit-text-stroke: 1.5px rgba(250, 54, 0, .28); pointer-events: none; white-space: nowrap;
}
.invoice.is-void::after { content: "Anulada"; -webkit-text-stroke-color: rgba(38, 38, 36, .25); }
.inv-head { display: flex; justify-content: space-between; gap: 2rem; padding-bottom: 2rem; border-bottom: 1px solid var(--ink); flex-wrap: wrap; }
.inv-brand { display: flex; gap: 1rem; }
.inv-mark { width: 40px; height: 40px; color: var(--ink); }
.inv-company { font: 700 1.6rem/1 var(--sans); text-transform: uppercase; letter-spacing: -.035em; margin: .2rem 0 .6rem; }
.inv-legal { color: var(--ink-2); font-size: .85rem; line-height: 1.55; margin: 0; }
.inv-title { text-align: right; }
.inv-title h2 { font: 700 2.2rem/1 var(--sans); text-transform: uppercase; letter-spacing: -.04em; margin-bottom: .9rem; }
.inv-title dl { margin: 0; font-size: .88rem; }
.inv-title dl div { display: flex; justify-content: flex-end; gap: 1rem; padding: .1rem 0; }
.inv-title dt { color: var(--muted); font: 10.5px/1.9 var(--mono); text-transform: uppercase; letter-spacing: .06em; }
.inv-title dd { margin: 0; min-width: 7.5rem; text-align: right; font-weight: 600; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; padding: 1.75rem 0; }
.inv-label { margin: 0 0 .45rem; font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.inv-client { font: 600 1.15rem/1.3 var(--sans); letter-spacing: -.01em; margin: 0 0 .25rem; }
.inv-lines { width: 100%; border-collapse: collapse; margin-bottom: 1.5rem; }
.inv-lines th { font: 500 10.5px var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); text-align: left; padding: .65rem .4rem; border-bottom: 1px solid var(--ink); }
.inv-lines th.num { text-align: right; }
.inv-lines td { padding: .7rem .4rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.inv-lines td:first-child, .inv-lines th:first-child { padding-left: 0; }
.inv-lines td:last-child, .inv-lines th:last-child { padding-right: 0; }
.inv-foot { display: grid; grid-template-columns: 1fr minmax(260px, 330px); gap: 2rem; align-items: start; }
.inv-notes { font-size: .88rem; color: var(--ink-2); }
.inv-qr { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }
.inv-qr p { margin: 0; }
.inv-totals { width: 100%; border-collapse: collapse; }
.inv-totals th { text-align: left; font: 400 10.5px var(--mono); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: .45rem 0; }
.inv-totals td { padding: .45rem 0; }
.inv-totals .grand th, .inv-totals .grand td { border-top: 1px solid var(--ink); padding-top: .8rem; color: var(--ink); }
.inv-totals .grand td { font: 700 1.6rem/1.1 var(--sans); letter-spacing: -.04em; }
.inv-legalfoot { margin-top: 2.5rem; padding-top: 1rem; border-top: 1px dashed var(--line); font-size: .8rem; color: var(--muted); }
.inv-legalfoot p { margin: 0 0 .3rem; }
.meta { max-width: 880px; }

/* ---------- Acceso: lámina + formulario ---------- */

.auth {
  display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(380px, 1fr);
  min-height: 100vh; padding: var(--gap); gap: 0;
}
.auth-panel {
  position: relative; display: grid; grid-template-rows: auto 1fr auto; min-height: calc(100vh - var(--gap) * 2);
  border: 1px solid var(--line); overflow: hidden;
}
.auth-panel::before { /* cuadrícula de dibujo */
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: .55;
  background:
    linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0 / 40px 40px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 48%, #000 30%, transparent 85%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 48%, #000 30%, transparent 85%);
}
.sheet-top { position: relative; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 1px solid var(--line); padding: 0 1.25rem 0 0; min-height: 56px; }
.sheet-top .brand-sm { align-self: stretch; padding: 0 1.25rem; border-right: 1px solid var(--line); }
.brand-sm { display: inline-flex; align-items: center; gap: .7rem; color: var(--ink); text-decoration: none; font-weight: 700; text-transform: uppercase; letter-spacing: -.03em; font-size: 1.05rem; }
.brand-sm .mark { width: 24px; height: 24px; }
.sheet-tag { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.drawing { position: relative; display: grid; place-items: center; padding: clamp(1rem, 3vw, 2.5rem); min-height: 0; }
.elev { width: min(100%, 760px); height: auto; max-height: 62vh; overflow: visible; }
.elev .ln path { fill: none; stroke: var(--ink); stroke-width: 1.4; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.6s var(--ease) forwards; }
.elev .ln.thin path { stroke-width: .8; }
.elev .ln.dash path { stroke-width: .6; stroke: var(--muted); }
.elev .ln.hatch path { stroke-width: .5; stroke: var(--muted); }
.elev .ln-floor path { stroke-width: 1; animation-duration: 1.1s; }
.elev .ln-a path { animation-delay: .25s; }
.elev .ln-b path { animation-delay: .75s; }
.elev .ln-c path { animation-delay: 1.25s; }
.elev .dim path { fill: none; stroke: var(--muted); stroke-width: .6; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.2s var(--ease) 1.5s forwards; }
.elev text { font: 500 9.5px var(--mono); fill: var(--ink-2); text-anchor: middle; letter-spacing: .04em; opacity: 0; animation: fade .6s ease 2s forwards; }
.elev .dim-total { font-size: 10.5px; fill: var(--accent-ink); }
.elev .note path { fill: none; stroke: var(--accent); stroke-width: .8; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw .9s var(--ease) 2.2s forwards; }
.elev .note circle { fill: none; stroke: var(--accent); stroke-width: .8; opacity: 0; animation: fade .4s ease 2.3s forwards; }
.elev .note rect { fill: var(--accent); opacity: 0; animation: fade .3s ease 2.4s forwards; }
.elev .note text { text-anchor: start; fill: var(--ink); animation-delay: 2.6s; }
@property --pct { syntax: "<integer>"; inherits: true; initial-value: 0; }
.scan { --pct: 0; position: absolute; left: 0; right: 0; top: 12%; height: 0; border-top: 1px solid var(--accent); animation: scan 2.4s var(--ease) .1s both; pointer-events: none; }
.scan span { position: absolute; left: 1.25rem; bottom: 4px; font: 10.5px var(--mono); color: var(--accent-ink); counter-reset: pct var(--pct); }
.scan span::after { content: counter(pct) "%"; }

.sheet-foot { position: relative; display: flex; justify-content: space-between; align-items: flex-end; gap: 2rem; border-top: 1px solid var(--line); }
.auth-name {
  margin: 0; padding: 1.4rem 1.25rem 1.25rem; font: 700 clamp(1.8rem, 3.6vw, 3.1rem)/.92 var(--sans);
  text-transform: uppercase; letter-spacing: -.045em; color: var(--ink);
  animation: rise .9s var(--ease) .4s both;
}
.cajetin { margin: 0; align-self: stretch; min-width: 300px; border-left: 1px solid var(--line); font-size: 11px; }
.cajetin div { display: grid; grid-template-columns: 6.5rem 1fr; border-bottom: 1px solid var(--line-soft); }
.cajetin div:last-child { border-bottom: 0; }
.cajetin dt { padding: .4rem .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; font-size: 10px; border-right: 1px solid var(--line-soft); }
.cajetin dd { margin: 0; padding: .4rem .75rem; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .03em; }
.cajetin div:first-child dd { color: #fff; background: var(--ink); }

.auth-form { display: flex; align-items: center; justify-content: center; padding: 2.5rem clamp(1.25rem, 4vw, 3.5rem); border: 1px solid var(--line); border-left: 0; }
.card-auth { width: 100%; max-width: 380px; display: grid; gap: 1.1rem; animation: rise .8s var(--ease) .2s both; }
.form-label {
  display: flex; align-items: center; gap: .6rem; margin: 0 0 .4rem; padding: .45rem .7rem;
  background: var(--ink); color: #fff; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; width: max-content;
}
.form-label span { color: var(--accent); }
.card-auth h1 { margin: 0; font-size: clamp(2.4rem, 4vw, 3.4rem); }
.card-auth .muted { margin: -.3rem 0 .6rem; }
.card-auth .flash { margin: 0; }
.card-auth .code-input { max-width: none; }
.card-auth .btn-block { margin-top: .4rem; }

/* ---------- Animaciones ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes grow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fade { to { opacity: 1; } }
@keyframes scan {
  0% { top: 12%; --pct: 0; opacity: 1; }
  80% { top: 86%; --pct: 100; opacity: 1; }
  100% { top: 86%; --pct: 100; opacity: 0; }
}

/* ---------- Móvil ---------- */

@media (max-width: 960px) {
  :root { --gap: 0px; }
  .frame, .coords { display: none; }
  .app { grid-template-columns: 1fr; padding: 0; }
  .side {
    position: fixed; inset: 0 auto 0 0; top: 0; height: 100vh; width: 284px; z-index: 50;
    background: var(--paper) var(--grain); transform: translateX(-100%); transition: transform .3s var(--ease);
  }
  .side.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(38, 38, 36, .4); }
  .topbar {
    display: flex; align-items: stretch; justify-content: space-between; position: sticky; top: 0; z-index: 40;
    background: var(--paper) var(--grain); border-bottom: 1px solid var(--line); min-height: 54px;
  }
  .topbar .brand-sm { padding: 0 1rem; }
  .menu-btn {
    background: var(--ink); border: 0; color: #fff; font: 500 11px var(--mono); text-transform: uppercase; letter-spacing: .08em;
    padding: 0 1.25rem; cursor: pointer;
  }
  .menu-btn::after { content: " ☰"; color: var(--accent); }
  .main { padding: 0 1rem 4rem; }
  .page-head::after { left: -1rem; right: -1rem; }
  .figures { grid-template-columns: 1fr; }
  .figure + .figure { border-left: 0; border-top: 1px solid var(--line); }
  .fig-label { margin-bottom: .9rem; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .span-3, .span-4 { grid-column: 1 / -1; }
  .totals-wrap, .inv-foot, .inv-parties { grid-template-columns: 1fr; }
  .inv-title { text-align: left; }
  .inv-title dl div { justify-content: flex-start; }
  .inv-title dd { text-align: left; }
  .auth { grid-template-columns: 1fr; padding: 0; }
  .auth-panel { min-height: 0; border: 0; border-bottom: 1px solid var(--line); }
  .drawing { padding: 1rem .5rem; }
  .elev { max-height: 34vh; }
  .cajetin { display: none; }
  .auth-name { font-size: 1.6rem; padding: 1rem; }
  .auth-name br { display: none; }
  .auth-form { border: 0; padding: 2rem 1.25rem 3rem; }
  .codes { grid-template-columns: repeat(2, max-content); }
  .bars { gap: .3rem; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: 1 / -1; }
  .sheet-tag { display: none; }
  .bar-label { font-size: 9px; letter-spacing: 0; }
}
@media (hover: none) { .coords { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0s !important; transition: none !important; }
  .scan { display: none; }
}

/* ---------- Impresión ---------- */

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .app { display: block; padding: 0; }
  .side, .topbar, .no-print, .flash, .page-head .actions, .skip, .frame, .coords { display: none !important; }
  .page-head::after { display: none; }
  .main { padding: 0; max-width: none; }
  * { animation: none !important; }
  .invoice { border: 0; padding: 0; max-width: none; margin: 0; box-shadow: none; background-image: none; }
  .invoice .inv-lines tr { break-inside: avoid; }
  .panel-accent { border: 1px solid #000; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
}
