:root {
  /* ===================== Paleta oscura ISES ===================== */
  /* Superficies */
  --canvas: #0a0a0c;        /* fondo de la app */
  --rail: #0c0c0f;          /* barra lateral */
  --surface: #131316;       /* paneles / tarjetas */
  --surface-2: #1a1a1f;     /* inputs y fondos suaves */
  --surface-3: #1c1c22;     /* chips neutros */
  --seg-active: #242430;    /* pestaña activa del control segmentado */

  /* Líneas */
  --line: #26262b;
  --line-soft: #1f1f24;
  --line-strong: #2b2b31;

  /* Texto */
  --ink: #e4e4e8;           /* cuerpo */
  --ink-strong: #f4f4f5;    /* títulos / valores */
  --muted: #9a9aa2;         /* secundario */
  --steel: #7a7a82;         /* labels de formulario */
  --faint: #6a6a72;         /* pistas / metadatos */

  /* Acento (azul) */
  --accent: #6aa6f2;
  --accent-hover: #8fbdf7;
  --accent-deep: #2f6bc4;
  --accent-ink: #061020;    /* texto sobre acento */
  --accent-surface: #0e1520;
  --accent-line: #22303e;

  /* Estados semánticos */
  --green: #6ee7a0;
  --green-surface: rgba(110, 231, 160, 0.10);
  --green-line: #24402e;
  --amber: #e6a15a;
  --amber-surface: rgba(230, 161, 90, 0.12);
  --danger: #e0686a;
  --danger-surface: rgba(224, 104, 106, 0.12);
  --danger-line: #3a2023;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --ring: 0 0 0 3px rgba(106, 166, 242, 0.30);

  --rail-w: 68px;

  --font-body: 'IBM Plex Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', ui-monospace, 'Courier New', monospace;
}

* {
  box-sizing: border-box;
}

/* El atributo hidden debe ganar siempre, incluso sobre .btn/.tab-btn (que
   fijan su propio display:flex y si no, lo pisarían). */
[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: rgba(106, 166, 242, 0.28);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
  border: 3px solid var(--canvas);
}

::-webkit-scrollbar-track {
  background: transparent;
}

/* ==========================================================================
   Cascarón: rail lateral + main
   ========================================================================== */

.app-shell {
  display: flex;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.rail {
  flex: 0 0 var(--rail-w);
  width: var(--rail-w);
  background: var(--rail);
  border-right: 1px solid #1b1b20;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 6px;
}

.rail-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 11px;
  background: #fff;
  padding: 4px;
  margin-bottom: 12px;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rail-spacer {
  flex: 1;
}

.rail-foot {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
}

.rail-foot svg {
  width: 20px;
  height: 20px;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 30px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--faint);
  flex-wrap: wrap;
}

.status-online {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px 6px 11px;
  border: 1px solid var(--accent-line);
  background: var(--accent-surface);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.status-online .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.status-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.status-item svg {
  width: 13px;
  height: 13px;
}

.status-pill {
  margin-left: auto;
  min-width: 96px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.02em;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 30px 48px;
}

/* ==========================================================================
   Navegación (botones de pestaña convertidos en íconos del rail)
   ========================================================================== */

.tab-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: #5c5c64;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn svg {
  width: 21px;
  height: 21px;
}

.tab-btn:hover {
  background: #161619;
  color: #c4c4cc;
}

.tab-btn.active {
  background: #1b1b21;
  color: var(--ink-strong);
}

.tab-btn:focus-visible,
.btn:focus-visible,
.modal-close:focus-visible,
.suggestion-item:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* ==========================================================================
   Secciones y encabezados
   ========================================================================== */

.section {
  display: none;
  max-width: 1240px;
}

.section.active {
  display: block;
  animation: sectionIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes sectionIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 5px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
  text-wrap: balance;
}

h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  color: var(--ink-strong);
}

h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  margin: 0 0 12px;
}

.section-header p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}

/* ==========================================================================
   Mensajes
   ========================================================================== */

.message-box {
  margin-bottom: 18px;
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--danger-line);
  background: var(--danger-surface);
  color: var(--danger);
  font-weight: 500;
}

/* ==========================================================================
   Paneles / tarjetas
   ========================================================================== */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.panel-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title-row h2 {
  margin-bottom: 0;
}

.panel-hint {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: -8px;
  margin-bottom: 16px;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.span-two {
  grid-column: span 2;
}

/* ==========================================================================
   Formularios
   ========================================================================== */

label {
  display: block;
  color: var(--steel);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

input,
textarea,
select {
  width: 100%;
  margin-top: 7px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--ink-strong);
  background: var(--surface-2);
  font: inherit;
  font-size: 13px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

/* Los value monetarios y de folio en mono */
input[type="number"],
#numeroCotizacion {
  font-family: var(--font-mono);
}

input::placeholder,
textarea::placeholder {
  color: #4d4d55;
}

textarea {
  resize: vertical;
  line-height: 1.6;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #33507a;
  box-shadow: var(--ring);
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% + 1px),
    calc(100% - 13px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}

input[type="file"] {
  padding: 8px 12px;
  font-size: 12px;
  color: var(--muted);
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.35;
}

.type-selector {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 0 0 18px;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-2);
}

.type-selector legend {
  padding: 0 6px;
  color: var(--steel);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.type-selector label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  margin-top: 22px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
}

.checkbox-label input {
  width: auto;
  margin: 0;
}

.search-label {
  width: min(360px, 100%);
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.inline-form input,
.inline-form select {
  flex: 1 1 150px;
  margin-top: 0;
}

.inline-form .btn {
  flex: 0 0 auto;
}

/* ==========================================================================
   Botones
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  min-height: 40px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover {
  background: var(--accent-hover);
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line-strong);
}

.btn.secondary:hover {
  background: #22222a;
}

.btn.dark {
  background: var(--accent-surface);
  color: var(--accent);
  border-color: var(--accent-line);
}

.btn.dark:hover {
  background: #111d2e;
}

.btn.ghost {
  color: var(--ink);
  background: transparent;
  border-color: var(--line-strong);
}

.btn.ghost:hover {
  background: #22222a;
}

.btn.warning {
  color: var(--danger);
  background: var(--danger-surface);
  border-color: var(--danger-line);
}

.btn.warning:hover {
  background: rgba(224, 104, 106, 0.18);
}

.btn.icon {
  padding: 8px 12px;
  color: var(--danger);
  background: var(--danger-surface);
  border-color: var(--danger-line);
  font-size: 12px;
}

.btn.icon:hover {
  background: rgba(224, 104, 106, 0.18);
}

.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 20px;
}

.inline-actions {
  align-items: end;
  margin-top: 18px;
}

.saved-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.saved-actions .btn {
  padding: 7px 11px;
  min-height: 34px;
  font-size: 12px;
}

/* ==========================================================================
   Tablas
   ========================================================================== */

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th {
  background: transparent;
  color: var(--faint);
  text-align: left;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 12px 14px;
  vertical-align: middle;
  font-size: 13px;
}

thead th {
  border-bottom: 1px solid var(--line);
  padding-top: 8px;
  padding-bottom: 10px;
}

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: #16161a;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.items-table th:nth-child(2),
.items-table th:nth-child(3),
.items-table th:nth-child(4) {
  width: 140px;
}

.items-table th:nth-child(1) {
  width: 230px;
}

.items-table th:nth-child(2) {
  min-width: 260px;
}

.items-table th:nth-child(6) {
  width: 110px;
}

.item-total {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-strong);
  white-space: nowrap;
}

.item-total,
.saved-table td,
.products-table td {
  font-variant-numeric: tabular-nums;
}

/* Nth-last-child: "Productos" y "Acciones" son siempre las 2 últimas columnas
   tanto en marcas/categorías (3 col) como en subcategorías (4 col). */
.lexico-table th:nth-last-child(2) {
  width: 90px;
}

.lexico-table th:last-child {
  width: 150px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 26px;
}

.description-short {
  max-width: 340px;
  color: var(--muted);
}

/* ==========================================================================
   Totales
   ========================================================================== */

.totals {
  width: min(340px, 100%);
  margin-left: auto;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}

.totals div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
  color: var(--muted);
}

.totals div:last-child {
  border-bottom: 0;
}

.totals strong {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--ink-strong);
}

.grand-total {
  align-items: baseline;
  background: var(--surface-2);
}

.grand-total span {
  color: var(--ink-strong);
  font-weight: 600;
}

.grand-total strong {
  font-size: 22px;
  color: var(--accent);
}

/* ==========================================================================
   Buscador de producto (autocompletado)
   ========================================================================== */

.product-picker {
  position: relative;
}

.product-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  display: none;
  max-height: 240px;
  overflow-y: auto;
  background: #17171b;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 12;
}

.product-suggestions.open {
  display: block;
}

.suggestion-item {
  width: 100%;
  display: block;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.suggestion-item:hover {
  background: #1f1f26;
}

.suggestion-item strong,
.suggestion-item span {
  display: block;
}

.suggestion-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.inventory-note {
  display: block;
  margin-top: 7px;
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.3;
}

.inventory-note.warning {
  color: var(--amber);
  font-weight: 600;
}

/* ==========================================================================
   Imágenes de producto
   ========================================================================== */

.image-preview-box {
  display: grid;
  gap: 8px;
  align-self: end;
}

.current-image {
  min-height: 20px;
  color: var(--muted);
  font-size: 12px;
}

.current-image span {
  display: block;
  margin-bottom: 5px;
}

.current-image img,
.product-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
}

.preview-imagen-producto {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 92px;
  min-height: 58px;
  padding: 6px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 11px;
  text-align: center;
}

.preview-imagen-producto img {
  width: 76px;
  height: 48px;
  object-fit: contain;
  border-radius: 5px;
}

.product-thumb.placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--faint);
  background: var(--surface-2);
  font-size: 10px;
  background-image: repeating-linear-gradient(135deg, #232329 0 5px, transparent 5px 10px);
}

/* ==========================================================================
   Badges de tipo y estado
   ========================================================================== */

.type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 70px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.type-badge.producto {
  color: var(--green);
  background: var(--green-surface);
}

.type-badge.servicio {
  color: #7fa8e0;
  background: rgba(127, 168, 224, 0.10);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 86px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}

.status-badge.pendiente {
  color: var(--amber);
  background: var(--amber-surface);
}

.status-badge.aprobada {
  color: var(--green);
  background: var(--green-surface);
}

.status-badge.rechazada {
  color: var(--danger);
  background: var(--danger-surface);
}

/* ==========================================================================
   Métricas (rediseño 2026 — dashboard según captura de referencia)
   ========================================================================== */

/* En la pestaña de métricas la statusbar global se oculta: la vista trae su
   propio encabezado + línea de estado (diseño de referencia). */
.main:has(#sectionMetricas.active) .statusbar {
  display: none;
}

/* La sección escapa del padding de .content para que el encabezado y sus
   bordes corran de lado a lado; el cuerpo se vuelve a acotar con .mx-body. */
#sectionMetricas {
  max-width: none;
}

#sectionMetricas.active {
  margin: -24px -30px 0;
}

.mx-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 18px 30px;
  border-bottom: 1px solid var(--line-soft);
}

.mx-topbar h1 {
  margin-bottom: 4px;
  font-size: 25px;
}

.mx-topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.mx-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mx-icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.mx-icon-btn:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.mx-icon-btn svg {
  width: 18px;
  height: 18px;
}

.mx-icon-btn.sm {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

.mx-icon-btn.sm svg {
  width: 15px;
  height: 15px;
}

.mx-bell-dot {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface);
}

.mx-statusline {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  padding: 12px 30px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}

.mx-status-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.mx-status-item svg {
  width: 13px;
  height: 13px;
  color: var(--faint);
}

.mx-status-meta {
  color: var(--faint);
}

.mx-status-right {
  margin-left: auto;
}

.mx-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.mx-dot.green {
  background: var(--green);
  box-shadow: 0 0 7px rgba(110, 231, 160, 0.55);
}

.mx-dot.red {
  background: var(--danger);
  box-shadow: 0 0 7px rgba(224, 104, 106, 0.55);
}

#mxDiagnostico.ok {
  color: var(--green);
  font-weight: 600;
}

#mxDiagnostico.error {
  color: var(--danger);
  font-weight: 600;
}

.mx-body {
  max-width: 1240px;
  padding: 22px 30px 0;
}

/* Filtros: periodos + chip de rango de fechas */
.mx-filters {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.segmented.mx-periods {
  height: 42px;
  padding: 4px;
  border-radius: 12px;
}

.mx-periods .seg-btn {
  height: 32px;
  padding: 0 16px;
  border-radius: 9px;
  font-size: 12.5px;
}

.mx-range-wrap {
  position: relative;
}

.mx-range-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  height: 42px;
  padding: 0 15px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.mx-range-chip:hover {
  background: var(--surface-2);
}

.mx-range-chip svg {
  width: 15px;
  height: 15px;
  color: var(--muted);
}

.mx-range-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 30;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.mx-range-popover label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--steel);
  white-space: nowrap;
}

/* Tarjetas KPI */
.mx-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.mx-kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.mx-kpi-label {
  display: block;
  color: var(--steel);
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.mx-kpi-value {
  display: block;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}

.mx-kpi-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.mx-kpi-delta {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
}

.mx-kpi-delta.up { color: var(--green); }
.mx-kpi-delta.down { color: var(--amber); }
.mx-kpi-delta.flat { color: var(--faint); }

/* Rejillas principales */
.mx-main-grid,
.mx-bottom-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.62fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.mx-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.mx-panel-head h2 {
  margin-bottom: 3px;
}

.mx-panel-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.mx-panel-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  white-space: nowrap;
}

.mx-sales-chart {
  height: 220px;
}

.mx-mini-label {
  margin: 20px 0 10px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--faint);
}

.mx-volume-chart {
  height: 92px;
}

/* Distribución por estado */
.mx-state-bar {
  display: flex;
  gap: 3px;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  margin: 4px 0 14px;
}

.mx-state-bar span {
  display: block;
  height: 100%;
  min-width: 6px;
}

.mx-state-bar .seg-aprobada { background: var(--green); }
.mx-state-bar .seg-pendiente { background: var(--amber); }
.mx-state-bar .seg-rechazada { background: var(--danger); }

.mx-state-legend {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mx-state-legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 13px;
}

.mx-state-legend li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.mx-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: 0 0 auto;
}

.mx-legend-value {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
}

.mx-legend-value .pct {
  color: var(--faint);
}

/* Top 5 productos */
.mx-top-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mx-top-list li {
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft);
}

.mx-top-list li:first-child {
  padding-top: 2px;
}

.mx-top-list li:last-child {
  border-bottom: 0;
  padding-bottom: 2px;
}

.mx-top-list li.empty,
.mx-quotes-list li.empty {
  border-bottom: 0;
  display: block;
}

.mx-top-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 13px;
  color: var(--ink);
}

.mx-top-amount {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.mx-top-track {
  height: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.mx-top-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

/* Tablas del dashboard */
.mx-table th.num,
.mx-table td.num {
  text-align: right;
}

.mx-table td.num {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-strong);
}

/* Cotizaciones aprobadas recientes */
.mx-quotes-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.mx-quote-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}

.mx-quote-row:last-child {
  border-bottom: 0;
  padding-bottom: 4px;
}

.mx-quote-num {
  display: block;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-strong);
}

.mx-quote-client {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.mx-quote-total {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ==========================================================================
   Modal (vista previa de cotización)
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  background: rgba(4, 4, 6, 0.72);
  backdrop-filter: blur(3px);
  padding: 40px 20px;
  z-index: 50;
  overflow-y: auto;
}

.modal.open {
  display: flex;
}

.modal-content {
  position: relative;
  width: min(820px, 100%);
  background: #0f0f12;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 30px 34px;
  box-shadow: var(--shadow-lg);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: #22222a;
  color: var(--ink-strong);
}

/* ==========================================================================
   Documento de vista previa (dentro del modal — estilo oscuro)
   El PDF real se genera aparte con jsPDF y no usa estas clases.
   ========================================================================== */

.pdf-document {
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
}

.pdf-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #23232a;
  padding-bottom: 18px;
}

.pdf-company {
  display: flex;
  gap: 14px;
}

.pdf-company img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 10px;
  background: #fff;
  padding: 4px;
}

.pdf-company h3,
.pdf-title h2 {
  margin: 0 0 7px;
  color: var(--ink-strong);
}

.pdf-company p,
.pdf-title p,
.pdf-block p {
  margin: 0 0 4px;
  color: var(--muted);
}

.pdf-title {
  text-align: right;
  min-width: 200px;
}

.pdf-title h2 {
  font-size: 20px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--accent);
}

.pdf-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 20px 0;
}

.pdf-block {
  border: 1px solid #23232a;
  border-radius: 10px;
  padding: 14px;
}

.pdf-block h4 {
  margin: 0 0 10px;
  color: var(--ink-strong);
  font-size: 12px;
}

.pdf-block p strong {
  color: var(--ink);
}

.pdf-table {
  margin: 18px 0;
}

.pdf-table th {
  color: var(--faint);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
}

.pdf-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--ink);
}

/* ==========================================================================
   Catálogo Syscom
   ========================================================================== */

.syscom-search {
  display: flex;
  gap: 8px;
  align-items: center;
}

.syscom-search input[type="search"] {
  min-width: 260px;
  margin-top: 0;
}

.syscom-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 8px;
}

.syscom-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  overflow: hidden;
}

.syscom-card-img {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 140px;
  background: #171719;
  background-image: repeating-linear-gradient(135deg, #202026 0 7px, transparent 7px 14px);
  border-bottom: 1px solid var(--line-soft);
}

.syscom-card-img img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.syscom-card-body {
  padding: 14px;
  flex: 1;
}

.syscom-card-body h3 {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.35;
}

.syscom-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0 0 8px;
  font-size: 11.5px;
  color: var(--steel);
}

.syscom-desc {
  margin: 0 0 10px;
  font-size: 12.5px;
  color: var(--muted);
}

.syscom-card-numbers {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.syscom-price {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  color: var(--ink-strong);
}

.syscom-stock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--green);
}

.syscom-stock.agotado {
  color: var(--danger);
}

.syscom-card-action {
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
}

.syscom-card-action .btn {
  width: 100%;
}

.syscom-added {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 0;
  color: var(--green);
  font-weight: 600;
  font-size: 13px;
}

/* ==========================================================================
   Documento imprimible (PDF real) — se mantiene en claro para impresión
   ========================================================================== */

.pdf-document.print-sheet,
.pdf-document.compact { /* la vista previa usa el tema oscuro de arriba */
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 980px) {
  .mx-kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mx-main-grid,
  .mx-bottom-grid {
    grid-template-columns: 1fr;
  }

  .mx-status-right {
    margin-left: 0;
  }
}

@media (max-width: 820px) {
  .statusbar {
    padding: 12px 18px;
    gap: 12px;
  }

  .status-item {
    display: none;
  }

  .content {
    padding: 20px 18px 40px;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .span-two {
    grid-column: span 1;
  }

  .panel {
    padding: 18px;
  }

  .mx-kpis {
    grid-template-columns: 1fr;
  }

  #sectionMetricas.active {
    margin: -20px -18px 0;
  }

  .mx-topbar,
  .mx-statusline {
    padding-left: 18px;
    padding-right: 18px;
  }

  .mx-body {
    padding: 18px 18px 0;
  }

  .panel-title-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-label {
    width: 100%;
  }

  .syscom-search {
    flex-direction: column;
    align-items: stretch;
  }

  .syscom-search input[type="search"] {
    min-width: 0;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .actions {
    justify-content: stretch;
  }

  .actions .btn {
    flex: 1 1 180px;
  }
}

/* Móviles: rail horizontal arriba + tablas como tarjetas. */
@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .rail {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid #1b1b20;
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--rail);
  }

  .rail-logo {
    margin-bottom: 0;
    margin-right: 6px;
  }

  .rail-nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .rail-nav::-webkit-scrollbar {
    display: none;
  }

  .rail-foot {
    display: none;
  }

  .main {
    overflow: visible;
  }

  /* Evita el zoom automático de iOS al enfocar un campo. */
  input,
  textarea,
  select {
    font-size: 16px;
  }

  .actions .btn {
    flex: 1 1 100%;
  }

  /* --- Tablas a tarjetas --- */
  table.data-cards,
  table.data-cards tbody {
    display: block;
    width: 100%;
  }

  table.data-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
  }

  table.data-cards tr {
    display: block;
    margin-bottom: 12px;
    padding: 4px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }

  table.data-cards tbody tr:hover {
    background: var(--surface);
  }

  table.data-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 14px;
    border: 0;
    border-bottom: 1px solid var(--line-soft);
    text-align: right;
  }

  table.data-cards tr td:last-child {
    border-bottom: 0;
  }

  table.data-cards td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    color: var(--faint);
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    text-align: left;
  }

  table.data-cards td:not([data-label])::before,
  table.data-cards td[data-label=""]::before {
    content: none;
  }

  table.data-cards td.description-short {
    max-width: none;
  }

  table.data-cards td.empty {
    display: block;
    text-align: center;
  }

  table.data-cards td.empty::before {
    content: none;
  }

  table.data-cards td[data-label="Acciones"] {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  table.data-cards td[data-label="Acciones"] .saved-actions {
    width: 100%;
  }

  table.data-cards td[data-label="Acciones"] .saved-actions .btn {
    flex: 1 1 auto;
  }

  table.items-table.data-cards td {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  table.items-table.data-cards td::before {
    margin-bottom: 6px;
  }

  table.items-table.data-cards .product-picker {
    width: 100%;
  }

  .modal {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    padding: 24px 18px 28px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .pdf-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 21px;
  }

  .panel {
    padding: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Vista "Productos y servicios" — layout de dos columnas
   ============================================================ */

.catalogo-layout {
  display: grid;
  /* Proporción tomada de la referencia: 664px / 255px de contenido. */
  grid-template-columns: minmax(0, 2.604fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

/* ---------- Columna izquierda: catálogo ---------- */
.catalogo-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.search-field {
  position: relative;
  flex: 0 0 271px;
  min-width: 0;
}

.search-field .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--faint);
  pointer-events: none;
}

.search-field input[type="search"] {
  display: block;
  width: 100%;
  margin: 0; /* anula el margin-top global de input/textarea/select */
  padding: 6px 12px 6px 34px;
  height: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  font: 400 12.5px/1 var(--font-body);
  appearance: none;
}

.search-field input[type="search"]::placeholder { color: var(--faint); }
.search-field input[type="search"]:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

/* Tabs segmentados: Todo / Productos / Servicios */
.segmented {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  height: 30px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  flex: 0 0 auto;
}

.seg-btn {
  height: 20px;
  padding: 0 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font: 500 10px/1 var(--font-body);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover { color: var(--ink); }

.seg-btn.active {
  background: var(--seg-active);
  color: var(--ink-strong);
  box-shadow: var(--shadow-sm);
}

.catalogo-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.catalogo-table {
  width: 100%;
  border-collapse: collapse;
  /* Anchos fijos: sin esto los nombres largos empujan Precio e Inv. fuera
     de la tarjeta (la tabla se ensancha más allá del 100%). */
  table-layout: fixed;
}

.catalogo-table .col-nombre { width: 39.88%; }
.catalogo-table .col-tipo   { width: 12.54%; }
.catalogo-table .col-meta   { width: 22.21%; }
.catalogo-table .col-precio { width: 11.33%; }
.catalogo-table .col-inv    { width: 14.05%; }

.catalogo-table thead th {
  height: 31px;
  padding: 0;
  text-align: left;
  font: 600 8px/1 var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  background: transparent;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}

.catalogo-table thead th.col-precio,
.catalogo-table thead th.col-inv { text-align: right; }

.catalogo-table tbody td {
  height: 44px;
  padding: 0;
  border-bottom: 1px solid var(--line-soft);
  font: 400 12.5px/1.35 var(--font-body);
  color: var(--ink);
  vertical-align: middle;
  overflow: hidden;
}

.catalogo-table th:first-child,
.catalogo-table td:first-child { padding-left: 16px; }
.catalogo-table th:last-child,
.catalogo-table td:last-child { padding-right: 16px; }

.catalogo-table tbody tr:last-child td { border-bottom: 0; }

.catalogo-table tbody tr.row-clickable { cursor: pointer; }
.catalogo-table tbody tr.row-clickable:hover td { background: var(--surface-2); }
.catalogo-table tbody tr.row-clickable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Nombre + miniatura */
.catalogo-table td.col-nombre .nombre-cell {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.row-thumb {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background-color: var(--surface-2);
  background-image: repeating-linear-gradient(
    45deg,
    var(--line-strong) 0 1px,
    transparent 1px 4px
  );
  object-fit: cover;
  display: block;
}

img.row-thumb { background-image: none; }

.row-name {
  color: var(--ink-strong);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.col-meta {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.col-precio {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.col-inv {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.inv-num { color: var(--green); }
.inv-none { color: var(--faint); }

/* Badges de tipo */
.badge-tipo {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font: 500 10.5px/1.35 var(--font-body);
  white-space: nowrap;
}
.badge-tipo.producto {
  background: var(--green-surface);
  color: var(--green);
  border: 1px solid var(--green-line);
}
.badge-tipo.servicio {
  background: rgba(106, 166, 242, 0.10);
  color: var(--accent);
  border: 1px solid var(--accent-line);
}

/* ---------- Columna derecha ---------- */
.catalogo-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
}

.side-card > h2 {
  margin: 0 0 14px;
  font: 600 13.5px/1.2 var(--font-display);
  color: var(--ink-strong);
}

.side-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 13px;
}
.side-card-head h2 {
  margin: 0;
  font: 600 13.5px/1.2 var(--font-display);
  color: var(--ink-strong);
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: 500 11.5px/1 var(--font-body);
  cursor: pointer;
}
.link-btn:hover { color: var(--accent-hover); }

/* Toggle Producto / Servicio */
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  margin-bottom: 15px;
}
.type-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.type-toggle label {
  text-align: center;
  padding: 7px 0;
  border-radius: 7px;
  font: 500 12px/1 var(--font-body);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  /* Anula el `label { text-transform: uppercase }` global. */
  text-transform: none;
  letter-spacing: normal;
}
.type-toggle label:hover { color: var(--ink); }
.type-toggle input[type="radio"]:checked + label {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.type-toggle input[type="radio"]:focus-visible + label { box-shadow: var(--ring); }

/* Campos del formulario */
#productForm .field { display: block; margin-bottom: 13px; }

#productForm .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
}

#productForm .field-label {
  display: block;
  margin-bottom: 6px;
  font: 600 9.5px/1 var(--font-body);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--steel);
}

#productForm input[type="text"],
#productForm input[type="number"],
#productForm select,
#productForm textarea {
  width: 100%;
  margin: 0; /* anula el margin-top global de input/textarea/select */
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 400 12.5px/1.3 var(--font-body);
}
#productForm input::placeholder,
#productForm textarea::placeholder { color: var(--faint); }

#productForm input[type="number"] { font-family: var(--font-mono); }

#productForm select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%239a9aa2' stroke-width='1.4' stroke-linecap='round' d='M3 4.7l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  /* La columna derecha es angosta (~127px por campo): el texto de la opción
     debe caber junto al chevron sin recortarse. */
  padding-right: 22px;
  font-size: 11.5px;
  text-overflow: ellipsis;
  cursor: pointer;
}

#productForm textarea { resize: vertical; min-height: 46px; }

#productForm input:focus-visible,
#productForm select:focus-visible,
#productForm textarea:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

#productForm input:disabled,
#productForm select:disabled,
#productForm textarea:disabled { opacity: 0.45; cursor: not-allowed; }

/* Checkbox de inventario */
#productForm .checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 13px;
  cursor: pointer;
  font: 400 12px/1 var(--font-body);
  color: var(--ink);
  text-transform: none;
  letter-spacing: normal;
}
#productForm .checkbox-row input[type="checkbox"] {
  appearance: none;
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-2);
  cursor: pointer;
  position: relative;
}
#productForm .checkbox-row input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
#productForm .checkbox-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4.5px;
  top: 1.5px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
#productForm .checkbox-row input[type="checkbox"]:focus-visible { box-shadow: var(--ring); }

.inline-stock { max-width: 52%; }

/* Zona de imagen */
.upload-box {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 68px;
  padding: 14px;
  margin-bottom: 15px;
  background: #141418;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease;
  text-transform: none;
  letter-spacing: normal;
}
.upload-box:hover { border-color: var(--line-strong); }
.upload-box input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.upload-box .upload-icon { width: 19px; height: 19px; color: var(--faint); }
.upload-box #previewImagenTexto { font: 400 11.5px/1.3 var(--font-body); color: var(--faint); }
.upload-box #previewImagenProducto {
  max-height: 92px;
  max-width: 100%;
  border-radius: 7px;
  object-fit: contain;
}
.upload-box .current-image { font-size: 10.5px; color: var(--faint); }
.upload-box .current-image img { display: none; }
.upload-box .current-image:empty { display: none; }

/* Botón principal */
.btn-full {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 12.5px/1.2 var(--font-body);
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-full:hover { background: var(--accent-hover); }
.btn-full:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-full-ghost { width: 100%; margin-top: 8px; }

/* Botón "Detectar datos con IA": acción secundaria de ancho completo bajo la
   zona de imagen. Estilo de contorno con acento, sin competir con "Guardar". */
#detectProductAiBtn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  font: 600 12px/1.2 var(--font-body);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
#detectProductAiBtn:hover:not(:disabled) {
  border-color: var(--accent);
  background: rgba(106, 166, 242, 0.08);
}
#detectProductAiBtn:focus-visible { outline: none; box-shadow: var(--ring); }
#detectProductAiBtn:disabled { opacity: 0.6; cursor: default; }
#detectProductAiBtn svg { width: 16px; height: 16px; }

.detect-ai-status {
  margin-top: 7px;
  font: 500 11.5px/1.35 var(--font-body);
  color: var(--accent);
}
.detect-ai-status.is-error { color: var(--danger); }
.detect-ai-status[hidden] { display: none; }

/* Pills de categorías */
.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 13px;
}
.pill {
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font: 400 11.5px/1.3 var(--font-body);
  white-space: nowrap;
}
.pill.inactiva { color: var(--faint); border-style: dashed; }
.pill-empty { font: 400 11.5px/1.3 var(--font-body); color: var(--faint); }

.side-hint {
  margin: 0;
  font: 400 10.8px/1.55 var(--font-body);
  color: var(--faint);
}

/* Modal de administración del léxico */
.lexico-modal-content { max-width: 1040px; width: min(1040px, 94vw); }
.lexico-modal-content > h2 { margin-top: 0; }

@media (max-width: 900px) {
  .catalogo-layout { grid-template-columns: minmax(0, 1fr); }
  .catalogo-toolbar { flex-wrap: wrap; }
  .search-field { flex: 1 1 240px; }
}

/* Al mostrar la vista previa, el ícono de la zona de carga sobra. */
#previewImagenProducto:not([hidden]) ~ .upload-icon { display: none; }

/* ============================================================
   Nueva cotización — rediseño (barra de folio, cliente+descripción,
   conceptos con badge de stock, pie con acciones + resumen).
   Comparte los mismos tokens de :root. Ver preview_editar.html.
   ============================================================ */

/* La sección se centra en un ancho cómodo, como el resto del layout. */
#sectionNueva { max-width: 1040px; }

/* ===== Barra superior: folio + fechas + estado ===== */
.quote-head {
  display: flex;
  align-items: center;
  gap: 40px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 22px;
  margin-bottom: 16px;
}
.qh-item { display: flex; flex-direction: column; gap: 3px; }
.qh-item .lbl {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 500;
}
.qh-item .val { font-size: 13px; color: var(--ink); font-weight: 500; }
.qh-folio .val {
  font-family: var(--font-mono);
  font-size: 20px;
  color: var(--ink-strong);
  letter-spacing: 0.01em;
}
.qh-badge {
  margin-left: auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

/* ===== Dos columnas: cliente + descripción ===== */
.quote-cols {
  display: grid;
  grid-template-columns: 1.42fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
.quote-cols .stack { display: grid; gap: 14px; }
.desc-panel { display: flex; flex-direction: column; }
.desc-panel label { flex: 1; display: flex; flex-direction: column; }
.desc-panel textarea { flex: 1; min-height: 200px; }

/* ===== Conceptos ===== */
.concept-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.concept-head h2 { margin: 0; white-space: nowrap; }
/* Buscador del encabezado: el wrapper crece; el input llena y no arrastra el
   margin-top global de los inputs. */
.concept-search { flex: 1; margin-top: 0; }
.concept-search-input { margin-top: 0; }
.concept-add { flex-shrink: 0; }

.concepts-table input { margin-top: 0; }
.concepts-table th.num, .concepts-table td.num { text-align: right; }
.concepts-table th.ctr, .concepts-table td.ctr { text-align: center; }
.concepts-table .col-qty input { width: 64px; text-align: center; padding: 8px; }
.concepts-table .col-price input { width: 96px; text-align: right; padding: 8px 10px; }
.concept-main { color: var(--ink-strong); font-weight: 500; }
.concept-sub { color: var(--muted); }
.concepts-table .total {
  font-family: var(--font-mono);
  color: var(--ink-strong);
  text-align: right;
  white-space: nowrap;
}
.row-del {
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  line-height: 0;
}
.row-del:hover { color: var(--danger); background: var(--danger-surface); }
.row-del svg { width: 16px; height: 16px; }

/* Celda de concepto: por defecto muestra el concepto como texto (dos tonos);
   al editar cambia a un input que parece texto hasta enfocar. */
.concept-cell .product-picker { position: relative; }

.concept-display {
  display: flex;
  align-items: baseline;
  gap: 5px;
  width: 100%;
  margin: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  cursor: text;
  font: inherit;
}
.concept-display:hover { border-color: var(--line); }
.concept-display .concept-sub:empty { display: none; }

.concept-input {
  width: 100%;
  margin: 0;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink-strong);
  font: 500 13px/1.35 var(--font-body);
}
.concept-input::placeholder { color: var(--faint); font-weight: 400; }
.concept-input:hover { border-color: var(--line); }
.concept-input:focus {
  outline: none;
  background: var(--surface-2);
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

/* Alternancia display / edición */
.concept-cell .item-product-search { display: none; }
.concept-cell.editing .item-product-search { display: block; }
.concept-cell.editing .concept-display { display: none; }

.stock-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.stock-badge.ok  { color: var(--green); background: var(--green-surface); border: 1px solid var(--green-line); }
.stock-badge.na  { color: var(--muted); background: var(--surface-3); border: 1px solid var(--line); }
.stock-badge.low { color: var(--amber); background: var(--amber-surface); border: 1px solid #4a3620; }
.stock-badge.none { color: var(--faint); background: transparent; border: 1px solid var(--line-soft); }

/* ===== Pie: acciones + totales ===== */
.quote-foot {
  display: grid;
  grid-template-columns: 1.42fr 1fr;
  gap: 16px;
  align-items: start;
}
.action-card .action-row { display: flex; gap: 10px; flex-wrap: wrap; }
.action-card .btn svg { width: 15px; height: 15px; }
.action-note { color: var(--faint); font-size: 12px; line-height: 1.45; margin: 14px 0 0; }
.action-note .link-btn { font-size: 12px; }

.summary { padding: 0; overflow: hidden; }
.summary .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 20px;
  font-size: 13px;
}
.summary .row span { color: var(--muted); }
.summary .row strong { font-family: var(--font-mono); font-weight: 500; color: var(--ink); }
.summary .divider { height: 1px; background: var(--line-soft); }
.summary .grand { padding: 16px 20px 18px; }
.summary .grand .g-label { color: var(--ink-strong); font-weight: 600; font-size: 14px; }
.summary .grand .g-val {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.summary .grand .g-note {
  display: block;
  text-align: right;
  color: var(--faint);
  font-size: 11px;
  margin-top: 2px;
}

@media (max-width: 820px) {
  .quote-head { flex-wrap: wrap; gap: 18px 28px; }
  .quote-cols,
  .quote-foot { grid-template-columns: 1fr; }
  .desc-panel textarea { min-height: 120px; }
}

/* ============================================================
   Nueva cotización — Cotización con IA (toggle normal/IA, panel de
   preguntas guiadas, selector de 3 planes generados).
   Reutiliza .segmented/.seg-btn (ya definidos arriba) y los tokens
   de :root; no se duplican reglas ya existentes.
   ============================================================ */

/* ===== Toggle Normal / IA (mismo .segmented reutilizado) ===== */
.quote-mode-toggle {
  margin: 16px 0;
}

/* ===== Panel de preguntas guiadas ===== */
.ia-panel {
  /* Hereda fondo/borde/radius de .panel y flex column de .desc-panel;
     aquí solo se ajusta lo que .desc-panel asume para un único
     textarea grande, que no aplica a un formulario de varios campos. */
  gap: 14px;
}

.ia-panel label {
  /* Anula el flex:1 + flex-column que .desc-panel label define para el
     textarea de descripción: aquí cada .ia-field es un campo normal. */
  flex: none;
  display: block;
}

.ia-panel textarea {
  /* Anula min-height:200px de .desc-panel textarea: el textarea opcional
     de "algo más que debamos saber" es de 2 renglones, no ocupa el panel. */
  flex: none;
  min-height: 64px;
}

.ia-field {
  display: block;
}

input.ia-field {
  /* Cuando .ia-field se usa en un input suelto (no envuelto en label),
     conserva el spacing vertical del resto de campos del .stack. */
  margin-top: 0;
}

/* Fila de 2 columnas (grid.two ya cubre esto; se deja el alias por si el
   HTML usa .ia-field-row en vez de reusar grid.two). */
.ia-field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

/* Hint bajo un campo (mismo look que .field-hint). */
.hint {
  display: block;
  margin-top: 6px;
  color: var(--faint);
  font-size: 11.5px;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.35;
}

/* Grupo de checkboxes de cobertura (interior/exterior) */
.ia-checkbox-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin: 0;
  padding: 0;
  border: 0;
}

.ia-checkbox-group legend {
  width: 100%;
  padding: 0 0 2px;
  color: var(--steel);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.ia-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

/* Preguntas booleanas tipo switch: texto a la izquierda, checkbox a la
   derecha (row-reverse invierte el orden visual de input + texto). */
.ia-switch-row.switch-row {
  display: flex;
  flex-direction: row-reverse;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.ia-switch-row.switch-row input[type="checkbox"] {
  flex: 0 0 auto;
}

/* ===== Selector de 3 planes (mismo .segmented reutilizado) ===== */
.plan-toggle {
  margin-bottom: 4px;
}

/* Texto secundario debajo del selector de planes (mismo look que .action-note) */
.plan-summary {
  color: var(--faint);
  font-size: 12px;
  line-height: 1.45;
  margin: 8px 0 14px;
}

.plan-summary:empty {
  display: none;
}

@media (max-width: 820px) {
  .ia-field-row {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   AUTENTICACIÓN — carga inicial, pantalla de login y estados de sesión
   ========================================================================== */

/* Estados de visibilidad según la sesión.
   auth-cargando: verificando sesión (oculta todo, muestra spinner).
   sesion-activa: usuario autenticado (muestra la app, oculta el login). */
#authLoading { display: none; }
body.auth-cargando #authLoading { display: flex; }
body.auth-cargando .login-screen,
body.auth-cargando .app-shell { display: none !important; }
body:not(.sesion-activa) .app-shell { display: none !important; }
body.sesion-activa .login-screen { display: none !important; }

.auth-loading {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--canvas);
}

.auth-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

/* --- Pantalla de login (dos columnas: marca + formulario) --- */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  background: var(--canvas);
}

.login-aside {
  flex: 1 1 0;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  overflow: hidden;
  background:
    radial-gradient(1100px 620px at 18% 12%, rgba(106, 166, 242, 0.16), transparent 60%),
    radial-gradient(900px 600px at 92% 88%, rgba(47, 107, 196, 0.14), transparent 62%),
    linear-gradient(160deg, #0d1420 0%, #0a0a0c 62%);
  border-right: 1px solid var(--line-soft);
}

.login-aside::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--line-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-soft) 1px, transparent 1px);
  background-size: 46px 46px;
  opacity: 0.35;
  -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 0%, transparent 75%);
  mask-image: radial-gradient(circle at 30% 40%, #000 0%, transparent 75%);
  pointer-events: none;
}

.login-aside-inner {
  position: relative;
  z-index: 1;
  max-width: 420px;
}

.login-aside-logo {
  width: 66px;
  height: 66px;
  object-fit: contain;
  border-radius: 16px;
  background: #fff;
  padding: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 26px;
}

.login-aside-inner h2 {
  margin: 0 0 14px;
  font: 600 27px/1.25 var(--font-display);
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  text-transform: none;
}

.login-aside-inner > p {
  margin: 0 0 26px;
  max-width: 360px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.login-aside-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-aside-list li {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 13.5px;
  color: var(--ink);
}

.login-aside-list svg {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-surface);
  border: 1px solid var(--accent-line);
}

.login-panel {
  flex: 0 0 clamp(360px, 42%, 520px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 36px;
}

.login-card {
  width: 100%;
  max-width: 372px;
}

.login-brand {
  display: none;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.login-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 12px;
  background: #fff;
  padding: 5px;
}

.login-brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.login-brand-name {
  font: 700 17px/1 var(--font-display);
  letter-spacing: 0.02em;
  color: var(--ink-strong);
}
.login-brand-sub { font-size: 11.5px; color: var(--muted); }

.login-title {
  margin: 0 0 6px;
  font: 600 24px/1.2 var(--font-display);
  letter-spacing: -0.01em;
  color: var(--ink-strong);
  text-transform: none;
}

.login-lead {
  margin: 0 0 26px;
  font-size: 13.5px;
  color: var(--muted);
}

.login-form { display: flex; flex-direction: column; gap: 15px; }

.login-field { display: flex; flex-direction: column; gap: 7px; }

.login-field > label {
  font: 600 9.5px/1 var(--font-body);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--steel);
}

.login-input {
  position: relative;
  display: flex;
  align-items: center;
}

.login-input-icon {
  position: absolute;
  left: 12px;
  width: 17px;
  height: 17px;
  color: var(--faint);
  pointer-events: none;
}

.login-input input {
  width: 100%;
  margin: 0;
  height: 46px;
  padding: 0 44px 0 40px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 14px/1 var(--font-body);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.login-input input::placeholder { color: var(--faint); }

.login-input input:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.login-toggle {
  position: absolute;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.login-toggle:hover { color: var(--ink); background: var(--surface-3); }
.login-toggle svg { width: 18px; height: 18px; }
.login-toggle.is-visible { color: var(--accent); }

.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-surface);
  border: 1px solid var(--danger-line);
  color: var(--danger);
  font-size: 12.5px;
}

.login-submit {
  position: relative;
  height: 46px;
  margin-top: 5px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font: 600 14px/1 var(--font-body);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.login-submit:hover { background: var(--accent-hover); }
.login-submit:active { transform: translateY(1px); }
.login-submit:focus-visible { outline: none; box-shadow: var(--ring); }
.login-submit:disabled { cursor: default; opacity: 0.85; }

.login-submit-spinner {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid rgba(6, 16, 32, 0.35);
  border-top-color: var(--accent-ink);
  animation: auth-spin 0.7s linear infinite;
}
.login-submit.is-loading .login-submit-label { opacity: 0; }
.login-submit.is-loading .login-submit-spinner { display: block; }

.login-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 26px 0 0;
  font-size: 11.5px;
  color: var(--faint);
}
.login-foot svg { width: 14px; height: 14px; }

/* --- Control de sesión en el rail --- */
.rail-session {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding-bottom: 2px;
}

.rail-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.rail-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
  background: var(--accent-surface);
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font: 600 14px/1 var(--font-mono);
  text-transform: uppercase;
}

.rail-role {
  font: 700 7.5px/1 var(--font-body);
  letter-spacing: 0.1em;
  color: var(--accent);
}

.rail-logout {
  width: 38px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: #5c5c64;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.rail-logout:hover {
  color: var(--danger);
  background: var(--danger-surface);
  border-color: var(--danger-line);
}
.rail-logout svg { width: 19px; height: 19px; }
.rail-logout:focus-visible { outline: none; box-shadow: var(--ring); }

.tab-admin { margin-top: 4px; }

/* ==========================================================================
   SECCIÓN USUARIOS (administración de credenciales)
   ========================================================================== */
.usuarios-layout {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.usuarios-card {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  overflow: hidden;
}

.usuarios-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.usuarios-table thead th {
  height: 34px;
  padding: 0 14px;
  text-align: left;
  font: 600 8px/1 var(--font-body);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.usuarios-table thead th.col-acciones { text-align: right; }

.usuarios-table tbody td {
  height: 52px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line-soft);
  font: 400 13px/1.4 var(--font-body);
  color: var(--ink);
  vertical-align: middle;
}
.usuarios-table tbody tr:last-child td { border-bottom: 0; }
.usuarios-table tbody tr:hover td { background: var(--surface-2); }

.usuarios-table td.empty {
  height: 68px;
  text-align: center;
  color: var(--faint);
}

.user-name {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}
.user-badge-avatar {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--ink-strong);
  font: 600 12px/1 var(--font-mono);
  text-transform: uppercase;
}
.user-name-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-strong);
  font-weight: 500;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font: 600 10.5px/1 var(--font-body);
  letter-spacing: 0.02em;
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--muted);
}
.user-chip.rol { color: var(--accent); background: var(--accent-surface); border-color: var(--accent-line); }
.user-chip.on  { color: var(--green); background: var(--green-surface); border-color: var(--green-line); }
.user-chip.off { color: var(--faint); }

.user-date { color: var(--muted); font-size: 12px; white-space: nowrap; }

.usuarios-table td[data-label="Acciones"] .user-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { color: var(--ink-strong); background: var(--surface-3); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-surface); border-color: var(--danger-line); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }

.usuarios-side { display: flex; flex-direction: column; gap: 12px; }

.side-hint {
  margin: -8px 0 16px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

#userForm .field { display: block; margin-bottom: 14px; }

#userForm .field-label {
  display: block;
  margin-bottom: 6px;
  font: 600 9.5px/1 var(--font-body);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--steel);
}

#userForm input[type="text"],
#userForm input[type="password"] {
  width: 100%;
  margin: 0;
  height: 42px;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: 400 13px/1 var(--font-body);
}
#userForm input::placeholder { color: var(--faint); }
#userForm input:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.pass-field { position: relative; display: flex; align-items: center; }
.pass-field input { padding-right: 42px !important; }
.pass-toggle {
  position: absolute;
  right: 5px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}
.pass-toggle:hover { color: var(--ink); background: var(--surface-3); }
.pass-toggle svg { width: 17px; height: 17px; }
.pass-toggle.is-visible { color: var(--accent); }

.field-help {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--faint);
}

.switch-field {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 6px;
  cursor: pointer;
  text-transform: none;
  letter-spacing: normal;
}
.switch-field input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.15s ease, background 0.15s ease;
}
.switch-field input:checked + .switch {
  background: var(--accent-surface);
  border-color: var(--accent-line);
}
.switch-field input:checked + .switch::after {
  transform: translateX(16px);
  background: var(--accent);
}
.switch-field input:focus-visible + .switch { box-shadow: var(--ring); }
.switch-text { font-size: 12.5px; color: var(--ink); }

.form-error {
  padding: 9px 11px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: var(--danger-surface);
  border: 1px solid var(--danger-line);
  color: var(--danger);
  font-size: 12px;
}

.side-actions { display: flex; gap: 8px; margin-top: 4px; }
.side-actions .btn { flex: 1; }

/* --- Responsive login + usuarios --- */
@media (max-width: 860px) {
  .login-aside { display: none; }
  .login-panel { flex: 1 1 auto; }
  .login-brand { display: flex; }
  .usuarios-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   BUSCADOR DE CONCEPTOS — modal centrado (reemplaza el dropdown inferior)
   ========================================================================== */
.modal.modal-center { align-items: center; }

.picker-content {
  width: min(560px, 100%);
  padding: 26px 26px 22px;
}

.picker-title {
  margin: 0 0 4px;
  font: 600 18px/1.2 var(--font-display);
  color: var(--ink-strong);
}

.picker-sub {
  margin: 0 0 16px;
  font-size: 12.5px;
  color: var(--muted);
}

.picker-search {
  position: relative;
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.picker-search-icon {
  position: absolute;
  left: 13px;
  width: 17px;
  height: 17px;
  color: var(--faint);
  pointer-events: none;
}

.picker-search input {
  width: 100%;
  margin: 0;
  height: 46px;
  padding: 0 14px 0 40px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 14px/1 var(--font-body);
}
.picker-search input::placeholder { color: var(--faint); }
.picker-search input:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.picker-results {
  max-height: min(46vh, 380px);
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.picker-results:empty { display: none; }

.picker-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover,
.picker-item.is-active { background: var(--surface-2); }
.picker-item:focus-visible { outline: none; background: var(--surface-2); box-shadow: inset 0 0 0 2px var(--accent-line); }

.picker-item-body { min-width: 0; flex: 1; }
.picker-item-name {
  display: block;
  color: var(--ink-strong);
  font-weight: 500;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picker-item-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11.5px;
}
.picker-item-tag {
  flex: 0 0 auto;
  padding: 3px 9px;
  border-radius: 999px;
  font: 600 10px/1 var(--font-body);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  background: var(--surface-3);
  color: var(--muted);
}
.picker-item-tag.servicio { color: var(--accent); background: var(--accent-surface); border-color: var(--accent-line); }

.picker-empty {
  padding: 22px 14px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}

.picker-foot { margin-top: 14px; }
.picker-free { width: 100%; }

/* ==========================================================================
   SELECTORES NUMÉRICOS (stepper) — flechas azules, incremento de 1 en 1
   ========================================================================== */
/* Se ocultan las flechas nativas (no se pueden recolorear) y se reemplazan por
   un stepper propio azul, construido en JS (enhanceNumberSteppers). */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.stepper {
  position: relative;
  display: block;
  margin-top: 7px;
}
.stepper > input[type="number"] {
  margin: 0;
  padding-right: 26px;
}

.stepper-btns {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stepper-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 10px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--accent-surface);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.stepper-btn:hover { background: var(--accent); color: var(--accent-ink); }
.stepper-btn:active { transform: scale(0.9); }
.stepper-btn svg { width: 9px; height: 9px; display: block; }
.stepper-btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* En la tabla de conceptos los inputs tienen ancho fijo y van centrados:
   el stepper se ajusta a ellos en vez de ocupar toda la celda. */
.concepts-table .stepper { display: inline-flex; margin-top: 0; vertical-align: middle; }
.concepts-table .col-qty .stepper > input,
.concepts-table .col-price .stepper > input { padding-right: 22px; }

/* El formulario de productos usa inputs con margin:0 y padding propio (mayor
   especificidad): el stepper se alinea a esa convención. */
#productForm .stepper { margin-top: 0; }
#productForm .stepper > input[type="number"] { padding-right: 26px; }

/* ==========================================================================
   CHECKBOXES — rediseño azul con animación limpia (sin bug de tamaño)
   Reemplaza el render nativo. Los checkbox de #productForm y los .switch-field
   (usuarios) conservan su propio estilo por mayor especificidad.
   ========================================================================== */
input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  padding: 0;
  border: 1.5px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface-2);
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
input[type="checkbox"]:hover { border-color: var(--accent-line); }
input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 2px;
  width: 4px;
  height: 8px;
  border: solid var(--accent-ink);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  transform-origin: center;
  animation: cb-check 0.16s ease-out;
}
input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* Animación única y contenida: el check aparece con un pop suave. No cambia el
   tamaño de la caja (18x18 fijo), así que no altera la distribución. */
@keyframes cb-check {
  0%   { opacity: 0; transform: rotate(45deg) scale(0.4); }
  100% { opacity: 1; transform: rotate(45deg) scale(1); }
}

/* ==========================================================================
   BORDER GLOW — borde con degradado que sigue el cursor (port vanilla de
   React Bits <BorderGlow/>). Solo pseudo-elementos: no altera el layout.
   ========================================================================== */
@property --cursor-angle { syntax: "<angle>"; initial-value: 135deg; inherits: false; }
@property --edge-proximity { syntax: "<number>"; initial-value: 0; inherits: false; }

.border-glow {
  --cursor-angle: 135deg;
  --edge-proximity: 0;
  position: relative;
}

/* Anillo de degradado (técnica de borde con máscara XOR: funciona sobre
   cualquier fondo, incluido transparente). */
.border-glow::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1.5px;
  background: conic-gradient(from var(--cursor-angle) at 50% 50%,
    #38bdf8, #c084fc, #f472b6, #38bdf8);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
  opacity: calc(0.4 + 0.6 * var(--edge-proximity));
  pointer-events: none;
  transition: --cursor-angle 0.18s ease-out, opacity 0.35s ease-out;
  z-index: 1;
}

/* Halo exterior suave que se intensifica cerca del cursor. */
.border-glow::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 20px 1px rgb(140 130 250 / calc(0.10 + 0.30 * var(--edge-proximity)));
  transition: box-shadow 0.35s ease-out;
  z-index: 0;
}

/* En el botón IA (dentro del control segmentado) el contenido debe ir sobre
   el anillo. */
#modoIaBtn.border-glow { z-index: 0; }
#modoIaBtn.border-glow > * { position: relative; z-index: 2; }

/* ==========================================================================
   BOTÓN METÁLICO — barrido metálico/líquido animado (interpretación ligera de
   MetallicPaint para un botón; sin WebGL).
   ========================================================================== */
.btn-metallic {
  position: relative;
  overflow: hidden;
  border: 0;
  background: linear-gradient(100deg,
    var(--accent-deep) 0%,
    var(--accent) 25%,
    #a9cbfb 45%,
    var(--accent) 65%,
    var(--accent-deep) 100%);
  background-size: 260% 100%;
  animation: metallic-flow 5s linear infinite;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), var(--shadow-sm);
}
.btn-metallic:hover { background-size: 260% 100%; filter: brightness(1.05); }

.btn-metallic::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 30%,
    rgb(255 255 255 / 0.35) 44%,
    rgb(255 255 255 / 0.75) 50%,
    rgb(255 255 255 / 0.35) 56%,
    transparent 70%);
  transform: translateX(-130%);
  animation: metallic-sheen 3.6s ease-in-out infinite;
  pointer-events: none;
}
.btn-metallic-label { position: relative; z-index: 1; }

@keyframes metallic-flow {
  0% { background-position: 0% 50%; }
  100% { background-position: 260% 50%; }
}
@keyframes metallic-sheen {
  0% { transform: translateX(-130%); }
  55%, 100% { transform: translateX(130%); }
}

/* ==========================================================================
   MODAL DE CONFIRMACIÓN + TOASTS (reemplazan confirm/prompt/alert nativos)
   ========================================================================== */
.confirm-content {
  width: min(430px, 100%);
  padding: 26px 26px 22px;
  text-align: center;
}

.confirm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--accent-surface);
  border: 1px solid var(--accent-line);
  color: var(--accent);
}
.confirm-icon svg { width: 24px; height: 24px; }
.confirm-content.tone-danger .confirm-icon {
  background: var(--danger-surface);
  border-color: var(--danger-line);
  color: var(--danger);
}
.confirm-content.tone-warning .confirm-icon {
  background: var(--amber-surface);
  border-color: #40331f;
  color: var(--amber);
}

.confirm-title {
  margin: 0 0 6px;
  font: 600 18px/1.25 var(--font-display);
  color: var(--ink-strong);
}
.confirm-message {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--muted);
  white-space: pre-line;
}

.confirm-reason {
  margin-top: 16px;
  text-align: left;
}
.confirm-reason-label {
  display: block;
  margin-bottom: 6px;
  font: 600 9.5px/1 var(--font-body);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--steel);
}
.confirm-reason textarea {
  width: 100%;
  margin: 0;
  min-height: 70px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 13px/1.5 var(--font-body);
  resize: vertical;
}
.confirm-reason textarea:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: var(--ring);
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
}
.confirm-actions .btn { min-width: 130px; }

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 44px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
  pointer-events: auto;
  animation: toast-in 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.leaving { animation: toast-out 0.25s ease-in forwards; }
.toast-ic {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 1px;
}
.toast.ok { border-color: var(--green-line); }
.toast.ok .toast-ic { color: var(--green); }
.toast.error { border-color: var(--danger-line); }
.toast.error .toast-ic { color: var(--danger); }
.toast.info .toast-ic { color: var(--accent); }
.toast-close {
  flex: 0 0 auto;
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}
.toast-close:hover { color: var(--ink); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(20px); }
}

/* ==========================================================================
   MODO IA — optimización del espacio vacío bajo "Datos del cliente"
   ========================================================================== */
/* En modo IA los dos paneles ya no se estiran a la altura del más alto: cada
   uno toma su altura natural (se elimina la tarjeta con hueco enorme), y se da
   más ancho al cuestionario para que sea menos alto. */
.quote-cols.ia-mode {
  align-items: start;
  grid-template-columns: 1fr 1.3fr;
}
