/* ============================================================
   COMPONENTS — button, input, card, modal, toast, badge, chip
   ============================================================ */

/* ── Buttons ───────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: var(--shadow-accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 24px rgba(99, 102, 241, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--glass-border);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #dc2626;
  transform: translateY(-1px);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

.btn-sm {
  padding: var(--s-1) var(--s-3);
  font-size: var(--fs-xs);
  border-radius: var(--r-sm);
}

.btn-lg {
  padding: var(--s-3) var(--s-6);
  font-size: var(--fs-md);
  border-radius: var(--r-lg);
}

.btn-icon {
  padding: var(--s-2);
  border-radius: var(--r-md);
  color: var(--text-secondary);
}
.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn-icon-round {
  padding: var(--s-2);
  border-radius: var(--r-full);
  color: var(--text-secondary);
}
.btn-icon-round:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Inputs ────────────────────────────────────────────────── */

.input {
  width: 100%;
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-base);
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}

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

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface-hover);
}

.input:invalid {
  border-color: var(--danger);
}

.input-sm {
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-sm);
  border-radius: var(--r-sm);
}

.input-lg {
  padding: var(--s-4) var(--s-5);
  font-size: var(--fs-lg);
  border-radius: var(--r-lg);
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-left: var(--s-9);
}

.input-group .input-icon {
  position: absolute;
  left: var(--s-3);
  color: var(--text-muted);
  pointer-events: none;
}

textarea.input {
  min-height: 100px;
  resize: vertical;
}

.input-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--s-2);
}

.input-hint {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--s-1);
}

.input-error {
  font-size: var(--fs-xs);
  color: var(--danger);
  margin-top: var(--s-1);
}

/* Select */
select.input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='rgba(255,255,255,0.5)' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  padding-right: var(--s-7);
}

/* Checkbox & Radio */
.checkbox, .radio {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}

.checkbox input[type="checkbox"],
.radio input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Toggle switch */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--s-3);
  cursor: pointer;
}

.toggle__track {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-full);
  transition: background var(--t-fast), border-color var(--t-fast);
  flex-shrink: 0;
}

.toggle__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: var(--r-full);
  background: var(--text-muted);
  transition: transform var(--t-fast), background var(--t-fast);
}

.toggle input:checked + .toggle__track {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked + .toggle__track::after {
  transform: translateX(20px);
  background: #fff;
}

.toggle input { display: none; }

/* ── Cards ─────────────────────────────────────────────────── */

.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--glass-shadow);
}

/* ── Modal ─────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--s-4);
  animation: fadeIn var(--t-fast) ease;
}

.modal-overlay.closing {
  animation: fadeIn var(--t-fast) ease reverse;
}

.modal {
  background: var(--glass-bg);
  backdrop-filter: blur(30px) saturate(200%);
  -webkit-backdrop-filter: blur(30px) saturate(200%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90dvh;
  overflow-y: auto;
  animation: scaleIn 300ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

.modal.closing {
  animation: scaleOut 200ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-5) var(--s-6);
  border-bottom: 1px solid var(--divider);
}

.modal-title {
  font-size: var(--fs-lg);
  font-weight: 600;
}

.modal-body {
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-6);
  border-top: 1px solid var(--divider);
}

/* ── Toast ─────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: var(--s-6);
  right: var(--s-6);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  min-width: 260px;
  max-width: 360px;
  pointer-events: all;
  animation: slideUp 300ms cubic-bezier(0.4, 0, 0.2, 1) both;
  font-size: var(--fs-sm);
}

.toast.exiting {
  animation: slideOutDown 250ms cubic-bezier(0.4, 0, 0.2, 1) both;
}

.toast__icon {
  font-size: 18px;
  flex-shrink: 0;
}

.toast__msg {
  flex: 1;
  font-weight: 500;
  color: var(--text-primary);
}

.toast__close {
  color: var(--text-muted);
  flex-shrink: 0;
  font-size: 18px;
  cursor: pointer;
  transition: color var(--t-fast);
}
.toast__close:hover { color: var(--text-primary); }

.toast--success { border-left: 3px solid var(--success); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--warning { border-left: 3px solid var(--warning); }
.toast--info    { border-left: 3px solid var(--info); }

/* ── Badge ─────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--s-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  border-radius: var(--r-full);
  background: var(--accent-light);
  color: var(--accent);
  line-height: 1.4;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger  { background: var(--danger-light);  color: var(--danger); }
.badge-info    { background: var(--info-light);     color: var(--info); }

.badge-count {
  min-width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xs);
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-full);
  padding: 0 var(--s-1);
}

/* ── Chip (tag) ─────────────────────────────────────────────── */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--s-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-full);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--t-fast);
  user-select: none;
}
.chip:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.chip.active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: var(--r-full);
  font-size: 10px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.chip__remove:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* ── Divider ────────────────────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--divider);
  border: none;
}

.divider-vertical {
  width: 1px;
  background: var(--divider);
  align-self: stretch;
}

/* ── Empty state ───────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-4);
  padding: var(--s-10) var(--s-5);
  text-align: center;
  color: var(--text-muted);
}

.empty-state__icon {
  font-size: 48px;
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--fs-lg);
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state__subtitle {
  font-size: var(--fs-sm);
  max-width: 280px;
  line-height: var(--lh-relaxed);
}

/* ── Dropdown ───────────────────────────────────────────────── */

.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 160px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xl);
  z-index: var(--z-dropdown);
  animation: slideDown 200ms cubic-bezier(0.4, 0, 0.2, 1) both;
  overflow: hidden;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.dropdown-item:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}
.dropdown-item.danger {
  color: var(--danger);
}
.dropdown-item.danger:hover {
  background: var(--danger-light);
}

.dropdown-separator {
  height: 1px;
  background: var(--divider);
  margin: var(--s-1) 0;
}

/* ── Progress bar ───────────────────────────────────────────── */

.progress {
  width: 100%;
  height: 4px;
  background: var(--surface);
  border-radius: var(--r-full);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  background: var(--accent);
  border-radius: var(--r-full);
  transition: width var(--t-med);
}

/* ── Loading spinner ────────────────────────────────────────── */

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--divider);
  border-top-color: var(--accent);
  border-radius: var(--r-full);
  animation: spin 0.8s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

/* ── Tabs ───────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: var(--s-1);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 3px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-4);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--t-fast);
  border: none;
  background: none;
}

.tab:hover {
  color: var(--text-secondary);
  background: var(--surface-hover);
}

.tab.active {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ── Section title ──────────────────────────────────────────── */

.section-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: var(--s-2) var(--s-3);
}
