:root {
  --color-primary:   #1a3a5c;
  --color-primary-d: #142d48;
  --color-accent:    #e8732a;
  --sidebar-w:       230px;
  --header-h:        52px;
}

/* ── Reset / Base ────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: #f0f3f7;
  font-size: 0.875rem;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #212529;
}

/* ── Header ──────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0 1.25rem;
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

.logo-text {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  flex: 1;
}

.version-tag {
  font-size: 0.68rem;
  background: rgba(255,255,255,.15);
  padding: 0.15rem 0.55rem;
  border-radius: 20px;
  letter-spacing: 0.04em;
}

/* ── Layout ──────────────────────────────────────── */
.app-layout {
  display: flex;
  margin-top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────── */
.app-sidebar {
  width: var(--sidebar-w);
  background: var(--color-primary);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-top: 1rem;
  border-right: 1px solid rgba(255,255,255,.06);
}

.sidebar-group-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,.4);
  padding: 0.25rem 1.1rem 0.6rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.65rem 1.1rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  color: rgba(255,255,255,.65);
  font-size: 0.82rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  line-height: 1.3;
}

.sidebar-item i {
  font-size: 1rem;
  flex-shrink: 0;
  width: 1.1rem;
  text-align: center;
}

.sidebar-item:hover {
  background: rgba(255,255,255,.07);
  color: #fff;
}

.sidebar-item.active {
  background: rgba(255,255,255,.1);
  color: #fff;
  border-left-color: var(--color-accent);
  font-weight: 700;
}

/* ── Contenido ───────────────────────────────────── */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.1rem;
}

.content-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0 0 0.15rem;
}

.content-subtitle {
  font-size: 0.78rem;
  color: #6c757d;
  margin: 0;
}

/* ── Tablas ──────────────────────────────────────── */
.table thead th {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  padding: 0.6rem 0.75rem;
  border: none;
}

.table tbody tr {
  transition: background 0.1s;
}

.table tbody tr:hover {
  background: #e8f0fa;
}

.table td {
  vertical-align: middle;
  padding: 0.5rem 0.75rem;
}

/* ── Modal ───────────────────────────────────────── */
.modal-header-custom {
  background: var(--color-primary);
  color: #fff;
}

/* ── Secciones del formulario ────────────────────── */
.seccion-form {
  border-top: 1px solid #dee2e6;
  padding-top: 1rem;
  margin-top: 1.1rem;
}

.seccion-titulo {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.seccion-titulo .total-badge {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--color-accent);
  text-transform: none;
  letter-spacing: 0;
  margin-left: auto;
}

/* ── Matriz de precios ───────────────────────────── */
.tabla-matriz th {
  background: var(--color-primary);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 0.4rem;
}

.tabla-matriz td {
  padding: 0.2rem 0.4rem;
  vertical-align: middle;
}

.tabla-matriz .lbl-periodo {
  font-weight: 700;
  color: var(--color-primary);
  font-size: 0.82rem;
  width: 2.5rem;
}

.tabla-matriz input[type=number] { text-align: right; }

.tabla-matriz input[readonly] {
  background-color: #dde1e7;
  color: #6c757d;
  cursor: not-allowed;
  border-color: #ced4da;
}
.tabla-matriz input[readonly]:hover {
  cursor: not-allowed;
}

/* ── Tabla de reglas de comisión ─────────────────── */
.tabla-comision th {
  background: var(--color-primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: center;
  padding: 0.4rem;
  white-space: nowrap;
}
.tabla-comision td {
  padding: 0.2rem 0.3rem;
  vertical-align: middle;
}
.tabla-comision tfoot td {
  background: #f8fafc;
}

/* ── Sidebar: separador y grupo ──────────────────── */
.sidebar-divider {
  border-top: 1px solid rgba(255,255,255,.1);
  margin: 0.75rem 0.75rem 0.5rem;
}

/* ── Sidebar: colapsable ─────────────────────────── */
.sidebar-submenu {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.22s ease;
}

.sidebar-submenu.open {
  max-height: 200px;
}

.sidebar-subitem {
  padding-left: 2.5rem;
  font-size: 0.78rem;
}

.sidebar-chevron {
  font-size: 0.72rem;
  transition: transform 0.22s;
}

.sidebar-chevron.rotated {
  transform: rotate(90deg);
}

/* ── Sección configuración ───────────────────────── */
.config-card-header {
  background: #f0f4fa;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-primary);
  padding: 0.55rem 1rem;
  border-bottom: 1px solid #dee2e6;
}

/* ── Simulación ──────────────────────────────────── */
.sim-zona {
  background: #f4f7fb;
  border: 1px solid #d0daea !important;
  border-radius: 6px;
  padding: 0.9rem 1rem 0.75rem !important;
}

.sim-formula-texto {
  font-family: monospace;
  color: #6c757d;
  line-height: 1.7;
}

.sim-vals {
  font-family: monospace;
  font-size: 0.80rem;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 0.5rem 0.75rem;
  color: #343a40;
  line-height: 1.8;
}

/* ── Campo código ────────────────────────────────── */
#f_codigo {
  font-family: monospace;
  background: #f8f9fa;
  color: #888;
}

/* ── Botón principal ─────────────────────────────── */
.btn-guardar {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  min-width: 130px;
  font-weight: 600;
}

.btn-guardar:hover {
  background: var(--color-primary-d);
  border-color: var(--color-primary-d);
  color: #fff;
}

/* ── Barra de filtros ────────────────────────────── */
.filtros-barra {
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 0.6rem 0.9rem;
}

/* ── Línea temporal de producto ──────────────────── */
.timeline-tarifa-header {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-left: 3px solid;
  padding: 0.25rem 0.5rem;
  margin: 0.6rem 0 0.35rem 0;
  background: rgba(0,0,0,.03);
  border-radius: 0 3px 3px 0;
}

#prod-timeline-zona {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.timeline-scroll {
  overflow-x: hidden;
  padding-bottom: 0.5rem;
  width: 100%;
}

.timeline-row {
  display: flex;
  align-items: stretch;
  margin-bottom: 5px;
}

.timeline-label {
  width: 100px;
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--color-primary);
  padding-right: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  text-align: right;
  line-height: 1.2;
}

.timeline-track {
  flex: 1;
  position: relative;
  background: #eef2f8;
  border-radius: 4px;
  min-width: 0;
  min-height: 32px;
  overflow: hidden;
}

.timeline-block {
  position: absolute;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0 5px;
  overflow: hidden;
  min-width: 3px;
  transition: filter 0.12s, outline 0.1s;
  box-sizing: border-box;
}

.timeline-block:hover {
  filter: brightness(1.15);
  outline: 2px solid rgba(255,255,255,.6);
  z-index: 5;
}

.timeline-block-label {
  font-size: 0.60rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
  pointer-events: none;
}

.timeline-hoy {
  position: absolute;
  top: 0;
  width: 2px;
  background: var(--color-accent);
  opacity: 0.7;
  pointer-events: none;
}

.timeline-axis-label {
  position: absolute;
  bottom: 0;
  font-size: 0.60rem;
  color: #6c757d;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Tooltip flotante */
.timeline-tooltip-box {
  position: fixed;
  z-index: 9999;
  background: var(--color-primary);
  color: #fff;
  padding: 9px 13px;
  border-radius: 7px;
  font-size: 0.78rem;
  line-height: 1.55;
  pointer-events: none;
  max-width: 300px;
  box-shadow: 0 6px 18px rgba(0,0,0,.28);
}

/* ══════════════════════════════════════════════════════════════════════════ */
/* MEJORAS UI/UX — ui-ux-pro-max                                             */
/* ══════════════════════════════════════════════════════════════════════════ */

/* ── Tipografía mejorada ─────────────────────────────────────────────────── */
body {
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Header: separador + breadcrumb ─────────────────────────────────────── */
.header-sep {
  width: 1px;
  height: 18px;
  background: rgba(255,255,255,.22);
  margin: 0 0.65rem;
  flex-shrink: 0;
}

.header-breadcrumb {
  font-size: 0.76rem;
  color: rgba(255,255,255,.72);
  font-weight: 500;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Pills de filtros activos ────────────────────────────────────────────── */
.filtros-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 0;
}
.filtros-pills:empty { display: none; }

.filtro-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #e8f0fe;
  color: var(--color-primary);
  border: 1px solid #c5d6f5;
  border-radius: 20px;
  font-size: 0.70rem;
  font-weight: 500;
  padding: 0.18rem 0.55rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
}
.filtro-pill:hover { background: #d0e0fb; border-color: #a8c4f0; }
.filtro-pill .pill-label { opacity: 0.65; }
.filtro-pill .pill-x { font-size: 0.95rem; line-height: 1; opacity: 0.5; margin-left: 1px; }
.filtro-pill:hover .pill-x { opacity: 1; }

/* ── Contador de resultados ──────────────────────────────────────────────── */
.result-info-bar {
  font-size: 0.73rem;
  color: #6c757d;
  padding: 0 0.1rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}
.result-info-bar .result-count {
  font-weight: 700;
  color: var(--color-primary);
}

/* ── Empty state en tablas ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 2.75rem 1rem 3rem;
  color: #6c757d;
}
.empty-state-icon {
  font-size: 2.6rem;
  opacity: 0.22;
  display: block;
  margin-bottom: 0.8rem;
  color: var(--color-primary);
}
.empty-state-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.3rem;
}
.empty-state-sub {
  font-size: 0.77rem;
  color: #9ca3af;
  margin-bottom: 1rem;
}

/* ── Badges de estado — rediseñados ─────────────────────────────────────── */
.badge-vigente {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
  font-weight: 600;
  font-size: 0.69rem;
  padding: 0.28em 0.65em;
}
.badge-obsoleta {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #d1d5db;
  font-weight: 500;
  font-size: 0.69rem;
  padding: 0.28em 0.65em;
}
.badge-futura {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #93c5fd;
  font-weight: 600;
  font-size: 0.69rem;
  padding: 0.28em 0.65em;
}
.badge-proxima {
  background: #fffbeb;
  color: #92400e;
  border: 1px solid #fcd34d;
  font-weight: 600;
  font-size: 0.69rem;
  padding: 0.28em 0.65em;
}

/* ── Confirmación de borrado inline ─────────────────────────────────────── */
.confirm-del-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  white-space: nowrap;
  animation: fadeInScale 0.14s ease;
}
@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Grupo de botones de acción en tabla ────────────────────────────────── */
.action-btn-group {
  display: inline-flex;
  gap: 0.2rem;
  align-items: center;
}
.action-btn-group .btn { border-radius: 5px !important; }

/* ── Estética: cards más pulidas ─────────────────────────────────────────── */
.card {
  border-radius: 8px !important;
  border: 1px solid #e9edf4 !important;
}
.card.shadow-sm {
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.04) !important;
}

/* ── Estética: filtros-barra mejorada ────────────────────────────────────── */
.filtros-barra {
  background: #fff;
  border: 1px solid #e5eaf2 !important;
  border-radius: 8px;
  padding: 0.65rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

/* ── Estética: inputs con focus ring de marca ───────────────────────────── */
.form-control:focus, .form-select:focus {
  border-color: #6e9ecb;
  box-shadow: 0 0 0 3px rgba(26,58,92,.12);
}

/* ── Estética: hover de tabla más cálido ─────────────────────────────────── */
.table-hover > tbody > tr:hover > * {
  background-color: #eef4ff !important;
}

/* ── Estética: btn-guardar con gradiente sutil ───────────────────────────── */
.btn-guardar {
  background: linear-gradient(160deg, var(--color-primary) 0%, #1e4878 100%);
  border: none;
  box-shadow: 0 2px 6px rgba(26,58,92,.28);
  transition: box-shadow 0.15s, transform 0.1s;
}
.btn-guardar:hover {
  background: linear-gradient(160deg, var(--color-primary-d) 0%, #16385c 100%);
  box-shadow: 0 3px 10px rgba(26,58,92,.38);
  color: #fff;
  transform: translateY(-1px);
}
.btn-guardar:active { transform: translateY(0); }

/* ── Estética: tabla cabecera con radio inferior ─────────────────────────── */
.card > .card-body.p-0 > .table thead tr:first-child th:first-child { border-radius: 7px 0 0 0; }
.card > .card-body.p-0 > .table thead tr:first-child th:last-child  { border-radius: 0 7px 0 0; }

/* ── Estética: modal-header-custom con gradiente ─────────────────────────── */
.modal-header-custom {
  background: linear-gradient(135deg, var(--color-primary) 0%, #1e4878 100%);
  border-bottom: none;
}

/* ── Estética: config-card-header refinado ───────────────────────────────── */
.config-card-header {
  background: linear-gradient(90deg, #f5f7fb 0%, #eef2f9 100%);
  border-bottom: 1px solid #e5eaf2;
}

/* ── Buscador predictivo "Reemplaza a" ──────────────────────────────────── */
.pred-dropdown {
  position: absolute;
  z-index: 1060;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}
.pred-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.83rem;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
}
.pred-item:last-child { border-bottom: none; }
.pred-item:hover { background: #f0f7ff; }
.pred-item-none { color: #94a3b8; font-style: italic; cursor: default; }
.pred-item-none:hover { background: transparent; }

/* ══════════════════════════════════════════════════════════════════════════ */
/* LINAJE DE REFERENCIA                                                        */
/* ══════════════════════════════════════════════════════════════════════════ */

.linaje-visual {
  display: flex;
  align-items: center;
  gap: 0;
  overflow-x: auto;
  padding: 1.25rem 0.25rem;
  min-height: 130px;
}

.linaje-nodo {
  flex: 0 0 190px;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.8rem 1rem;
  background: #f8fafc;
  transition: box-shadow 0.15s, border-color 0.15s;
}

.linaje-nodo-actual {
  border-color: var(--color-primary);
  background: linear-gradient(135deg, #eef4ff 0%, #f0f7ff 100%);
  box-shadow: 0 0 0 3px rgba(26,58,92,.1);
}

.linaje-nodo-otro {
  cursor: pointer;
}

.linaje-nodo-otro:hover {
  box-shadow: 0 4px 14px rgba(0,0,0,.1);
  border-color: #94a3b8;
}

.linaje-nodo-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
  margin-bottom: 0.35rem;
}

.linaje-nodo-actual .linaje-nodo-label {
  color: var(--color-primary);
}

.linaje-nodo-codigo {
  font-size: 0.82rem;
  font-weight: 700;
  font-family: monospace;
  color: #1e293b;
  margin-bottom: 0.2rem;
  word-break: break-all;
}

.linaje-nodo-fecha {
  font-size: 0.72rem;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.linaje-nodo-hint {
  font-size: 0.68rem;
  color: #94a3b8;
  margin-top: 0.4rem;
}

.linaje-flecha {
  display: flex;
  align-items: center;
  padding: 0 0.5rem;
  color: #94a3b8;
  font-size: 2rem;
  flex-shrink: 0;
}

.linaje-solo {
  display: flex;
  align-items: center;
  color: #94a3b8;
  font-size: 0.8rem;
  font-style: italic;
  margin-left: 1.25rem;
  align-self: center;
}

.linaje-fila-nav {
  cursor: pointer;
}

/* ── Filtro multi-selección ──────────────────────────────────────────────── */
.filtro-multi {
  position: relative;
}

.filtro-multi-btn {
  display: flex;
  align-items: center;
  width: 100%;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.82rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  line-height: 1.5;
  min-height: 30px;
}

.filtro-multi-btn::after {
  content: "";
  display: inline-block;
  flex-shrink: 0;
  width: 16px;
  height: 12px;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px 12px;
  margin-left: 4px;
}

.filtro-multi-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  color: #6c757d;
}

.filtro-multi-btn:hover { border-color: #adb5bd; }

.filtro-multi.filtro-multi-open .filtro-multi-btn {
  border-color: #6e9ecb;
  box-shadow: 0 0 0 3px rgba(26,58,92,.12);
  outline: 0;
}

.filtro-multi.filtro-multi-active .filtro-multi-btn {
  border-color: var(--color-primary);
  background: #eef2fa;
}

.filtro-multi.filtro-multi-active .filtro-multi-label {
  color: var(--color-primary);
  font-weight: 600;
}

.filtro-multi-menu {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  min-width: max-content;
  background: #fff;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  z-index: 1050;
  padding: 0.25rem 0;
  max-height: 220px;
  overflow-y: auto;
}

.filtro-multi-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.85rem;
  cursor: pointer;
  font-size: 0.82rem;
  white-space: nowrap;
  user-select: none;
  transition: background 0.1s;
}

.filtro-multi-item:hover { background: #f0f4fb; }

.filtro-multi-item input[type=checkbox] {
  margin: 0;
  cursor: pointer;
  accent-color: var(--color-primary);
}
