/* ============================================
   Components — buttons, inputs, badges, etc.
   ============================================ */

/* — Buttons — */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--r-3);
  font-size: var(--t-body);
  font-weight: 500;
  letter-spacing: -0.005em;
  transition: all var(--dur-2) var(--ease-out);
  position: relative;
  white-space: nowrap;
  user-select: none;
  border: 1px solid transparent;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; flex-shrink: 0; }

/* Primary — violet with glow */
.btn-primary {
  background: linear-gradient(180deg, #8b6cff 0%, #6a48f0 100%);
  color: #fff;
  border-color: rgba(255,255,255,0.12);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.25) inset,
    0 -1px 0 rgba(0,0,0,0.20) inset,
    0 4px 16px rgba(124,92,255,0.35),
    0 0 0 1px rgba(124,92,255,0.4);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #9a7dff 0%, #7c5cff 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,0.28) inset,
    0 -1px 0 rgba(0,0,0,0.20) inset,
    0 8px 24px rgba(124,92,255,0.5),
    0 0 0 1px rgba(124,92,255,0.6);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

/* Secondary — hairline */
.btn-secondary {
  background: var(--bg-3);
  color: var(--text-1);
  border-color: var(--line-2);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-4);
  border-color: var(--line-3);
}

/* Ghost — text only */
.btn-ghost {
  background: transparent;
  color: var(--text-2);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,0.04);
  color: var(--text-1);
}

/* Danger */
.btn-danger {
  background: linear-gradient(180deg, rgba(248,113,113,0.16), rgba(248,113,113,0.08));
  color: #fca5a5;
  border-color: rgba(248,113,113,0.3);
}
.btn-danger:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(248,113,113,0.24), rgba(248,113,113,0.12));
  border-color: rgba(248,113,113,0.5);
  color: #fecaca;
  box-shadow: 0 0 0 1px rgba(248,113,113,0.4), 0 4px 16px rgba(248,113,113,0.2);
}

/* Sizes */
.btn-sm { height: 28px; padding: 0 10px; font-size: var(--t-small); border-radius: var(--r-2); }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; border-radius: var(--r-4); }
.btn-icon { padding: 0; width: 32px; }
.btn-icon.btn-sm { width: 28px; }

/* — Inputs — */
.input,
.textarea,
.select {
  display: block;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: var(--bg-2);
  color: var(--text-1);
  border: 1px solid var(--line-1);
  border-radius: var(--r-3);
  font-size: var(--t-body);
  transition: all var(--dur-2) var(--ease-out);
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset;
}
.input::placeholder, .textarea::placeholder { color: var(--text-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-2); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: rgba(124,92,255,0.6);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.15), 0 1px 0 rgba(255,255,255,0.02) inset;
}
.textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M3 4.5L6 7.5L9 4.5' stroke='%238a8a9a' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }

.input-group { position: relative; }
.input-group .input { padding-left: 36px; }
.input-group .input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-4); pointer-events: none; width: 14px; height: 14px; }

.field-label {
  display: block;
  font-size: var(--t-small);
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
  letter-spacing: 0;
}
.field-label .req { color: var(--violet-300); margin-left: 2px; }
.field-help { font-size: var(--t-tiny); color: var(--text-4); margin-top: 6px; }

/* — Checkbox — */
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: var(--t-body);
  color: var(--text-2);
}
.checkbox input { display: none; }
.checkbox .box {
  width: 16px;
  height: 16px;
  border-radius: var(--r-1);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  display: grid;
  place-items: center;
  transition: all var(--dur-2) var(--ease-out);
  flex-shrink: 0;
}
.checkbox .box svg { width: 10px; height: 10px; opacity: 0; transform: scale(0.5); transition: all var(--dur-2) var(--ease-spring); color: #fff; }
.checkbox input:checked + .box {
  background: linear-gradient(180deg, #8b6cff, #6a48f0);
  border-color: rgba(124,92,255,0.6);
  box-shadow: 0 0 0 3px rgba(124,92,255,0.15);
}
.checkbox input:checked + .box svg { opacity: 1; transform: scale(1); }
.checkbox:hover .box { border-color: var(--line-3); }

/* — Badges / Status pills — */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--r-full);
  font-size: var(--t-tiny);
  font-weight: 500;
  letter-spacing: 0.01em;
  border: 1px solid var(--line-1);
  background: var(--bg-3);
  color: var(--text-2);
  height: 22px;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge .dot { width: 6px; height: 6px; border-radius: 99px; background: currentColor; box-shadow: 0 0 8px currentColor; }

.badge-violet { color: var(--violet-300); background: rgba(124,92,255,0.10); border-color: rgba(124,92,255,0.25); }
.badge-success { color: var(--success); background: var(--success-soft); border-color: rgba(52,211,153,0.25); }
.badge-warning { color: var(--warning); background: var(--warning-soft); border-color: rgba(251,191,36,0.25); }
.badge-danger { color: var(--danger); background: var(--danger-soft); border-color: rgba(248,113,113,0.25); }
.badge-info { color: var(--info); background: var(--info-soft); border-color: rgba(96,165,250,0.25); }
.badge-neutral { color: var(--text-3); background: var(--bg-3); border-color: var(--line-1); }

.badge .dot.pulse { animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 0 currentColor, 0 0 8px currentColor; }
  50% { box-shadow: 0 0 0 4px transparent, 0 0 12px currentColor; }
}

/* — Card — */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--r-5);
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 1px 2px rgba(0,0,0,0.3);
  position: relative;
}
.card-elevated {
  background: linear-gradient(180deg, var(--bg-3) 0%, var(--bg-2) 100%);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 8px 32px rgba(0,0,0,0.4);
}

/* — Progress bar — */
.progress {
  position: relative;
  height: 6px;
  background: rgba(255,255,255,0.05);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--line-1);
}
.progress-bar {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #6a48f0, #a78bfa, #6a48f0);
  background-size: 200% 100%;
  box-shadow: 0 0 12px rgba(124,92,255,0.6);
  transition: width var(--dur-4) var(--ease-out);
  animation: progress-flow 2.4s linear infinite;
  position: relative;
}
@keyframes progress-flow {
  0% { background-position: 0% 0; }
  100% { background-position: -200% 0; }
}
.progress-bar.success { background: linear-gradient(90deg, #34d399, #6ee7b7, #34d399); background-size: 200% 100%; box-shadow: 0 0 12px rgba(52,211,153,0.5); }
.progress-bar.danger { background: #f87171; box-shadow: 0 0 12px rgba(248,113,113,0.5); animation: none; }
.progress-bar.paused { animation: none; opacity: 0.6; }

.progress-lg { height: 8px; }

/* — Toast — */
.toast {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-radius: var(--r-4);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.05) inset;
  min-width: 320px;
  max-width: 420px;
}
.toast .icon-wrap {
  width: 28px; height: 28px; border-radius: var(--r-2);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.toast.toast-success .icon-wrap { background: var(--success-soft); color: var(--success); border: 1px solid rgba(52,211,153,0.3); }
.toast.toast-info .icon-wrap { background: var(--info-soft); color: var(--info); border: 1px solid rgba(96,165,250,0.3); }
.toast.toast-warning .icon-wrap { background: var(--warning-soft); color: var(--warning); border: 1px solid rgba(251,191,36,0.3); }
.toast.toast-error .icon-wrap { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(248,113,113,0.3); }

/* — Modal — */
.modal-backdrop {
  position: fixed; inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  display: grid; place-items: center;
  z-index: 100;
  animation: enter-fade 200ms var(--ease-out);
}
.modal {
  width: min(560px, 92vw);
  max-height: 88vh;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-6);
  box-shadow: 0 24px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(124,92,255,0.15), 0 1px 0 rgba(255,255,255,0.05) inset;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modal-in 320ms var(--ease-out);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); filter: blur(8px); }
  to { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
}
.modal-head { padding: 20px 24px; border-bottom: 1px solid var(--line-1); }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line-1); display: flex; justify-content: flex-end; gap: 8px; background: var(--bg-1); }

/* — Skeleton — */
.skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  border-radius: var(--r-3);
  animation: skeleton-flow 1.6s ease-in-out infinite;
}
@keyframes skeleton-flow {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* — Divider — */
.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--line-1) 20%, var(--line-1) 80%, transparent);
}

/* — Kbd — */
.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-3);
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  border-bottom-width: 2px;
  border-radius: var(--r-1);
}

/* — Segmented control — */
.segmented {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--line-1);
  border-radius: var(--r-3);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  padding: 5px 10px;
  border-radius: var(--r-2);
  font-size: var(--t-small);
  color: var(--text-3);
  transition: all var(--dur-2) var(--ease-out);
  white-space: nowrap;
  flex-shrink: 0;
}
.segmented button:hover { color: var(--text-2); }
.segmented button.active {
  background: var(--bg-4);
  color: var(--text-1);
  box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
}
