/**
 * Component Pattern Library - Botify ModBot Mini-App
 * =====================================================
 *
 * Reusable component patterns for consistent UI.
 * Requires: unified-theme.css
 *
 * COMPONENTS:
 * 1. SettingRow - Settings toggle/input rows
 * 2. SectionCard - Content section containers
 * 3. Modal - Confirmation dialogs and overlays
 * 4. Toast - Notification messages
 * 5. NavCard - Dashboard navigation cards
 * 6. StatCard - Statistics display cards
 * 7. Buttons - Button variants
 * 8. Forms - Input, select, textarea
 * 9. Tabs - Tab navigation
 * 10. Badges - Status badges and tags
 */

/* ============================================
 * 1. SETTING ROW
 * Settings toggle/input row component
 * ============================================ */

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-4);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row__content {
  flex: 1;
  min-width: 0;
}

.setting-row__label {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.setting-row__description {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  line-height: var(--line-height-relaxed);
}

.setting-row__control {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-switch .slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  transition: var(--transition-base);
}

.toggle-switch .slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  transition: var(--transition-base);
}

.toggle-switch input:checked + .slider {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-secondary-500));
  border-color: var(--color-primary-500);
}

.toggle-switch input:checked + .slider::before {
  transform: translateX(24px);
  background: var(--text-primary);
}

.toggle-switch input:focus-visible + .slider {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

.toggle-switch input:disabled + .slider {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
 * 2. SECTION CARD
 * Content section container
 * ============================================ */

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  transition: var(--transition-base);
}

.section-card:hover {
  border-color: var(--border-strong);
}

.section-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.section-card__icon {
  font-size: 1.25rem;
  margin-right: var(--space-2);
}

.section-card__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.section-card__actions {
  display: flex;
  gap: var(--space-2);
}

.section-card__body {
  color: var(--text-secondary);
}

.section-card--compact {
  padding: var(--space-3);
}

.section-card--no-border {
  border: none;
}

/* ============================================
 * 3. MODAL
 * Confirmation dialogs and overlays
 * ============================================ */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-base);
}

.modal-overlay.active,
.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: var(--transition-base);
  box-shadow: var(--shadow-xl);
}

.modal-overlay.active .modal-dialog,
.modal-overlay.is-open .modal-dialog {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-4);
  color: var(--text-secondary);
  line-height: var(--line-height-relaxed);
}

.modal-actions {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
}

.modal-actions--right {
  justify-content: flex-end;
}

.modal-actions--center {
  justify-content: center;
}

.modal-actions--stack {
  flex-direction: column;
}

/* Confirm Modal specific */
.confirm-modal .modal-icon {
  text-align: center;
  font-size: 3rem;
  margin-bottom: var(--space-4);
}

.confirm-modal .modal-message {
  text-align: center;
}

/* ============================================
 * 4. TOAST / NOTIFICATIONS
 * Notification messages
 * ============================================ */

.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  left: var(--space-4);
  z-index: var(--z-notification);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-slide-in var(--duration-normal) var(--ease-out);
}

@keyframes toast-slide-in {
  from {
    transform: translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.toast.is-leaving {
  animation: toast-slide-out var(--duration-fast) var(--ease-in) forwards;
}

@keyframes toast-slide-out {
  to {
    transform: translateY(-100%);
    opacity: 0;
  }
}

.toast__icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.toast__content {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.toast__message {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.toast__close {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
}

.toast__close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Toast variants */
.toast--success {
  border-color: var(--color-success-500);
  background: linear-gradient(135deg, var(--bg-surface-solid) 0%, rgba(34, 197, 94, 0.1) 100%);
}

.toast--success .toast__icon {
  color: var(--color-success-500);
}

.toast--error {
  border-color: var(--color-danger-500);
  background: linear-gradient(135deg, var(--bg-surface-solid) 0%, rgba(239, 68, 68, 0.1) 100%);
}

.toast--error .toast__icon {
  color: var(--color-danger-500);
}

.toast--warning {
  border-color: var(--color-warning-500);
  background: linear-gradient(135deg, var(--bg-surface-solid) 0%, rgba(245, 158, 11, 0.1) 100%);
}

.toast--warning .toast__icon {
  color: var(--color-warning-500);
}

.toast--info {
  border-color: var(--color-info-500);
  background: linear-gradient(135deg, var(--bg-surface-solid) 0%, rgba(59, 130, 246, 0.1) 100%);
}

.toast--info .toast__icon {
  color: var(--color-info-500);
}

/* Inline Alert (non-floating) */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.alert--success {
  background: rgba(34, 197, 94, 0.1);
  border-color: var(--color-success-500);
}

.alert--error {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--color-danger-500);
}

.alert--warning {
  background: rgba(245, 158, 11, 0.1);
  border-color: var(--color-warning-500);
}

.alert--info {
  background: rgba(59, 130, 246, 0.1);
  border-color: var(--color-info-500);
}

/* ============================================
 * 5. NAV CARD
 * Dashboard navigation cards
 * ============================================ */

.nav-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

.nav-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: var(--transition-base);
  text-decoration: none;
  display: block;
  position: relative;
}

.nav-card:hover {
  border-color: var(--color-primary-500);
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
}

.nav-card:active {
  transform: translateY(0);
}

.nav-card.is-disabled,
.nav-card.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.nav-card__icon {
  font-size: 2rem;
  margin-bottom: var(--space-2);
  display: block;
}

.nav-card__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.nav-card__desc {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  line-height: var(--line-height-normal);
}

.nav-card__badge {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1);
  background: var(--color-danger-500);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Full width nav card */
.nav-card--full {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  text-align: left;
  gap: var(--space-4);
  padding: var(--space-4);
}

.nav-card--full .nav-card__icon {
  margin-bottom: 0;
  font-size: 1.5rem;
}

.nav-card--full .nav-card__content {
  flex: 1;
}

/* ============================================
 * 6. STAT CARD
 * Statistics display cards
 * ============================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.stat-card {
  background: var(--bg-hover);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  transition: var(--transition-base);
}

.stat-card:hover {
  border-color: var(--color-primary-500);
  background: var(--bg-active);
}

.stat-card__icon {
  font-size: 1.5rem;
  margin-bottom: var(--space-2);
  opacity: 0.8;
}

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-primary-500);
  line-height: 1;
  margin-bottom: var(--space-1);
}

.stat-card__label {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wide);
}

/* Stat card variants */
.stat-card--success .stat-card__value {
  color: var(--color-success-500);
}

.stat-card--warning .stat-card__value {
  color: var(--color-warning-500);
}

.stat-card--danger .stat-card__value {
  color: var(--color-danger-500);
}

/* ============================================
 * 7. BUTTONS
 * Button variants
 * ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-medium);
  line-height: 1;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary-500);
  outline-offset: 2px;
}

.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary button */
.btn--primary,
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-600));
  color: var(--text-on-primary);
  border-color: var(--color-primary-500);
  box-shadow: var(--glow-primary);
}

.btn--primary:hover,
.btn-primary:hover {
  background: linear-gradient(135deg, var(--color-primary-400), var(--color-primary-500));
  transform: translateY(-1px);
  box-shadow: var(--glow-primary-strong);
}

.btn--primary:active,
.btn-primary:active {
  transform: translateY(0);
}

/* Secondary button */
.btn--secondary,
.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn--secondary:hover,
.btn-secondary:hover {
  background: var(--bg-active);
  border-color: var(--color-primary-500);
}

/* Danger button */
.btn--danger,
.btn-danger {
  background: var(--color-danger-500);
  color: var(--text-primary);
  border-color: var(--color-danger-500);
}

.btn--danger:hover,
.btn-danger:hover {
  background: var(--color-danger-600);
  transform: translateY(-1px);
}

/* Ghost button */
.btn--ghost,
.btn-ghost {
  background: transparent;
  color: var(--color-primary-500);
  border-color: var(--color-primary-500);
}

.btn--ghost:hover,
.btn-ghost:hover {
  background: var(--bg-hover);
}

/* Button sizes */
.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}

.btn--lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--font-size-lg);
}

.btn--full {
  width: 100%;
}

/* Icon-only button */
.btn--icon {
  width: 40px;
  height: 40px;
  padding: 0;
}

/* Action button (full-width with icon) */
.action-btn {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-hover);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--font-size-base);
  cursor: pointer;
  transition: var(--transition-fast);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.action-btn:hover {
  background: var(--bg-active);
  border-color: var(--color-primary-500);
}

.action-btn:last-child {
  margin-bottom: 0;
}

/* ============================================
 * 8. FORMS
 * Input, select, textarea
 * ============================================ */

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 3px rgba(0, 240, 255, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-placeholder);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-input.has-error,
.form-select.has-error,
.form-textarea.has-error {
  border-color: var(--color-danger-500);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-helper {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--color-danger-500);
  margin-top: var(--space-1);
}

/* Character counter */
.char-counter {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  text-align: right;
  margin-top: var(--space-1);
}

.char-counter.is-warning {
  color: var(--color-warning-500);
}

.char-counter.is-error {
  color: var(--color-danger-500);
}

/* ============================================
 * 9. TABS
 * Tab navigation
 * ============================================ */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active,
.tab.is-active {
  color: var(--color-primary-500);
  border-bottom-color: var(--color-primary-500);
}

.tab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 var(--space-1);
  margin-left: var(--space-2);
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
}

.tab.active .tab__count {
  background: rgba(0, 240, 255, 0.2);
  color: var(--color-primary-500);
}

.tab-content {
  display: none;
}

.tab-content.active,
.tab-content.is-active {
  display: block;
}

/* ============================================
 * 10. BADGES
 * Status badges and tags
 * ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge--primary {
  background: rgba(0, 240, 255, 0.15);
  color: var(--color-primary-500);
  border: 1px solid rgba(0, 240, 255, 0.3);
}

.badge--secondary {
  background: rgba(138, 43, 226, 0.15);
  color: var(--color-secondary-500);
  border: 1px solid rgba(138, 43, 226, 0.3);
}

.badge--success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-success-500);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge--warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-warning-500);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge--danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-danger-500);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge--info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-info-500);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge--neutral {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-default);
}

/* Badge with dot indicator */
.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
}

/* Rarity badges (for gamification) */
.badge--common {
  background: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
}

.badge--uncommon {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.badge--rare {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.badge--epic {
  background: rgba(168, 85, 247, 0.15);
  color: #a855f7;
}

.badge--legendary {
  background: rgba(251, 191, 36, 0.15);
  color: #fbbf24;
}

/* ============================================
 * RESPONSIVE ADJUSTMENTS
 * ============================================ */

@media (max-width: 480px) {
  .nav-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-dialog {
    margin: var(--space-4);
    max-height: calc(100vh - var(--space-8));
  }

  .tabs {
    gap: 0;
  }

  .tab {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
  }
}
