/**
 * Admin Components — Unified Design System
 * Consistent buttons, badges, cards, toasts, skeletons
 */

/* ============================================ */
/* ACCESSIBILITY                                */
/* ============================================ */

/* Skip-to-content link — visible only on focus */
.skip-to-content:focus {
  top: 0 !important;
}

/* Universal focus-visible indicator for all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Screen reader only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================ */
/* BUTTONS                                      */
/* ============================================ */
.btn,
.hub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-md);
  font-weight: var(--font-weight-semibold);
  font-family: inherit;
  font-size: var(--font-size-sm);
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:focus-visible,
.hub-btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
.btn:disabled,
.hub-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn:hover:not(:disabled),
.hub-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

/* Color variants — .btn-X and .hub-btn--X aliases */
.btn-primary,
.hub-btn--primary,
.btn--primary {
  background: var(--color-primary);
  color: var(--color-white);
}
.btn-primary:hover:not(:disabled),
.hub-btn--primary:hover:not(:disabled),
.btn--primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-green,
.hub-btn--green {
  background: var(--color-success-dark);
  color: var(--color-white);
}
.btn-green:hover:not(:disabled),
.hub-btn--green:hover:not(:disabled) {
  background: var(--color-success);
}

.btn-danger,
.hub-btn--danger {
  background: var(--color-error-dark);
  color: var(--color-white);
}
.btn-danger:hover:not(:disabled),
.hub-btn--danger:hover:not(:disabled) {
  background: var(--color-error);
}

.btn-blue,
.hub-btn--blue {
  background: var(--color-info-dark);
  color: var(--color-white);
}
.btn-blue:hover:not(:disabled),
.hub-btn--blue:hover:not(:disabled) {
  background: var(--color-info);
}

.btn-purple {
  background: var(--color-purple);
  color: var(--color-white);
}
.btn-purple:hover:not(:disabled) {
  background: #6d28d9;
}

.btn-orange,
.hub-btn--orange {
  background: var(--color-orange);
  color: var(--color-white);
}
.btn-orange:hover:not(:disabled),
.hub-btn--orange:hover:not(:disabled) {
  background: var(--color-orange-dark);
}

.btn-outline,
.hub-btn--outline,
.btn--secondary {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-primary);
}
.btn-outline:hover:not(:disabled),
.hub-btn--outline:hover:not(:disabled),
.btn--secondary:hover:not(:disabled) {
  background: var(--color-surface-hover);
  border-color: var(--color-gray-400);
}

.btn-ghost {
  background: transparent;
  color: var(--color-gray-500);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-gray-100);
}

/* Size variants */
.btn-sm,
.hub-btn--sm {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
}
.btn-xs {
  padding: 2px var(--spacing-sm);
  font-size: 0.7em;
  border-radius: var(--radius-sm);
}
.btn-lg {
  padding: var(--spacing-md) var(--spacing-lg);
  font-size: var(--font-size-base);
}
.btn-block {
  width: 100%;
}
.btn-icon {
  padding: var(--spacing-xs);
  min-width: 32px;
  min-height: 32px;
}

/* ============================================ */
/* BADGES                                       */
/* ============================================ */
/* Unified badge/chip base — used by .badge and .status-chip */
.badge,
.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--spacing-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  white-space: nowrap;
  line-height: 1.5;
}

/* Semantic badge variants */
.badge-success {
  background: var(--color-success-light);
  color: var(--color-success-dark);
}
.badge-danger {
  background: var(--color-error-light);
  color: var(--color-error-dark);
}
.badge-warning {
  background: var(--color-warning-light);
  color: var(--color-warning-dark);
}
.badge-info {
  background: var(--color-info-light);
  color: var(--color-info-dark);
}
.badge-purple {
  background: var(--color-purple-light);
  color: var(--color-purple);
}
.badge-gray {
  background: var(--color-gray-100);
  color: var(--color-gray-500);
}
.badge-orange {
  background: #fff7ed;
  color: var(--color-orange-dark);
}

/* ============================================ */
/* CARDS                                        */
/* ============================================ */
/* Unified card system — .card, .hub-card, .content-card all share this base */
.card,
.hub-card,
.content-card {
  background: var(--color-surface);
  border: 1px solid var(--table-border, var(--color-border));
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.card-body {
  padding: var(--spacing-lg);
}
.card-header {
  padding: var(--spacing-md) var(--spacing-lg);
  border-bottom: 1px solid var(--table-border, var(--color-border));
  font-weight: var(--font-weight-bold);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-footer {
  padding: var(--spacing-md) var(--spacing-lg);
  border-top: 1px solid var(--table-border, var(--color-border));
  background: var(--color-surface-hover);
}

/* Stat cards */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-md);
}
.stat-item {
  padding: var(--spacing-md);
  border-radius: var(--radius-lg);
  text-align: center;
  border: 1px solid;
  transition: transform var(--transition-fast);
}
.stat-item:hover {
  transform: translateY(-2px);
}
.stat-value {
  font-size: 1.7em;
  font-weight: var(--font-weight-bold);
}
.stat-label {
  font-size: var(--font-size-xs);
  margin-top: 2px;
}
.stat-trend {
  font-size: 0.7em;
  margin-top: var(--spacing-xs);
}
.stat-trend-up {
  color: var(--color-success-dark);
}
.stat-trend-down {
  color: var(--color-error-dark);
}

/* ============================================ */
/* TOAST NOTIFICATIONS                          */
/* ============================================ */
.toast-container {
  position: fixed;
  bottom: 20px;
  left: auto;
  right: auto;
  inset-inline-end: 20px;
  z-index: var(--z-index-tooltip, 1070);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 380px;
}
.toast {
  padding: 12px 16px;
  border-radius: 10px;
  color: var(--color-white);
  font-weight: 600;
  font-size: 0.9em;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  animation: toast-slide-in 0.3s ease-out;
  cursor: pointer;
}
.toast-success {
  background: var(--color-success-dark);
}
.toast-error {
  background: var(--color-error-dark);
}
.toast-info {
  background: var(--color-info-dark);
}
.toast-warning {
  background: var(--color-warning);
  color: var(--color-gray-800);
}
.toast-exit {
  animation: toast-slide-out 0.3s ease-in forwards;
}

@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes toast-slide-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ============================================ */
/* SKELETON LOADING                             */
/* ============================================ */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s infinite ease-in-out;
  border-radius: 6px;
}
.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}
.skeleton-text-sm {
  height: 10px;
  margin-bottom: 6px;
  width: 60%;
}
.skeleton-card {
  height: 80px;
  border-radius: 10px;
  margin-bottom: 10px;
}
.skeleton-stat {
  height: 90px;
  border-radius: 10px;
}
.skeleton-row {
  height: 44px;
  margin-bottom: 2px;
  border-radius: 4px;
}
.skeleton-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

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

/* ============================================ */
/* CONNECTION STATUS INDICATOR                  */
/* ============================================ */
.ws-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-left: 8px;
  transition: background 0.3s;
}
.ws-status-connected {
  background: var(--color-success-dark);
  box-shadow: 0 0 4px var(--color-success-dark);
}
.ws-status-reconnecting {
  background: var(--color-warning);
  animation: ws-blink 1s infinite;
}
.ws-status-disconnected {
  background: var(--color-error-dark);
}

@keyframes ws-blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* ============================================ */
/* PIPELINE / FUNNEL                            */
/* ============================================ */
.pipeline {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 20px;
  background: var(--color-white);
  border-radius: 12px;
  border: 1px solid var(--color-gray-200);
  overflow: hidden;
}
.pipeline-step {
  flex: 1;
  text-align: center;
  padding: 16px 8px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.pipeline-step:hover {
  background: var(--color-gray-50);
}
.pipeline-step-value {
  font-size: 1.5em;
  font-weight: 700;
}
.pipeline-step-label {
  font-size: 0.72em;
  margin-top: 2px;
}
.pipeline-arrow {
  font-size: 1.2em;
  color: var(--color-gray-300);
  flex-shrink: 0;
  padding: 0 2px;
}

/* ============================================ */
/* ACTIVITY FEED                                */
/* ============================================ */
.activity-feed {
  list-style: none;
  padding: 0;
  margin: 0;
}
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-gray-100);
  font-size: 0.88em;
}
.activity-item:last-child {
  border-bottom: none;
}
.activity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.activity-text {
  flex: 1;
  color: var(--color-gray-700);
  line-height: 1.5;
}
.activity-time {
  font-size: 0.8em;
  color: var(--color-gray-400);
  white-space: nowrap;
}

/* ============================================ */
/* QUICK ACTIONS                                */
/* ============================================ */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.quick-action {
  padding: 16px;
  border-radius: 10px;
  border: 1px solid var(--color-gray-200);
  background: var(--color-white);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--color-gray-700);
}
.quick-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--color-primary, #8bc53f);
}
.quick-action-icon {
  font-size: 28px;
  margin-bottom: 6px;
}
.quick-action-label {
  font-size: 0.85em;
  font-weight: 600;
}

/* ============================================ */
/* EMPTY STATE                                  */
/* ============================================ */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-gray-400);
}
.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.empty-state-text {
  font-size: 1em;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--color-gray-500);
}
.empty-state-sub {
  font-size: 0.85em;
}

/* ============================================ */
/* MOBILE RESPONSIVE                            */
/* ============================================ */
@media (max-width: 767px) {
  .toast-container {
    inset-inline-start: var(--spacing-sm);
    inset-inline-end: var(--spacing-sm);
    max-width: 100%;
  }
}

@media (max-width: 480px) {
  .toast-container {
    inset-inline-end: 10px;
    inset-inline-start: 10px;
    max-width: 100%;
  }
  .toast {
    font-size: 0.82em;
    padding: 10px 12px;
  }
  .empty-state {
    padding: 24px 12px;
  }
  .empty-state-icon {
    font-size: 36px;
  }
  .card-body {
    padding: 12px;
  }
  .card-header {
    padding: 12px 14px;
    font-size: 0.95em;
  }
  .activity-item {
    gap: 8px;
    padding: 8px 0;
    font-size: 0.82em;
  }
  .pipeline {
    flex-direction: column;
    align-items: center;
    gap: 4px;
  }
  .pipeline-arrow {
    transform: rotate(90deg);
  }
  .pipeline-step {
    width: 100%;
    text-align: center;
  }
}

/* ═══════════════════════════════════════════════════════════════
   VISUAL BUG FIXES — Hover, Focus, Contrast, Spacing, Transitions
   ═══════════════════════════════════════════════════════════════ */

/* Fix: All interactive elements get focus-visible */
.btn:focus-visible,
.hub-btn:focus-visible,
.hub-tab:focus-visible,
.sidebar-item:focus-visible,
.quick-action:focus-visible,
.pipeline-step:focus-visible,
.nav-card:focus-visible {
  outline: 2px solid var(--color-primary, #8bc53f);
  outline-offset: 2px;
}

/* Fix: Active/pressed states for better feedback */
.btn:active,
.hub-btn:active {
  transform: scale(0.97);
}
.sidebar-item:active {
  background: rgba(255, 255, 255, 0.15);
}
.hub-tab:active {
  transform: scale(0.98);
}

/* Fix: Disabled button should not show hover */
.btn:disabled:hover,
.hub-btn:disabled:hover {
  transform: none;
  box-shadow: none;
  opacity: 0.5;
}

/* Fix: Ghost button contrast */
.btn-ghost {
  color: var(--color-text-secondary, #4b5563);
}
.btn-ghost:hover {
  background: var(--color-gray-100, #f3f4f6);
  color: var(--color-text-primary, #111827);
}

/* Fix: Pipeline step transition */
.pipeline-step {
  transition:
    background 0.15s ease,
    transform 0.15s ease;
  cursor: pointer;
}
.pipeline-step:hover {
  background: rgba(0, 0, 0, 0.03);
}

/* Fix: Quick action transition */
.quick-action {
  transition: all 0.2s ease;
}

/* Fix: Sidebar active border for RTL — handled via border-inline-start in admin-sidebar.css */

/* Fix: Sidebar item better hover visibility */
.sidebar-item:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Stat item transitions — merged into main .stat-item above */
/* Card header/body spacing — merged into main .card rules above */

/* Fix: Toast better visibility */
.toast-warning {
  color: var(--color-white);
  background: var(--color-warning-dark);
}

/* Badge minimum size — merged into main .badge rule above */

/* Fix: Skeleton animation smoother */
.skeleton {
  border-radius: var(--radius-md, 8px);
}

/* Fix: Selected row transition */
.data-table tbody tr.selected-row {
  transition: background 0.15s ease;
}

/* Fix: Better empty state layout */
.empty-state {
  max-width: 400px;
  margin: 0 auto;
}

/* Notification Bell */
.notification-bell {
  position: relative;
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: var(--spacing-xs) var(--spacing-sm);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}
.notification-bell:hover {
  background: var(--color-gray-100);
}
.notification-badge {
  position: absolute;
  top: 0;
  right: 0;
  background: var(--color-error);
  color: var(--color-white);
  font-size: 0.65rem;
  font-weight: var(--font-weight-bold);
  min-width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.notification-dropdown {
  position: absolute;
  top: 100%;
  inset-inline-start: 0;
  width: 350px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-index-dropdown, 1000);
  display: none;
}
.notification-dropdown.open {
  display: block;
}
.notification-item {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--color-gray-100);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.notification-item:hover {
  background: var(--color-gray-50);
}
.notification-item.unread {
  background: var(--color-info-light);
}
.notification-item__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-sm);
}
.notification-item__time {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}
