/* ==========================================================================
   Componentes
   ========================================================================== */

/* ---------- Botones ---------- */
.btn {
  --h: 40px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--h);
  padding: 0 16px;
  border-radius: 11px;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t), transform 0.15s var(--ease-out);
  user-select: none;
  text-decoration: none !important;
}
.btn:active {
  transform: scale(0.97);
}
.btn[disabled],
.btn.is-loading {
  opacity: 0.6;
  pointer-events: none;
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.1) inset, 0 6px 16px -8px rgba(17, 60, 95, 0.6);
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-accent {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px -8px var(--accent);
}
.btn-accent:hover {
  filter: brightness(1.06);
}
.btn-outline {
  background: var(--surface);
  border-color: var(--line-2);
  color: var(--ink);
}
.btn-outline:hover {
  border-color: var(--ink-4);
  background: var(--surface-2);
}
.btn-ghost {
  color: var(--ink-2);
}
.btn-ghost:hover {
  background: var(--surface-3);
  color: var(--ink);
}
.btn-soft {
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.btn-soft:hover {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  filter: brightness(1.05);
}
.btn-danger-ghost {
  color: var(--danger);
}
.btn-danger-ghost:hover {
  background: var(--danger-soft);
}
.btn-success {
  background: var(--success);
  color: #fff;
}
.btn-sm {
  --h: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
}
.btn-lg {
  --h: 48px;
  padding: 0 22px;
  font-size: 15px;
  border-radius: 13px;
}
.btn-block {
  width: 100%;
}
.btn .spin {
  animation: spin 0.8s linear infinite;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  color: var(--ink-2);
  position: relative;
  transition: background var(--t), color var(--t);
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink);
}
.icon-btn.sm {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}
.icon-btn.solid {
  background: var(--primary);
  color: var(--primary-ink);
}
.icon-btn.outline {
  border: 1px solid var(--line-2);
  background: var(--surface);
}
.icon-btn .dot {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}
.icon-btn .count {
  position: absolute;
  top: 3px;
  right: 2px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px var(--surface);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
  min-width: 0;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 0;
  flex-wrap: wrap;
}
.card-head h3 {
  font-size: 15.5px;
  font-weight: 600;
}
.card-head .eyebrow + h3 {
  margin-top: 2px;
}
.card-body {
  padding: 18px 20px 20px;
}
.card-body.tight {
  padding: 12px 12px 14px;
}
.card-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.card.pad {
  padding: 20px;
}
.card.flat {
  box-shadow: none;
}
.card.hoverable {
  transition: border-color var(--t), box-shadow 0.35s var(--ease-out), transform 0.35s var(--ease-out);
}
.card.hoverable:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow);
}

/* ---------- KPI ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
@media (max-width: 1280px) {
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 560px) {
  .kpis {
    grid-template-columns: 1fr;
  }
}
.kpi {
  --c: var(--accent);
  position: relative;
  padding: 18px 20px;
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  min-width: 0;
}
.kpi::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 20px;
  top: 0;
  height: 2px;
  border-radius: 0 0 3px 3px;
  background: var(--c);
  opacity: 0.85;
}
.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.025em;
  margin-top: 10px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-sub {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 600;
  font-size: 12px;
  padding: 1px 7px 1px 5px;
  border-radius: 999px;
}
.delta.up {
  color: var(--success);
  background: var(--success-soft);
}
.delta.down {
  color: var(--danger);
  background: var(--danger-soft);
}
.delta.flat {
  color: var(--neutral);
  background: var(--neutral-soft);
}

/* ---------- Formularios ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > label,
.field-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 6px;
}
.field .req {
  color: var(--danger);
}
.field-help {
  font-size: 12px;
  color: var(--ink-3);
}
.field-error {
  font-size: 12px;
  color: var(--danger);
  font-weight: 500;
}
.input,
.select,
.textarea {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border-radius: 11px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  outline: none;
  min-width: 0;
}
.input::placeholder,
.textarea::placeholder {
  color: var(--ink-4);
}
.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--ink-4);
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.textarea {
  height: auto;
  min-height: 96px;
  padding: 11px 13px;
  line-height: 1.55;
  resize: vertical;
}
.select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237b8ea3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.has-error .input,
.has-error .select,
.has-error .textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 4px var(--danger-soft);
}
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}
.input-group .prefix,
.input-group .suffix {
  position: absolute;
  top: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  padding: 0 12px;
  color: var(--ink-3);
  font-weight: 600;
  font-size: 13px;
  pointer-events: none;
}
.input-group .prefix {
  left: 0;
}
.input-group .suffix {
  right: 0;
}
.input-group .prefix + .input {
  padding-left: 32px;
}
.input-group .input:has(+ .suffix) {
  padding-right: 34px;
}
.input-icon {
  position: relative;
}
.input-icon > svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  pointer-events: none;
}
.input-icon .input {
  padding-left: 38px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 16px;
}
.form-grid .span-2 {
  grid-column: span 2;
}
@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
  .form-grid .span-2 {
    grid-column: span 1;
  }
}
.form-section {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.form-section span {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-ink);
  font-weight: 600;
  white-space: nowrap;
}
.form-section::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

/* Interruptor */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
}
.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.switch .track {
  position: relative;
  width: 40px;
  height: 23px;
  border-radius: 999px;
  background: var(--line-2);
  transition: background 0.25s;
  flex-shrink: 0;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s var(--ease-out);
}
.switch input:checked + .track {
  background: var(--accent);
}
.switch input:checked + .track::after {
  transform: translateX(17px);
}
.switch input:focus-visible + .track {
  box-shadow: var(--ring);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
.check input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

/* Control segmentado (ej. ISV 12.5% / 15% / Exento) */
.seg {
  position: relative;
  display: inline-flex;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  gap: 2px;
}
.seg button {
  position: relative;
  z-index: 1;
  height: 32px;
  padding: 0 14px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  transition: color 0.25s;
  white-space: nowrap;
}
.seg button.is-active {
  color: var(--ink);
}
.seg-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  z-index: 0;
}

/* ---------- Toolbar / filtros ---------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.toolbar .search {
  flex: 1 1 260px;
  max-width: 420px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chips-label {
  align-self: center;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 0 2px 0 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 500;
  transition: all var(--t);
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--line-2);
  color: var(--ink);
}
.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent-ink);
  font-weight: 600;
}
.chip .n {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.8;
}

/* ---------- Tablas ---------- */
.table-card {
  overflow: hidden;
}
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  user-select: none;
}
.table th.sortable {
  cursor: pointer;
}
.table th.sortable:hover {
  color: var(--ink);
}
.table th .sort {
  display: inline-block;
  vertical-align: -2px;
  margin-left: 4px;
  opacity: 0.4;
}
.table th.is-sorted .sort {
  opacity: 1;
  color: var(--accent-ink);
}
.table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.table tbody tr {
  transition: background 0.18s;
}
.table tbody tr:last-child td {
  border-bottom: 0;
}
.table tbody tr.clickable {
  cursor: pointer;
}
.table tbody tr:hover {
  background: var(--surface-2);
}
.table td.num,
.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.table .cell-title {
  font-weight: 600;
  color: var(--ink);
}
.table .cell-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 1px;
}
.table .row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  opacity: 0.55;
  transition: opacity 0.2s;
}
.table tr:hover .row-actions {
  opacity: 1;
}
.cell-ico {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  flex-shrink: 0;
}
.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--ink-3);
  flex-wrap: wrap;
}
.pager {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pager .select {
  height: 32px;
  width: auto;
  font-size: 12.5px;
  padding-left: 10px;
}

/* ---------- Tabla → tarjetas apiladas en teléfono (escritorio intacto) ---------- */
@media (max-width: 640px) {
  .table-stack { display: block; width: 100%; font-size: 14px; }
  .table-stack thead { display: none; }
  .table-stack tbody { display: block; width: 100%; }
  .table-stack tbody tr {
    display: block;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 4px 14px 8px;
    margin-bottom: 12px;
  }
  .table-stack tbody tr:hover { background: var(--surface-2); }
  .table-stack tbody tr:last-child td { border-bottom: 1px solid var(--line); }
  .table-stack td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 44px;
    padding: 9px 0;
    border: 0;
    border-bottom: 1px solid var(--line);
    text-align: right;
  }
  .table-stack td:last-child { border-bottom: 0; }
  .table-stack td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-3);
    text-align: left;
  }
  /* Celda principal = encabezado de la tarjeta (avatar + nombre), sin etiqueta */
  .table-stack td.cell-main { padding: 10px 0 12px; text-align: left; }
  .table-stack td.cell-main::before { content: none; }
  .table-stack td.cell-main .row { width: 100%; }
  /* Paneles: etiqueta arriba y chips abajo, alineados a la izquierda */
  .table-stack td[data-label="Paneles"] { flex-direction: column; align-items: stretch; gap: 8px; text-align: left; }
  .table-stack td[data-label="Paneles"] .chips { justify-content: flex-start; flex-wrap: wrap; }
  /* Acciones: sin etiqueta, a la derecha; se oculta si no hay botón (ej. el dueño) */
  .table-stack td.cell-actions { justify-content: flex-end; }
  .table-stack td.cell-actions::before { content: none; }
  .table-stack td.cell-actions:empty { display: none; }
  .table-stack td.cell-actions .row-actions { opacity: 1; }
  /* Sin línea sobrante bajo la última fila visible cuando no hay acciones */
  .table-stack td:has(+ td.cell-actions:empty) { border-bottom: 0; }
  /* Sin scroll horizontal cuando ya es tarjeta */
  .table-card .table-wrap:has(.table-stack) { overflow: visible; }
}

/* ---------- Badges ---------- */
.badge {
  --c: var(--neutral);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.no-dot::before {
  display: none;
}
.badge.success {
  --c: var(--success);
}
.badge.warning {
  --c: var(--warning);
}
.badge.danger {
  --c: var(--danger);
}
.badge.info {
  --c: var(--info);
}
.badge.accent {
  --c: var(--accent-ink);
}
.badge.violet {
  --c: #7a68e8;
}
.badge.gold {
  --c: #a77d3c;
}
.badge.teal {
  --c: #2c8691;
}
.badge.dark {
  --c: var(--ink);
}
.badge.pulse::before {
  animation: pulse-dot 1.6s ease-out infinite;
}
@keyframes pulse-dot {
  0% {
    box-shadow: 0 0 0 0 currentColor;
  }
  70% {
    box-shadow: 0 0 0 6px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
}
.code-pill {
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-3);
  color: var(--ink-2);
  white-space: nowrap;
}

/* ---------- Avatar ---------- */
.avatar {
  --c: var(--accent);
  width: 34px;
  height: 34px;
  border-radius: 11px;
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--c);
  flex-shrink: 0;
  text-transform: uppercase;
}
.avatar.sm {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  font-size: 10px;
}
.avatar.lg {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  font-size: 16px;
}
.avatar.round {
  border-radius: 50%;
}
.avatar-stack {
  display: flex;
}
.avatar-stack .avatar {
  box-shadow: 0 0 0 2px var(--surface);
  margin-left: -8px;
}
.avatar-stack .avatar:first-child {
  margin-left: 0;
}

/* ---------- Progreso ---------- */
.progress {
  --c: var(--accent);
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--c);
  width: 0;
}
.progress.sm {
  height: 5px;
}
.progress.lg {
  height: 12px;
}
.ring {
  --c: var(--accent);
  position: relative;
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
}
.ring svg {
  transform: rotate(-90deg);
}
.ring .ring-val {
  position: absolute;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
}

/* ---------- Tabs ---------- */
.tabs {
  position: relative;
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  overflow-x: auto;
}
.tabs button {
  position: relative;
  height: 42px;
  padding: 0 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-3);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 0.2s;
}
.tabs button:hover {
  color: var(--ink);
}
.tabs button.is-active {
  color: var(--ink);
}
.tabs .tab-ind {
  position: absolute;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.tabs .n {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--ink-3);
}

/* ---------- Capas: drawer, modal ---------- */
.layer {
  position: fixed;
  inset: 0;
  z-index: 100;
}
.backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.drawer {
  position: absolute;
  top: 10px;
  right: 10px;
  bottom: 10px;
  width: min(620px, calc(100vw - 20px));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.drawer.wide {
  width: min(880px, calc(100vw - 20px));
}
.drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h3 {
  font-size: 19px;
}
.drawer-head .eyebrow {
  color: var(--accent-ink);
}
.drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px 22px 26px;
}
.drawer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.drawer-foot .spacer {
  flex: 1;
}
.modal-wrap {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
}
.modal {
  pointer-events: auto;
  width: min(520px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal.lg {
  width: min(760px, 100%);
}
.modal.sm {
  width: min(420px, 100%);
}
.modal-head {
  padding: 20px 22px 0;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.modal-head h3 {
  font-size: 18px;
}
.modal-body {
  padding: 14px 22px 20px;
  overflow-y: auto;
  color: var(--ink-2);
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.modal-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.modal-icon.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 10px;
  pointer-events: none;
  max-width: calc(100vw - 40px);
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 280px;
  max-width: 420px;
  padding: 13px 14px;
  border-radius: 14px;
  background: var(--surface-inv);
  color: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
}
.toast .t-ico {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.toast.success .t-ico {
  background: var(--success);
  color: #fff;
}
.toast.error .t-ico {
  background: var(--danger);
  color: #fff;
}
.toast.info .t-ico {
  background: var(--info);
  color: #fff;
}
.toast.warning .t-ico {
  background: var(--warning);
  color: #fff;
}
.toast b {
  display: block;
  font-weight: 600;
}
.toast small {
  opacity: 0.7;
}
.toast .t-close {
  margin-left: auto;
  opacity: 0.5;
}
.toast .t-close:hover {
  opacity: 1;
}

/* ---------- Menú contextual ---------- */
.menu {
  position: fixed;
  z-index: 150;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--ink);
  text-align: left;
  text-decoration: none !important;
}
.menu-item svg {
  color: var(--ink-3);
}
.menu-item:hover,
.menu-item.is-focus {
  background: var(--surface-3);
}
.menu-item.danger {
  color: var(--danger);
}
.menu-item.danger svg {
  color: var(--danger);
}
.menu-item .hint {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--ink-3);
}
.menu-sep {
  height: 1px;
  background: var(--line);
  margin: 6px 4px;
}
.menu-label {
  padding: 8px 10px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- Estados vacíos y carga ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-3);
}
.empty-ico {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-ink);
  margin-bottom: 16px;
}
.empty h4 {
  font-size: 16px;
  color: var(--ink);
}
.empty p {
  margin-top: 4px;
  max-width: 40ch;
  font-size: 13.5px;
}
.empty .btn {
  margin-top: 18px;
}
.empty.sm {
  padding: 28px 16px;
}
.empty.sm .empty-ico {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  margin-bottom: 10px;
}

.skel {
  position: relative;
  overflow: hidden;
  background: var(--surface-3);
  border-radius: 8px;
}
.skel::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 60%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}
.skel-line {
  height: 12px;
  margin: 8px 0;
}

.error-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 22px;
  border-radius: var(--r-lg);
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--ink);
}
.error-card .modal-icon {
  background: var(--danger);
  color: #fff;
}

.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  background: var(--info-soft);
  color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--info) 22%, transparent);
}
.alert svg {
  color: var(--info);
  margin-top: 1px;
}
.alert.warning {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 28%, transparent);
}
.alert.warning svg {
  color: var(--warning);
}
.alert.danger {
  background: var(--danger-soft);
  border-color: color-mix(in srgb, var(--danger) 28%, transparent);
}
.alert.danger svg {
  color: var(--danger);
}
.alert.success {
  background: var(--success-soft);
  border-color: color-mix(in srgb, var(--success) 28%, transparent);
}
.alert.success svg {
  color: var(--success);
}

/* ---------- Listas ---------- */
.list {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px dashed var(--line);
  min-width: 0;
  color: inherit;
  text-decoration: none !important;
}
.list-item:last-child {
  border-bottom: 0;
}
a.list-item:hover .li-title,
button.list-item:hover .li-title {
  color: var(--accent-ink);
}
button.list-item {
  width: 100%;
  text-align: left;
}
.li-ico {
  --c: var(--accent);
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent);
  flex-shrink: 0;
}
.li-main {
  flex: 1 1 auto;
  min-width: 0;
}
.li-title {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}
.li-sub {
  font-size: 12px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.li-end {
  text-align: right;
  flex-shrink: 0;
}
.li-date {
  width: 46px;
  flex-shrink: 0;
  text-align: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  overflow: hidden;
  line-height: 1;
}
.li-date small {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 0;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}
.li-date b {
  display: block;
  font-family: var(--font-display);
  font-size: 17px;
  padding: 5px 0 6px;
}

/* ---------- Línea de tiempo ---------- */
.timeline {
  position: relative;
  padding-left: 26px;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--line);
  border-radius: 2px;
}
.tl-item {
  position: relative;
  padding-bottom: 18px;
}
.tl-item:last-child {
  padding-bottom: 0;
}
.tl-dot {
  --c: var(--accent);
  position: absolute;
  left: -26px;
  top: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--c);
  display: grid;
  place-items: center;
}
.tl-dot::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
}
.tl-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tl-title {
  font-weight: 600;
  font-size: 13.5px;
}
.tl-date {
  font-size: 11.5px;
  color: var(--ink-3);
  font-family: var(--font-mono);
}
.tl-body {
  margin-top: 4px;
  font-size: 13px;
  color: var(--ink-2);
  white-space: pre-wrap;
}

/* ---------- Kanban ---------- */
.kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(270px, 1fr);
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
  align-items: start;
}
.kb-col {
  --c: var(--neutral);
  display: flex;
  flex-direction: column;
  min-height: 200px;
  max-height: calc(100vh - 230px);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: background 0.2s, border-color 0.2s;
}
.kb-col.is-over {
  background: color-mix(in srgb, var(--c) 7%, var(--surface-2));
  border-color: color-mix(in srgb, var(--c) 40%, var(--line));
}
.kb-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 14px 10px;
}
.kb-head .dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 18%, transparent);
}
.kb-head h4 {
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  letter-spacing: 0.01em;
}
.kb-head .n {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 1px 7px;
  border-radius: 999px;
}
.kb-head .icon-btn {
  margin-left: auto;
}
.kb-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 2px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}
.kb-card {
  position: relative;
  padding: 12px 12px 11px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-xs);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}
.kb-card:hover {
  border-color: var(--line-2);
  box-shadow: var(--shadow-sm);
}
.kb-card.is-ghost {
  opacity: 0.3;
}
.kb-card.is-dragging {
  position: fixed;
  z-index: 300;
  pointer-events: none;
  box-shadow: var(--shadow-lg);
  cursor: grabbing;
  border-color: var(--accent-line);
}
.kb-placeholder {
  border-radius: 12px;
  border: 2px dashed var(--accent-line);
  background: var(--accent-soft);
}
.kb-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
}
.kb-desc {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
}
.kb-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--ink-3);
}
.kb-meta .due {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kb-meta .due.late {
  color: var(--danger);
  font-weight: 600;
}
.prio {
  --c: var(--neutral);
  display: inline-block;
  width: 4px;
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  border-radius: 0 3px 3px 0;
  background: var(--c);
}

/* ---------- Calendario ---------- */
.cal {
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}
.cal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.cal-head h3 {
  font-size: 18px;
  text-transform: capitalize;
  min-width: 170px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.cal-dow {
  padding: 10px 10px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.cal-day {
  min-height: 116px;
  padding: 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  transition: background 0.2s;
  cursor: pointer;
}
.cal-day:nth-child(7n) {
  border-right: 0;
}
.cal-day:hover {
  background: var(--surface-2);
}
.cal-day.is-out {
  background: color-mix(in srgb, var(--surface-2) 60%, transparent);
}
.cal-day.is-out .cal-num {
  color: var(--ink-4);
}
.cal-num {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
}
.cal-day.is-today .cal-num {
  background: var(--accent);
  color: #fff;
}
.cal-ev {
  --c: var(--accent);
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 3px 6px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--c) 13%, transparent);
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid var(--c);
  min-width: 0;
}
.cal-ev span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-more {
  font-size: 11px;
  color: var(--ink-3);
  padding-left: 4px;
}
@media (max-width: 760px) {
  .cal-day {
    min-height: 64px;
    padding: 4px;
  }
  .cal-ev span {
    display: none;
  }
  .cal-ev {
    padding: 0;
    height: 6px;
    border-left: 0;
    background: var(--c);
  }
}

/* ---------- Gráficas ---------- */
.chart {
  position: relative;
  width: 100%;
}
.chart svg {
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart .grid-line {
  stroke: var(--line);
  stroke-dasharray: 3 4;
}
.chart .axis-label {
  fill: var(--ink-3);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
}
.chart-tip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-inv);
  color: var(--surface);
  font-size: 12px;
  box-shadow: var(--shadow);
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, calc(-100% - 10px));
  transition: opacity 0.15s;
}
.chart-tip b {
  font-family: var(--font-display);
  font-size: 13px;
}
.chart-tip .row {
  gap: 6px;
}
.chart-tip i {
  width: 8px;
  height: 8px;
  border-radius: 3px;
  display: inline-block;
}
.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
}
.legend i {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: -1px;
}
.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
}
.donut-center strong {
  display: block;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
}

/* ---------- Command palette ---------- */
.cmdk {
  position: absolute;
  left: 50%;
  top: 12vh;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 24px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.cmdk-input {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.cmdk-input input {
  flex: 1;
  border: 0;
  outline: 0;
  background: none;
  font-size: 16px;
}
.cmdk-list {
  max-height: 56vh;
  overflow-y: auto;
  padding: 8px;
}
.cmdk-group {
  padding: 10px 10px 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.cmdk-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 10px;
  border-radius: 11px;
  text-align: left;
  color: var(--ink);
}
.cmdk-item .ci {
  --c: var(--accent);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--c) 13%, transparent);
  color: var(--c);
  flex-shrink: 0;
}
.cmdk-item small {
  display: block;
  color: var(--ink-3);
  font-size: 12px;
}
.cmdk-item.is-focus {
  background: var(--surface-3);
}
.cmdk-item .enter {
  margin-left: auto;
  opacity: 0;
  color: var(--ink-3);
}
.cmdk-item.is-focus .enter {
  opacity: 1;
}
.cmdk-foot {
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--ink-3);
  background: var(--surface-2);
}
kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
}

/* ---------- Hilo de conversación (tickets) ---------- */
.thread {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.msg {
  display: flex;
  gap: 12px;
  max-width: 86%;
}
.msg.me {
  margin-left: auto;
  flex-direction: row-reverse;
}
.msg-bubble {
  padding: 12px 14px;
  border-radius: 16px;
  border-top-left-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 13.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  min-width: 0;
}
.msg.me .msg-bubble {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  border-top-left-radius: 16px;
  border-top-right-radius: 6px;
}
.msg.internal .msg-bubble {
  background: var(--warning-soft);
  border-color: color-mix(in srgb, var(--warning) 35%, transparent);
  border-style: dashed;
}
.msg.system {
  max-width: 100%;
  justify-content: center;
  font-size: 12px;
  color: var(--ink-3);
}
.msg.system span {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-3);
}
.msg-meta {
  font-size: 11.5px;
  color: var(--ink-3);
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.msg.me .msg-meta {
  justify-content: flex-end;
}
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--ink);
  text-decoration: none !important;
  max-width: 240px;
}
.file-chip img {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
}
.file-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Varios ---------- */
.divider {
  height: 1px;
  background: var(--line);
  margin: 16px 0;
}
.kv {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 10px 16px;
  font-size: 13.5px;
}
.kv dt {
  color: var(--ink-3);
}
.kv dd {
  margin: 0;
  font-weight: 500;
  min-width: 0;
  overflow-wrap: anywhere;
}
.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 13.5px;
}
.stat-row:last-child {
  border-bottom: 0;
}
.stat-row b {
  font-variant-numeric: tabular-nums;
}
.pill-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--surface-3);
}
.pill-tabs button {
  height: 30px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-3);
}
.pill-tabs button.is-active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}
.dropzone {
  border: 2px dashed var(--line-2);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}
.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}
.color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.swatches button {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 2px var(--surface);
}
.swatches button.is-active {
  border-color: var(--ink);
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 26px 0 14px;
}
.section-title h3 {
  font-size: 16px;
}
