/**
 * @module dashboard-components
 * @description Reusable UI components: cards, stats grid, data tables, badges,
 * loading states, skeleton rows, error states, action buttons, analytics bar charts,
 * section headers, tab badges, and billing banner.
 */

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-card, 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04));
}

.card-title {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Table ────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

tr:last-child td { border-bottom: none; }

tbody tr:hover { background: var(--bg-hover); }

/* ── Badges ───────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-urgent   { background: rgba(239,68,68,0.12);   color: #b91c1c; }
.badge-normal   { background: rgba(245,158,11,0.12);  color: #92400e; }
.badge-routine  { background: rgba(34,197,94,0.12);   color: #166534; }
.badge-resolved { background: rgba(34,197,94,0.12);   color: #166534; }
.badge-callback { background: rgba(8,145,178,0.12);   color: var(--teal-dim); }
.badge-transferred { background: rgba(99,102,241,0.12); color: #4338ca; }
.badge-positive { background: rgba(34,197,94,0.12);   color: #166534; }
.badge-negative { background: rgba(239,68,68,0.12);   color: #b91c1c; }
.badge-neutral  { background: rgba(90,107,100,0.12);  color: #5a6b64; }

/* ── Loading & Empty ──────────────────────────────── */
.loading {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 0.75rem;
}

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

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* ── Skeleton rows ────────────────────────────────── */
.skeleton-row td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.skeleton-cell {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--border) 25%, var(--bg-hover) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

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

/* ── Error state ──────────────────────────────────── */
.error-state {
  text-align: center;
  padding: 3rem 1rem;
}

.error-state-msg {
  color: #b91c1c;
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.retry-btn {
  padding: 0.4rem 1rem;
  background: transparent;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  color: #b91c1c;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.retry-btn:hover {
  background: rgba(239,68,68,0.1);
}

/* ── Complete button ──────────────────────────────── */
.complete-btn {
  padding: 0.3rem 0.7rem;
  background: var(--teal-dim);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.complete-btn:hover { background: var(--teal); }

/* ── Analytics bar chart ──────────────────────────── */
.bar-chart { margin-top: 0.5rem; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

.bar-label {
  width: 110px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
  text-transform: capitalize;
}

.bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 999px;
  transition: width 0.4s;
}

.bar-count {
  width: 32px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── Charts grid ─────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 0.5rem;
}

/* ── Pagination ───────────────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Section header ───────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
}

.refresh-btn {
  padding: 0.3rem 0.65rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.refresh-btn:hover { border-color: var(--teal); color: var(--teal-lt); }

/* ── Nav Badge ────────────────────────────────────── */
.tab-badge {
  display: inline-block;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  margin-left: 6px;
  vertical-align: middle;
}

.tab-badge-teal {
  background: rgba(8,145,178,0.15);
  color: var(--teal);
}

.tab-badge-red {
  background: rgba(239,68,68,0.15);
  color: #b91c1c;
}

/* ── Billing Banner ───────────────────────────────── */
.billing-banner {
  padding: 0.55rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}

.billing-banner-active {
  background: rgba(8,145,178,0.1);
  border-bottom: 1px solid rgba(8,145,178,0.25);
  color: var(--teal);
}

.billing-banner-pastdue {
  background: rgba(239,68,68,0.08);
  border-bottom: 1px solid rgba(239,68,68,0.25);
  color: #b91c1c;
}

.billing-banner-pastdue a { color: inherit; }
