/**
 * components.css — the shared UI kit. Anything used by more than one
 * module (or by the shell) lives here so modules stay tiny.
 */

/* ---------------------------- Buttons ---------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: transform var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out),
              border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { box-shadow: var(--shadow-md); }

.btn-secondary {
  background: var(--color-bg-elevated);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-hover); }

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

.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-muted);
}
.btn-icon:hover { background: var(--color-surface-hover); color: var(--color-text); }
.btn-icon.is-active { background: var(--color-surface-active); color: var(--color-primary); }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--fs-xs); }

/* ---------------------------- Inputs ---------------------------- */

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); }
.field label {
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--color-text-muted);
}
.field .field-hint { font-size: var(--fs-2xs); color: var(--color-text-faint); }

.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: var(--fs-base);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}
.textarea { resize: vertical; min-height: 96px; font-family: var(--font-body); }

.search-input {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-surface-hover);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-muted);
}
.search-input input {
  border: none; background: transparent; flex: 1; color: var(--color-text); font-size: var(--fs-sm);
}
.search-input input:focus { outline: none; box-shadow: none; }
.search-input svg { width: 16px; height: 16px; flex-shrink: 0; }
.search-input kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ---------------------------- Cards ---------------------------- */

.card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: transform var(--duration-base) var(--ease-out),
              box-shadow var(--duration-base) var(--ease-out),
              border-color var(--duration-base) var(--ease-out);
}
.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--color-border-strong);
}
.tool-card__icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(79,70,229,0.12), rgba(124,58,237,0.12));
  color: var(--color-primary);
}
.tool-card__icon svg { width: 20px; height: 20px; }
.tool-card__title { font-weight: 650; font-size: var(--fs-base); }
.tool-card__desc { font-size: var(--fs-xs); color: var(--color-text-muted); line-height: var(--lh-relaxed); }
.tool-card__meta { display: flex; align-items: center; justify-content: space-between; margin-top: auto; }
.tool-card__fav {
  background: none; border: none; color: var(--color-text-faint); padding: var(--space-1);
}
.tool-card__fav.is-favorite { color: var(--brand-amber-500); }

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: var(--space-4);
}

/* ---------------------------- Chips / badges ---------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--fs-2xs);
  font-weight: 650;
  background: var(--color-surface-hover);
  color: var(--color-text-muted);
}
.chip-brand { background: linear-gradient(135deg, rgba(79,70,229,0.14), rgba(124,58,237,0.14)); color: var(--color-primary); }

/* ---------------------------- Skeletons ---------------------------- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--color-surface-hover);
  border-radius: var(--radius-sm);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: shimmer 1.4s infinite;
}
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
}

/* ---------------------------- Toasts ---------------------------- */

#toast-region {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm);
  min-width: 260px;
  max-width: 360px;
}
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-warning { border-left-color: var(--color-warning); }
.toast.toast-danger { border-left-color: var(--color-danger); }
.toast svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------------------------- Modal ---------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 10, 18, 0.5);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: flex-start center;
  padding-top: 10vh;
  z-index: var(--z-modal);
}
/* Our own display:grid above has the same specificity as the browser's
   built-in [hidden] { display: none } rule and loads later, so it would
   otherwise always win — meaning `element.hidden = true` silently does
   nothing and the modal can never actually be closed. Force it explicitly. */
.modal-backdrop[hidden] {
  display: none !important;
}
.modal {
  width: min(560px, 92vw);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.modal-body { padding: var(--space-5); max-height: 60vh; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
}

/* ---------------------------- Command Palette (search) ---------------------------- */

.palette-result {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
}
.palette-result:hover, .palette-result.is-selected { background: var(--color-surface-hover); }
.palette-result__icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(79,70,229,0.12), rgba(124,58,237,0.12));
  color: var(--color-primary);
  flex-shrink: 0;
}
.palette-result__icon svg { width: 16px; height: 16px; }
.palette-result__title { font-weight: 600; font-size: var(--fs-sm); }
.palette-result__cat { font-size: var(--fs-2xs); color: var(--color-text-faint); }

/* ---------------------------- Empty state ---------------------------- */

.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-5);
  color: var(--color-text-muted);
}
.empty-state svg { width: 40px; height: 40px; margin: 0 auto var(--space-3); opacity: 0.5; }

/* ---------------------------- Dynamic form extras ---------------------------- */

.dynamic-form .field.has-error .input,
.dynamic-form .field.has-error .textarea,
.dynamic-form .field.has-error .select {
  border-color: var(--color-danger);
}
.field-error {
  display: block;
  font-size: var(--fs-2xs);
  color: var(--color-danger);
  min-height: 14px;
}

.radio-group, .checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}
.radio-option, .checkbox-option, .toggle-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-sm);
  color: var(--color-text);
  cursor: pointer;
}
.radio-option input, .checkbox-option input { accent-color: var(--color-primary); width: 16px; height: 16px; }

.toggle-option input[type="checkbox"] {
  appearance: none;
  width: 38px; height: 22px;
  border-radius: var(--radius-full);
  background: var(--color-surface-active);
  position: relative;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out);
  flex-shrink: 0;
}
.toggle-option input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration-fast) var(--ease-out);
}
.toggle-option input[type="checkbox"]:checked { background: var(--brand-gradient); }
.toggle-option input[type="checkbox"]:checked::before { transform: translateX(16px); }

.range { width: 100%; accent-color: var(--color-primary); }
.range-output {
  display: inline-block;
  margin-top: var(--space-1);
  font-size: var(--fs-xs);
  font-weight: 650;
  color: var(--color-primary);
  font-family: var(--font-mono);
}

/* ---------------------------- Tabs ---------------------------- */

.tabs__strip {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.tabs__tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: var(--space-2) var(--space-3) var(--space-3);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  transform: translateY(1px);
}
.tabs__tab:hover { color: var(--color-text); }
.tabs__tab.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

/* ---------------------------- Progress ring ---------------------------- */

.progress-ring { display: inline-flex; flex-direction: column; align-items: center; gap: var(--space-2); position: relative; }
.progress-ring__track { stroke: var(--color-border); }
.progress-ring__value { stroke: var(--color-primary); stroke-linecap: round; transition: stroke-dashoffset var(--duration-slow) var(--ease-out); }
.progress-ring__label { font-size: var(--fs-sm); font-weight: 650; color: var(--color-text); text-align: center; }

/* ---------------------------- Drag list ---------------------------- */

.drag-list { display: flex; flex-direction: column; gap: var(--space-2); }
.drag-list > * { cursor: grab; }
.drag-list__ghost { opacity: 0.4; }
.drag-list__chosen { box-shadow: var(--shadow-md); }
.drag-list__dragging { cursor: grabbing; }
.drag-handle { color: var(--color-text-faint); cursor: grab; padding: 0 var(--space-1); }

/* ---------------------------- Action bar ---------------------------- */

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

/* ---------------------------- Output card (generator result) ---------------------------- */

.output-card__title { margin-bottom: var(--space-3); }
.output-card__body { font-size: var(--fs-base); line-height: var(--lh-relaxed); }
.output-card__body h1, .output-card__body h2, .output-card__body h3 { margin-top: var(--space-4); }
.output-card__body ul, .output-card__body ol { margin: 0 0 var(--space-3) var(--space-5); list-style: revert; }
.output-card__body p { margin: 0 0 var(--space-3); }
.output-card__body code { font-family: var(--font-mono); background: var(--color-surface-hover); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.output-card__body pre { background: var(--color-bg-sunken); padding: var(--space-3); border-radius: var(--radius-sm); overflow-x: auto; }

