/* ==========================================================================
   components.css — the reusable UI kit
   Buttons · Badges · Forms · Alerts · Table · Tabs · Pagination · Dropdown ·
   Modal · Toast · Skeleton · Empty state
   Every component draws from the tokens in base.css only.
   ========================================================================== */

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-weight: 550;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  isolation: isolate;
  transition: transform var(--t-fast), background-color var(--t),
    border-color var(--t), box-shadow var(--t), color var(--t), opacity var(--t);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn .icon { width: 16px; height: 16px; }

/* Primary — gradient fill, brightened on hover by an overlay (no repaint). */
.btn--primary {
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-glow);
}
.btn--primary::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(135deg, #6b9dff, #a480ff);
  opacity: 0;
  transition: opacity var(--t);
}
.btn--primary:hover { box-shadow: 0 12px 34px -10px var(--primary-glow); }
.btn--primary:hover::after { opacity: 1; }

/* Secondary — soft outline over glass. */
.btn--secondary {
  border-color: var(--border-strong);
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  color: var(--text-secondary);
}
.btn--secondary:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--text);
}

/* Ghost — for tertiary actions inside panels. */
.btn--ghost { color: var(--text-muted); }
.btn--ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }

/* Danger */
.btn--danger {
  border-color: rgba(244, 63, 94, 0.3);
  background: var(--danger-soft);
  color: var(--danger);
}
.btn--danger:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 10px 28px -12px rgba(244, 63, 94, 0.8);
}

.btn--sm { padding: 6px 11px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn--lg { padding: 13px 22px; font-size: var(--text-md); border-radius: var(--radius-md); }
.btn--block { width: 100%; }
.btn--icon { padding: 0; width: 38px; height: 38px; }

/* Ripple — spawned by ui.js, fades out and removes itself. */
.ripple {
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  transform: scale(0);
  animation: ripple 0.6s var(--ease) forwards;
  pointer-events: none;
}
@keyframes ripple {
  to { transform: scale(2.6); opacity: 0; }
}

/* Loading state — swaps the label for a spinner without resizing the button. */
.btn__spinner {
  display: none;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
.btn.is-loading { pointer-events: none; }
.btn.is-loading .btn__label,
.btn.is-loading .icon { opacity: 0.35; }
.btn.is-loading .btn__spinner { display: block; }

/* Icon-only control (header, toolbars). */
.icon-btn {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--glass);
  color: var(--text-muted);
  transition: background-color var(--t), border-color var(--t), color var(--t), transform var(--t-fast);
}
.icon-btn:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn__dot {
  position: absolute;
  top: 8px;
  right: 9px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--bg-sidebar), 0 0 10px var(--primary-glow);
}

/* ==========================================================================
   Badges & pills
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.5;
  white-space: nowrap;
}
.badge--brand { background: var(--primary-soft); color: #93b8ff; }
.badge--accent { background: var(--secondary-soft); color: #c4b1fd; }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--neutral {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
}
.badge--lg { padding: 5px 12px; font-size: var(--text-sm); }

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge__dot--live { animation: pulse 2s var(--ease) infinite; }
@keyframes pulse {
  50% { opacity: 0.35; transform: scale(0.8); }
}

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.field__label {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text-secondary);
  letter-spacing: -0.002em;
}
.field__hint { font-size: var(--text-sm); color: var(--text-subtle); }
.field__value {
  padding: 2px 9px;
  border-radius: var(--radius-pill);
  background: var(--primary-soft);
  color: #93b8ff;
  font-size: var(--text-xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.field-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-4);
}

.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
  color: var(--text);
  font-size: var(--text-base);
  transition: border-color var(--t), box-shadow var(--t), background-color var(--t);
}
.input::placeholder { color: var(--text-subtle); }
.input:hover:not(:focus) { border-color: var(--border-strong); }
.input:focus {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.04);
  box-shadow: var(--ring);
}
.input--area { resize: vertical; min-height: 100px; line-height: 1.65; }
.input--mono { font-family: var(--font-mono); font-size: var(--text-sm); }

/* Validation */
.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.35); }
.input.is-valid { border-color: var(--success); }
.field__error {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  color: var(--danger);
  animation: slide-up var(--t-fast) both;
}
.field__error .icon { width: 14px; height: 14px; }

.input-group { position: relative; display: flex; align-items: center; }
.input-group__affix {
  position: absolute;
  left: 13px;
  display: grid;
  place-items: center;
  color: var(--text-subtle);
  font-size: var(--text-sm);
  pointer-events: none;
  transition: color var(--t);
}
.input-group:focus-within .input-group__affix { color: var(--primary); }
.input-group__affix .icon { width: 16px; height: 16px; }
.input-group:has(.input-group__affix:not(.input-group__affix--end)) .input { padding-left: 40px; }
.input-group__affix--end {
  left: auto;
  right: 14px;
  font-weight: 550;
}
.input-group:has(.input-group__affix--end) .input { padding-right: 54px; }

.select { position: relative; }
.select .input { appearance: none; padding-right: 40px; cursor: pointer; }
.select option { background: var(--surface); color: var(--text); }
.select__chevron {
  position: absolute;
  top: 50%;
  right: 13px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-subtle);
  pointer-events: none;
}

/* Range */
.range {
  width: 100%;
  height: 5px;
  appearance: none;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}
.range::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--primary), 0 0 12px var(--primary-glow);
  transition: transform var(--t-fast);
}
.range::-webkit-slider-thumb:hover { transform: scale(1.2); }
.range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid var(--bg);
  cursor: pointer;
}

/* Switch */
.switch {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}
.switch__input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  position: relative;
  flex: none;
  width: 40px;
  height: 23px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.05);
  transition: background var(--t), border-color var(--t);
}
.switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-subtle);
  transition: transform var(--t), background-color var(--t);
}
.switch__input:checked + .switch__track {
  background: var(--gradient);
  border-color: transparent;
}
.switch__input:checked + .switch__track .switch__thumb {
  transform: translateX(17px);
  background: #fff;
}
.switch__input:focus-visible + .switch__track { box-shadow: var(--ring); }
.switch__label { font-size: var(--text-base); color: var(--text-muted); }
.switch:hover .switch__label { color: var(--text-secondary); }

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  font-size: var(--text-base);
  color: var(--text-secondary);
}
.alert .icon { margin-top: 1px; width: 17px; height: 17px; }
.alert__title { font-weight: 600; color: var(--text); }
.alert__text { color: var(--text-muted); font-size: var(--text-sm); }

.alert--info { border-color: rgba(79, 140, 255, 0.25); background: var(--primary-soft); }
.alert--info .icon { color: var(--primary); }
.alert--success { border-color: rgba(52, 211, 153, 0.25); background: var(--success-soft); }
.alert--success .icon { color: var(--success); }
.alert--warning { border-color: rgba(251, 191, 36, 0.25); background: var(--warning-soft); }
.alert--warning .icon { color: var(--warning); }
.alert--danger { border-color: rgba(244, 63, 94, 0.25); background: var(--danger-soft); }
.alert--danger .icon { color: var(--danger); }

/* ==========================================================================
   Table
   ========================================================================== */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--glass);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; max-height: 420px; overflow-y: auto; }

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-base);
}
.table th,
.table td {
  padding: 13px var(--space-5);
  text-align: left;
  white-space: nowrap;
}
.table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border);
  background: var(--glass-strong);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.table tbody tr { transition: background-color var(--t-fast); }
.table tbody tr:not(:last-child) td { border-bottom: 1px solid rgba(255, 255, 255, 0.04); }
.table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }

.table__tool {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 550;
}
.table__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}
.table__icon .icon { width: 16px; height: 16px; }
.table__muted { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.table__actions { text-align: right; }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
}
.tab {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 550;
  transition: background-color var(--t), color var(--t);
}
.tab:hover { color: var(--text-secondary); }
.tab.is-active {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}
.tabpanel { animation: fade-in var(--t) both; }

/* ==========================================================================
   Pagination
   ========================================================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.pagination__info { font-size: var(--text-sm); color: var(--text-muted); }
.pagination__pages { display: flex; align-items: center; gap: 4px; }
.page-btn {
  display: grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  transition: background-color var(--t), color var(--t), border-color var(--t);
}
.page-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.page-btn:disabled { opacity: 0.35; pointer-events: none; }
.page-btn.is-active {
  border-color: rgba(79, 140, 255, 0.35);
  background: var(--primary-soft);
  color: #93b8ff;
}
.page-btn .icon { width: 15px; height: 15px; }

/* ==========================================================================
   Dropdown
   ========================================================================== */
.dropdown { position: relative; }
.dropdown__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 90;
  min-width: 216px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--glass-strong);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow-lg);
  transform-origin: top right;
  animation: scale-in var(--t) both;
}
.dropdown__header {
  padding: 10px 12px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.dropdown__name { font-size: var(--text-base); font-weight: 600; }
.dropdown__mail { font-size: var(--text-sm); color: var(--text-muted); }
.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--text-base);
  text-align: left;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.dropdown__item .icon { width: 16px; height: 16px; color: var(--text-subtle); }
.dropdown__item:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.dropdown__item:hover .icon { color: var(--text-secondary); }
.dropdown__item--danger { color: var(--danger); }
.dropdown__item--danger .icon { color: var(--danger); }
.dropdown__item--danger:hover { background: var(--danger-soft); color: var(--danger); }
.dropdown__sep { height: 1px; margin: 6px 0; background: var(--border); }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: var(--space-5);
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(9, 9, 11, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fade-in var(--t) both;
}
.modal__dialog {
  position: relative;
  width: min(440px, 100%);
  padding: var(--space-6);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: linear-gradient(160deg, rgba(79, 140, 255, 0.09), transparent 55%), var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--t-slow) both;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.97); }
}
.modal__close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  color: var(--text-subtle);
  transition: background-color var(--t), color var(--t);
}
.modal__close:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.modal__icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--gradient-soft);
  color: var(--primary);
}
.modal__title { font-size: var(--text-lg); }
.modal__text {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: var(--text-base);
}
.modal__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: var(--space-5) 0;
}
.modal__list li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-base);
  color: var(--text-secondary);
}
.modal__list .icon { width: 16px; height: 16px; color: var(--success); }
.modal__actions { display: flex; gap: var(--space-3); }
.modal__actions .btn { flex: 1; }

/* ==========================================================================
   Toast
   ========================================================================== */
.toasts {
  position: fixed;
  right: var(--space-6);
  bottom: var(--space-6);
  z-index: 150;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: min(340px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 13px 15px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--glass-strong);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--t-slow) both;
}
.toast.is-leaving { animation: toast-out var(--t) forwards; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px) scale(0.96); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px) scale(0.96); }
}
.toast__icon { margin-top: 1px; width: 17px; height: 17px; }
.toast--success .toast__icon { color: var(--success); }
.toast--info .toast__icon { color: var(--primary); }
.toast--danger .toast__icon { color: var(--danger); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-size: var(--text-base); font-weight: 600; }
.toast__text { font-size: var(--text-sm); color: var(--text-muted); }
.toast__close {
  color: var(--text-subtle);
  transition: color var(--t);
}
.toast__close:hover { color: var(--text); }
.toast__close .icon { width: 15px; height: 15px; }

/* ==========================================================================
   Skeleton (loading state)
   ========================================================================== */
.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 25%,
    rgba(255, 255, 255, 0.09) 37%,
    rgba(255, 255, 255, 0.04) 63%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton__line { height: 12px; margin-bottom: 10px; }
.skeleton__line:nth-child(2n) { width: 82%; }
.skeleton__line:nth-child(3n) { width: 64%; }
.skeleton__block { height: 120px; border-radius: var(--radius-md); margin-bottom: 14px; }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 240px;
  padding: var(--space-8) var(--space-6);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.015);
  text-align: center;
}
.empty__icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-md);
  background: var(--gradient-soft);
  color: var(--primary);
}
.empty__title { font-size: var(--text-md); font-weight: 600; }
.empty__text {
  max-width: 34ch;
  color: var(--text-muted);
  font-size: var(--text-sm);
}
