/* NEXAR Facturación · UI responsiva (sin depender de Tailwind) */
:root {
  --nexar-blue: #0A74DA;
  --nexar-dark: #0D1B2A;
  --nexar-accent: #00C2FF;
  --nexar-light: #E8F4FD;
  --nexar-green: #10B981;
  --nexar-red: #EF4444;
  --nexar-gray: #6B7280;
  --nexar-bg: #f1f5f9;
  --nav-h: 56px;
  --sidebar-w: 260px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(13, 27, 42, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--nexar-dark);
  background: var(--nexar-bg);
  min-height: 100dvh;
}

img { max-width: 100%; height: auto; }

a { color: var(--nexar-blue); }

/* Isotipo NEXAR · PNG */
.nexar-logo-png {
  display: block;
  height: 34px;
  width: auto;
  object-fit: contain;
}

.nexar-logo-link {
  display: inline-flex;
  align-items: center;
  line-height: 0;
  text-decoration: none;
  flex-shrink: 0;
}

.nexar-login-card .nexar-logo-png {
  height: 40px;
  max-width: 180px;
}

/* ========== LOGIN ========== */
body.nexar-login-page {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  background: linear-gradient(145deg, var(--nexar-dark) 0%, #152a45 45%, #0a5fad 100%);
}

.nexar-login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 20px;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow), 0 20px 60px rgba(0, 0, 0, 0.25);
}

.nexar-login-card .nexar-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
}

.nexar-login-subtitle {
  text-align: center;
  color: var(--nexar-gray);
  font-size: 0.9rem;
  margin: 0 0 0.25rem;
}

.nexar-login-empresa {
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
  margin: 0 0 1.5rem;
}

/* ========== APP SHELL ========== */
.nexar-app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.nexar-navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
  background: var(--nexar-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 1rem;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.nexar-navbar-start {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.nexar-menu-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  padding: 0.5rem;
  cursor: pointer;
  border-radius: 8px;
  line-height: 0;
}

.nexar-menu-toggle:hover { background: rgba(255,255,255,0.1); }

.nexar-menu-toggle svg { width: 24px; height: 24px; }

.nexar-navbar-title {
  font-size: 0.8rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 479px) {
  .nexar-navbar-title { display: none; }
}

.nexar-navbar-end {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  flex-shrink: 1;
  min-width: 0;
  margin-left: auto;
}

.nexar-user-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  min-width: 0;
  max-width: min(200px, 45vw);
}

.nexar-user-name {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  line-height: 1.2;
}

.nexar-user-chip .badge-rol {
  flex-shrink: 0;
  align-self: flex-end;
}

@media (min-width: 640px) {
  .nexar-user-chip {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    max-width: none;
  }

  .nexar-user-name {
    font-size: 0.8rem;
    max-width: 220px;
  }

  .nexar-user-chip .badge-rol { align-self: center; }
}

@media (min-width: 480px) {
  .nexar-navbar { padding: 0 1.25rem; }
  .nexar-logo-png { height: 36px; }
}

.nexar-logout {
  color: #fff;
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  white-space: nowrap;
}

.nexar-logout:hover {
  background: rgba(255,255,255,0.1);
  color: var(--nexar-accent);
}

.nexar-app-body {
  display: flex;
  flex: 1;
  align-items: stretch;
  min-height: calc(100dvh - var(--nav-h));
  position: relative;
}

.nexar-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--nav-h);
  background: rgba(0, 0, 0, 0.5);
  z-index: 89;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.nexar-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: var(--nav-h);
  min-height: calc(100dvh - var(--nav-h));
  max-height: calc(100dvh - var(--nav-h));
  background: var(--nexar-dark);
  color: #cbd5e1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.nexar-sidebar nav {
  flex-shrink: 0;
}

.nexar-nav-item {
  display: block;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  color: #94a3b8;
  text-decoration: none;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.nexar-nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nexar-nav-item.active {
  background: rgba(10, 116, 218, 0.25);
  color: #fff;
  border-left-color: var(--nexar-blue);
  font-weight: 500;
}

.nexar-sidebar-cai {
  margin-top: 1rem;
  flex-shrink: 0;
  padding: 0.85rem;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.7rem;
  color: #94a3b8;
  word-break: break-all;
}

.nexar-sidebar-cai strong {
  display: block;
  color: var(--nexar-accent);
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
}

.nexar-main {
  flex: 1;
  min-width: 0;
  padding: 1rem;
  padding-bottom: calc(1rem + var(--safe-bottom));
  overflow-x: hidden;
}

@media (min-width: 768px) {
  .nexar-main { padding: 1.5rem; }
}

/* Mobile sidebar drawer */
@media (max-width: 767px) {
  .nexar-menu-toggle { display: flex; }

  .nexar-sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
  }

  body.nexar-sidebar-open .nexar-sidebar {
    transform: translateX(0);
  }

  body.nexar-sidebar-open .nexar-sidebar-overlay {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }
}

/* ========== COMPONENTES ========== */
.nexar-page-title {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
  font-weight: 700;
  margin: 0 0 1.25rem;
  color: var(--nexar-dark);
}

.nexar-page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.nexar-page-header .nexar-page-title { margin-bottom: 0; }

.nexar-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.nexar-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 1rem;
}

.nexar-grid-2 {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 900px) {
  .nexar-grid-2 { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 900px) {
  .nexar-grid-2-productos {
    align-items: start;
  }

  .nexar-card-form-producto {
    position: sticky;
    top: calc(var(--nav-h) + 1rem);
  }
}

.nexar-form-group {
  margin-bottom: 1rem;
}

.nexar-form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--nexar-gray);
  margin-bottom: 0.35rem;
}

.nexar-form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 480px) {
  .nexar-form-row-2 { grid-template-columns: 1fr 1fr; }
}

.nexar-input,
.nexar-select,
.nexar-textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
  color: var(--nexar-dark);
  -webkit-appearance: none;
  appearance: none;
}

.nexar-textarea { min-height: 80px; resize: vertical; }

.nexar-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236B7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1.1rem;
  padding-right: 2.25rem;
}

.nexar-input:focus,
.nexar-select:focus,
.nexar-textarea:focus {
  outline: none;
  border-color: var(--nexar-blue);
  box-shadow: 0 0 0 3px rgba(10, 116, 218, 0.2);
}

.nexar-input:-webkit-autofill,
.nexar-input:-webkit-autofill:hover,
.nexar-input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px #fff inset;
  -webkit-text-fill-color: var(--nexar-dark);
  transition: background-color 5000s ease-in-out 0s;
}

.nexar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 44px;
  padding: 0.6rem 1.25rem;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  appearance: none;
  -webkit-appearance: none;
}

.nexar-btn:active { transform: scale(0.98); }

.nexar-btn-primary {
  background: var(--nexar-blue);
  color: #fff;
}

.nexar-btn-primary:hover { background: #0860b8; }

.nexar-btn-secondary {
  background: #fff;
  color: var(--nexar-blue);
  border: 2px solid var(--nexar-blue);
}

.nexar-btn-secondary:hover { background: var(--nexar-light); }

.nexar-btn-block { width: 100%; }

.nexar-btn-sm {
  min-height: 32px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: 8px;
}

.nexar-table-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.nexar-btn-danger {
  background: #fff;
  color: var(--nexar-red);
  border: 2px solid var(--nexar-red);
}

.nexar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.nexar-actions-end {
  justify-content: flex-end;
  align-items: flex-end;
}

.nexar-totals {
  text-align: right;
  font-size: 0.9rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #e2e8f0;
}

.nexar-totals p { margin: 0.25rem 0; }

.nexar-totals-grand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--nexar-blue);
  margin-top: 0.5rem !important;
}

.nexar-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -0.25rem;
}

.nexar-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.nexar-table thead th {
  background: var(--nexar-dark);
  color: #fff;
  padding: 0.75rem;
  text-align: left;
  font-weight: 500;
  white-space: nowrap;
}

.nexar-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.nexar-table tbody tr:nth-child(even) { background: var(--nexar-light); }

/* Catálogo productos: panel con scroll + búsqueda */
.nexar-card-catalogo {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.nexar-catalogo-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.35rem 1rem;
  margin-bottom: 0.75rem;
}

.nexar-catalogo-head-title {
  margin-bottom: 0 !important;
}

.nexar-catalogo-count {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--nexar-gray);
  white-space: nowrap;
}

.nexar-catalogo-toolbar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.nexar-search-box {
  position: relative;
  flex: 1;
  min-width: 0;
}

.nexar-search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--nexar-gray);
  pointer-events: none;
  display: flex;
  line-height: 0;
}

.nexar-input-search {
  padding-left: 2.65rem !important;
  min-height: 42px;
  background: #fff;
}

.nexar-input-search::-webkit-search-cancel-button {
  cursor: pointer;
}

.nexar-catalogo-limpiar {
  flex-shrink: 0;
  border: none;
  background: none;
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--nexar-blue);
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.nexar-catalogo-limpiar:hover {
  color: var(--nexar-dark);
}

.nexar-catalogo-panel {
  flex: 1;
  min-height: 240px;
  max-height: min(68vh, calc(100dvh - 13rem));
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: linear-gradient(180deg, #fafbfc 0%, #f8fafc 100%);
  padding: 0.85rem 0.75rem;
  box-shadow: inset 0 1px 2px rgba(13, 27, 42, 0.04);
}

.nexar-catalogo-panel:focus-within {
  border-color: #93c5fd;
  box-shadow: inset 0 1px 2px rgba(13, 27, 42, 0.04), 0 0 0 3px rgba(10, 116, 218, 0.12);
}

.nexar-catalogo-panel::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.nexar-catalogo-panel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.nexar-catalogo-panel::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.nexar-catalogo-list {
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.nexar-catalogo-item.is-hidden {
  display: none !important;
}

.nexar-catalogo-panel--activo {
  border-color: #93c5fd;
}

.nexar-catalogo-grupo.is-empty {
  display: none;
}

.nexar-catalogo-sin-resultados {
  margin: 2rem 1rem;
  text-align: center;
  font-size: 0.88rem;
  color: var(--nexar-gray);
  line-height: 1.5;
}

.nexar-catalogo-sin-resultados strong {
  color: var(--nexar-dark);
  font-weight: 600;
}

/* Buscador de productos en nueva factura */
.nexar-card-agregar-item {
  position: relative;
  z-index: 20;
  overflow: visible;
}

.nexar-factura-producto-picker {
  position: relative;
  z-index: 21;
  margin-bottom: 0;
}

.nexar-factura-search-anchor {
  position: relative;
  z-index: 22;
}

.nexar-factura-search-box {
  margin-bottom: 0;
}

.nexar-factura-input-search {
  padding-right: 2.5rem !important;
}

.nexar-factura-clear {
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--nexar-blue);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nexar-factura-clear:hover {
  background: var(--nexar-light);
}

.nexar-factura-resultados {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 200;
  border: 1px solid #dbeafe;
  border-radius: 12px;
  max-height: min(50vh, 340px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.35rem 0.25rem;
  background: #fff;
  box-shadow: 0 12px 32px rgba(13, 27, 42, 0.14);
}

.nexar-factura-resultados.is-open {
  display: block;
}

.nexar-factura-resultados[hidden] {
  display: none !important;
}

.nexar-factura-resultados::-webkit-scrollbar {
  width: 8px;
}

.nexar-factura-resultados::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.nexar-factura-resultados::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.nexar-factura-opcion {
  width: 100%;
  border: none;
  background: transparent;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.85rem;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.nexar-factura-opcion:hover,
.nexar-factura-opcion:focus-visible,
.nexar-factura-opcion.is-active {
  background: var(--nexar-light);
  outline: none;
}

.nexar-factura-opcion-main {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
  flex: 1;
}

.nexar-factura-opcion-grupo {
  color: var(--nexar-blue);
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.2;
}

.nexar-factura-opcion-nombre {
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--nexar-dark);
  word-break: break-word;
}

.nexar-factura-opcion-precio {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--nexar-dark);
  white-space: nowrap;
  padding-top: 0.95rem;
  flex-shrink: 0;
}

.nexar-factura-sin-resultados {
  margin: 0.75rem 0.35rem;
  font-size: 0.85rem;
  color: var(--nexar-gray);
  text-align: center;
}

.nexar-catalogo-grupo-title {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--nexar-dark);
}

.nexar-catalogo-table { min-width: 640px; }

.nexar-catalogo-plan { vertical-align: top; max-width: 28rem; }

.nexar-catalogo-plan-nombre {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--nexar-dark);
}

.nexar-catalogo-plan-desc {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--nexar-gray);
}

.nexar-record-card-desc {
  margin: -0.25rem 0 0.5rem;
}

.nexar-nowrap { white-space: nowrap; }

.nexar-hint {
  margin: 0.35rem 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--nexar-gray);
}

.nexar-card-catalogo .nexar-catalogo-grupo + .nexar-catalogo-grupo {
  padding-top: 0;
}

.nexar-table .nexar-input {
  min-height: 38px;
  min-width: 70px;
  font-size: 0.85rem;
  padding: 0.4rem 0.5rem;
}

/* Listados en móvil (clientes, productos, etc.) */
.nexar-record-cards { display: none; }

.nexar-record-card {
  background: var(--nexar-light);
  border: 1px solid #dbeafe;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
}

.nexar-record-card:last-child { margin-bottom: 0; }

.nexar-record-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
  color: var(--nexar-dark);
  word-break: break-word;
}

.nexar-record-card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.nexar-record-card-field--full { grid-column: 1 / -1; }

.nexar-record-card-field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--nexar-gray);
  margin-bottom: 0.15rem;
}

.nexar-record-card-field span,
.nexar-record-card-field a {
  display: block;
  word-break: break-word;
}

.badge-activo {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #d1fae5;
  color: #065f46;
}

.badge-inactivo {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #f1f5f9;
  color: #64748b;
}

/* Líneas de factura en móvil (cards) */
.nexar-line-cards { display: none; }

@media (max-width: 767px) {
  .nexar-table-desktop,
  .nexar-table-desktop-only { display: none !important; }

  .nexar-record-cards { display: block; }
}

@media (max-width: 639px) {
  .nexar-line-cards { display: block; }

  .nexar-line-card {
    background: var(--nexar-light);
    border-radius: 10px;
    padding: 0.85rem;
    margin-bottom: 0.65rem;
    border: 1px solid #dbeafe;
  }

  .nexar-line-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
  }

  .nexar-line-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    flex: 1;
    word-break: break-word;
  }

  .nexar-line-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .nexar-line-card-grid label {
    font-size: 0.7rem;
    color: var(--nexar-gray);
    display: block;
    margin-bottom: 0.2rem;
  }
}

.nexar-kpi-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
  margin-bottom: 1.5rem;
}

@media (min-width: 480px) {
  .nexar-kpi-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1024px) {
  .nexar-kpi-grid { grid-template-columns: repeat(4, 1fr); }
}

.nexar-kpi {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.25rem;
  border-left: 4px solid var(--nexar-blue);
  box-shadow: var(--shadow);
}

.nexar-kpi-label { font-size: 0.8rem; color: var(--nexar-gray); margin: 0; }

.nexar-kpi-value {
  font-size: clamp(1.25rem, 5vw, 1.75rem);
  font-weight: 700;
  margin: 0.25rem 0 0;
}

.nexar-kpi.accent { border-left-color: var(--nexar-accent); }
.nexar-kpi.green { border-left-color: var(--nexar-green); }
.nexar-kpi.dark { border-left-color: var(--nexar-dark); }

.nexar-alert,
.nexar-flash {
  padding: 0.85rem 1rem;
  border-radius: 10px;
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.nexar-flash-success {
  background: #d1fae5;
  color: #065f46;
}

.nexar-flash-error {
  background: #fee2e2;
  color: #991b1b;
}

.nexar-alert {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  color: #92400e;
}

.badge-emitida {
  background: #d1fae5;
  color: #065f46;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-anulada {
  background: #fee2e2;
  color: #991b1b;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-rol {
  display: inline-block;
  background: var(--nexar-accent);
  color: var(--nexar-dark);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  line-height: 1.2;
  white-space: nowrap;
}

.nexar-filter-bar {
  display: grid;
  gap: 0.65rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .nexar-filter-bar { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 900px) {
  .nexar-filter-bar { grid-template-columns: repeat(5, 1fr); }
}

.nexar-empty {
  text-align: center;
  color: var(--nexar-gray);
  padding: 2rem;
}

.nexar-btn-remove {
  background: transparent;
  border: none;
  color: var(--nexar-red);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.nexar-dl-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.875rem;
}

.nexar-dl-row dt { color: var(--nexar-gray); margin: 0; }
.nexar-dl-row dd { margin: 0; text-align: right; word-break: break-all; }

.nexar-list-item {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.875rem;
}

.nexar-list-item a {
  font-family: ui-monospace, monospace;
  font-weight: 500;
}

.nexar-mono { font-family: ui-monospace, monospace; word-break: break-all; }

.nexar-meta { color: var(--nexar-gray); font-size: 0.875rem; margin: 0.25rem 0 0; }

.nexar-sticky-footer {
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, #fff 12%);
  padding-top: 1rem;
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  justify-content: space-between;
}

.nexar-sticky-footer .nexar-input-descuento {
  width: 100%;
  max-width: 140px;
}

@media (max-width: 479px) {
  .nexar-sticky-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .nexar-sticky-footer .nexar-input-descuento { max-width: none; }
  .nexar-sticky-footer .nexar-btn { width: 100%; }
}

/* ========== MÓDULO TRIBUTARIO SAR ========== */
.nexar-nav-section {
  display: block;
  margin: 1rem 0 0.35rem;
  padding: 0 0.85rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.nexar-periodo-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.nexar-select-inline {
  width: auto;
  min-width: 120px;
  min-height: 40px;
}

.nexar-trib-semaforo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  background: #fff;
  border: 1px solid #e2e8f0;
}

.nexar-trib-semaforo-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.nexar-trib-semaforo--verde .nexar-trib-semaforo-dot { background: var(--nexar-green); }
.nexar-trib-semaforo--amarillo .nexar-trib-semaforo-dot { background: #F59E0B; }
.nexar-trib-semaforo--rojo .nexar-trib-semaforo-dot { background: var(--nexar-red); }

.nexar-trib-badge {
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--nexar-blue);
  background: var(--nexar-light);
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}

.nexar-kpi-sub {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--nexar-gray);
}

.nexar-trib-links {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nexar-trib-alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nexar-trib-alert {
  padding: 0.65rem 0;
  border-bottom: 1px solid #e2e8f0;
}

.nexar-trib-alert:last-child { border-bottom: none; }
.nexar-trib-alert p { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--nexar-gray); }
.nexar-trib-alert--critical strong { color: var(--nexar-red); }
.nexar-trib-alert--warning strong { color: #B45309; }

.nexar-trib-resumen {
  font-size: 0.88rem;
  color: var(--nexar-gray);
  margin: 0 0 1rem;
}

.nexar-trib-resumen-card { margin-bottom: 1rem; }

.nexar-trib-formula {
  font-size: 0.85rem;
  color: var(--nexar-gray);
  margin: 0 0 1rem;
  font-style: italic;
}

.nexar-kpi-grid-trib {
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 900px) {
  .nexar-kpi-grid-trib { grid-template-columns: repeat(3, 1fr); }
}

.nexar-kpi-value-sm { font-size: 1rem; }

.nexar-form-hint {
  font-size: 0.85rem;
  color: var(--nexar-gray);
  margin: 0 0 1rem;
}

.nexar-compra-ficha td {
  background: #f8fafc;
  padding: 0.75rem 1rem !important;
}

.nexar-compra-ficha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.5rem 1rem;
  font-size: 0.85rem;
}

.nexar-ficha-label {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--nexar-gray);
  letter-spacing: 0.03em;
}

.nexar-ficha-motivo { color: var(--nexar-gray); }

.nexar-btn-link {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--nexar-blue);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  padding: 0;
  text-decoration: underline;
  appearance: none;
  -webkit-appearance: none;
}

.nexar-table-totals td {
  background: #f1f5f9;
  font-weight: 600;
  border-top: 2px solid #cbd5e1;
}

.compra-adjunto-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: #e2e8f0;
}

.compra-adjunto-body img {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  display: block;
}

.compra-adjunto-body iframe {
  width: 100%;
  min-height: 75vh;
  border: none;
  background: #fff;
}

.nexar-adjunto-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.factura-modal-panel--sm {
  max-width: 420px;
}

.nexar-compra-adjuntos {
  grid-column: 1 / -1;
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #cbd5e1;
}

.nexar-adjunto-list {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nexar-adjunto-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.nexar-ficha-sin-adjunto {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--nexar-gray);
}

.nexar-muted-sm {
  font-size: 0.85rem;
  color: var(--nexar-gray);
}

.nexar-trib-cierre { margin-bottom: 1.25rem; }

.nexar-sar-copy {
  background: #f8fafc;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  margin: 0.5rem 0 1rem;
}

.nexar-trib-hint-box {
  font-size: 0.88rem;
  background: #E8F4FD;
  border-left: 4px solid var(--nexar-blue);
  padding: 0.65rem 0.85rem;
  border-radius: 0 8px 8px 0;
  margin: 0.75rem 0 0;
}

.nexar-trib-cierre-pasos { margin-top: 1rem; }

.nexar-cierre-paso {
  padding: 1rem 0;
  border-top: 1px solid #e2e8f0;
}

.nexar-cierre-paso:first-child { border-top: none; padding-top: 0; }

.nexar-cierre-paso h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.nexar-cierre-form { margin-top: 0.75rem; max-width: 520px; }

.nexar-cierre-meta {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  font-size: 0.88rem;
  color: var(--nexar-gray);
}

.nexar-cierre-meta li { margin-bottom: 0.35rem; }

.nexar-trib-cierre-ok { margin-top: 0.75rem; }

.nexar-dl-trib { margin: 0; }

.badge-sev {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-sev-critical { background: #fee2e2; color: #991b1b; }
.badge-sev-warning { background: #fef3c7; color: #92400e; }
.badge-sev-info { background: #dbeafe; color: #1e40af; }

.nexar-row-highlight { background: #fffbeb !important; }

.nexar-check-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.nexar-card .dataTables_wrapper { font-size: 0.85rem; }

.nexar-card .dt-buttons {
  margin-bottom: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.nexar-card .dt-button {
  border: 1px solid #dbeafe !important;
  background: #fff !important;
  color: var(--nexar-blue) !important;
  border-radius: 8px !important;
  padding: 0.35rem 0.65rem !important;
  font-size: 0.8rem !important;
}

.nexar-card .dataTables_filter input {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.35rem 0.55rem;
}
