/* UI components: cards, badges, tables, buttons, forms, HTMX states */

/* ---------- Cards / KPI ---------- */
.card,
.kpi-card,
.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.kpi-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 100%;
}

.kpi-card__label {
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi-card__value {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.kpi-card__value .badge {
  vertical-align: middle;
}

.kpi-card__meta {
  margin: 0;
  margin-top: auto;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.link-arrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}

.link-arrow:hover {
  color: var(--primary-hover);
  text-decoration: none;
}

.link-arrow svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.panel-card {
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
}

.panel-card__title {
  margin: 0 0 var(--space-3);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

/* Stat rows inside Queues / Backup / Migration */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: 8px 0;
  border-bottom: 1px dashed #E2E8F0;
}

.stat-row:last-of-type {
  border-bottom: none;
}

.stat-label {
  color: var(--text-muted);
  font-size: 14px;
}

.stat-value {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
  text-align: right;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}

.card {
  padding: var(--space-4);
  margin: var(--space-3) 0;
}

.card.inline {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

.card.secret {
  border-color: #F59E0B;
  background: #FFFBEB;
}

.report-green {
  border-left: 4px solid var(--success-text);
}

.report-red {
  border-left: 4px solid var(--danger-text);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-3);
  margin: var(--space-3) 0;
}

.grid2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: var(--space-4);
}

/* ---------- Badges (compact) ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.4;
  background: #E2E8F0;
  color: var(--text-main);
  white-space: nowrap;
}

.badge-success,
.badge.st-ok,
.badge.pk-delivered,
.badge.lv-info {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge-warning,
.badge.st-degraded,
.badge.lv-warning,
.badge.pk-pending,
.badge.pk-sent {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.badge-danger,
.badge.st-down,
.badge.lv-critical,
.badge.pk-failed {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.table,
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
}

.table thead th,
table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 12px 16px;
  background: #F8FAFC;
  border-bottom: 1px solid #E2E8F0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
}

.table thead th.num,
table thead th.num {
  text-align: right;
}

.table td,
table td {
  padding: 12px 16px;
  border-bottom: 1px solid #E2E8F0;
  border-top: none;
  border-left: none;
  border-right: none;
  font-size: 14px;
  color: var(--text-main);
  vertical-align: middle;
}

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

.table tbody tr:hover td,
table tbody tr:hover td {
  background: var(--hover-row);
}

.table .num,
table .num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 13px;
}

tr.row-archived td {
  color: var(--text-muted);
  background: #FAFBFC;
}

tr.row-dlq td {
  background: #FFFBEB;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font: inherit;
  font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-main);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: var(--hover-row);
  text-decoration: none;
}

.btn.small {
  padding: 4px 10px;
  font-size: 12px;
}

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

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

.btn.danger {
  border-color: #FECACA;
  color: var(--danger-text);
}

.btn.danger:hover {
  background: var(--danger-bg);
}

.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 16px;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  cursor: pointer;
}

.btn-ghost:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-decoration-color: currentColor;
}

.btn-ghost svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.inline-form {
  display: inline;
  margin: 0;
}

.actions form {
  margin-right: var(--space-1);
}

/* ---------- Forms ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: end;
  margin-bottom: var(--space-4);
}

.filters label,
.card label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--text-muted);
  gap: var(--space-1);
}

input,
select,
textarea {
  font: inherit;
  padding: 7px 10px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-main);
}

input[type="checkbox"] {
  padding: 0;
  width: 16px;
  height: 16px;
}

.bulk {
  margin: var(--space-3) 0 var(--space-5);
}

/* ---------- Flash / alerts ---------- */
.flash {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  border: 1px solid;
  font-size: 14px;
}

.flash-ok {
  background: var(--success-bg);
  border-color: #86EFAC;
  color: var(--success-text);
}

.flash-error {
  background: var(--danger-bg);
  border-color: #FECACA;
  color: var(--danger-text);
}

/* ---------- Health / dashboard sections ---------- */
.section {
  margin: 0;
}

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.section__title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
}

.section__title--spaced {
  margin-bottom: var(--space-3);
}

.section__meta {
  font-size: 12px;
  color: var(--text-subtle);
}

.health {
  display: flex;
  flex-direction: column;
  gap: 32px;
  margin: 0;
}

.empty-state {
  padding: var(--space-5);
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* ---------- HTMX loading ---------- */
.htmx-indicator {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-dark);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: cb-spin 0.7s linear infinite;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
}

.btn-ghost .htmx-indicator {
  margin-left: 2px;
}

.table-skeleton {
  display: none;
  padding: var(--space-4);
}

.htmx-request .table-skeleton {
  display: block;
}

.htmx-request .table-skeleton + .table-wrap,
.htmx-request ~ .table-wrap.is-swappable {
  opacity: 0.45;
}

.skeleton-line {
  height: 12px;
  margin-bottom: var(--space-3);
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, #EEF2F7 25%, #F8FAFC 50%, #EEF2F7 75%);
  background-size: 200% 100%;
  animation: cb-shimmer 1.2s ease-in-out infinite;
}

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

@keyframes cb-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Legacy helpers used by other pages ---------- */
.big {
  font-size: 32px;
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.err {
  color: var(--danger-text);
}

.health-head {
  font-size: 16px;
}

/* keep old meta-list usable on other pages */
.meta-list {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-4);
  display: flex;
  flex-direction: column;
}

.meta-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 8px 0;
  border-bottom: 1px dashed #E2E8F0;
  font-size: 14px;
}

.meta-list li:last-child {
  border-bottom: none;
}

.meta-list__label {
  color: var(--text-muted);
}

.meta-list__value {
  color: var(--text-main);
  font-weight: 600;
  text-align: right;
}
