/* ==========================================================================
   UNVRSL Design — UI Components v1
   Usage: <link rel="stylesheet" href="/design/ui/v1.css">
   Requires: design/standards/v1.css (design tokens)
   ========================================================================== */

/* ---------------------------------------------------------------------------
   1.  BUTTONS
   --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-m);
  font-size: var(--text-s);
  font-weight: var(--weight-medium);
  line-height: 1;
  border-radius: var(--radius-m);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.btn:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ---- Variants ---- */
.btn--primary {
  background: var(--brand);
  color: var(--text-on-brand);
  border-color: var(--brand);
}
.btn--primary:hover {
  background: var(--brand-strong);
  border-color: var(--brand-strong);
}

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

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

.btn--danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}
.btn--danger:hover {
  filter: brightness(0.85);
}

/* ---- Sizes ---- */
.btn--s  { padding: var(--space-xxs) var(--space-s); font-size: var(--text-xs); }
.btn--l  { padding: var(--space-s) var(--space-l); font-size: var(--text-m); }
.btn--xl { padding: var(--space-m) var(--space-xl); font-size: var(--text-l); }

/* ---- States ---- */
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: var(--opacity-muted);
  pointer-events: none;
}

/* ---------------------------------------------------------------------------
   2.  CARDS
   --------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-l);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--duration-fast) var(--ease-out);
}

.card--interactive:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.card__header {
  margin-bottom: var(--space-m);
}

.card__footer {
  margin-top: var(--space-m);
  padding-top: var(--space-m);
  border-top: 1px solid var(--border-faint);
}

/* ---------------------------------------------------------------------------
   3.  FORMS
   --------------------------------------------------------------------------- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-label {
  font-size: var(--text-s);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-s) var(--space-m);
  font-size: var(--text-m);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  transition:
    border-color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.form-input:hover,
.form-textarea:hover,
.form-select:hover {
  border-color: var(--border-strong);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-faint);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-faint);
}

.form-textarea {
  min-height: 6rem;
  resize: vertical;
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-s) center;
  padding-right: var(--space-xl);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
}

/* ---- Checkbox / Radio ---- */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-s);
  cursor: pointer;
}

.form-check input[type="checkbox"],
.form-check input[type="radio"] {
  width: 1.125rem;
  height: 1.125rem;
  accent-color: var(--brand);
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   4.  BADGES & TAGS
   --------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xxs);
  padding: 2px var(--space-s);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge--brand   { background: var(--brand-soft);  color: var(--brand-strong); }
.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--info    { background: var(--info-soft);    color: var(--info); }
.badge--neutral { background: var(--surface-2);    color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   5.  DIVIDER
   --------------------------------------------------------------------------- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-l) 0;
}

hr[data-spacing="s"]  { margin: var(--space-s) 0; }
hr[data-spacing="m"]  { margin: var(--space-m) 0; }
hr[data-spacing="xl"] { margin: var(--space-xl) 0; }

/* ---------------------------------------------------------------------------
   6.  KBD / CODE
   --------------------------------------------------------------------------- */
code {
  padding: 0.125rem 0.375rem;
  font-size: 0.875em;
  background: var(--surface-2);
  border: 1px solid var(--border-faint);
  border-radius: var(--radius-s);
}

pre {
  padding: var(--space-m);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  overflow-x: auto;
  font-size: var(--text-s);
  line-height: 1.6;
}

kbd {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  font-size: 0.75em;
  font-family: monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  box-shadow: 0 1px 0 var(--border);
}

/* ---------------------------------------------------------------------------
   7.  TABLE
   --------------------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-s);
}

.table th,
.table td {
  padding: var(--space-s) var(--space-m);
  text-align: left;
  border-bottom: 1px solid var(--border-faint);
}

.table th {
  font-weight: var(--weight-semibold);
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tr:hover td {
  background: var(--surface-2);
}

/* ---------------------------------------------------------------------------
   8.  PROGRESS / SPINNER
   --------------------------------------------------------------------------- */
.progress {
  width: 100%;
  height: 0.5rem;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  background: var(--brand);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--brand);
  border-radius: var(--radius-full);
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------------------------------------------------------------------------
   9.  MODAL / POPUP
   --------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-normal) var(--ease-out),
    visibility var(--duration-normal) var(--ease-out);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-l);
  position: relative;
  transform: scale(0.95) translateY(8px);
  transition: transform var(--duration-normal) var(--ease-out);
}

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

.modal__close {
  position: absolute;
  top: var(--space-m);
  right: var(--space-m);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  background: transparent;
  border: none;
  transition: background var(--duration-fast) var(--ease-out);
}

.modal__close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal__header {
  margin-bottom: var(--space-m);
}

.modal__title {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  color: var(--text);
  margin: 0;
  padding-right: var(--space-xl);
}

.modal__body {
  color: var(--text-muted);
  line-height: 1.6;
}

.modal__footer {
  margin-top: var(--space-l);
  padding-top: var(--space-m);
  border-top: 1px solid var(--border-faint);
  display: flex;
  gap: var(--space-s);
  justify-content: flex-end;
}

/* ---------------------------------------------------------------------------
   10.  TOAST NOTIFICATIONS (bottom-right)
   --------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  bottom: var(--space-l);
  right: var(--space-l);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-s);
  pointer-events: none;
  max-width: 380px;
  width: 100%;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-s);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-m);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  transform: translateX(120%);
  opacity: 0;
  transition:
    transform var(--duration-normal) var(--ease-out),
    opacity var(--duration-normal) var(--ease-out);
  overflow: hidden;
  position: relative;
}

.toast.active {
  transform: translateX(0);
  opacity: 1;
}

.toast.exiting {
  transform: translateX(120%);
  opacity: 0;
}

.toast__icon {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-s);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  background: var(--surface-2);
  color: var(--text-muted);
}

.toast__icon svg {
  width: 1.125rem;
  height: 1.125rem;
}

.toast__body {
  flex: 1;
  min-width: 0;
}

.toast__title {
  font-size: var(--text-s);
  font-weight: var(--weight-semibold);
  color: var(--text);
  margin: 0 0 var(--space-xxs) 0;
}

.toast__description {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin: 0;
  line-height: 1.4;
}

.toast__dismiss {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-faint);
  cursor: pointer;
  background: transparent;
  border: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.toast__dismiss:hover {
  color: var(--text-muted);
}

.toast__dismiss svg {
  width: 0.75rem;
  height: 0.75rem;
}

/* Toast type variants */
.toast--neutral .toast__icon {
  background: var(--surface-3);
  color: var(--text-muted);
}

.toast--success .toast__icon {
  background: var(--success-soft, color-mix(in oklch, var(--success, #22c55e), white 85%));
  color: var(--success, #22c55e);
}

.toast--warning .toast__icon {
  background: var(--warning-soft, color-mix(in oklch, var(--warning, #f59e0b), white 85%));
  color: var(--warning, #f59e0b);
}

.toast--error .toast__icon {
  background: var(--danger-soft, color-mix(in oklch, var(--danger, #ef4444), white 85%));
  color: var(--danger, #ef4444);
}

.toast--info .toast__icon {
  background: var(--info-soft, color-mix(in oklch, var(--info, #3b82f6), white 85%));
  color: var(--info, #3b82f6);
}

/* Toast progress bar */
.toast__progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  background: var(--brand);
  border-radius: 0 0 var(--radius-l) var(--radius-l);
  transition: width 0.1s linear;
}

.toast--success .toast__progress { background: var(--success, #22c55e); }
.toast--warning .toast__progress { background: var(--warning, #f59e0b); }
.toast--error .toast__progress   { background: var(--danger, #ef4444); }
.toast--info .toast__progress    { background: var(--info, #3b82f6); }
.toast--neutral .toast__progress { background: var(--text-muted); }

/* ---------------------------------------------------------------------------
   11.  TOP-MIDDLE ALERT NOTIFICATIONS
   --------------------------------------------------------------------------- */
.alert-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-notification);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-s);
  padding: var(--space-m);
  pointer-events: none;
}

.alert {
  display: flex;
  align-items: center;
  gap: var(--space-s);
  background: color-mix(in oklch, var(--surface), transparent 8%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  padding: var(--space-s) var(--space-m);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  max-width: 480px;
  width: 100%;
  transform: translateY(-120%);
  opacity: 0;
  transition:
    transform var(--duration-slow) var(--ease-out),
    opacity var(--duration-slow) var(--ease-out);
}

.alert.active {
  transform: translateY(0);
  opacity: 1;
}

.alert.exiting {
  transform: translateY(-120%);
  opacity: 0;
}

.alert__icon {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.alert__icon svg {
  width: 1rem;
  height: 1rem;
}

.alert__text {
  flex: 1;
  font-size: var(--text-s);
  color: var(--text);
  line-height: 1.4;
}

.alert__dismiss {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-faint);
  cursor: pointer;
  background: transparent;
  border: none;
  transition: color var(--duration-fast) var(--ease-out);
}

.alert__dismiss:hover {
  color: var(--text-muted);
}

.alert__dismiss svg {
  width: 0.75rem;
  height: 0.75rem;
}

/* Alert type variants */
.alert--neutral { border-left: 3px solid var(--text-muted); }
.alert--success { border-left: 3px solid var(--success, #22c55e); }
.alert--warning { border-left: 3px solid var(--warning, #f59e0b); }
.alert--error   { border-left: 3px solid var(--danger, #ef4444); }
.alert--info    { border-left: 3px solid var(--info, #3b82f6); }
