/* ---------------------------------------------------------------------------
   Paleta por tokens.

   Todo color vive aqui como variable para que el modo oscuro sea un unico
   bloque de sobrescritura. Sin eleccion explicita se sigue la preferencia del
   sistema; data-theme en <html> la fuerza en cualquier direccion.
--------------------------------------------------------------------------- */
:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --surface-sunken: #fafbfc;

  --text: #1f2937;
  --text-strong: #0f172a;
  --muted: #64748b;
  --muted-2: #475569;

  --border: #e2e8f0;
  --border-input: #ccd0d8;
  --border-soft: #e8ebf0;

  --accent: #2d6cdf;
  --accent-strong: #1e3a8a;
  --accent-text: #1f3b85;
  --accent-soft: #eff6ff;
  --accent-soft-border: #93c5fd;
  --accent-hover-bg: #f0f6ff;

  --danger: #d0393e;
  --danger-soft: #fff4f4;
  --success: #16a34a;
  --info: #0ea5e9;
  --neutral-btn: #5a6472;

  /* Panel de logs: mantiene aspecto de terminal en ambos temas. */
  --term-bg: #0f172a;
  --term-surface: #1e293b;
  --term-text: #e2e8f0;
  --term-muted: #94a3b8;
  --term-border: #334155;

  --shadow-card: 0 14px 40px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.06);
  --shadow-pop: 0 12px 28px rgba(15, 23, 42, 0.15);

  --header-from: #1e3a8a;
  --header-to: #2d6cdf;
  --login-bg: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #2d6cdf 100%);

  color-scheme: light;
}

/* El modo oscuro se aplica solo con data-theme="dark", que estampa theme.js a
   partir de la eleccion guardada. No se sigue prefers-color-scheme: el oscuro
   es una opcion que el usuario activa, no algo heredado del sistema. */
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #141d30;
  --surface-2: #1a2438;
  --surface-3: #1f2b42;
  --surface-sunken: #111a2b;

  --text: #dde5f2;
  --text-strong: #f1f5f9;
  --muted: #9fb0c9;
  --muted-2: #c3cfe1;

  --border: #2b3853;
  --border-input: #3a4a6b;
  --border-soft: #263149;

  --accent: #5590f5;
  --accent-strong: #9cc2ff;
  --accent-text: #a9c6ff;
  --accent-soft: #16233b;
  --accent-soft-border: #3d5f9c;
  --accent-hover-bg: #1b2942;

  --danger: #ef5f64;
  --danger-soft: #2c1417;
  --success: #34d399;
  --info: #38bdf8;
  --neutral-btn: #4a5568;

  --term-bg: #080e1c;
  --term-surface: #0f1829;
  --term-text: #dde5f2;
  --term-muted: #8fa3c0;
  --term-border: #2b3853;

  --shadow-card: 0 14px 40px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 8px 20px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 12px 28px rgba(0, 0, 0, 0.5);

  --header-from: #16264f;
  --header-to: #24509f;
  --login-bg: linear-gradient(135deg, #060b16 0%, #16264f 50%, #24509f 100%);

  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  transition: background-color .18s ease, color .18s ease;
}
#app { max-width: 1600px; margin: 0 auto; padding: 24px; }

.status-bar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; justify-content: center; gap: 24px; flex-wrap: wrap; background: #0f172a; color: #e2e8f0; padding: 8px 16px; font-size: 0.85rem; font-weight: 600; letter-spacing: 0.02em; box-shadow: 0 2px 10px rgba(0,0,0,0.2); }
.status-bar .status-item { display: flex; align-items: center; gap: 6px; }
.status-bar .status-item strong { color: #93c5fd; font-weight: 700; }
.currency-rate-hint { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 0.85rem; color: var(--accent-text); font-weight: 600; }

header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; background: linear-gradient(135deg, var(--header-from) 0%, var(--header-to) 100%); color: #fff; padding: 20px 26px; border-radius: 14px; box-shadow: 0 12px 30px rgba(30,58,138,0.25); }
header h1 { margin: 0 0 4px; font-size: 1.5rem; letter-spacing: -0.02em; }
header p { margin: 0; opacity: 0.85; font-size: 0.9rem; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(45,108,223,0.25);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, filter .12s ease;
}
button:hover { transform: translateY(-2px); filter: brightness(1.05); box-shadow: 0 8px 18px rgba(45,108,223,0.3); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: none; }
button:focus-visible { outline: 3px solid var(--accent-soft-border); outline-offset: 2px; }
button.secondary { background: var(--neutral-btn); box-shadow: 0 4px 10px rgba(90,100,114,0.25); }
button.danger { background: var(--danger); box-shadow: 0 4px 10px rgba(208,57,62,0.3); }

input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--border-input); border-radius: 8px; background: var(--surface-sunken); color: var(--text); font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,108,223,0.15); }
input.field-error, select.field-error, textarea.field-error { border-color: var(--danger); background: var(--danger-soft); box-shadow: 0 0 0 3px rgba(208,57,62,0.16); }
.selected-vin { min-width: 180px; padding: 8px 10px; border: 1px solid var(--accent-soft-border); border-left: 4px solid var(--accent); border-radius: 6px; background: var(--accent-soft); color: var(--accent-text); font-size: 0.85rem; }
.line-field-label { margin-bottom: 5px; color: var(--muted); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; white-space: nowrap; }
.table .lineSerialSelect { width: 210px; min-width: 210px; font-weight: 700; color: var(--accent-text); border-color: var(--accent-soft-border); background: var(--accent-soft); }
.table .lineUom { width: 105px; min-width: 105px; font-weight: 700; color: var(--muted-2); background: var(--surface-2); }
.lineTaxCode { width: 125px; min-width: 125px; font-weight: 600; color: var(--accent-text); border-color: var(--accent-soft-border); background: var(--accent-soft); }
.money-input { font-variant-numeric: tabular-nums; text-align: right; }
textarea { min-height: 100px; resize: vertical; }

.autocomplete-list { display: none; position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-pop); max-height: 260px; overflow-y: auto; }
.autocomplete-item { padding: 10px 14px; cursor: pointer; font-size: 0.9rem; border-bottom: 1px solid var(--border-soft); color: var(--text); }
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--accent-hover-bg); }
.autocomplete-empty { padding: 10px 14px; font-size: 0.9rem; color: var(--muted); }
/* Cuando el buscador no encuentra al socio, el aviso ofrece darlo de alta
   sin salir del documento. */
.autocomplete-empty .autocomplete-create {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
}

.card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-card); padding: 24px; margin-bottom: 24px; }

.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 40px 16px; background: var(--login-bg); }
.login-card { width: 100%; max-width: 420px; padding: 36px; text-align: center; }
.login-card h1 { margin: 0 0 10px; font-size: 2rem; letter-spacing: -0.03em; color: var(--text-strong); }
.login-card h1::before { content: '🏪'; display: block; font-size: 2.4rem; margin-bottom: 10px; }
.login-card p { margin: 0 0 24px; color: var(--muted); line-height: 1.6; }
.login-field { margin-bottom: 18px; text-align: left; }
.login-field label { display: block; margin-bottom: 8px; font-weight: 600; color: var(--text-strong); }
.login-actions { justify-content: center; }
.login-actions button { width: 100%; padding: 13px 18px; font-size: 1rem; }
.login-card input { background: var(--surface-sunken); }

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }

.module-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 16px; }
.module-btn {
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px 14px;
  box-shadow: var(--shadow-soft);
  font-weight: 600;
}
.module-btn:hover { background: var(--accent-hover-bg); border-color: var(--accent-soft-border); box-shadow: 0 10px 24px rgba(45,108,223,0.18); }
.module-btn .module-icon { font-size: 2rem; line-height: 1; }
.module-btn .module-label { font-size: 0.92rem; }

.table { width: 100%; border-collapse: collapse; }
.detail-card .table { min-width: 1120px; }
.table th { padding: 12px 10px; text-align: left; background: var(--surface-3); color: var(--muted-2); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table td { padding: 14px 10px; border-bottom: 1px solid var(--border-soft); }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------------------
   Tablas de detalle de documento

   Las filas se veian desalineadas porque cada celda con control llevaba encima
   su propia etiqueta ("VIN / N° SERIE", "UNIDAD", ...), lo que hacia que unas
   celdas fueran mas altas que otras y que nada coincidiera con la cabecera.
   Las etiquetas sobran: la cabecera de la tabla ya dice que es cada columna.
--------------------------------------------------------------------------- */
.table td, .table th { vertical-align: middle; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Los controles dentro de una fila no deben estirar la celda. */
.table td > input,
.table td > select { margin: 0; padding: 8px 10px; }
.table td > button { padding: 8px 12px; font-size: 0.85rem; box-shadow: none; }
.table td > button:hover { transform: none; box-shadow: none; }

/* Boton compacto de accion (eliminar una linea). */
.btn-icon {
  padding: 8px 10px;
  font-size: 0.95rem;
  line-height: 1;
  box-shadow: none;
}
.btn-icon:hover { transform: none; box-shadow: none; }

/* Columna de acciones siempre visible.

   Los listados de documentos tienen muchas columnas y se desplazan en
   horizontal; sin esto el boton de ver el documento quedaba fuera de la
   pantalla y habia que desplazarse a ciegas para encontrarlo. */
.table-sticky-actions th:last-child,
.table-sticky-actions td:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: -6px 0 8px -6px rgba(15, 23, 42, 0.25);
  white-space: nowrap;
}
.table-sticky-actions th:last-child { background: var(--surface-3); }
.table-sticky-actions tbody tr:hover td:last-child { background: var(--surface-2); }
.table-sticky-actions td:last-child { display: table-cell; }
.table-sticky-actions td:last-child > button { margin: 0 2px; }

.table-compact th { padding: 9px 10px; font-size: 0.72rem; }
.table-compact td { padding: 8px 10px; }
.table tfoot th { background: var(--surface-2); border-top: 2px solid var(--border); }

/* ---------------------------------------------------------------------------
   Modal
--------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.55);
}
.modal {
  width: 100%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-header strong { font-size: 1.05rem; color: var(--text-strong); }
.modal-header .modal-close { padding: 6px 12px; box-shadow: none; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 18px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}
.modal-totals span { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.modal-totals strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }

.alert { background: var(--accent-soft); border-left: 4px solid var(--accent); padding: 18px; margin-bottom: 16px; border-radius: 6px; }
.form-header { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 24px; }
.form-header .panel { background: var(--accent-soft); border: 1px solid var(--accent-soft-border); padding: 20px; border-radius: 10px; }
.form-header .panel strong { display: block; margin-bottom: 6px; color: var(--accent-text); }
.detail-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-top: 18px; overflow-x: auto; }
.field-group { margin-top: 18px; display: flex; justify-content: flex-end; gap: 10px; }
.report-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.report-buttons button { min-width: 180px; }
.label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.label-row strong { color: var(--accent); }

/* Texto de ayuda bajo un campo. Ya se usaba en las plantillas pero no estaba
   definido, asi que se veia como parrafo normal. */
.help-text { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.5; }

/* ---------------------------------------------------------------------------
   Panel de logs de sincronizacion.

   El contenido son lineas muy largas (JSON de contexto de SAP). Antes se
   volcaban en un <pre> sin ajuste de linea, lo que estiraba el contenedor y
   obligaba a desplazarse en horizontal. Ahora cada registro es una fila que
   ajusta el texto, y el contexto queda plegado hasta que se pide verlo.
--------------------------------------------------------------------------- */
/* Cabecera del módulo: fondo oscuro fijo en ambos temas, con texto claro. */
.sync-hero {
  padding: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.2);
}
.sync-hero h2 { color: #f8fafc; }

.sync-log-card { padding: 0; overflow: hidden; }
.sync-log-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.sync-log-toolbar strong { color: var(--text-strong); }
.sync-log-toolbar .spacer { flex: 1 1 auto; }
.chip {
  font-size: 12px;
  color: var(--muted-2);
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
/* Estado del arqueo: cuadrado o con diferencia, de un vistazo. */
.chip-ok {
  color: var(--success);
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border-color: color-mix(in srgb, var(--success) 35%, transparent);
  font-weight: 600;
}
.chip-alert {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  font-weight: 600;
}

/* Un faltante y un sobrante no se leen igual: el color lo dice antes que el signo. */
.diff-negative { color: var(--danger); font-weight: 700; }
.diff-positive { color: var(--success); font-weight: 700; }

/* Los importes a depositar son la cifra que se entrega: se destacan. */
.deposit-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-text);
}

.log-filters { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.log-filters button {
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted-2);
  border: 1px solid var(--border);
  box-shadow: none;
}
.log-filters button:hover { transform: none; background: var(--accent-hover-bg); border-color: var(--accent-soft-border); box-shadow: none; }
.log-filters button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.sync-log-viewer {
  margin: 0;
  padding: 8px;
  /* Altura acotada: el panel no crece con 100 registros. */
  max-height: 380px;
  min-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--term-bg);
  color: var(--term-text);
  font-size: 12.5px;
  line-height: 1.5;
}
.log-entry {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, max-content) minmax(0, 1fr);
  gap: 4px 10px;
  align-items: baseline;
  padding: 7px 10px;
  border-radius: 8px;
  border-left: 3px solid transparent;
  background: var(--term-surface);
  margin-bottom: 6px;
}
.log-entry:last-child { margin-bottom: 0; }
.log-entry--error { border-left-color: var(--danger); }
.log-entry--warn { border-left-color: #f59e0b; }
.log-entry--info { border-left-color: var(--info); }

.log-time {
  color: var(--term-muted);
  font-family: 'Consolas', 'SF Mono', 'Menlo', monospace;
  font-size: 11.5px;
  white-space: nowrap;
}
.log-level {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 1px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.log-entry--error .log-level { background: rgba(239, 95, 100, 0.18); color: #ff9a9d; }
.log-entry--warn .log-level { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.log-entry--info .log-level { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }

/* La clave del arreglo: el mensaje ajusta en lugar de estirar el contenedor. */
.log-message {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.log-context { grid-column: 1 / -1; margin-top: 2px; min-width: 0; }
.log-context summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--term-muted);
  padding: 2px 0;
  user-select: none;
}
.log-context summary:hover { color: var(--term-text); }
.log-context pre {
  margin: 6px 0 0;
  padding: 10px 12px;
  background: var(--term-bg);
  border: 1px solid var(--term-border);
  border-radius: 6px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 11.5px;
  font-family: 'Consolas', 'SF Mono', 'Menlo', monospace;
}
.log-empty { padding: 24px; text-align: center; color: var(--term-muted); }
.sync-log-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--surface-2); }

/* ---------------------------------------------------------------------------
   Conmutador de tema
--------------------------------------------------------------------------- */
.theme-toggle {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-pop);
  font-size: 0.88rem;
  font-weight: 600;
}
.theme-toggle:hover { background: var(--accent-hover-bg); border-color: var(--accent-soft-border); }
.theme-toggle .theme-toggle-icon { font-size: 1.1rem; line-height: 1; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  button:hover { transform: none; }
}

/* Bloques que solo salen en la impresion (p.ej. las observaciones ya guardadas,
   que en pantalla se muestran como campo editable). */
.print-only { display: none; }

/* Barra de paginación de los listados. */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 14px 0;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.pager-info { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.pager-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-controls button {
  padding: 6px 12px;
  min-width: 38px;
  font-size: 0.95rem;
  line-height: 1;
}
.pager-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.pager-page {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  padding: 0 8px;
  white-space: nowrap;
}
.pager-controls select { width: auto; padding: 6px 10px; font-size: 0.85rem; }

/* Marca de la empresa al encabezar un reporte en pantalla. */
.report-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.report-brand-logo { max-height: 40px; max-width: 200px; }
.report-brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-text);
}
.report-brand-text { display: flex; flex-direction: column; }
.report-brand-text strong { font-size: 1.05rem; }
.report-brand-text span { font-size: 0.82rem; color: var(--muted); }

/* =========================================================================
   Modelo de impresión de documentos

   Una sola hoja sirve a ventas y a compras: cambian el título, el subtítulo,
   los datos de la contraparte y las columnas, pero la maqueta es la misma.
   Los colores son fijos y no siguen el tema: el documento impreso debe verse
   igual con la aplicación en modo claro o en modo oscuro.
   ====================================================================== */
.print-sheet {
  display: none;
  color: #1a1a1a;
  background: #fff;
  font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
  font-size: 10pt;
  line-height: 1.45;
}

/* Cabecera: marca a la izquierda, título del documento a la derecha. */
.ps-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 26px;
}
.ps-brand { display: flex; align-items: center; gap: 10px; }
.ps-brand img { max-height: 34px; max-width: 220px; }
.ps-brand-name {
  font-size: 15pt;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #23306b;
}
.ps-title { text-align: right; }
.ps-title h1 {
  margin: 0;
  font-size: 24pt;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #2b3a8f;
  text-transform: uppercase;
}
.ps-title p { margin: 3px 0 0; font-size: 9pt; color: #6b7280; }

/* Datos del emisor. */
.ps-company { margin-bottom: 20px; }
.ps-company h2 { margin: 0 0 4px; font-size: 12.5pt; font-weight: 700; color: #111827; }
.ps-company p { margin: 1px 0; font-size: 9pt; color: #6b7280; }

/* Fila de metadatos: etiqueta gris pequeña sobre valor destacado. */
.ps-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 26px 46px;
  padding: 14px 0;
  border-top: 1px solid #e3e6ee;
  border-bottom: 1px solid #e3e6ee;
  margin-bottom: 18px;
}
.ps-meta > div { min-width: 96px; }
.ps-label {
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: #8b93a7;
}
.ps-value { font-size: 10pt; font-weight: 700; color: #111827; }

/* Las dos partes del documento, cada una en su recuadro. */
.ps-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid #e3e6ee;
  border-radius: 5px;
  margin-bottom: 20px;
}
.ps-party { padding: 13px 16px; }
.ps-party + .ps-party { border-left: 1px solid #e3e6ee; }
.ps-party .ps-label { color: #6a7699; margin-bottom: 5px; }
.ps-party p { margin: 1px 0; font-size: 9.5pt; color: #1f2937; }
.ps-party p.ps-party-name { font-weight: 600; }

/* Bloque de series/VIN: solo aparece si el documento tiene artículos con serie. */
.ps-serials { margin-bottom: 20px; }
.ps-serials .ps-label { color: #6a7699; margin-bottom: 3px; }
.ps-serial-line { font-size: 9.5pt; color: #1f2937; }
.ps-serial-line span { color: #6b7280; }

/* Tablas de detalle. */
.ps-section-title { margin: 0 0 8px; font-size: 12.5pt; font-weight: 700; color: #111827; }
.ps-block { margin-bottom: 18px; }
.ps-table { width: 100%; border-collapse: collapse; }
.ps-table thead th {
  background: #eef1f7;
  padding: 7px 9px;
  font-size: 7.5pt;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6a7699;
  text-align: left;
  white-space: nowrap;
}
.ps-table tbody td {
  padding: 9px;
  font-size: 9.5pt;
  color: #1f2937;
  border-bottom: 1px solid #edeff5;
  vertical-align: top;
}
.ps-table .ps-num { text-align: right; white-space: nowrap; }
.ps-table thead th.ps-num { text-align: right; }
.ps-line-note { display: block; font-size: 8.5pt; font-style: italic; color: #6b7280; }
.ps-empty { color: #6b7280; font-style: italic; }

/* Totales, alineados a la derecha como en el modelo. */
.ps-totals { display: flex; justify-content: flex-end; margin-top: 6px; }
.ps-totals table { border-collapse: collapse; min-width: 280px; }
.ps-totals td { padding: 5px 9px; font-size: 9.5pt; color: #4b5563; }
.ps-totals td.ps-num { text-align: right; color: #1f2937; }
.ps-totals tr.ps-grand td {
  border-top: 1px solid #d7dbe7;
  padding-top: 9px;
  font-size: 12pt;
  font-weight: 700;
  color: #2b3a8f;
}

.ps-notes { margin-top: 18px; }
.ps-notes .ps-label { color: #6a7699; margin-bottom: 3px; }
.ps-notes p { margin: 0; font-size: 9.5pt; color: #1f2937; white-space: pre-wrap; }

/* Firmas: quien entrega los valores y quien los recibe. Las tres columnas
   entran en el ancho del folio; con menos firmas se reparten el espacio. */
.ps-signatures {
  display: flex;
  gap: 26px;
  margin-top: 34px;
  page-break-inside: avoid;
  break-inside: avoid;
}
.ps-signature { flex: 1; text-align: center; }
.ps-signature-line {
  border-top: 1px solid #4b5563;
  margin-bottom: 6px;
}
.ps-signature-label {
  font-size: 9pt;
  font-weight: 700;
  color: #1f2937;
}
.ps-signature-hint {
  font-size: 7.5pt;
  color: #6a7699;
  margin-top: 2px;
}

.ps-foot {
  margin-top: 26px;
  padding-top: 10px;
  border-top: 1px solid #e3e6ee;
  font-size: 8pt;
  color: #8b93a7;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

/* Reportes anchos: se reduce la tipografía para que entren todas las columnas. */
.print-sheet.ps-dense .ps-table thead th { padding: 5px 5px; font-size: 6.5pt; letter-spacing: 0.05em; }
.print-sheet.ps-dense .ps-table tbody td { padding: 5px; font-size: 7.5pt; }
/* Con muchas columnas los encabezados deben poder partirse; si no, el ancho
   mínimo de la tabla supera el folio y se recortan las últimas columnas.
   El ancho queda automático: con ancho fijo las columnas de importe se
   quedaban cortas y el número invadía la columna vecina. */
.print-sheet.ps-dense .ps-table { table-layout: auto; }
.print-sheet.ps-dense .ps-table thead th { white-space: normal; }
.print-sheet.ps-dense .ps-table thead th.ps-num { white-space: nowrap; }
/* Los valores cortos (fechas, RUC) no deben partirse: solo se salta por espacios. */
.print-sheet.ps-dense .ps-table td { overflow-wrap: normal; }

/* La vista previa de un reporte ancho imita el folio apaisado. */
.print-sheet.ps-dense.ps-preview { max-width: 1120px; padding: 34px 36px; }

/* Vista previa en pantalla: la misma hoja, sobre un folio blanco. */
.print-sheet.ps-preview {
  overflow-x: auto;
  display: block;
  max-width: 820px;
  margin: 0 auto;
  padding: 42px 46px;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
}

@media print {
  @page { size: A4 portrait; margin: 14mm; }
  /* Los reportes de muchas columnas se imprimen apaisados. */
  @page apaisada { size: A4 landscape; margin: 12mm; }
  .print-sheet.ps-dense { page: apaisada; }

  /* Se oculta todo salvo la hoja, que pasa a ocupar el folio completo.
     La regla se condiciona a que la hoja exista: en los reportes paginados se
     arma recien al pedir impresion, y sin esta guarda un Ctrl+P antes de eso
     dejaba el folio en blanco en lugar de imprimir lo que se ve. */
  body:has(.print-sheet) * { visibility: hidden; }
  .print-sheet, .print-sheet * { visibility: visible; }
  .print-sheet {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .status-bar, .no-print, .theme-toggle { display: none !important; }
  .print-only { display: block !important; }
  body { background: #fff; color: #000; }
  .print-area { box-shadow: none; border: none; }

  /* Una fila no debe partirse entre dos páginas. */
  .ps-table tr, .ps-party, .ps-totals, .ps-signatures { break-inside: avoid; }
  .ps-table thead { display: table-header-group; }
}
