/* ==========================================================================
   COMPONENTS DESIGN SYSTEM (Commercial SaaS Grade)
   ========================================================================== */

/* --- 1. BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: all var(--transition-fast) var(--ease-snappy);
  text-decoration: none;
}

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

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled, .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
  pointer-events: none;
}

.btn-primary {
  background-color: var(--primary-600);
  color: var(--text-inverse);
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.2), 0 2px 4px var(--primary-glow);
}
.btn-primary:hover {
  background-color: var(--primary-700);
  box-shadow: 0 2px 4px rgba(79, 70, 229, 0.3), 0 4px 8px var(--primary-glow);
}
.btn-primary:active {
  background-color: var(--primary-800);
}

.btn-secondary {
  background-color: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.btn-danger {
  background-color: var(--danger-50);
  border-color: var(--danger-100);
  color: var(--danger-700);
}
.btn-danger:hover {
  background-color: var(--danger-600);
  color: var(--text-inverse);
  border-color: transparent;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
}
.btn-icon:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
}

/* --- 2. STATS & KPI CARDS --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition-normal) var(--ease-snappy);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.stat-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-icon.primary { background-color: var(--primary-50); color: var(--primary-600); }
.stat-icon.success { background-color: var(--success-50); color: var(--success-600); }
.stat-icon.warning { background-color: var(--warning-50); color: var(--warning-600); }
.stat-icon.info { background-color: var(--info-50); color: var(--info-600); }

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  font-family: var(--font-mono);
  line-height: 1;
}

.stat-footer {
  margin-top: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.stat-trend-up {
  color: var(--success-600);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

/* --- 3. DATA TABLES --- */
.card-table-wrapper {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.table-toolbar {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
  flex-wrap: wrap;
}

.table-search-box {
  position: relative;
  max-width: 320px;
  width: 100%;
}

.table-search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.table-search-input {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 13px;
  background-color: var(--bg-app);
  color: var(--text-primary);
  transition: all var(--transition-fast) var(--ease-snappy);
}

.table-search-input:focus {
  outline: none;
  border-color: var(--border-focus);
  background-color: var(--bg-surface);
  box-shadow: 0 0 0 3px var(--primary-50);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.saas-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13.5px;
}

.saas-table th {
  background-color: #F8FAFC;
  padding: 12px 18px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.saas-table td {
  padding: 14px 18px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  transition: background-color var(--transition-fast);
}

.saas-table tbody tr:hover td {
  background-color: #F8FAFC;
}

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

.font-mono {
  font-family: var(--font-mono) !important;
  font-variant-numeric: tabular-nums;
}

/* User Identity Cell in Table */
.user-identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-identity-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background: var(--primary-100);
  color: var(--primary-700);
  font-weight: 700;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--primary-200);
}

.user-identity-text {
  display: flex;
  flex-direction: column;
}

.user-identity-email {
  font-weight: 600;
  color: var(--text-primary);
}

.user-identity-id {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Hash & Copy Chip */
.copy-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}

.copy-chip:hover {
  background-color: var(--primary-50);
  border-color: var(--primary-200);
  color: var(--primary-700);
}

.copy-chip svg {
  width: 12px;
  height: 12px;
}

/* --- 4. STATUS BADGES --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
}

.badge-success {
  background-color: var(--success-50);
  color: var(--success-700);
  border: 1px solid var(--success-100);
}
.badge-success .badge-dot { background-color: var(--success-500); }

.badge-warning {
  background-color: var(--warning-50);
  color: var(--warning-700);
  border: 1px solid var(--warning-100);
}
.badge-warning .badge-dot { background-color: var(--warning-500); }

.badge-danger {
  background-color: var(--danger-50);
  color: var(--danger-700);
  border: 1px solid var(--danger-100);
}
.badge-danger .badge-dot { background-color: var(--danger-500); }

.badge-info {
  background-color: var(--info-50);
  color: var(--info-700);
  border: 1px solid var(--info-100);
}
.badge-info .badge-dot { background-color: var(--info-500); }

.badge-neutral {
  background-color: var(--bg-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}
.badge-neutral .badge-dot { background-color: var(--text-muted); }

.badge-premium {
  background-color: var(--tier-premium-bg);
  color: var(--tier-premium-text);
  border: 1px solid var(--tier-premium-border);
}
.badge-premium .badge-dot { background-color: var(--tier-premium-text); }

/* --- 5. FORM INPUTS & DROPZONE --- */
.form-group {
  margin-bottom: 18px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-label-hint {
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 4px;
}

.form-control {
  width: 100%;
  height: 38px;
  padding: 0 14px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  color: var(--text-primary);
  transition: all var(--transition-fast) var(--ease-snappy);
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-50);
}

.form-control::placeholder {
  color: var(--text-muted);
}

textarea.form-control {
  height: auto;
  min-height: 80px;
  padding: 10px 14px;
  resize: vertical;
}

/* Custom Checkbox Switch */
.switch-control {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch-input {
  position: relative;
  width: 38px;
  height: 22px;
  appearance: none;
  background-color: var(--border-strong);
  border-radius: var(--radius-pill);
  outline: none;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.switch-input::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  background-color: var(--bg-surface);
  box-shadow: var(--shadow-xs);
  transition: transform var(--transition-fast) var(--ease-snappy);
}

.switch-input:checked {
  background-color: var(--primary-600);
}

.switch-input:checked::before {
  transform: translateX(16px);
}

.switch-label-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

/* Dropzone Upload Box */
.dropzone-box {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  background-color: var(--bg-app);
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-snappy);
  position: relative;
}

.dropzone-box:hover {
  border-color: var(--primary-500);
  background-color: var(--primary-50);
}

.dropzone-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background-color: var(--bg-surface);
  color: var(--primary-600);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  box-shadow: var(--shadow-sm);
}

.dropzone-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.dropzone-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.dropzone-file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* --- 6. MODAL DIALOGS --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal) var(--ease-smooth);
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-modal);
  transform: scale(0.97) translateY(8px);
  transition: transform var(--transition-normal) var(--ease-snappy);
  overflow: hidden;
}

.modal-backdrop.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.modal-close-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  max-height: calc(85vh - 140px);
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 24px;
  background-color: var(--bg-app);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* --- 7. TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.saas-toast {
  pointer-events: auto;
  min-width: 320px;
  max-width: 420px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transform: translateX(120%);
  opacity: 0;
  transition: transform var(--transition-normal) var(--ease-snappy), opacity var(--transition-normal) var(--ease-smooth);
}

.saas-toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-icon-wrap {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.saas-toast.success .toast-icon-wrap { background-color: var(--success-50); color: var(--success-600); }
.saas-toast.error .toast-icon-wrap { background-color: var(--danger-50); color: var(--danger-600); }
.saas-toast.info .toast-icon-wrap { background-color: var(--info-50); color: var(--info-600); }

.toast-content {
  flex: 1;
}

.toast-message {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
}

/* --- 8. EMPTY STATES --- */
.empty-state-box {
  padding: 48px 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.empty-state-icon-circle {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-pill);
  background-color: var(--bg-subtle);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-state-desc {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 360px;
  margin-bottom: 20px;
}

/* --- 9. PROGRESS BAR --- */
.progress-bar-wrap {
  width: 100%;
  height: 6px;
  background-color: var(--bg-subtle-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
  margin-top: 10px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
  border-radius: var(--radius-pill);
  transition: width 200ms ease;
  width: 0%;
}

/* --- 10. SEGMENTED TABS --- */
.saas-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background-color: var(--bg-app);
  padding: 4px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  width: fit-content;
}

.saas-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast) var(--ease-snappy);
}

.saas-tab-btn:hover {
  color: var(--text-primary);
  background-color: var(--bg-surface);
}

.saas-tab-btn.active {
  background-color: var(--bg-surface);
  color: var(--primary-600);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}

.saas-tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  background-color: var(--bg-subtle-2);
  color: var(--text-muted);
}

.saas-tab-btn.active .saas-tab-badge {
  background-color: var(--primary-50);
  color: var(--primary-700);
}

.saas-tab-badge.badge-pending-count {
  background-color: #fef3c7;
  color: #b45309;
}

/* --- 11. SWITCH TOGGLE --- */
.form-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background-color: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-top: 12px;
}

.switch-label-group {
  display: flex;
  flex-direction: column;
}

.switch-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.switch-desc {
  font-size: 11.5px;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd5e1;
  transition: .3s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
  background-color: var(--primary-600);
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

