/* ==========================================================================
   WEEM UI · piezas del Admin (issue #68). Solo Administración: Operaciones no
   carga esta hoja. Complementa /shared/weem-ui.css y /shared/weem-ui-app.css
   con los mismos tokens --w-* (claro/oscuro sin reglas propias de tema) y no
   redefine ninguna de sus clases.

   Tabla de leads   .w-sort (encabezado ordenable, [data-dir=asc|desc])
                    .w-table[data-hide~="col"] oculta las celdas [data-col="col"]
                    .w-colmenu (menú «Columnas»)  .w-facets (facetas y filtros)
                    .w-filter-chip (filtro activo que se quita)
                    .w-lead · .w-avatar · .w-status · .w-score · .w-lead-tags
   Pipeline         .w-kanban > .w-kanban__col > .w-kanban__list > .w-kanban__card
   Ficha            .w-sheet (panel lateral) · .w-facts · .w-timeline
   Origen / Links   .w-share (barra de participación) · .w-breakdown
   Utilidades       .w-muted · .w-sr-only · .w-stack · .w-dot · .w-row-actions
   Objetivos táctiles de 44px en pantallas angostas y punteros gruesos.
   ========================================================================== */

/* ---- Utilidades ---- */
.w-muted { color: var(--w-muted); }
.w-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.w-stack { display: flex; flex-direction: column; gap: var(--w-space-4); min-width: 0; }
.w-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--w-line-strong); }
.w-dot[data-tone=accent] { background: var(--w-accent); }
.w-dot[data-tone=warn] { background: var(--w-warning); }
.w-dot[data-tone=ok] { background: var(--w-success); }
.w-chip--mono { font-family: var(--w-font-mono); font-size: 11.5px; letter-spacing: 0; }
.w-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: var(--w-space-1); }
.w-row-actions .w-btn { min-width: var(--w-h-sm); }
td:first-child > .w-row-actions { justify-content: flex-start; }
.w-row-meta { display: flex; flex-wrap: wrap; gap: var(--w-space-2); margin-top: 2px; color: var(--w-muted); font-size: 12px; }
.w-link-mono { font-family: var(--w-font-mono); font-size: 13px; color: var(--w-accent); text-decoration: none; }
.w-link-mono:hover { text-decoration: underline; }

/* ---- Lead (celda) ---- */
.w-avatar {
  flex: none; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--w-line); background: var(--w-surface-2); color: var(--w-ink-2);
  font: 600 12px/1 var(--w-font); letter-spacing: .02em;
}
.w-avatar--sm { width: 26px; height: 26px; font-size: 10.5px; }
.w-avatar--lg { width: 48px; height: 48px; font-size: 16px; background: var(--w-accent-soft); border-color: var(--w-accent-line); color: var(--w-accent); }
.w-lead { display: flex; align-items: center; gap: var(--w-space-3); min-width: 220px; max-width: 300px; }
.w-lead__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.w-lead__name { overflow: hidden; color: var(--w-ink); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.w-lead__contact { display: flex; flex-direction: column; min-width: 0; color: var(--w-muted); font-size: 13px; line-height: 18px; white-space: nowrap; }
.w-lead__contact > * { overflow: hidden; text-overflow: ellipsis; }
.w-lead__contact a { color: inherit; text-decoration: none; }
.w-lead__contact a:hover { color: var(--w-ink); text-decoration: underline; }
.w-lead__signals { display: flex; flex-wrap: wrap; gap: var(--w-space-1); margin-top: 3px; }
.w-lead__signals .w-chip, .w-lead-tags .w-chip, .w-kanban__tags .w-chip, .w-row-actions .w-chip { min-height: 20px; padding: 0 7px; font-size: 11px; }
.w-lead-tags { display: flex; flex-direction: column; gap: 4px; min-width: 160px; max-width: 260px; white-space: normal; }
.w-lead-tags__row { display: flex; flex-wrap: wrap; gap: var(--w-space-1); }
.w-lead-tags__text { display: -webkit-box; overflow: hidden; color: var(--w-muted); font-size: 13px; line-height: 18px; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Estado: select con forma de cápsula y un punto de color. */
.w-status { position: relative; display: inline-flex; align-items: center; }
.w-status::before { content: ""; position: absolute; left: 12px; top: 50%; z-index: 1; width: 7px; height: 7px; margin-top: -3.5px; border-radius: 50%; background: var(--w-line-strong); pointer-events: none; }
.w-status[data-tone=accent]::before { background: var(--w-accent); }
.w-status[data-tone=warn]::before { background: var(--w-warning); }
.w-status[data-tone=ok]::before { background: var(--w-success); }
.w-status > .w-input { width: auto; min-width: 140px; min-height: var(--w-h-sm); padding-left: 26px; border-radius: var(--w-radius-full); font-size: 13px; font-weight: 600; }
.w-status--block, .w-status--block > .w-input { width: 100%; }
/* Solo lectura (acceso Ver): access.js cambia el select por un span con el mismo texto. */
.w-status > span { display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px 0 26px; border: 1px solid var(--w-line); border-radius: var(--w-radius-full); background: var(--w-surface-2); color: var(--w-ink); font: 600 13px/1 var(--w-font); box-shadow: none; }

/* Score: barra corta + número. */
.w-score { display: inline-flex; align-items: center; gap: var(--w-space-2); color: var(--w-ink-2); font: 600 13px/1 var(--w-font); font-variant-numeric: tabular-nums; }
.w-score__bar { display: inline-block; width: 52px; height: 6px; overflow: hidden; border-radius: var(--w-radius-full); background: var(--w-surface-2); box-shadow: inset 0 0 0 1px var(--w-line); }
.w-score__bar > span { display: block; height: 100%; border-radius: inherit; background: var(--w-line-strong); }
.w-score[data-tone=warn] .w-score__bar > span { background: var(--w-accent); }
.w-score[data-tone=ok] .w-score__bar > span { background: var(--w-success); }
.w-score[data-tone=ok], .w-score[data-tone=warn] { color: var(--w-ink); }

/* ---- Tabla: orden y columnas visibles ---- */
.w-table .w-sort {
  display: inline-flex; align-items: center; justify-content: flex-start; gap: 4px; min-width: 0; min-height: 32px; margin: -6px -6px; padding: 0 6px; box-shadow: none;
  border: 0; border-radius: var(--w-radius-sm); background: transparent; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer;
}
.w-table .w-sort:hover { background: color-mix(in srgb, var(--w-ink) 6%, transparent); color: var(--w-ink); }
.w-sort:focus-visible { outline: 2px solid transparent; box-shadow: 0 0 0 2px var(--w-ring); }
.w-sort__icon { opacity: .45; }
.w-sort[data-dir=asc], .w-sort[data-dir=desc] { color: var(--w-ink); }
.w-sort[data-dir=asc] .w-sort__icon, .w-sort[data-dir=desc] .w-sort__icon { opacity: 1; color: var(--w-accent); }
.w-sort[data-dir=asc] .w-sort__icon path:last-child, .w-sort[data-dir=desc] .w-sort__icon path:first-child { opacity: .2; }
.w-table[data-hide~=origen] [data-col=origen],
.w-table[data-hide~=etiquetas] [data-col=etiquetas],
.w-table[data-hide~=score] [data-col=score],
.w-table[data-hide~=ingreso] [data-col=ingreso] { display: none; }

/* Acciones siempre a la vista: la columna queda fija a la derecha cuando la tabla se desliza. */
.w-table td[data-col=acciones], .w-table th[data-col=acciones] { position: sticky; right: 0; z-index: 1; background: var(--w-surface); box-shadow: -1px 0 0 var(--w-line); }
.w-table thead th[data-col=acciones] { z-index: 3; background: var(--w-surface-2); }
.w-table td[data-col=acciones] { width: 1%; white-space: nowrap; }

.w-colmenu { position: relative; }
.w-colmenu > summary { list-style: none; }
.w-colmenu > summary::-webkit-details-marker { display: none; }
.w-colmenu__panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; display: flex; flex-direction: column; min-width: 190px; padding: var(--w-space-1);
  border: 1px solid var(--w-line); border-radius: var(--w-radius); background: var(--w-surface); box-shadow: var(--w-shadow);
}
.w-colmenu__item { display: flex; align-items: center; gap: var(--w-space-2); min-height: 36px; padding: 0 var(--w-space-3); border-radius: var(--w-radius-sm); color: var(--w-ink); font: 500 14px/1.2 var(--w-font); cursor: pointer; }
.w-colmenu__item:hover { background: var(--w-surface-2); }
.w-colmenu__item input { width: 16px; height: 16px; margin: 0; accent-color: var(--w-accent); }

/* ---- Facetas y filtros activos ---- */
.w-facets { display: flex; flex-wrap: wrap; align-items: center; gap: var(--w-space-2); min-width: 0; }
.w-facets[hidden] { display: none; }
.w-facets__group { display: flex; flex-wrap: wrap; align-items: center; gap: var(--w-space-2); min-width: 0; }
.w-facets__label { color: var(--w-muted); font: 600 12px/1 var(--w-font); letter-spacing: .04em; text-transform: uppercase; }
.w-facets__stats { display: flex; gap: var(--w-space-2); margin-left: auto; }
.w-facets__stats:empty { display: none; }
.w-facets--active { padding: var(--w-space-2) var(--w-space-3); border: 1px dashed var(--w-line-strong); border-radius: var(--w-radius); background: var(--w-surface-2); }
.w-facets--toolbar { margin-top: var(--w-space-1); }
.w-facets--toolbar .w-field .w-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.w-facets .w-filter-chip { gap: 6px; min-height: 28px; padding: 0 8px 0 10px; border: 1px solid var(--w-accent-line); background: var(--w-accent-soft); color: var(--w-ink); font: 600 12.5px/1 var(--w-font); cursor: pointer; }
.w-filter-chip:hover { border-color: var(--w-accent); }
.w-filter-chip:focus-visible { outline: 2px solid transparent; box-shadow: 0 0 0 2px var(--w-ring); }

/* ---- Pipeline (kanban por estado, estilo atomic-crm) ---- */
[data-lead-ledger][data-view=kanban] > .w-table-wrap,
[data-lead-ledger][data-view=kanban] > #leadsPagination,
[data-lead-ledger][data-view=kanban] .w-colmenu { display: none; }
.w-kanban[hidden] { display: none; }
.w-kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: var(--w-space-3); overflow-x: auto; padding-bottom: var(--w-space-2); scroll-snap-type: x proximity; }
.w-kanban__col {
  --_tone: var(--w-line-strong);
  display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--w-line); border-top: 3px solid var(--_tone);
  border-radius: var(--w-radius-lg); background: var(--w-surface-2); scroll-snap-align: start;
}
.w-kanban__col[data-tone=accent] { --_tone: var(--w-accent); }
.w-kanban__col[data-tone=warn] { --_tone: var(--w-warning); }
.w-kanban__col[data-tone=ok] { --_tone: var(--w-success); }
.w-kanban__head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--w-space-2); padding: var(--w-space-3) var(--w-space-3) var(--w-space-2); }
.w-kanban__head h4 { margin: 0; color: var(--w-ink); font: 650 14px/20px var(--w-font); }
.w-kanban__hint { flex-basis: 100%; padding-left: 16px; color: var(--w-muted); font-size: 12px; }
.w-kanban__col[data-kanban-status=legado] h4 { color: var(--w-muted); font-weight: 500; }
.w-kanban__list {
  display: flex; flex-direction: column; gap: var(--w-space-2); min-height: 140px; max-height: min(72vh, 760px); padding: 0 var(--w-space-2) var(--w-space-2);
  overflow-y: auto; border-radius: 0 0 var(--w-radius-lg) var(--w-radius-lg); transition: background-color var(--w-duration) var(--w-ease), box-shadow var(--w-duration) var(--w-ease);
}
.w-kanban__list.is-over { background: var(--w-accent-soft); box-shadow: inset 0 0 0 2px var(--w-accent-line); }
.w-kanban__card {
  display: flex; flex-direction: column; gap: var(--w-space-2); padding: var(--w-space-3); border: 1px solid var(--w-line); border-radius: var(--w-radius);
  background: var(--w-surface); box-shadow: var(--w-shadow-sm); cursor: pointer;
  transition: border-color var(--w-duration) var(--w-ease), box-shadow var(--w-duration) var(--w-ease), transform var(--w-duration) var(--w-ease);
}
.w-kanban__card:hover { border-color: var(--w-accent-line); box-shadow: var(--w-shadow); }
.w-kanban__card:focus-visible { outline: 2px solid transparent; box-shadow: 0 0 0 2px var(--w-ring-offset), 0 0 0 4px var(--w-ring); }
.w-kanban__card[draggable=true] { cursor: grab; }
.w-kanban__card.is-dragging { opacity: .5; transform: rotate(1.5deg); }
.w-kanban__card[aria-busy=true] { opacity: .6; }
.w-kanban__card-head { display: flex; align-items: center; gap: var(--w-space-2); min-width: 0; }
.w-kanban__card-head strong { flex: 1; min-width: 0; overflow: hidden; color: var(--w-ink); font: 600 14px/20px var(--w-font); text-overflow: ellipsis; white-space: nowrap; }
.w-kanban__card-head time { flex: none; color: var(--w-muted); font-size: 12px; white-space: nowrap; }
.w-kanban__tags { display: flex; flex-wrap: wrap; gap: var(--w-space-1); }
.w-kanban__product { margin: 0; overflow: hidden; color: var(--w-muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.w-kanban__card-foot { display: flex; align-items: center; gap: var(--w-space-2); min-height: 28px; }
.w-kanban__card-foot .w-score__bar { width: 36px; }
.w-kanban__meta { color: var(--w-muted); font-size: 12px; white-space: nowrap; }
.w-kanban__links { display: flex; gap: 2px; margin-left: auto; }
.w-kanban__empty, .w-kanban__more { margin: 0; padding: var(--w-space-3) var(--w-space-2); color: var(--w-muted); font-size: 13px; text-align: center; }
.w-kanban__empty { border: 1px dashed var(--w-line-strong); border-radius: var(--w-radius); }

/* ---- Ficha del lead (panel lateral) ---- */
.w-sheet__panel { display: flex; flex-direction: column; background: var(--w-surface); }
.w-sheet__head {
  position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: var(--w-space-3);
  padding: var(--w-space-5) var(--w-space-4) var(--w-space-4) var(--w-space-5); border-bottom: 1px solid var(--w-line); background: var(--w-surface);
}
.w-sheet__title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.w-sheet__title h3 { margin: 0; color: var(--w-ink); font: 650 18px/26px var(--w-font); letter-spacing: -.01em; overflow-wrap: anywhere; }
.w-sheet__title p { margin: 0; color: var(--w-muted); font-size: 13px; }
.w-sheet__tags { display: flex; flex-wrap: wrap; gap: var(--w-space-1); margin-top: 6px; }
.w-sheet__tags[hidden] { display: none; }
.w-sheet__nav { display: flex; align-items: center; gap: 2px; }
.w-sheet__pos { min-width: 44px; color: var(--w-muted); font: 500 12px/1 var(--w-font-mono); text-align: center; }
.w-sheet__pos:empty { display: none; }
.w-sheet__close { font-size: 22px; color: var(--w-muted); }
.w-sheet__body { display: flex; flex-direction: column; gap: var(--w-space-5); padding: var(--w-space-5); }
.w-sheet__row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--w-space-3); }
.w-sheet__row > .w-field { flex: 1 1 180px; }
.w-sheet__links { display: flex; flex-wrap: wrap; gap: var(--w-space-2); }
.w-sheet__context { display: flex; flex-direction: column; gap: var(--w-space-1); padding: var(--w-space-3) var(--w-space-4); border: 1px solid var(--w-accent-line); border-radius: var(--w-radius); background: var(--w-accent-soft); }
.w-sheet__context[hidden] { display: none; }
.w-sheet__context p { margin: 0; color: var(--w-ink-2); font-size: 14px; }
.w-sheet__context p.w-muted { color: var(--w-muted); font-size: 13px; }
.w-sheet__context-label { color: var(--w-accent); font: 650 11px/1.4 var(--w-font); letter-spacing: .05em; text-transform: uppercase; }
.w-sheet__section { display: flex; flex-direction: column; gap: var(--w-space-3); padding-top: var(--w-space-5); border-top: 1px solid var(--w-line); }
.w-sheet__section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--w-space-2); }
.w-sheet__section-head h4 { margin: 0; color: var(--w-ink); font: 650 15px/22px var(--w-font); }
.w-sheet__quick { display: flex; flex-wrap: wrap; align-items: center; gap: var(--w-space-2); font-size: 13px; }
.w-sheet__composer { display: flex; align-items: flex-end; gap: var(--w-space-2); }
.w-sheet__composer > .w-field { flex: 1; }
.w-sheet__composer .w-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.w-facts { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: var(--w-space-2) var(--w-space-3); margin: 0; padding: var(--w-space-4); border: 1px solid var(--w-line); border-radius: var(--w-radius); font-size: 14px; }
.w-facts dt { color: var(--w-muted); }
.w-facts dd { margin: 0; min-width: 0; color: var(--w-ink); overflow-wrap: anywhere; }
.w-facts a { color: var(--w-accent); }

/* ---- Línea de tiempo: notas + historial ---- */
.w-timeline { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.w-timeline__item { position: relative; display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: var(--w-space-3); padding-bottom: var(--w-space-4); }
.w-timeline__item::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; border-radius: 2px; background: var(--w-line); }
.w-timeline__item:last-child { padding-bottom: 0; }
.w-timeline__item:last-child::before { display: none; }
.w-timeline__dot { position: relative; width: 16px; height: 16px; margin-top: 2px; border: 3px solid var(--w-surface); border-radius: 50%; background: var(--w-line-strong); box-shadow: 0 0 0 1px var(--w-line-strong); }
.w-timeline__item[data-tone=accent] .w-timeline__dot { background: var(--w-accent); box-shadow: 0 0 0 1px var(--w-accent); }
.w-timeline__item[data-tone=warn] .w-timeline__dot { background: var(--w-warning); box-shadow: 0 0 0 1px var(--w-warning); }
.w-timeline__item[data-tone=ok] .w-timeline__dot { background: var(--w-success); box-shadow: 0 0 0 1px var(--w-success); }
.w-timeline__body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.w-timeline__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px var(--w-space-2); font-size: 14px; }
.w-timeline__head strong { color: var(--w-ink); font-weight: 600; }
.w-timeline__head time { color: var(--w-muted); font-size: 12px; }
.w-timeline__text { margin: 0; padding: var(--w-space-2) var(--w-space-3); border: 1px solid var(--w-line); border-radius: var(--w-radius-sm); background: var(--w-surface-2); color: var(--w-ink-2); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.w-timeline__item[data-kind=history] .w-timeline__text { padding: 0; border: 0; background: none; color: var(--w-muted); font-size: 13px; }
.w-timeline__delete { color: var(--w-muted); font-size: 18px; }
.w-timeline__delete:hover { color: var(--w-danger); background: var(--w-danger-soft); }
.w-timeline__empty { padding: var(--w-space-4); border: 1px dashed var(--w-line-strong); border-radius: var(--w-radius); color: var(--w-muted); font-size: 14px; text-align: center; }

/* ---- Origen y Links: participación ---- */
.w-table--compact th, .w-table--compact td { padding: 8px 12px; }
.w-table-wrap > .w-table--compact { min-width: 420px; }
.w-share { display: flex; align-items: center; gap: var(--w-space-2); min-width: 120px; }
.w-share__bar { flex: 1; height: 8px; min-width: 60px; overflow: hidden; border-radius: var(--w-radius-full); background: var(--w-surface-2); box-shadow: inset 0 0 0 1px var(--w-line); }
.w-share__bar > span { display: block; height: 100%; border-radius: inherit; background: var(--w-accent); }
.w-share__pct { flex: none; min-width: 64px; color: var(--w-muted); font: 500 12px/1 var(--w-font-mono); text-align: right; }
.w-breakdown { display: flex; flex-direction: column; gap: var(--w-space-3); margin: 0; padding: 0; list-style: none; }
.w-breakdown li { display: grid; grid-template-columns: 150px minmax(0, 1fr); align-items: center; gap: var(--w-space-3); }
.w-breakdown li > .w-chip { justify-self: start; }

/* ---- Táctil y pantallas angostas: objetivos de 44px ---- */
@media (pointer: coarse), (max-width: 640px) {
  .w-table .w-sort { min-height: var(--w-touch); }
  .w-status > .w-input { min-height: var(--w-touch); }
  .w-facets .w-filter-chip { min-height: var(--w-touch); padding: 0 12px; }
  .w-colmenu__item { min-height: var(--w-touch); }
  .w-kanban__links .w-btn--icon, .w-row-actions .w-btn { min-width: var(--w-touch); }
  .w-kanban__links .w-btn--icon { width: var(--w-touch); }
}
@media (max-width: 959px) {
  .w-kanban { grid-auto-columns: minmax(80vw, 1fr); }
  .w-facets__stats { margin-left: 0; }
  /* Facetas en una fila que se desliza: no empujan la tabla hacia abajo. */
  .w-facets__group { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
  .w-facets__group > * { flex: none; }
  .w-lead { min-width: 200px; max-width: 230px; }
}
@media (max-width: 520px) {
  .w-sheet__head { grid-template-columns: auto minmax(0, 1fr); padding: var(--w-space-4); }
  .w-sheet__nav { grid-column: 1 / -1; justify-content: flex-end; }
  .w-sheet__body { padding: var(--w-space-4); }
  .w-sheet__composer { flex-direction: column; align-items: stretch; }
  .w-sheet__links > a { flex: 1; }
  .w-facts { grid-template-columns: 84px minmax(0, 1fr); }
  .w-breakdown li { grid-template-columns: 1fr; gap: var(--w-space-1); }
  .w-colmenu__panel { right: auto; left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .w-kanban__card, .w-kanban__list { transition: none; }
  .w-kanban__card.is-dragging { transform: none; }
}
