* { box-sizing: border-box; }

:root{
  --font-family: "AppSans", "Geist Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --text-2xs: 0.6875rem;
  --text-xs: 0.8125rem;
  --text-sm: 0.9375rem;
  --text-base: 1rem;
  --text-md: 1.0625rem;
  --text-lg: 1.25rem;
  --text-xl: 1.3125rem;
  --text-2xl: 1.5rem;
  --fw-normal: 450;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  --bg: #fafafa;
  --card-bg: #fff;
  --text: #0d1f1c;
  --text-secondary: #4b5e5b;
  --muted: #3d524f;
  --border: rgba(13, 31, 28, 0.08);
  --border-strong: rgba(13,31,28,.14);
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --focus: rgba(99,102,241,.22);
  --radius: 14px;
  --shadow: 0 10px 30px rgba(13,31,28,.06);
  --label-color: #2d3d3a;

  --concept-cols: 120px minmax(260px, 2.2fr) minmax(220px, 1.6fr) 170px 140px 260px 44px;
  --sidebar-w: 260px;
  --main-pad: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body{ background: var(--bg); }

body{
  font-family: var(--font-family);
  margin: 0;
  padding: 0;
  color: var(--text);
  font-size: var(--text-base);
  font-weight: var(--fw-normal);
  line-height: var(--leading-body, 1.55);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* clip: no crea scroll container (hidden sí, y rompía el sticky del topbar) */
  overflow-x: hidden;
  overflow-x: clip;
}

h2{ font-size: var(--text-2xl); font-weight: var(--fw-semibold); letter-spacing: -0.02em; margin: 8px 0 6px; }
h3{ font-size: var(--text-md); font-weight: var(--fw-semibold); margin: 0 0 10px; }

/* P31: contenedores flex/grid con min-width:0 para evitar overlap/overflow */
/* P30: sin scroll horizontal en body/wrapper; tablas solo en .table-wrap / .items */
.row{ display: grid; grid-template-columns: 1fr 1fr; gap: 14px; min-width: 0; }
.row > div{ min-width: 0; }
.app-content{ min-width: 0; max-width: 100%; overflow-x: hidden; }
.app-header{ min-width: 0; }
.tax-global-card{ min-width: 0; }
.tax-global-row{ min-width: 0; }
form{ min-width: 0; max-width: 100%; }

/* ----- 04 IVA + 05 Retenciones: una hilera (desktop), 2 filas (mobile); P31 no-overlap ----- */
.tax-global-card__head{
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 6px;
  min-width: 0;
}
.tax-global-card__title2{
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--muted);
}
.tax-global-card__intro{
  margin: 0 0 8px;
  font-size: var(--text-xs);
}
.tax-global-row{
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: flex-end;
}
.tax-global-field{
  flex: 0 0 auto;
  min-width: 0;
}
.tax-global-field__label{
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted);
  margin-bottom: 6px;
}
.tax-global-field__input{
  width: 100%;
  max-width: 160px;
  min-width: 120px;
  height: 40px;
  padding: 8px 10px;
  font-size: var(--text-sm);
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: #fff;
  box-sizing: border-box;
}
.tax-global-field__input:focus{
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}
/* P31: IVA/Retenciones móvil: 2 filas (grid 2 cols), sin overflow ni body scroll-x */
@media (max-width: 640px){
  .tax-global-row{
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-items: stretch;
    min-width: 0;
  }
  .tax-global-field{ min-width: 0; }
  .tax-global-field__input{ max-width: none; min-width: 0; width: 100%; }
}
/* Móvil muy estrecho: 1 columna para evitar apretar inputs */
@media (max-width: 419px){
  .tax-global-row{ grid-template-columns: 1fr; min-width: 0; }
}

label{ font-size: var(--text-2xs, 0.6875rem); font-weight: var(--fw-semibold); display: block; margin-bottom: 8px; color: var(--label-color, var(--muted)); letter-spacing: var(--ls-wide, 0.04em); text-transform: uppercase; }

/* Tooltip "?" */
.tip{
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--border-strong, rgba(13,31,28,.14));
  color: var(--muted, #3d524f);
  font-size: 10px; font-weight: 600; line-height: 1;
  cursor: help; position: relative; margin-left: 5px;
  vertical-align: middle; text-transform: none; letter-spacing: 0;
  flex-shrink: 0;
}
.tip::after{
  content: attr(data-tip);
  position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%);
  background: var(--text, #0d1f1c); color: #fff;
  padding: 8px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 400; line-height: 1.45;
  width: max-content; max-width: 280px; white-space: normal;
  opacity: 0; pointer-events: none;
  transition: opacity .15s ease;
  z-index: 200;
  text-transform: none; letter-spacing: 0;
}
.tip:hover::after,
.tip:focus::after,
.tip.is-active::after{
  opacity: 1; pointer-events: auto;
}
/* Left-align tooltip when near left edge */
.tip--left::after{ left: 0; transform: none; }
/* Right-align tooltip when near right edge */
.tip--right::after{ left: auto; right: 0; transform: none; }
@media(max-width:600px){
  .tip::after{ max-width: 220px; font-size: 12px; }
}

input, select, textarea{
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  font-size: var(--text-base);
  font-family: var(--font-family);
  line-height: 1.35;
  background: var(--surface, #fff);
  color: var(--text, #0a0a0a);
  min-height: 36px;
  height: 36px;
  box-sizing: border-box;
  transition: box-shadow var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease;
}
html.nightmode input,
html.nightmode select,
html.nightmode textarea {
  background: var(--surface-1, #161b22);
  color: var(--text, #c9d1d9);
}
textarea{
  padding: 8px 12px;
  min-height: 4em;
  height: auto;
  resize: vertical;
}

input:focus, select:focus, textarea:focus{
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}

@media (prefers-reduced-motion: no-preference) {
  input:focus, select:focus, textarea:focus{
    transition: box-shadow var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease;
  }
}

input::placeholder, textarea::placeholder{ color:#94a3b8; }

/* Override Chrome/Edge/Safari autofill: por defecto el browser pinta los
   inputs auto-completados con su propio fondo lavanda/azul Y fuerza el color
   del texto al claro, lo que rompe contraste. Forzamos el fondo y el color
   con un trick: box-shadow inset grueso simula el fondo, y -webkit-text-fill-color
   gana sobre el color del browser. Cubre nightmode también. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface, #fff) inset !important;
  box-shadow: 0 0 0 1000px var(--surface, #fff) inset !important;
  -webkit-text-fill-color: var(--text, #0a0a0a) !important;
  caret-color: var(--text, #0a0a0a);
  transition: background-color 9999s ease-in-out 0s;
}

html.nightmode input:-webkit-autofill,
html.nightmode input:-webkit-autofill:hover,
html.nightmode input:-webkit-autofill:focus,
html.nightmode input:-webkit-autofill:active,
html.nightmode textarea:-webkit-autofill,
html.nightmode select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--surface-1, #161b22) inset !important;
  box-shadow: 0 0 0 1000px var(--surface-1, #161b22) inset !important;
  -webkit-text-fill-color: var(--text, #c9d1d9) !important;
  caret-color: var(--text, #c9d1d9);
}

.card{
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--motion-page, 180ms) ease, border-color var(--motion-page, 180ms) ease;
  overflow: hidden;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  align-self: stretch;
}

/* Fix: los menús de custom-select (.ui-sel__menu = absolute, z-index 320) NO deben
   recortarse por el overflow del card en el formulario de factura. Sin esto, un
   dropdown cerca del borde inferior del card se corta / se encima con la sección
   siguiente (bug reportado). El menú abre por encima con su z-index propio. */
form[data-draft="invoice-form"] .card { overflow: visible; }

/* ── Opción B: UN solo panel contenedor con divisores internos entre secciones,
   en vez de N cards flotando (que se veían poco pro y escondían dropdowns). ── */
form[data-draft="invoice-form"] .form-panel {
  background: var(--card-bg, #fff);
  border: 1px solid var(--border, rgba(0,0,0,0.08));
  border-radius: 16px;
  box-shadow: var(--shadow-1, 0 1px 3px rgba(0,0,0,0.05));
  overflow: visible;
}
/* Las secciones internas dejan de ser cards: sin fondo/borde/sombra/radius propios. */
form[data-draft="invoice-form"] .form-panel > .card {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  height: auto;
  padding: 22px 26px;
  /* Sin stacking context propio: deja que el menú del select (z-index 320) pinte
     por encima de las secciones siguientes, en vez de empalmarse. */
  will-change: auto;
  transform: none;
}
form[data-draft="invoice-form"] .form-panel > .card:hover {
  transform: none;
  box-shadow: none;
}
/* Divisor fino entre secciones (en vez de bordes de card). */
form[data-draft="invoice-form"] .form-panel > .card + .card {
  border-top: 1px solid var(--divider-row, #F2F1F4);
}
/* Garantía anti-brinco/sombra: NINGUNA card ni botón cambia en hover dentro del
   formulario — ni sube (transform) ni le aparece sombra al borde (box-shadow).
   Se respeta el anillo de la card seleccionada (.is-active). */
form[data-draft="invoice-form"] [class*="card"]:hover:not(:active):not(.is-active),
form[data-draft="invoice-form"] [class*="btn"]:hover:not(:active),
form[data-draft="invoice-form"] .ui-btn:hover:not(:active) {
  transform: none !important;
  box-shadow: none !important;
}
/* Card de concepto (.item-row-top / .concept-block__inner): su clase no lleva
   "card", así que se lista aparte. Sin sombra de "lift" en hover — pero se
   conserva el anillo de foco (:focus-within) cuando escribes dentro. */
form[data-draft="invoice-form"] .item-row-top:hover:not(:focus-within),
form[data-draft="invoice-form"] .concept-block__inner:hover:not(:focus-within) {
  transform: none !important;
  box-shadow: none !important;
}

@media (prefers-reduced-motion: no-preference) {
  .card{ transition: box-shadow var(--motion-page, 180ms) ease, transform var(--motion-page, 180ms) ease, border-color var(--motion-page, 180ms) ease; will-change: transform; }
}

.card:hover{
  border-color: var(--border-strong);
  box-shadow: 0 12px 36px rgba(15,23,42,.08);
}

.items{
  margin-top: 6px;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  min-width: 0;
  max-width: 100%;
}

/* P31: Conceptos con tabla: scroll interno (no body), sticky header; sin body scroll-x */
.items:not(.items--cards){
  max-height: min(60vh, 400px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  min-width: 0;
}
.items:not(.items--cards) .item-head{
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--card-bg);
  box-shadow: 0 1px 0 var(--border);
  min-width: 0;
}

/* Conceptos card layout: cero scroll horizontal, cards en 2 filas */
.items--cards{
  overflow-x: visible;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}

/* Concept rows: contain width, spacing vertical entre filas */
.items .item {
  display: block;
  min-width: 0;
  max-width: 100%;
  margin-bottom: 10px;
}
.items--cards .item{
  margin-bottom: 0;
}
.items .item:last-child{ margin-bottom: 0; }

/* ----- Concept card: 2-row layout (Cant/Desc/Precio | ProdServ/Unidad/Desc%) ----- */
.conceptos-card{ min-width: 0; }
.concept-block__inner{
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  transition: border-color var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease;
  min-width: 0;
}
.concept-block__inner:hover{
  border-color: var(--border-strong);
  box-shadow: 0 10px 30px rgba(15,23,42,.06);
}
.concept-block__inner:focus-within{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}
.concept-block__row-actions{ margin-top: 10px; }

.concept-card__row{
  display: grid;
  gap: 8px 12px;
  align-items: center;
  min-width: 0;
}
.concept-card__row1{
  grid-template-columns: 72px 1fr 120px auto;
}
.concept-card__row2{
  grid-template-columns: 1fr minmax(0, 180px) 72px;
}

.concept-card__row .field{
  min-width: 0;
}
.concept-card__qty input{ text-align: center; }
.concept-card__price{ justify-self: end; }
.concept-card__remove{ justify-self: end; }

/* ProdServ: icon button inside field (no scroll) */
.prodserv-wrap--inline{
  width: 100%;
  min-width: 0;
}
.prodserv-wrap--inline .prodserv-input{
  position: relative;
  display: flex;
  align-items: center;
  min-width: 0;
}
.prodserv-wrap--inline .prodserv-input input{
  padding-right: 46px;
  width: 100%;
  min-width: 0;
}
.prodserv-wrap--inline .prodservBtn{
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  border-radius: 10px;
  border: none;
  background: rgba(0,0,0,.06);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.prodserv-wrap--inline .prodservBtn:hover{
  background: rgba(0,0,0,.10);
  color: var(--text);
}

/* Eliminar button: icon + label */
.btn-remove-concept{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  white-space: nowrap;
}
.btn-remove-concept:hover{
  border-color: #fca5a5;
  background: #fef2f2;
  color: #b91c1c;
}
.btn-remove-concept .icon{ flex-shrink: 0; }

.conceptos-actions{
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

/* Unify input/select height inside concept block (igual que Comprobante) */
.conceptos-card .concept-block__inner .row input,
.conceptos-card .concept-block__inner .row select,
.conceptos-card .concept-block__inner .price-wrap{
  min-height: 44px;
  height: 44px;
}
.conceptos-card .concept-block__inner .price-wrap input{ height: 100%; }
.conceptos-card .concept-block__inner .prodserv-wrap--inline .prodserv-input input{ min-height: 44px; height: 44px; }
.conceptos-card .concept-block__inner .unit-wrap select,
.conceptos-card .concept-block__inner .unit-wrap input.unitOther{ min-height: 44px; height: 44px; }

.conceptos-card .item-head{ display: none; }

.muted{ color: var(--muted); font-size: var(--text-xs); }
.danger { color: #b00020; font-weight: var(--fw-semibold); }
.hidden { display: none; }

button{
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-family);
  font-size: var(--text-base);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: transform var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease, background var(--motion-micro, 150ms) ease;
}

button:hover{
  background: var(--primary-hover);
  box-shadow: none;
}

button:active{
  box-shadow: none;
}
@media (prefers-reduced-motion: no-preference) {
  button:active{ transform: translateY(0) scale(0.98); }
}
button:focus-visible{
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

/* ===== Conceptos layout (alineado con las filas de abajo como “Genera tu factura”) ===== */
.item-head{
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  color: var(--muted);
  display: grid;
  grid-template-columns: var(--concept-cols);
  gap: 14px;
  align-items: center;
  padding: 8px 12px 10px;
  min-width: 0;
}

.item-head > div,
.item-head-bottom > div{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.btn-secondary{
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border-strong);
  font-weight: 700;
  transition: background var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease;
}
.btn-secondary:hover{
  filter: brightness(.98);
  border-color: var(--border);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .08);
}
.btn-secondary:focus-visible{
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}
@media (prefers-reduced-motion: no-preference) {
  .btn-secondary{ transition: background var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease, transform var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease; }
  .btn-secondary:active{ transform: translateY(0) scale(0.98); }
}
.btn-secondary:active{
  box-shadow: none;
}

.pill{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  color: var(--muted);
  background: #f8fafc;
  transition: transform var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease, background var(--motion-micro, 150ms) ease;
}
.pill:empty{ min-width: 2ch; }

.cust-item { display:flex; align-items:flex-start; gap:10px; padding:8px 8px; border-radius:8px; }
.cust-item:hover { background:#fafafa; }
.cust-meta { font-size:12px; color:#444; }
.cust-sub { font-size:12px; color:#666; margin-top:2px; }
.cust-check { width:auto; margin-top:2px; }

details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▶"; display:inline-block; margin-right:8px; transition: transform var(--motion-micro, 150ms) ease; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary { user-select:none; }

.unit-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}
.unit-wrap select,
.unit-wrap input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.unit-wrap select {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.unit-back { font-size:12px; color:#2b6; text-decoration:none; }
.unit-back:hover { text-decoration:underline; }

/* ====== Conceptos: retenciones abajo + buscador ProdServ ====== */
.item-row { display:block; }
/* Ensure legacy .item styles never override the new layout */
.item.item-row { display:block !important; }

.item-row-top{
  display: grid;
  grid-template-columns: var(--concept-cols);
  gap: 14px;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}
/* Override for concept block: mismo patrón que Comprobante (row + label arriba) */
.conceptos-card .item-row-top.concept-block__inner{
  display: block;
  grid-template-columns: unset;
}
.conceptos-card .concept-block__inner .row{
  margin-top: 0;
}
.conceptos-card .concept-block__inner .row + .row{
  margin-top: 12px;
}
.conceptos-card .concept-block__inner .row:first-child{
  margin-top: 0;
}

/* Unificar altura y borde de inputs/selects/botón buscar en Conceptos */
.item-row-top .field input,
.item-row-top .field select,
.item-row-top .price-wrap input,
.item-row-top .prodserv-input input{
  min-height: 44px;
  height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  box-sizing: border-box;
}
.item-row-top .prodservBtn{
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  flex-shrink: 0;
}

/* Each concept cell wrapper – contain so select/inputs don't overflow card */
.field{
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

/* Hide mobile labels by default (desktop) */
.field::before{ content:""; display:none; }

/* Allow grid children to shrink properly (prevents overflow/collapsing) */
.item-row-top > *,
.item-row-bottom > *,
.item-head > *{ min-width: 0; }

/* Ensure the remove (✕) button stays compact */
.item-row-top .removeItemBtn{
  width:44px;
  height:44px;
  padding:0;
  border-radius:12px;
  background:#fff;
  color:#0f172a;
  border:1px solid var(--border-strong);
  font-weight:900;
}
.item-row-top .removeItemBtn:hover{ background:#f8fafc; }

.small-head{ font-size:12px; }

.mini-label{
  display:block;
  font-size:12px;
  margin:0 0 6px;
}

.ret-wrap{ justify-self:start; }
.ret-wrap select{ max-width:180px; height:44px; }

/* $ prefijo en Precio unitario (P31: min-width 0 para no overlap) */
.price-wrap{
  display:flex;
  align-items:center;
  border:1px solid var(--border-strong);
  border-radius:12px;
  padding:0 12px;
  height:44px;
  background:#fff;
  min-width: 0;
}
.price-prefix{ font-weight:700; margin-right:8px; opacity:.8; }
.price-wrap input{
  border:0 !important;
  outline:none;
  height:42px;
  width:100%;
  padding:0 !important;
  background:transparent;
}

/* ProdServ grid alignment fix */
.prodserv-wrap{ width:100%; }
.prodserv-input{ display:flex; gap:8px; align-items:center; min-width:0; }
.prodserv-input > input{ flex:1 1 auto; }
.prodservBtn{
  flex: 0 0 44px;
  height: 44px;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 12px;
  border:1px solid var(--border-strong);
  background:#f7f7f7;
  color: var(--text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:0;
  font-weight:900;
}
.prodservBtn:hover{ background:#f3f4f6; }

/* Modal ProdServ (form): namespace .form-modal para no colisionar con .modal del portal) */
.form-modal{ position:fixed; inset:0; z-index: var(--z-modal, 400); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.form-modal__backdrop{ position:absolute; inset:0; background:rgba(0,0,0,.35); cursor:pointer; }
.form-modal__panel{
  position: relative;
  width: min(860px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-width: 100%;
  margin: 60px auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--border);
  overflow: hidden;
  min-width: 0;
}
.form-modal__head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding:16px;
  border-bottom:1px solid var(--border);
}
.form-modal__title{ font-weight:700; font-size:16px; }
.form-modal__close{
  height:40px;
  width:40px;
  min-width:44px;
  min-height:44px;
  border-radius:12px;
  border:1px solid var(--border-strong);
  background:#fff;
  color: var(--text);
  cursor:pointer;
  padding:0;
  font-weight:900;
  display:inline-flex;
  align-items:center;
  justify-content:center;
}
.form-modal__close:hover{ background:#f8fafc; }

.form-modal__body{ padding:16px; }
.form-modal__input,
#prodservModalInput{
  width:100%;
  height:44px;
  min-height:44px;
  border-radius:12px;
  border:1px solid var(--border-strong);
  padding:0 14px;
}
.form-modal__results{
  margin-top:12px;
  max-height:420px;
  overflow:auto;
  -webkit-overflow-scrolling: touch;
  border:1px solid var(--border);
  border-radius:12px;
}
.form-modal__results .result-row{
  width:100%;
  display:grid;
  grid-template-columns:130px 1fr;
  gap:12px;
  text-align:left;
  padding:14px 12px;
  min-height:48px;
  border:0;
  background:#fff;
  cursor:pointer;
  color: var(--text);
}

.form-modal__results .result-row + .result-row{ border-top:1px solid var(--border); }

.form-modal__results .result-row:hover{
  background:#fff;
  filter:brightness(0.98);
}

.result-code{ font-weight:700; }
.result-desc{ color:#333; }

/* Form modal: móvil */
@media (max-width: 768px){
  .form-modal__panel{
    width: min(100%, calc(100vw - 24px - var(--safe-left) - var(--safe-right)));
    margin: calc(20px + env(safe-area-inset-top, 0)) auto 20px;
    max-height: calc(100vh - 40px - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
    max-height: calc(100dvh - 40px - env(safe-area-inset-top, 0) - env(safe-area-inset-bottom, 0));
    display:flex;
    flex-direction:column;
  }
  .form-modal__body{
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex:1;
    min-height:0;
  }
  .form-modal__results{ max-height: 50vh; }
  .form-modal__results .result-row{
    grid-template-columns: 1fr;
    gap: 4px;
    padding: 12px;
  }
}

@media (max-width: 520px){
  .row{ grid-template-columns: 1fr; }
  .app-content{ padding-left: calc(12px + var(--safe-left)); padding-right: calc(12px + var(--safe-right)); }
  .app-header{ padding-left: 12px; padding-right: 12px; flex-wrap: wrap; }
}

/* Responsive: reflow Conceptos instead of horizontal scroll */
@media (max-width:1200px){
  /* Switch from “table headers” to per-field labels */
  .item-head{ display:none; }

  .item-row-top{
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: start;
    gap: 14px;
  }

  .field{
    display:flex;
    flex-direction:column;
    gap:6px;
  }

  .field::before{
    content: attr(data-label);
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--muted);
  }

  .field[data-label=""]::before{ display:none; }

  /* Keep remove button neat inside a grid cell */
  .field[data-label=""]{
    align-items:flex-end;
    justify-content:flex-end;
  }
}

@media (max-width: 1024px){
  .item-row-top{ grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
}

@media (max-width: 768px){
  .item-row-top{ grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
}

@media (max-width: 520px){
  .item-row-top{ grid-template-columns: 1fr; gap: 16px; }
  .item-row-top .field[data-label=""]{ align-items: stretch; justify-content: center; }
}

/* Concept card: stacked on mobile (cero scroll, tarjeta vertical) */
@media (max-width: 768px){
  .concept-card__row1{
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .concept-card__row2{
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .concept-card__price{ justify-self: stretch; }
  .concept-card__remove{ justify-self: stretch; }
  .concept-card__row .field::before{
    content: attr(data-label);
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 4px;
  }
  .concept-card__row .field[data-label=""]::before{ display: none; }
}

@media (max-width: 480px){
  .btn-remove-concept__label{ display: none; }
  .btn-remove-concept{ padding: 10px 12px; min-height: 44px; min-width: 44px; }
}

/* Form crear factura: móvil 390–480px — secciones apiladas, conceptos en card, botones táctiles */
@media (max-width: 480px){
  .app-content{ padding-left: calc(12px + var(--safe-left)); padding-right: calc(12px + var(--safe-right)); }
  .action-bar .btn-primary,
  .action-bar .btn,
  .sticky-action-card .btn{ min-height: 44px; }
  .concept-card,
  .item-row-top{ padding: 14px; }
}

/* 390px demo: conceptos en cards, IVA/retenciones compactos, botones 44px */
@media (max-width: 390px){
  .action-bar .btn-primary,
  .action-bar .btn,
  .sticky-action-card .btn,
  .btn-primary{ min-height: 44px; padding-top: 12px; padding-bottom: 12px; }
  .concept-card,
  .items--cards .item{ padding: 12px; }
  .tax-global-card__head{ margin-bottom: 4px; }
  .tax-global-row{ gap: 8px 12px; }
  .tax-global-field__label{ font-size: 11px; margin-bottom: 4px; }
  .tax-global-field__input{ height: 38px; padding: 6px 10px; font-size: var(--text-xs); max-width: none; }
  .conceptos-card .concept-block__inner .row input,
  .conceptos-card .concept-block__inner .row select,
  .conceptos-card .concept-block__inner .price-wrap{ min-height: 40px; }
}

/* ===== App header (P31: min-width 0 para no overlap) ===== */
.app-header{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:14px;
  padding:14px 16px;
  margin: 12px auto 12px;
  max-width: 1100px;
  min-width: 0;
}
.app-header__left,
.app-header__right{
  min-width: 0;
}
.app-header__right{
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-title{
  font-size: var(--text-xl, 1.375rem);
  font-weight: var(--fw-semibold, 600);
  letter-spacing: var(--ls-tight, -0.03em);
}

.app-subtitle{
  margin-top: 4px;
  font-size: var(--text-2xs, 0.75rem);
  font-weight: var(--fw-medium, 500);
  opacity: 0.85;
}

.status-pill{
  display:inline-flex;
  align-items:center;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:700;
  border:1px solid rgba(0,0,0,.08);
  background: rgba(0,0,0,.03);
}

/* ===== Main container (boundaries: no tocar bordes de pantalla) ===== */
.app-content{
  max-width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 0 max(16px, env(safe-area-inset-left)) 88px max(16px, env(safe-area-inset-right));
  min-width: 0;
}

/* ===== Card title row (P31: min-width 0 para no overlap) ===== */
.card-title-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-bottom:6px;
  min-width: 0;
}

.action-label{
  font-size:12px;
  opacity:.7;
  font-weight:700;
}

.action-total{
  font-size:18px;
  font-weight:900;
  margin-top:2px;
}

.action-hint, .action-note{
  font-size:12px;
  opacity:.7;
  margin-top:2px;
}

.action-bar__right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:6px;
}

.btn-primary{
  appearance:none;
  border:0;
  border-radius:12px;
  padding:10px 14px;
  font-weight:700;
  cursor:pointer;
}

/* ===== Action bar (sticky bottom) ===== */
.action-bar{
  position: fixed;
  bottom: calc(10px + var(--safe-bottom));
  z-index: var(--z-modal, 400);

  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:16px;

  /* Mobile-first: full width with gutters + safe area */
  left: calc(16px + var(--safe-left));
  right: calc(16px + var(--safe-right));
  width: auto;
  max-width: 860px;

  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,.10);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px rgba(0,0,0,.18);
}

/* Tighten on small screens */
@media (max-width: 520px){
  .action-bar{
    flex-direction:column;
    align-items:stretch;
    left: calc(12px + var(--safe-left));
    right: calc(12px + var(--safe-right));
  }
  .action-bar__right{
    align-items:stretch;
  }
  .btn-primary{
    width:100%;
    min-height: 48px;
  }
}

/* App content: extra bottom padding on mobile for action bar + safe area */
@media (max-width: 768px){
  .app-content{
    padding-bottom: calc(100px + var(--safe-bottom));
  }
}

/* Desktop: center the bar within the content area (shifted right by half sidebar) */
@media (min-width: 981px){
  .action-bar{
    left: calc(50% + (var(--sidebar-w) / 2));
    right: auto;
    transform: translateX(-50%);

    /* Match the card/content column width (a bit tighter than before) */
    width: min(860px, calc(100vw - var(--sidebar-w) - 48px));
  }
}

/* Sticky action card (Factura nueva) */
.sticky-action-card{
  position: sticky;
  bottom: 16px;
  z-index: 30;
  margin-top: 14px;
  box-shadow: 0 16px 40px rgba(15,23,42,.12);
}
/* Móvil: el tab bar inferior (56px + safe area) y su FAB "+" (sobresale 18px)
   son fixed con z-index mayor; sin este offset tapan el botón "Emitir factura". */
@media (max-width: 768px){
  .sticky-action-card{
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 24px);
  }
}
/* When drawer overlay is open, dim the sticky card too */
body.sidebar-open #stickyActionCard{
  filter: brightness(.86);
}

/* =========================
   PRO polish (Factura Nueva) — estándar spacing/jerarquía
   Cada sección = card con padding 24px; gap entre cards 20px; títulos consistentes.
   ========================= */

/* Estándar: cada sección = card con padding compacto (menos página larga) */
.main-inner .card{
  padding: 16px;
}

/* Gap vertical entre todas las cards */
.main-inner .card + .card{
  margin-top: 12px;
}

/* Títulos de sección */
.main-inner .card .card-title-row{
  margin-bottom: 8px;
  line-height: 1.25;
}
.main-inner .card .card-title-row .section-title{
  margin: 0;
  line-height: 1.25;
  letter-spacing: -0.01em;
}
.main-inner .card .card-title-row.mb-14{
  margin-bottom: 10px;
}

/* Filas de campos dentro de cada card */
.main-inner .card .row + .row{
  margin-top: 12px;
}


/* Separador sutil dentro de cards */
.hr{
  height: 1px;
  background: var(--border);
  margin: 10px 0;
}

/* Labels más pro */
label{
  letter-spacing: .01em;
}

/* Checkboxes globales: estilo Filters (cuadrado, teal al marcar) */
input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  accent-color: var(--primary);
  cursor: pointer;
}

/* Inputs: look más limpio */
input, select, textarea{
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

/* Focus: un poco más “Apple” */
input:focus, select:focus, textarea:focus{
  border-color: var(--primary);
  box-shadow: none;
}

/* Estados de validación (para después usar con JS o server-side) */
.field-ok input,
.field-ok select,
.field-ok textarea{
  border-color: rgba(20,184,166,.35);
}

.field-err input,
.field-err select,
.field-err textarea{
  border-color: rgba(176,0,32,.35);
  box-shadow: 0 0 0 4px rgba(176,0,32,.10);
}

.help{
  margin-top:6px;
  font-size:12px;
  color: var(--muted);
}
.help.err{ color:#b00020; font-weight:650; }

/* Botones secundarios más suaves */
.btn-secondary{
  transition: background var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease, transform var(--motion-micro, 150ms) ease;
}
.btn-secondary:hover{
  background:#fafafb;
  border-color: var(--border-strong);
}
.btn-secondary:active{
  transform: translateY(1px);
}

/* Conceptos: headers y filas un poco más “tabla” */
.item-head{
  color: var(--muted);
}
.item-row-top{
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  transition: border-color var(--motion-micro, 150ms) ease, box-shadow var(--motion-micro, 150ms) ease, transform var(--motion-micro, 150ms) ease;
}
.item-row-top:hover{
  border-color: var(--border-strong);
  box-shadow: 0 10px 30px rgba(15,23,42,.06);
}

/* Animación suave al insertar conceptos */
.anim-in{
  animation: fadeInUp var(--motion-modal, 200ms) var(--ease-out, ease) forwards;
}
@keyframes fadeInUp{
  from{ opacity: 0; transform: translateY(8px); }
  to{ opacity: 1; transform: translateY(0); }
}

/* Card entrance (opcional: añadir .card-enter al cargar para efecto escalonado) */
.card-enter{
  animation: cardEnter var(--motion-modal, 200ms) var(--ease-out, ease) forwards;
}
@keyframes cardEnter{
  from{ opacity: 0; transform: translateY(10px); }
  to{ opacity: 1; transform: translateY(0); }
}

/* Form modal: entrada más pro (respetar prefers-reduced-motion) */
.form-modal__panel{
  box-shadow: 0 22px 70px rgba(0,0,0,.18);
}
@media (prefers-reduced-motion: no-preference) {
  .form-modal__panel{ animation: formModalIn var(--motion-modal, 200ms) ease forwards; }
}
@keyframes formModalIn{
  from{ opacity:0; transform: translateY(8px) scale(.99); }
  to{ opacity:1; transform: translateY(0) scale(1); }
}

/* Sticky total: más “Stripe” */
.sticky-action-card{
  /* D1: fondo sólido — el backdrop-blur forzaba repaint de toda la página al scrollear */
  background: rgba(255,255,255,.97);
  border: 1px solid rgba(0,0,0,.10);
}

/* ===== Inline checkbox rows (receptor / guardar cliente) ===== */
.inline-check{
  display:flex;
  align-items:center;
  gap:10px;
}

.inline-check input[type="checkbox"]{
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  accent-color: var(--primary, #6366f1);
  cursor: pointer;
  transform: translateY(0.5px);
}

.inline-check__label{
  margin:0;
  font-size:12px;
  font-weight:700;
}

.inline-check__label--normal{
  font-weight:700;
}

.inline-check__hint{
  font-size:12px;
}

/* ===== Icon buttons (search / close / remove) ===== */
.icon-btn{
  width:40px;
  height:44px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  color: var(--muted);
  padding:0;
}

.icon-btn:hover{
  border-color: var(--border-strong);
  background:#fafafb;
  color: var(--text);
}

.icon-btn:active{
  transform: translateY(1px);
}

/* Form modal close compact */
.form-modal__close.icon-btn{
  width:40px;
  height:40px;
}

/* ===== Concept list spacing ===== */
.items-head{ margin-top:10px; }
.item-row{ margin-top:8px; }

/* ===== Sticky action layout helpers ===== */
.sticky-action-head{ align-items:center; }
.sticky-action-title{ margin:0; }
.sticky-action-row{ align-items:center; }
.sticky-action-note{ margin:0; }
.sticky-action-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
}

/* =========================
   Live edit alignment (form.html new classes)
   ========================= */

/* SVG icons inside buttons — usa tokens de iconos (portal_tokens.css) */
.icon{
  width: var(--icon-size-sm, 1rem);
  height: var(--icon-size-sm, 1rem);
  stroke: currentColor;
  fill: none;
  stroke-width: var(--icon-stroke, 1.75);
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Checkbox inline rows (new HTML uses checkline) */
.checkline{
  display:flex;
  align-items:center;
  gap:10px;
}

.checkline input[type="checkbox"]{
  width: 20px;
  height: 20px;
  min-width: 20px;
  min-height: 20px;
  border-radius: 4px;
  border: 1.5px solid var(--border-strong);
  accent-color: var(--primary, #6366f1);
  cursor: pointer;
  transform: translateY(0.5px);
}

.checkline__label{
  margin:0;
  font-size:12px;
  font-weight:700;
}

.checkline__label--bold{
  font-weight:700;
}

.checkline__hint{
  font-size:12px;
}

/* Small margin helpers (replacing inline styles) */
.mt-6{ margin-top:6px; }
.mt-8{ margin-top:8px; }
.mt-10{ margin-top:10px; }
.m-0{ margin:0; }

/* Sticky action card class alignment (sac-*) */
.sac-title{ align-items:center; }
.sac-h{ margin:0; }
.sac-row{ align-items:center; }
.sac-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
}

/* =========================
   Next polish pass (3 items)
   1) Unified icon buttons
   2) Sticky total more "Stripe"
   3) Concept row focus glow
   ========================= */

/* 1) Unified icon buttons (ProdServ / Remove / Modal close)
   Keep existing classes in HTML; unify their look here.
*/
.prodservBtn,
.item-row-top .removeItemBtn,
.form-modal__close{
  width:40px;
  height:40px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  color: var(--muted);
  padding:0;
  box-shadow:none;
}

/* Ensure remove keeps a consistent column size */
.item-row-top .removeItemBtn{
  width:44px;
  height:44px;
}

.prodservBtn:hover,
.item-row-top .removeItemBtn:hover,
.form-modal__close:hover{
  border-color: var(--border-strong);
  background:#fafafb;
  color: var(--text);
}

.prodservBtn:active,
.item-row-top .removeItemBtn:active,
.form-modal__close:active{
  transform: translateY(1px);
}
@media (prefers-reduced-motion: reduce) {
  .prodservBtn:active,
  .item-row-top .removeItemBtn:active,
  .form-modal__close:active{ transform: none; }
}

/* SVG icons inherit color nicely */
.prodservBtn .icon,
.item-row-top .removeItemBtn .icon,
.form-modal__close .icon{
  width:18px;
  height:18px;
}

/* 2) Sticky total: more Stripe-like hierarchy */
.sticky-action-card{
  border: 1px solid rgba(0,0,0,.10);
  box-shadow: 0 18px 52px rgba(15,23,42,.14);
}

.sticky-action-card .pill#action_total_text{
  font-size: 14px;
  font-weight: 900;
  letter-spacing: .01em;
  padding: 8px 12px;
  border-color: rgba(22,163,74,.18);
  background: rgba(22,163,74,.08);
  color: var(--text);
}

.sticky-action-card .section-title{
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

/* Concept row: focus ring consistente y hover */
.item-row-top:focus-within{
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--focus);
}
@media (prefers-reduced-motion: no-preference) {
  .item-row-top:focus-within{
    box-shadow: 0 0 0 3px var(--focus), 0 12px 32px rgba(15,23,42,.10);
  }
}

.item-row-top:hover{
  box-shadow: 0 10px 28px rgba(15,23,42,.07);
}
.item-row-top:focus-within:hover{
  box-shadow: 0 0 0 3px var(--focus), 0 12px 32px rgba(15,23,42,.10);
}
@media (prefers-reduced-motion: no-preference) {
  .item-row-top:focus-within:hover{
    /* tone-only hover — no translateY */
  }
}

/* Form modal close button (size + centering) */
.form-modal__close{
  width:36px;
  height:36px;
  border-radius:12px;
  line-height:0;
  display:flex;
  align-items:center;
  justify-content:center;
}

.form-modal__close .icon{
  width:20px;
  height:20px;
  display:block;
}

/* ===== Wizard step indicator (form.html) ===== */
.form-step-indicator{
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  margin-bottom: var(--space-6, 24px);
  padding: 10px 0;
  list-style: none;
  counter-reset: step;
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface, #fff);
  border-bottom: 1px solid transparent;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.form-step-indicator.is-stuck{
  border-bottom-color: var(--border, #e6e8ef);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.form-step{
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  font-size: var(--text-xs, 0.8125rem);
  font-weight: var(--fw-semibold, 600);
  color: var(--text-muted, #64748b);
  counter-increment: step;
}
.form-step__number{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--neutral-bg, #f3f4f6);
  color: var(--text-muted, #64748b);
  font-size: var(--text-2xs, 0.6875rem);
  font-weight: var(--fw-bold, 700);
  border: 2px solid transparent;
  transition: background var(--motion-micro, 150ms) ease, color var(--motion-micro, 150ms) ease, border-color var(--motion-micro, 150ms) ease;
}
.form-step--active .form-step__number{
  background: var(--accent-soft, #eef2ff);
  color: var(--accent, #6366f1);
  border-color: var(--accent, #6366f1);
}
.form-step--active{
  color: var(--text, #0d1f1c);
  font-weight: var(--fw-bold, 700);
}
.form-step--done .form-step__number{
  background: var(--success, #059669);
  color: #fff;
  border-color: var(--success, #059669);
}
.form-step--done{
  color: var(--success, #059669);
}
.form-step__connector{
  width: 24px;
  height: 2px;
  background: var(--border, #e6e8ef);
  border-radius: 1px;
  flex-shrink: 0;
}
.form-step--done + .form-step__connector,
.form-step--active + .form-step__connector{
  background: var(--accent, #6366f1);
}

/* ===== Form section header ===== */
.form-section-header{
  display: flex;
  align-items: center;
  gap: var(--space-3, 12px);
  margin-bottom: var(--space-4, 16px);
  padding-bottom: var(--space-3, 12px);
  border-bottom: 1px solid var(--border, #e6e8ef);
}
.form-section-header__title{
  font-size: var(--text-md, 1.0625rem);
  font-weight: var(--fw-bold, 700);
  color: var(--text, #0d1f1c);
  letter-spacing: var(--ls-tight, -0.02em);
  margin: 0;
}
.form-section-header__icon{
  width: 20px;
  height: 20px;
  color: var(--text-muted, #64748b);
  flex-shrink: 0;
}

/* ===== Field validation states ===== */
.field--error input,
.field--error select,
.field--error textarea{
  border-color: var(--danger, #dc2626);
  box-shadow: 0 0 0 2px var(--danger-bg, #fee2e2);
}
.field--error .field__error{
  display: block;
  margin-top: var(--space-1, 4px);
  font-size: var(--text-2xs, 0.6875rem);
  color: var(--danger, #dc2626);
  font-weight: var(--fw-medium, 500);
}
.field--success input,
.field--success select,
.field--success textarea{
  border-color: var(--success, #059669);
  box-shadow: 0 0 0 2px var(--success-bg, #d1fae5);
}
.field__error{
  display: none;
}

/* ===== Sticky action card: more prominent ===== */
.sticky-action-card{
  box-shadow: 0 -4px 20px rgba(13, 31, 28, 0.08), 0 18px 52px rgba(15, 23, 42, 0.14);
}

/* ===== Narrow screen improvements ===== */
@media (max-width: 640px){
  .form-step-indicator{
    gap: var(--space-1, 4px);
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .form-step-indicator::-webkit-scrollbar { display: none; }
  .form-step__connector{
    width: 16px;
    flex-shrink: 0;
  }
  .form-step{
    flex-shrink: 0;
  }
}

/* ===== Resumen card — differentiated background ===== */
#totalsCard{
  background: var(--surface-1, #fafafa);
  border: 1.5px solid var(--border-strong, rgba(0,0,0,.10));
  position: relative;
}
#totalsCard::before{
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--gradient-card-shine, linear-gradient(135deg, rgba(99,102,241,.03) 0%, rgba(139,92,246,.03) 100%));
  pointer-events: none;
}
#totalsCard input:disabled{
  background: var(--surface-0, #fff);
  font-weight: var(--fw-semibold, 600);
  color: var(--text, #0f172a);
}
/* Total payable — accent highlight */
#total_payable_preview:disabled{
  font-size: var(--text-lg, 1.125rem);
  font-weight: var(--fw-bold, 700) !important;
  color: var(--primary, #6366f1) !important;
}
html.nightmode #totalsCard{
  background: var(--surface-1, #161b22);
  border-color: var(--border-strong, rgba(255,255,255,.12));
}

/* ===== Submit button loading state ===== */
.btn-loading{
  pointer-events: none;
  opacity: .75;
  position: relative;
}
.btn-loading::after{
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes btn-spin{
  to{ transform: rotate(360deg); }
}

/* ===== Accordion chevron (extras section) ===== */
.form-accordion-chevron { transition: transform .2s ease; }
details[open] > .form-accordion-trigger .form-accordion-chevron { transform: rotate(90deg); }
.form-accordion-trigger::-webkit-details-marker { display: none; }

/* ===== Night mode overrides for invoice form ===== */
html.nightmode .invoice-form-page,
html.nightmode .portal .card { background: var(--surface, #161b22); color: var(--text, #e6edf3); }
html.nightmode .invoice-form-page .card { border-color: var(--border, rgba(255,255,255,.08)); }
html.nightmode .invoice-form-page h1,
html.nightmode .invoice-form-page h2,
html.nightmode .invoice-form-page h3 { color: var(--text, #e6edf3); }
/* ── C9: botón "Emitir factura" sólido del sistema (se veía lavanda,
   como deshabilitado, aun estando habilitado) ── */
.sticky-action-card .btn-primary{
  background: var(--primary, #6366f1);
  color: #fff;
}
.sticky-action-card .btn-primary:hover{ background: var(--primary-dark, #4f46e5); }
.sticky-action-card .btn-primary:disabled{ opacity: .55; }
