.icon-button, .ghost-button, .primary-button, .danger-button, .success-button, .soft-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 15px;
  font-weight: 600;
  transition: .18s ease;
  white-space: normal;
}
.icon-button { width: 42px; padding: 0; background: var(--surface-soft); color: var(--text); border: 1px solid var(--border); }
.ghost-button { background: var(--surface); color: var(--text-soft); border: 1px solid var(--border); }
.primary-button { background: var(--primary); color: var(--primary-contrast); box-shadow: var(--shadow-sm); }
.danger-button { background: var(--red); color: #fff; }
.success-button { background: var(--green); color: #fff; }
.soft-button { background: var(--surface-soft); color: var(--text-soft); border: 1px solid var(--border); }
.ghost-button:hover, .icon-button:hover, .soft-button:hover { border-color: var(--primary); color: var(--primary); }
.primary-button:hover { background: var(--primary-hover); transform: translateY(-1px); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.card-header { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.card-title { margin: 0; font-size: 15px; font-weight: 800; letter-spacing: -.01em; flex: 1; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.module-stack { display: grid; gap: 18px; min-width: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; min-width: 0; }
.mini-stat { min-width: 0; padding: 16px; display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.mini-stat span { color: var(--text-soft); font-size: 11px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.mini-stat strong { color: var(--text); font-size: 24px; font-weight: 850; letter-spacing: -.02em; }
.mini-stat small { color: var(--text-soft); font-size: 12px; overflow-wrap: anywhere; }
.metric-card { padding: 18px; display: flex; flex-direction: column; gap: 8px; min-height: 130px; position: relative; overflow: hidden; }
.metric-card::after { display:none; }
.metric-label { font-size: 12px; color: var(--text-soft); font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.metric-value { font-size: 30px; font-weight: 850; letter-spacing: -.04em; }
.metric-help { color: var(--text-soft); font-size: 12.5px; }
.sync-banner { min-width: 0; margin-bottom: 16px; padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; box-shadow: var(--shadow-sm); }
.sync-banner > div { min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-banner strong { color: var(--green); font-size: 12px; }
.sync-banner span { color: var(--text-soft); font-size: 12px; }
.sync-banner.warning strong { color: var(--amber); }
.sync-banner.danger strong { color: var(--red); }
.badge, .status-badge, .tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}
.badge.blue, .tag.blue { background: var(--blue-bg); color: var(--blue); }
.badge.green, .tag.green { background: var(--green-bg); color: var(--green); }
.badge.amber, .tag.amber { background: var(--amber-bg); color: #8a5a00; }
.badge.red, .tag.red { background: var(--red-bg); color: var(--red); }
.badge.purple, .tag.purple { background: var(--purple-bg); color: var(--purple); }
.badge.neutral, .tag.neutral { background: var(--surface-strong); color: var(--text-soft); }
.control-chip { border-left: 4px solid var(--control-aglo); }
.control-chip.secretaria { border-left-color: var(--control-secretaria); }
.control-chip.urgent { border-left-color: var(--control-urgent); }
.control-chip.closed { border-left-color: var(--control-closed); }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; min-width: 780px; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .06em; background: var(--surface-soft); }
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.field-inline { display: flex; gap: 10px; align-items: end; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--primary-soft); color: var(--primary-hover); overflow: hidden; }
.avatar.small { width: 28px; height: 28px; font-size: 11px; }
.avatar.large { width: 56px; height: 56px; font-size: 18px; }
.timeline { display: grid; gap: 12px; }
.timeline-item { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; }
.timeline-dot { width: 11px; height: 11px; border-radius: 50%; background: var(--primary); margin-top: 5px; box-shadow: 0 0 0 4px var(--primary-soft); }
.timeline-content strong { display: block; }
.timeline-content span { color: var(--text-soft); font-size: 12px; }
.modal-root { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0,0,0,.52); padding: 18px; }
.modal { width: min(720px, 100%); max-height: 92vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow-lg); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display:flex; align-items:center; gap:12px; }
.modal-header h2 { margin: 0; flex: 1; font-size: 18px; }
.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: grid; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-md); border-radius: var(--radius-md); padding: 12px 14px; font-weight: 700; }
.empty-state { padding: 34px; text-align: center; color: var(--text-soft); }


/* Formularios reales conectados al backend */
.real-form label {
  display: block;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-soft);
  margin-bottom: 6px;
}

.real-form input,
.real-form select,
.real-form textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

.real-form textarea {
  min-height: 86px;
  resize: vertical;
}

.real-form input:focus,
.real-form select:focus,
.real-form textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-grid .span-2 {
  grid-column: span 2;
}

.form-result {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 650;
}

.form-result.success {
  background: rgba(46, 125, 50, .10);
  border-color: rgba(46, 125, 50, .25);
  color: var(--green);
}

.form-result.error {
  background: rgba(198, 40, 40, .10);
  border-color: rgba(198, 40, 40, .25);
  color: var(--red);
}

.inline-footer {
  padding-left: 0;
  padding-right: 0;
  padding-bottom: 0;
}

.primary-button:disabled,
.ghost-button:disabled,
.soft-button:disabled {
  opacity: .65;
  cursor: not-allowed;
  transform: none;
}

@media (max-width: 720px) {
  .form-grid .span-2 {
    grid-column: span 1;
  }

  .modal {
    width: 100%;
    max-height: 95vh;
  }

  .modal-footer.inline-footer {
    flex-direction: column;
  }

  .modal-footer.inline-footer button {
    width: 100%;
  }
}

/* Edición y acciones reales conectadas al backend */
.mini-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.real-form .form-hint { color: var(--text-soft); font-size: 12px; margin-top: 4px; }
.kanban-cards.is-drop-target, .kanban-cards:has(.is-dragging) { outline: 2px dashed var(--primary); outline-offset: -4px; background: var(--primary-soft); }
.order-card.is-dragging { opacity: .55; transform: scale(.985); }
.order-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.order-actions .soft-button, .order-actions .ghost-button, .row-actions .soft-button, .row-actions .ghost-button, .mini-actions .soft-button { min-height: 32px; padding: 0 11px; font-size: 12px; }
@media (max-width: 820px) {
  .order-actions, .row-actions, .mini-actions { flex-direction: column; align-items: stretch; }
  .order-actions .soft-button, .order-actions .ghost-button, .row-actions .soft-button, .row-actions .ghost-button, .mini-actions .soft-button { width: 100%; }
}

/* Pagos y comprobantes - estilos adicionales */
.payments-layout { display: grid; gap: 18px; }
.proof-card { border-left: 4px solid var(--primary, #f57c00); }
.proof-card .title-line { align-items: flex-start; gap: 10px; }
.proof-card h3 { margin: 0; }

/* Escalamiento real */
.escalation-card .aglo-suggestion {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(245, 124, 0, .08);
  border: 1px solid rgba(245, 124, 0, .18);
  color: var(--text-main);
  font-size: 13px;
}
.escalation-card .title-line span {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.muted-text {
  color: var(--text-soft);
  font-size: 13px;
  margin: 4px 0 0;
}

/* Maletas y saldos */
.bags-layout { display: grid; gap: 18px; }
.bag-card { border-left: 4px solid var(--primary, #f57c00); }
.debt-card { border-left: 4px solid var(--red, #c62828); }
.loan-card { border-left: 4px solid var(--amber, #f9a825); }
.company-payment-card { border-left: 4px solid var(--green, #2e7d32); }
.bags-layout small { color: var(--text-soft); font-weight: 600; }
.bags-layout .title-line { align-items: flex-start; gap: 10px; }
.bags-layout .title-line h3 { margin: 0; }
.bags-layout .metric-value { font-size: clamp(22px, 2.2vw, 32px); }
.success-button,
.danger-button {
  border: 0;
  border-radius: 999px;
  min-height: 34px;
  padding: 0 13px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .18s ease, opacity .18s ease;
}
.success-button { background: rgba(46, 125, 50, .14); color: var(--green); }
.danger-button { background: rgba(198, 40, 40, .13); color: var(--red); }
.success-button:hover,
.danger-button:hover { transform: translateY(-1px); }
.success-button:disabled,
.danger-button:disabled { opacity: .65; cursor: not-allowed; transform: none; }
@media (max-width: 820px) {
  .bags-layout .card-header .row-actions { flex-direction: column; align-items: stretch; }
  .bags-layout .card-header .row-actions button { width: 100%; }
}

/* Plantillas WhatsApp */
.templates-view .metric-grid.compact {
  margin-bottom: 16px;
}
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}
.template-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 190px;
}
.template-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.template-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}
.template-card-top span,
.template-meta,
.templates-view .muted {
  color: var(--text-muted);
  font-size: 12px;
}
.template-card p {
  margin: 0;
  line-height: 1.45;
  color: var(--text);
  flex: 1;
}
.template-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.template-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.template-actions .soft-button {
  flex: 1 1 auto;
}

/* WhatsApp API configuration */
.whatsapp-config-view .card-body { overflow: visible; }
.wa-hero-card { border-left: 4px solid var(--primary, #f57c00); }
.split-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-help { margin: 4px 0 0; color: var(--text-muted, #64748b); font-size: 13px; line-height: 1.45; }
.wa-status-box { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 180px; }
.status-pill.neutral { background: rgba(100,116,139,.14); color: var(--text-secondary, #475569); border: 1px solid rgba(100,116,139,.22); }
.status-pill.success { background: rgba(22,163,74,.12); color: #15803d; border: 1px solid rgba(22,163,74,.22); }
.status-pill.warning { background: rgba(245,124,0,.13); color: #c2410c; border: 1px solid rgba(245,124,0,.28); }
.status-pill.danger { background: rgba(220,38,38,.12); color: #b91c1c; border: 1px solid rgba(220,38,38,.25); }
.counter-pill { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2, #f1f5f9); color: var(--text-secondary, #475569); font-size: 12px; font-weight: 700; }
.form-grid.one { grid-template-columns: 1fr; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface, #fff); padding-top: 14px; border-top: 1px solid var(--border, #e2e8f0); z-index: 2; }
.notice-box.danger { background: rgba(220,38,38,.08); border-color: rgba(220,38,38,.22); color: #991b1b; }
.compact-timeline .timeline-item { padding-bottom: 10px; }
.empty-table { text-align: center; color: var(--text-muted, #64748b); padding: 24px !important; }
.muted-line { display: block; color: var(--text-muted, #64748b); font-size: 12px; margin-top: 3px; }

[data-theme="dark"] .sticky-actions { background: var(--surface, #18181b); }
[data-theme="dark"] .notice-box.danger { color: #fecaca; }

@media (max-width: 820px) {
  .split-header { flex-direction: column; align-items: stretch; }
  .wa-status-box { align-items: flex-start; min-width: 0; }
  .whatsapp-config-view .form-grid { grid-template-columns: 1fr; }
  .whatsapp-config-view .span-2 { grid-column: auto; }
  .sticky-actions { position: static; flex-direction: column; }
  .sticky-actions .primary-button,
  .sticky-actions .soft-button { width: 100%; }
}


/* WhatsApp API test result */
.api-test-result {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--surface-2);
  color: var(--text);
}

.api-test-result strong {
  display: block;
  margin-bottom: 8px;
}

.api-test-result pre {
  margin: 0;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
  line-height: 1.45;
  color: inherit;
}

.api-test-result.success {
  border-color: rgba(46, 125, 50, .35);
  background: rgba(46, 125, 50, .08);
}

.api-test-result.danger {
  border-color: rgba(198, 40, 40, .35);
  background: rgba(198, 40, 40, .08);
}

.api-test-result.info {
  border-color: rgba(2, 119, 189, .35);
  background: rgba(2, 119, 189, .08);
}


/* AGLO GPT Brain */
.aglo-brain-page {
  display: grid;
  gap: 18px;
}

.aglo-hero-card .card-header {
  align-items: flex-start;
}

.aglo-hero-status {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.aglo-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.aglo-kpi {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 16px;
  padding: 14px;
  display: grid;
  gap: 6px;
}

.aglo-kpi strong {
  font-size: 22px;
  color: var(--text);
}

.aglo-kpi span {
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-weight: 700;
}

.check-row input {
  width: auto;
}

.aglo-case-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.aglo-case-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  padding: 14px;
  display: grid;
  gap: 10px;
}

.aglo-case-card > div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.aglo-case-card strong {
  color: var(--text);
}

.aglo-case-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.aglo-case-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
}

.aglo-decisions-table td {
  vertical-align: top;
  max-width: 280px;
}

.aglo-result-card {
  display: grid;
  gap: 14px;
}

.aglo-result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.aglo-result-grid span,
.aglo-reply-preview {
  border: 1px solid var(--border);
  background: var(--surface-soft);
  border-radius: 12px;
  padding: 10px;
}

.aglo-result-grid strong,
.aglo-reply-preview strong {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.aglo-result-card pre {
  max-height: 320px;
  overflow: auto;
  border-radius: 12px;
  background: var(--code-bg, #111827);
  color: #d1fae5;
  padding: 14px;
  font-size: 12px;
}

.primary-soft {
  border-color: rgba(245, 124, 0, 0.35) !important;
  background: rgba(245, 124, 0, 0.10) !important;
  color: var(--accent-strong) !important;
}

@media (max-width: 900px) {
  .aglo-kpi-grid,
  .aglo-result-grid {
    grid-template-columns: 1fr 1fr;
  }

  .aglo-hero-status {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .aglo-kpi-grid,
  .aglo-result-grid {
    grid-template-columns: 1fr;
  }
}

/* AGLO v16 · notificaciones superiores y toasts más limpios */
.toast-root {
  position: fixed;
  right: 22px;
  top: 22px;
  bottom: auto;
  z-index: 200;
  display: grid;
  gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: min(420px, calc(100vw - 44px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  box-shadow: var(--shadow-lg, 0 18px 60px rgba(0,0,0,.18));
  border-radius: 16px;
  padding: 12px 14px;
  font-weight: 800;
  color: var(--text);
  animation: agloToastIn .18s ease-out;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.toast > span { min-width: 0; overflow-wrap: anywhere; }
.toast > button { flex: 0 0 auto; padding: 0 2px; background: transparent; color: var(--text-soft); font-size: 20px; line-height: 1; }
@keyframes agloToastIn {
  from { opacity: 0; transform: translateY(-8px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Centro persistente: los toasts son breves, las alertas importantes quedan aquí. */
.notification-wrap { position: relative; }
.notification-button { position: relative; }
.notification-count {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border: 2px solid var(--surface);
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 900;
}
.notification-center {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 210;
  width: min(420px, calc(100vw - 28px));
  max-height: min(680px, calc(100dvh - 96px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.notification-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.notification-head strong,
.notification-head span { display: block; }
.notification-head span { margin-top: 3px; color: var(--text-soft); font-size: 11px; }
.notification-head-actions { display: flex; gap: 6px; }
.notification-list { max-height: min(580px, calc(100dvh - 170px)); overflow-y: auto; }
.notification-item {
  width: 100%;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-align: left;
}
.notification-item:hover { background: var(--surface-soft); }
.notification-item.read { opacity: .72; }
.notification-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--blue); }
.notification-item.warning .notification-dot { background: var(--amber); }
.notification-item.danger .notification-dot { background: var(--red); }
.notification-item.success .notification-dot { background: var(--green); }
.notification-copy { min-width: 0; display: grid; gap: 3px; }
.notification-copy strong { font-size: 13px; }
.notification-copy span { overflow-wrap: anywhere; color: var(--text-soft); font-size: 12px; line-height: 1.35; }
.notification-copy small { font-size: 10.5px; }
.notification-empty { padding: 28px 16px; color: var(--text-soft); text-align: center; }

.global-search { display: grid; gap: 14px; }
.global-search-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.global-search-groups section { min-width: 0; display: grid; align-content: start; gap: 7px; }
.global-search-groups h3 { margin: 0 0 3px; font-size: 12px; color: var(--text-soft); text-transform: uppercase; letter-spacing: .05em; }
.global-search-result { width: 100%; min-width: 0; display: grid; gap: 3px; padding: 10px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); color: var(--text); text-align: left; }
.global-search-result:hover { border-color: var(--primary); background: var(--primary-soft); }
.global-search-result strong,
.global-search-result span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.global-search-result span { color: var(--text-soft); font-size: 11px; }

@media (max-width: 760px) {
  .global-search-groups { grid-template-columns: 1fr; }
  .notification-head { flex-direction: column; }
}


.history-timeline { gap: 14px; padding: 2px 0; }
.history-timeline .history-section { display: grid; grid-column: 1 / -1; gap: 10px; margin-top: 12px; }
.history-timeline .history-section h3 { margin: 10px 0 2px; font-size: 16px; color: var(--text); }
.history-timeline .history-item { grid-template-columns: 22px minmax(0, 1fr); padding: 0 0 12px; border-bottom: 1px solid var(--border-soft); }
.history-timeline .history-item:last-child { border-bottom: 0; }
.history-timeline .timeline-content { min-width: 0; display: grid; gap: 5px; }
.history-timeline .history-item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.history-timeline .history-item-head strong { font-weight: 800; color: var(--text); }
.history-timeline .history-item-head span { color: var(--text-soft); font-size: 12px; white-space: nowrap; }
.history-timeline .timeline-content p { margin: 0; line-height: 1.35; color: var(--text); }
.history-timeline .history-meta { color: var(--text-soft) !important; font-size: 13px; }

/* Fallback para historiales antiguos que todavía usen timeline-list sin dot/content. */
.timeline-list { display: grid; gap: 12px; }
.timeline-list > .timeline-item { display: block; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.timeline-list > .timeline-item:last-child { border-bottom: 0; }
.timeline-list > .timeline-item > strong { display: block; margin-bottom: 4px; color: var(--text); }
.timeline-list > .timeline-item > span { display: block; margin-bottom: 8px; color: var(--text-soft); font-size: 12px; }
.timeline-list > .timeline-item > p { display: block; margin: 4px 0; line-height: 1.35; }
.timeline-list > h3 { margin: 14px 0 4px; }


/* AGLO v44 - Historial visual definitivo sin montajes */
.aglo-history-timeline {
  display: grid;
  gap: 14px;
  padding: 4px 0;
}

.aglo-history-section {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.aglo-history-section h3 {
  margin: 0 0 2px;
  font-size: 15px;
  font-weight: 850;
  color: var(--text);
}

.aglo-history-card {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-soft);
}

.aglo-history-marker {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-top: 5px;
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}

.aglo-history-content {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.aglo-history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.aglo-history-head strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
  color: var(--text);
  overflow-wrap: anywhere;
}

.aglo-history-head time {
  flex: 0 0 auto;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.aglo-history-kicker,
.aglo-history-extra {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.aglo-history-card p {
  margin: 0;
  color: var(--text);
  font-size: 13px;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.history-timeline .timeline-item,
.compact-timeline .timeline-item {
  min-height: auto;
}

/* Diagnóstico operativo AGLO */
.diagnostics-view .diagnostic-hero { overflow: hidden; }
.diagnostic-actions { display:flex; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
.diagnostic-score { display:flex; align-items:center; justify-content:space-between; gap:18px; padding:18px; border:1px solid var(--border); border-radius:18px; background:linear-gradient(135deg, rgba(251,123,0,.08), rgba(255,255,255,.72)); margin-bottom:16px; }
.diagnostic-score span { color:var(--muted); font-size:13px; font-weight:800; }
.diagnostic-score strong { display:block; font-size:38px; line-height:1; margin-top:6px; color:var(--text); }
.diagnostic-score p { margin:8px 0 0; color:var(--muted); }
.diagnostic-score.diagnostic-ok { border-color:rgba(22,163,74,.25); background:rgba(22,163,74,.08); }
.diagnostic-score.diagnostic-warning { border-color:rgba(245,158,11,.28); background:rgba(245,158,11,.08); }
.diagnostic-score.diagnostic-danger { border-color:rgba(220,38,38,.28); background:rgba(220,38,38,.08); }
.diagnostic-summary-grid { margin-top:14px; }
.diagnostic-metric strong { font-size:26px; }
.diagnostic-section-card .card-body { padding-top:0; }
.diagnostic-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.diagnostic-item { border:1px solid var(--border); border-radius:14px; padding:14px; background:var(--surface); min-width:0; }
.diagnostic-item-head { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; margin-bottom:8px; }
.diagnostic-item-head strong { font-size:14px; line-height:1.25; }
.diagnostic-item p { margin:0 0 8px; color:var(--text); font-size:13px; line-height:1.35; word-break:break-word; }
.diagnostic-item small { display:block; color:var(--muted); font-size:12px; line-height:1.35; margin-bottom:8px; }
.diagnostic-item .muted-line { display:block; font-size:11px; word-break:break-word; }
.diagnostic-ok { border-color:rgba(22,163,74,.20); background:rgba(22,163,74,.055); }
.diagnostic-warning { border-color:rgba(245,158,11,.24); background:rgba(245,158,11,.06); }
.diagnostic-danger { border-color:rgba(220,38,38,.24); background:rgba(220,38,38,.06); }
.diagnostic-info { border-color:rgba(59,130,246,.18); background:rgba(59,130,246,.05); }
@media (max-width: 980px) { .diagnostic-grid { grid-template-columns:1fr; } .diagnostic-score { align-items:flex-start; flex-direction:column; } .diagnostic-actions { justify-content:flex-start; } }

/* v52 debug diagnóstico */
.diagnostic-debug-view{display:flex;flex-direction:column;gap:16px}.diagnostic-debug-card{overflow:hidden}.diagnostic-debug-actions{display:flex;gap:10px;flex-wrap:wrap}.diagnostic-debug-score{display:grid;grid-template-columns:minmax(140px,220px) 1fr;gap:18px;align-items:center;border:1px solid var(--border,#dce4e8);border-radius:16px;padding:16px;background:#fbfdfe}.diagnostic-debug-score strong{font-size:42px;color:#fb7b00}.diagnostic-debug-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px;margin-top:14px}.diagnostic-debug-mini{border:1px solid var(--border,#dce4e8);border-radius:14px;padding:12px;background:#fff}.diagnostic-debug-mini b{display:block;font-size:20px}.diagnostic-debug-mini span{font-size:12px;color:#6b7b85}.diagnostic-debug-list{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px}.diagnostic-debug-item{border:1px solid var(--border,#dce4e8);border-radius:14px;padding:12px;background:#fbfdfe;display:flex;justify-content:space-between;gap:12px}.diagnostic-debug-item strong{display:block}.diagnostic-debug-item span,.diagnostic-debug-item small{display:block;margin-top:6px;color:#566873}.diagnostic-debug-item em{font-style:normal;font-weight:800;font-size:12px}.diagnostic-debug-item.success{border-color:#b8e3c0;background:#f4fff6}.diagnostic-debug-item.warning{border-color:#f5d99a;background:#fffaf0}.diagnostic-debug-item.danger{border-color:#f3b6b6;background:#fff5f5}@media(max-width:720px){.diagnostic-debug-score{grid-template-columns:1fr}}

/* AGLO V170 · monitor flotante de clientes activos */
.aglo-active-client-bubbles{
  position:fixed;right:16px;top:112px;z-index:70;display:flex;flex-direction:column;
  align-items:center;gap:9px;padding:8px 7px;border-radius:22px;background:rgba(255,255,255,.9);
  border:1px solid var(--border-color,#dfe5ea);box-shadow:0 12px 30px rgba(15,23,42,.16);
  backdrop-filter:blur(10px);max-height:calc(100vh - 150px);overflow:auto;
}
html[data-theme="dark"] .aglo-active-client-bubbles{background:rgba(20,29,35,.92)}
.active-bubbles-label{font-size:9px;font-weight:800;text-transform:uppercase;letter-spacing:.08em;color:var(--muted-text,#64748b)}
.active-client-bubble{width:43px;height:43px;border-radius:50%;border:3px solid transparent;color:#fff;font-weight:800;cursor:pointer;position:relative;box-shadow:0 5px 14px rgba(15,23,42,.22);transition:transform .16s ease,box-shadow .16s ease}
.active-client-bubble:hover{transform:translateX(-4px) scale(1.08);box-shadow:0 8px 18px rgba(15,23,42,.28)}
.active-client-bubble.green{background:#16a34a}.active-client-bubble.blue{background:#2563eb}.active-client-bubble.violet{background:#7c3aed}.active-client-bubble.orange{background:#ea580c}.active-client-bubble.red{background:#dc2626;animation:aglo-alert-pulse 1.5s infinite}
.active-client-bubble i{position:absolute;right:-3px;top:-4px;width:17px;height:17px;border-radius:50%;display:grid;place-items:center;background:#fff;color:#dc2626;font-size:11px;font-style:normal;border:1px solid #fecaca}
@keyframes aglo-alert-pulse{0%,100%{box-shadow:0 0 0 0 rgba(220,38,38,.35)}50%{box-shadow:0 0 0 8px rgba(220,38,38,0)}}
.payment-exceptions-section{border:1px solid #fed7aa}.payment-exception-card.pending{border-color:#f97316;background:#fffaf5}.payment-exception-card .payment-meta-grid{margin-top:8px}
@media(max-width:980px){.aglo-active-client-bubbles{right:7px;top:92px}.active-client-bubble{width:38px;height:38px}.active-bubbles-label{display:none}}

/* AGLO V171 · canales de servicio tipo Discord */
.aglo-active-client-bubbles.service-channel-rail{
  width:82px;align-items:stretch;gap:10px;padding:10px 7px;border-radius:24px;
}
.service-channel-group{display:flex;flex-direction:column;align-items:center;gap:7px;padding-bottom:9px;border-bottom:1px solid var(--border-color,#dfe5ea)}
.service-channel-group:last-child{border-bottom:0;padding-bottom:0}
.service-channel-head{width:60px;min-height:48px;border:0;background:transparent;color:var(--text-color,#1f2937);display:flex;flex-direction:column;align-items:center;justify-content:center;gap:2px;cursor:default;padding:2px}
.service-channel-head span{font-size:20px;line-height:1}
.service-channel-head small{font-size:8px;font-weight:800;line-height:1.05;text-align:center;color:var(--muted-text,#64748b);max-width:64px}
.service-channel-clients{display:flex;flex-direction:column;align-items:center;gap:7px}
.service-channel-rail .active-client-bubble{width:40px;height:40px;border-width:2px}
html[data-theme="dark"] .service-channel-head{color:#e5e7eb}
@media(max-width:980px){.aglo-active-client-bubbles.service-channel-rail{width:58px}.service-channel-head{width:48px}.service-channel-head small{display:none}.service-channel-rail .active-client-bubble{width:36px;height:36px}}
