/* ==============================================================================
   MRBOA COTIZAR — Modern 2026 SaaS Design System
   Paleta oficial de Tokens:
   Navy (#101A2D / #0B1426) · Green (#16B866 / #10A957 / #E7F8EF) · Page (#F5F8FB)
   Texto (#152033 / #6F7F96) · Borde (#DFE7F1) · Superficie (#FFFFFF)
   Tipografía: Inter (con fallback system-ui)
   ============================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Tokens Oficiales MRBOA COTIZAR */
  --navy-950: #0b1426;
  --navy-900: #101a2d;
  --navy-800: #16233a;
  --green-600: #10a957;
  --green-500: #16b866;
  --green-100: #e7f8ef;
  --blue-500: #3b82f6;
  --blue-100: #ebf5ff;
  --red-500: #ef4444;
  --red-100: #fef2f2;
  --amber-500: #f59e0b;
  --amber-100: #fef3c7;

  --ink: #152033;
  --muted: #6f7f96;
  --line: #dfe7f1;
  --line-subtle: #f1f5f9;
  --surface: #ffffff;
  --page: #f5f8fb;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.07);
  --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.02);
  --shadow-hover: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.04);

  /* Mapeo funcional de componentes */
  --primary: var(--green-500);
  --primary-hover: var(--green-600);
  --primary-light: var(--green-100);
  --primary-focus: rgba(22, 184, 102, 0.2);

  --bg-app: var(--page);
  --bg-surface: var(--surface);
  --bg-sidebar: var(--navy-900);
  --bg-sidebar-dark: var(--navy-950);
  --bg-sidebar-hover: rgba(255, 255, 255, 0.06);
  --bg-sidebar-active: rgba(22, 184, 102, 0.12);

  --text-main: var(--ink);
  --text-secondary: var(--muted);
  --text-muted: var(--muted);
  --border-color: var(--line);

  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, Monaco, Consolas, monospace;

  --sidebar-width: 240px;
  --sidebar-collapsed-width: 76px;
  --header-height: 64px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 200ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Compatibilidad con vistas existentes */
  --color-primary: var(--primary);
  --color-primary-hover: var(--primary-hover);
  --color-danger: var(--red-500);
  --color-warning: var(--amber-500);
  --color-info: var(--blue-500);
  --bg-body: var(--bg-app);
}

/* ==============================================================================
   Reset & Estilos Base
   ============================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

img, svg {
  display: block;
  max-width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

/* Iconos SVG inline */
.saas-icon {
  display: inline-block;
  vertical-align: middle;
  stroke-width: 1.8;
  fill: none;
  stroke: currentColor;
  flex-shrink: 0;
  transition: transform var(--transition-fast), stroke var(--transition-fast);
}

/* Utilidades Tipográficas y de Espaciado */
.font-mono { font-family: var(--font-mono) !important; }
.fw-normal { font-weight: 400 !important; }
.fw-medium { font-weight: 500 !important; }
.fw-semibold { font-weight: 600 !important; }
.fw-bold { font-weight: 700 !important; }
.fw-extrabold { font-weight: 800 !important; }

.text-main { color: var(--text-main) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-primary { color: var(--primary) !important; }
.text-danger { color: var(--red-500) !important; }
.text-success { color: var(--green-600) !important; }

.text-left { text-align: left !important; }
.text-center { text-align: center !important; }
.text-right, .text-end { text-align: right !important; }

.d-flex { display: flex !important; }
.d-none { display: none !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }
.justify-content-end { justify-content: flex-end !important; }
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }
.gap-4 { gap: 1.5rem !important; }

.m-0 { margin: 0 !important; }
.mb-1 { margin-bottom: 0.25rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mb-3 { margin-bottom: 1rem !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.mt-4 { margin-top: 1.5rem !important; }

/* ==============================================================================
   Layout Principal: Sidebar + Main Content (Header + Body)
   ============================================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
  background-color: var(--bg-app);
}

/* ==============================================================================
   Sidebar Navegación Lateral (SaaS Dark 240px #101A2D)
   ============================================================================== */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  transition: width var(--transition-normal), transform var(--transition-normal);
  user-select: none;
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  overflow: hidden;
  text-decoration: none;
}

.brand-logo-img {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-title {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.brand-title span {
  color: var(--green-500);
}

.brand-subtitle {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
}

.sidebar-collapse-btn {
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.sidebar-collapse-btn:hover {
  color: #f8fafc;
  background-color: var(--bg-sidebar-hover);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
  overflow-x: hidden;

  /* Firefox */
  scrollbar-width: none;

  /* Internet Explorer y Edge legado */
  -ms-overflow-style: none;
}

/* Chrome, Safari, Edge y Chromium */
.sidebar-nav::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.nav-section-title {
  padding: 0.75rem 1.25rem 0.35rem;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #4b5e7d;
}

.sidebar-divider {
  height: 1px;
  background-color: rgba(255, 255, 255, 0.06);
  margin: 0.75rem 1.25rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  margin: 0.15rem 0.75rem;
  border-radius: var(--radius-sm);
  color: #94a3b8;
  font-size: 13.5px;
  font-weight: 500;
  position: relative;
  transition: all var(--transition-fast);
}

.sidebar-item .saas-icon,
.sidebar-item i {
  color: #64748b;
  transition: color var(--transition-fast), transform var(--transition-fast);
}

.sidebar-item:hover {
  color: #f8fafc;
  background-color: var(--bg-sidebar-hover);
}

.sidebar-item:hover .saas-icon,
.sidebar-item:hover i {
  color: #cbd5e1;
}

.sidebar-item.active {
  color: #ffffff;
  background-color: var(--bg-sidebar-active);
  font-weight: 600;
}

.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: -0.75rem;
  top: 6px;
  bottom: 6px;
  width: 3.5px;
  background-color: var(--green-500);
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
}

.sidebar-item.active .saas-icon,
.sidebar-item.active i {
  color: var(--green-500);
}

/* ==============================================================================
   Submenú y Grupo Desplegable Fiscal / RESICO
   ============================================================================== */
.sidebar-fiscal-group {
  position: relative;
}

.sidebar-fiscal-toggle {
  width: calc(100% - 1.5rem);
  background: transparent;
  border: none;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  margin: 0.15rem 0.75rem;
  color: #94a3b8;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  user-select: none;
  outline: none;
}

.sidebar-fiscal-toggle:hover {
  color: #f8fafc;
  background-color: var(--bg-sidebar-hover);
}

.sidebar-fiscal-toggle:hover .saas-icon,
.sidebar-fiscal-toggle:hover i {
  color: #cbd5e1;
}

.sidebar-fiscal-toggle:hover .sidebar-chevron {
  color: #cbd5e1;
}

.sidebar-fiscal-toggle:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: -2px;
}

.sidebar-fiscal-toggle .saas-icon,
.sidebar-fiscal-toggle .nav-icon {
  flex-shrink: 0;
}

.sidebar-fiscal-title {
  white-space: nowrap !important;
  flex-shrink: 0;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 500;
  color: inherit;
  line-height: 1.2;
}

.sidebar-fiscal-badge {
  background: rgba(22, 184, 102, 0.18);
  color: #16b866;
  border: 1px solid rgba(22, 184, 102, 0.3);
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
}

.sidebar-fiscal-toggle .sidebar-chevron {
  width: 14px;
  height: 14px;
  margin-left: auto;
  flex-shrink: 0;
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), color var(--transition-fast);
  transform: rotate(0deg);
  color: #64748b;
}

.sidebar-fiscal-group.is-open .sidebar-fiscal-toggle .sidebar-chevron {
  transform: rotate(90deg);
  color: #94a3b8;
}

/* Contenedor de subelementos */
.sidebar-subnav {
  display: none;
  flex-direction: column;
  gap: 2px;
  margin: 0.2rem 0.75rem 0.4rem 1.6rem;
  padding-left: 0.65rem;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-fiscal-group.is-open .sidebar-subnav {
  display: flex;
}

/* Enlaces secundarios (hijos) - Alto contraste contra el fondo oscuro */
.sidebar-subitem {
  display: flex;
  align-items: center;
  padding: 0.42rem 0.75rem;
  border-radius: var(--radius-sm);
  color: #94a3b8; /* Gris claro visible sobre #101a2d */
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  position: relative;
  transition: color var(--transition-fast), background-color var(--transition-fast);
  line-height: 1.3;
}

.sidebar-subitem:hover {
  color: #ffffff;
  background-color: rgba(255, 255, 255, 0.05);
}

.sidebar-subitem.active {
  color: #ffffff;
  background-color: rgba(22, 184, 102, 0.12);
  font-weight: 600;
}

.sidebar-subitem.active::before {
  content: '';
  position: absolute;
  left: -0.65rem;
  top: 4px;
  bottom: 4px;
  width: 2.5px;
  background-color: var(--green-500);
  border-radius: 2px;
}


.sidebar-footer {
  padding: 0.85rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background-color: var(--bg-sidebar-dark);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  overflow: hidden;
}

.avatar-initials {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.avatar-img {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  object-fit: cover;
  flex-shrink: 0;
}

.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  line-height: 1.2;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--green-500);
}

.btn-sidebar-logout {
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.btn-sidebar-logout:hover {
  color: var(--red-500);
  background-color: rgba(239, 68, 68, 0.12);
}

/* ==============================================================================
   Main Content Area & Topbar Header
   ============================================================================== */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
  transition: margin-left var(--transition-normal);
}

.app-header {
  min-height: var(--header-height);
  background-color: var(--surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.55rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  position: sticky;
  top: 0;
  z-index: 90;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.02);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.header-brand-link {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-main);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.header-brand-link:hover {
  color: var(--green-600);
}

.header-brand-divider {
  width: 1px;
  height: 46px;
  background-color: var(--border-color);
  flex-shrink: 0;
}

.header-hierarchy-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  min-width: 0;
}

.header-hierarchy-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 12.5px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  padding: 1px 4px;
  margin-left: -4px;
  border-radius: 4px;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.header-hierarchy-link:hover {
  color: var(--text-main);
  background-color: var(--line-subtle);
}

.header-hierarchy-link.active {
  color: var(--green-600);
  font-weight: 600;
}

span.header-hierarchy-link:hover {
  background-color: transparent;
  color: var(--text-secondary);
}

span.header-hierarchy-link.active:hover {
  color: var(--green-600);
}

.header-hierarchy-module {
  font-size: 12px;
  color: var(--text-muted);
}

.header-hierarchy-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.header-hierarchy-link.active .header-hierarchy-icon {
  opacity: 1;
}

.mobile-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.breadcrumb-nav a {
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.breadcrumb-nav a:hover {
  color: var(--text-main);
}

.breadcrumb-separator {
  color: #cbd5e1;
  font-size: 12px;
}

.breadcrumb-current {
  color: var(--text-main);
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-shrink: 0;
}

.header-company-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  white-space: nowrap;
}

.header-company-pill--global {
  background: var(--page);
}

.header-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.header-status-dot--active {
  background: var(--green-500);
}

.header-status-dot--muted {
  background: var(--muted);
}

.header-company-rfc {
  color: var(--text-main);
  font-size: 11.5px;
}

.header-company-name {
  color: var(--text-muted);
  font-size: 11.5px;
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-company-global-label {
  color: var(--text-main);
  font-size: 11.5px;
  font-weight: 600;
}

.header-company-switch {
  color: var(--color-primary);
  font-size: 11px;
  text-decoration: none;
  font-weight: 500;
  margin-left: 2px;
}

.header-company-sep {
  color: var(--border-color);
  margin: 0 1px;
}

.header-company-exit {
  color: var(--text-muted);
  font-size: 11px;
  text-decoration: none;
}

.header-search {
  position: relative;
  width: 240px;
}

.header-search input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--page);
  font-size: 13px;
  color: var(--text-main);
  outline: none;
  transition: all var(--transition-fast);
}

.header-search input:focus {
  background-color: var(--surface);
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

.header-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.header-action-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.header-action-icon:hover {
  color: var(--text-main);
  background-color: var(--page);
  border-color: var(--border-color);
}

.header-action-badge {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--green-500);
}

.app-content {
  flex: 1;
  padding: 2rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

.page-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==============================================================================
   Page Header (Títulos de Sección & Subtítulos)
   ============================================================================== */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-header-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.page-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  margin: 0;
  line-height: 1.2;
}

.page-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin: 0;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* ==============================================================================
   Tarjetas (Cards) & Contenedores SaaS
   ============================================================================== */
.saas-card {
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.saas-card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.saas-card-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text-main);
  margin: 0;
}

.saas-card-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0.2rem 0 0 0;
}

.saas-card-body {
  padding: 1.5rem;
}

.saas-card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--page);
}

/* ==============================================================================
   KPI Cards (Tarjetas de Métricas Ejecutivas)
   ============================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
}

.kpi-card {
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.kpi-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-primary {
  background-color: var(--green-100);
  color: var(--green-600);
}

.icon-success {
  background-color: var(--green-100);
  color: var(--green-600);
}

.icon-warning {
  background-color: var(--amber-100);
  color: var(--amber-500);
}

.icon-info {
  background-color: var(--blue-100);
  color: var(--blue-500);
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--text-main);
  line-height: 1.1;
  font-family: var(--font-mono);
}

.kpi-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 12px;
}

.kpi-desc {
  color: var(--text-secondary);
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge-neutral {
  background-color: #f1f5f9;
  color: #475569;
}

/* ==============================================================================
   Botones (Buttons & Icon Buttons)
   ============================================================================== */
.btn-saas {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 38px;
  padding: 0 1rem;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-saas:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-focus);
}

/* Botón Principal (Verde Acción #16B866 / Hover #10A957) */
.btn-primary-saas {
  background-color: var(--green-500);
  color: #ffffff;
  border-color: var(--green-500);
  box-shadow: 0 1px 2px rgba(22, 184, 102, 0.2);
}

.btn-primary-saas:hover {
  background-color: var(--green-600);
  border-color: var(--green-600);
  box-shadow: 0 2px 4px rgba(16, 169, 87, 0.25);
  color: #ffffff;
}

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

/* Botón Secundario (Blanco con Borde #DFE7F1) */
.btn-secondary-saas {
  background-color: var(--surface);
  color: var(--text-main);
  border-color: var(--border-color);
  box-shadow: var(--shadow-sm);
}

.btn-secondary-saas:hover {
  background-color: var(--page);
  border-color: #cbd5e1;
  color: var(--text-main);
}

/* Botón Peligro (Rojo exclusivo acciones destructivas) */
.btn-danger-saas {
  background-color: var(--red-500);
  color: #ffffff;
  border-color: var(--red-500);
}

.btn-danger-saas:hover {
  background-color: #dc2626;
  border-color: #dc2626;
  color: #ffffff;
}

/* Botón Ghost (Transparente para acciones secundarias) */
.btn-ghost-saas {
  background-color: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost-saas:hover {
  background-color: var(--page);
  color: var(--text-main);
}

/* Icon Buttons (36x36px) */
.btn-action-saas {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background-color: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-action-saas:hover {
  background-color: var(--page);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-action-saas.btn-delete:hover {
  background-color: var(--red-100);
  border-color: #fecaca;
  color: var(--red-500);
}

/* ==============================================================================
   Tablas SaaS Ligeras y Elegantes
   ============================================================================== */
.table-responsive-saas {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.saas-table,
.table-saas {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

.saas-table thead th,
.table-saas thead th {
  background-color: #f8fafc;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 6px;
  border-bottom: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  white-space: nowrap;
}

.saas-table thead th:last-child,
.table-saas thead th:last-child {
  border-right: none;
}

.saas-table tbody tr,
.table-saas tbody tr {
  border-bottom: 1px solid var(--line-subtle);
  transition: background-color var(--transition-fast);
}

.saas-table tbody tr:last-child,
.table-saas tbody tr:last-child {
  border-bottom: none;
}

.saas-table tbody tr:hover,
.table-saas tbody tr:hover {
  background-color: #f8fafc;
}

.saas-table tbody td,
.table-saas tbody td {
  padding: 6px 6px;
  vertical-align: middle;
  color: var(--text-main);
  border-right: 1px solid #e2e8f0;
}

.saas-table tbody td:last-child,
.table-saas tbody td:last-child {
  border-right: none;
}

.table-folio-link {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--navy-900);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.table-folio-link:hover {
  color: var(--green-600);
  text-decoration: underline;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.35rem;
}

/* ==============================================================================
   Badges de Estado (Status Pills con Dot)
   ============================================================================== */
.status-badge-saas {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}

.status-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-draft {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}
.badge-draft .status-badge-dot {
  background-color: #94a3b8;
}

.badge-sent {
  background-color: var(--blue-100);
  color: var(--blue-500);
  border: 1px solid #bfdbfe;
}
.badge-sent .status-badge-dot {
  background-color: var(--blue-500);
}

.badge-accepted {
  background-color: var(--green-100);
  color: var(--green-600);
  border: 1px solid #a7f3d0;
}
.badge-accepted .status-badge-dot {
  background-color: var(--green-500);
}

.badge-cancelled {
  background-color: var(--red-100);
  color: var(--red-500);
  border: 1px solid #fecaca;
}
.badge-cancelled .status-badge-dot {
  background-color: var(--red-500);
}

.badge-success {
  background-color: var(--green-100);
  color: var(--green-600);
  border: 1px solid #a7f3d0;
}

.badge-info {
  background-color: var(--blue-100);
  color: var(--blue-500);
  border: 1px solid #bfdbfe;
}

.badge-warning {
  background-color: var(--amber-100);
  color: var(--amber-500);
  border: 1px solid #fde68a;
}

/* ==============================================================================
   Formularios e Inputs Limpios
   ============================================================================== */
.form-group-saas {
  margin-bottom: 1.25rem;
}

.form-label-saas {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.form-control-saas {
  width: 100%;
  height: 40px;
  padding: 0 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--text-main);
  font-size: 13.5px;
  transition: all var(--transition-fast);
  outline: none;
}

textarea.form-control-saas {
  height: auto;
  min-height: 80px;
  padding: 0.65rem 0.85rem;
  resize: vertical;
}

.form-control-saas:focus {
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px var(--primary-focus);
}

.form-control-saas::placeholder {
  color: #94a3b8;
}

.form-hint-saas {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 0.35rem;
}

.input-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon-wrapper i,
.input-icon-wrapper .icon-prefix {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-style: normal;
  pointer-events: none;
  font-weight: 600;
}

.input-icon-wrapper input {
  padding-left: 28px;
}

/* ==============================================================================
   Filtros & Pills de Navegación Rápida
   ============================================================================== */
.filter-pills-bar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.85rem;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  text-decoration: none;
  transition: all var(--transition-fast);
}

.filter-pill:hover {
  border-color: #cbd5e1;
  color: var(--text-main);
  background-color: var(--page);
}

.filter-pill.active {
  background-color: var(--navy-900);
  color: #ffffff;
  border-color: var(--navy-900);
  font-weight: 600;
}

.filter-pill-count {
  background-color: rgba(15, 23, 42, 0.08);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11.5px;
  font-weight: 700;
}

.filter-pill.active .filter-pill-count {
  background-color: var(--green-500);
  color: #ffffff;
}

/* ==============================================================================
   Tarjetas de Plantillas (Templates Grid)
   ============================================================================== */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.5rem;
}

.template-card {
  background-color: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.template-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.template-cover {
  width: 100%;
  height: 180px;
  background-color: var(--navy-950);
  position: relative;
  overflow: hidden;
}

.template-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 300ms ease;
}

.template-card:hover .template-cover-img {
  transform: scale(1.03);
}

.template-category-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background-color: rgba(16, 26, 45, 0.85);
  backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.template-body {
  padding: 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* ==============================================================================
   Estados Vacíos (Empty States)
   ============================================================================== */
.empty-state-saas {
  padding: 3.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 1rem;
}

.empty-illustration {
  width: 180px;
  height: auto;
  margin-bottom: 0.5rem;
}

.empty-icon-wrap {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background-color: #f1f5f9;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.empty-desc {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 420px;
  margin: 0 auto;
}

/* ==============================================================================
   Modales Modernos SaaS
   ============================================================================== */
.modal-overlay-saas {
  position: fixed;
  inset: 0;
  background-color: rgba(11, 20, 38, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
  padding: 1rem;
}

.modal-overlay-saas.active {
  opacity: 1;
  visibility: visible;
}

.modal-content-saas {
  background-color: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 540px;
  overflow: hidden;
  transform: translateY(16px) scale(0.98);
  transition: transform var(--transition-normal);
}

.modal-overlay-saas.active .modal-content-saas {
  transform: translateY(0) scale(1);
}

.modal-header-saas {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title-saas {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.modal-close-saas {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition-fast);
}

.modal-close-saas:hover {
  color: var(--text-main);
  background-color: var(--page);
}

.modal-body-saas {
  padding: 1.5rem;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-footer-saas {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background-color: var(--page);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ==============================================================================
   Toasts y Notificaciones
   ============================================================================== */
.toast-container-saas {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast-saas {
  background-color: var(--navy-900);
  color: #ffffff;
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 13.5px;
  font-weight: 500;
  pointer-events: auto;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.toast-saas.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.toast-icon.success {
  background-color: var(--green-500);
  color: #ffffff;
}

.toast-icon.warning {
  background-color: var(--amber-500);
  color: #ffffff;
}

.toast-icon.danger, .toast-icon.error {
  background-color: var(--red-500);
  color: #ffffff;
}

.toast-icon.info {
  background-color: var(--blue-500);
  color: #ffffff;
}

/* ==============================================================================
   Avatares de Clientes y Usuarios
   ============================================================================== */
.avatar-wrap {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--page);
  border: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 13px;
  color: var(--text-secondary);
}

.avatar-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ==============================================================================
   Responsive & Mobile Adaptations
   ============================================================================== */
@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(11, 20, 38, 0.5);
    z-index: 95;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast);
  }

  .sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
  }

  .app-main {
    margin-left: 0;
  }

  .mobile-toggle {
    display: flex;
  }

  .app-header {
    padding: 0.55rem 1rem;
    gap: 0.75rem;
  }

  .header-left {
    gap: 0.65rem;
  }

  .header-right {
    gap: 0.5rem;
  }

  .header-company-name {
    display: none;
  }

  .app-content {
    padding: 1.25rem 1rem;
  }

  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .header-search {
    display: none;
  }
}

@media (max-width: 1279px) {
  .header-search {
    width: 180px;
  }

  .header-company-name {
    max-width: 90px;
  }
}

@media (max-width: 639px) {
  .app-header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }

  .header-left {
    gap: 0.5rem;
  }

  .header-brand-link {
    font-size: 12px;
  }

  .header-brand-divider {
    height: 40px;
  }

  .header-hierarchy-link {
    font-size: 11.5px;
    line-height: 1.3;
    gap: 0.3rem;
  }

  .header-company-pill {
    display: none;
  }

  .header-primary-cta {
    padding: 0.45rem 0.6rem;
  }

  .header-primary-cta span {
    display: none;
  }
}

/* ==============================================================================
   MÓDULO FISCAL RESICO: Tarjetas en 1 Línea, Selector y Resumen por Factura
   ============================================================================== */

/* Grid de 5 KPIs del Dashboard Fiscal */
.fiscal-kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1279px) {
  .fiscal-kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 991px) {
  .fiscal-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .fiscal-kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Reglas de 1 sola línea para tarjetas KPI */
.fiscal-kpi-grid .kpi-card {
  padding: 1.15rem 1.25rem;
  min-width: 0;
}

.fiscal-kpi-grid .kpi-value {
  font-size: 23px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}

@media (min-width: 1440px) {
  .fiscal-kpi-grid .kpi-value {
    font-size: 25px;
  }
}

.kpi-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  font-size: 11.5px;
}

.kpi-meta-stack {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
  min-width: 0;
}

.kpi-pair {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 1.2;
}

.kpi-pair-label {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.kpi-pair-value {
  color: var(--text-main);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-link {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fiscal-blue);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.kpi-link:hover {
  text-decoration: underline;
  color: #1d4ed8;
}

.kpi-meta-row .status-badge-saas,
.kpi-meta .status-badge-saas {
  flex-shrink: 0;
  white-space: nowrap;
}


