/* ============================================================
   COMPONENTS.CSS — Shared UI Components
   ============================================================ */

/* --- Site Header (shared across all pages) --- */
.site-header {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
}

.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.wordmark {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  text-decoration: none;
}
.wordmark:hover { text-decoration: none; }
.wordmark__dot { color: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: 28px;
}
.site-nav__link {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink-muted);
  text-decoration: none;
  padding: 6px 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.site-nav__link:hover { color: var(--ink); text-decoration: none; }
.site-nav__link.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-toggle { display: none; }

@media (max-width: 640px) {
  .site-nav { display: none; }
  .site-nav.is-open {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 20px;
    position: absolute;
    top: 100%;
    left: 16px;
    right: 16px;
    background: var(--card, var(--color-card));
    border: 1px solid var(--border, var(--color-border));
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
  }
  .nav-toggle {
    display: inline-flex;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    color: var(--ink-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-md);
  }
  .nav-toggle:hover { background: var(--surface-2, var(--color-surface)); color: var(--ink); }
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 10px;
  font-size: var(--text-sm);
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
  white-space: nowrap;
  user-select: none;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2;
  fill: none;
}

/* Loading state for async buttons */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btnSpin 0.6s linear infinite;
}
@keyframes btnSpin {
  to { transform: rotate(360deg); }
}

.btn--primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(80, 70, 229, 0.25);
}
.btn--primary:hover {
  background: var(--color-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(80, 70, 229, 0.3);
}
.btn--primary:active { transform: translateY(0); }

.btn--outline {
  background: var(--color-card);
  color: var(--color-text);
  border: 1.5px solid var(--color-border);
}
.btn--outline:hover {
  background: var(--color-bg-alt);
  border-color: #d1d5db;
  transform: translateY(-1px);
}
.btn--outline:active { transform: translateY(0); }

.btn--ghost {
  background: none;
  border: none;
  color: var(--color-text-soft);
  padding: 0.4rem 0.6rem;
}
.btn--ghost:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.btn--danger {
  background: var(--color-error);
  color: #fff;
}
.btn--danger:hover {
  background: #dc2626;
}

.btn--sm {
  padding: 0.35rem 0.6rem;
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
}

.btn--icon {
  padding: 0.4rem;
  border-radius: var(--radius-md);
}

/* --- Cards --- */
.card {
  background: var(--color-card);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}

.card__title {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-soft);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.card__title svg {
  width: 14px;
  height: 14px;
  stroke: var(--color-text-soft);
  stroke-width: 2;
  fill: none;
}

/* --- Modals --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-default);
}
.modal-overlay.is-open {
  display: flex;
  opacity: 1;
  animation: fadeIn var(--duration-normal) var(--ease-default);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal {
  background: var(--color-card);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  width: 90%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: modalSlideIn var(--duration-normal) var(--ease-default);
}

.modal__title {
  font-size: var(--text-base);
  font-weight: 700;
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal__close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-soft);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  font-size: 1.2rem;
  line-height: 1;
}
.modal__close:hover { background: var(--color-surface); }

/* --- Toasts --- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-card);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--color-border);
  font-size: var(--text-sm);
  pointer-events: auto;
  transform: translateX(120%);
  transition: transform var(--duration-normal) var(--ease-default);
  max-width: 360px;
  position: relative;
  overflow: hidden;
}
.toast.is-visible { transform: translateX(0); }
.toast.is-leaving {
  animation: toastSlideOut var(--duration-normal) var(--ease-default) forwards;
}

@keyframes toastSlideOut {
  to { transform: translateX(120%); opacity: 0; }
}

/* Auto-dismiss progress bar */
.toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-md) 0;
  animation: toastProgress linear forwards;
}
.toast--success .toast__progress { background: var(--color-success); }
.toast--error .toast__progress { background: var(--color-error); }
.toast--warning .toast__progress { background: var(--color-warning); }
.toast--info .toast__progress { background: var(--color-info); }

@keyframes toastProgress {
  from { width: 100%; }
  to { width: 0%; }
}

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

.toast__icon { font-size: 1rem; line-height: 1; }
.toast--success .toast__icon { color: var(--color-success); }
.toast--error   .toast__icon { color: var(--color-error); }
.toast--warning .toast__icon { color: var(--color-warning); }
.toast--info    .toast__icon { color: var(--color-info); }

.toast__close {
  background: none;
  border: none;
  color: var(--color-text-soft);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 var(--space-1);
  margin-left: auto;
  line-height: 1;
}

/* --- Form Elements --- */
textarea,
input[type="text"],
input[type="email"],
input[type="search"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
textarea::placeholder,
input::placeholder { color: var(--color-text-muted); }
textarea:focus,
input[type="text"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(80, 70, 229, 0.1);
  background: var(--color-card);
}

textarea { resize: none; height: 100px; }

select {
  padding: 0.45rem 0.5rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  background: var(--color-card);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(80, 70, 229, 0.1);
}

/* Number inputs */
input[type="number"] {
  padding: 0.45rem 0.5rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}
input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(80, 70, 229, 0.1);
  background: var(--color-card);
}

/* --- Range Slider --- */
input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--color-border);
  border-radius: 4px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: var(--color-accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(80, 70, 229, 0.3);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--color-accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* --- Color Picker --- */
.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  flex-shrink: 0;
}
.color-swatch input[type="color"] {
  position: absolute;
  width: 150%;
  height: 150%;
  top: -25%;
  left: -25%;
  border: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}
.color-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch input[type="color"]::-webkit-color-swatch { border: none; }

/* --- Chips / Pills --- */
.chip {
  padding: 0.3rem 0.6rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.82rem;
  transition: all var(--duration-fast);
  white-space: nowrap;
  font-family: inherit;
}
.chip:hover {
  border-color: var(--color-border-focus);
  background: var(--color-accent-light);
}
.chip.is-active {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
}

.toggle-pill {
  padding: 0.3rem 0.65rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--color-text-soft);
  transition: all var(--duration-fast);
}
.toggle-pill:hover {
  border-color: var(--color-border-focus);
  background: var(--color-accent-light);
}
.toggle-pill.is-active {
  border-color: var(--color-accent);
  background: var(--color-accent-light);
  color: var(--color-accent);
}

/* --- Theme Toggle --- */
.theme-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--color-text-soft);
  transition: all var(--duration-fast);
}
.theme-toggle:hover {
  background: var(--color-surface);
  border-color: var(--color-accent);
  color: var(--color-accent);
}
.theme-toggle svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  fill: none;
}

/* Light mode: show moon icon (click to go dark) */
.theme-toggle__sun { display: none; }
.theme-toggle__moon { display: block; }

/* Dark mode: show sun icon (click to go light) */
[data-theme="dark"] .theme-toggle__sun { display: block; }
[data-theme="dark"] .theme-toggle__moon { display: none; }
