/* NovelHive shared component layer — one button, one card, one modal.
 * ─────────────────────────────────────────────────────────────────────────
 * Canonical implementations that replace 5 divergent "primary teal" button
 * systems, 6+ copies of the same card surface, and 10 bespoke modals. See
 * /styleguide for a live reference.
 *
 * HAND-WRITTEN, served as-is — deliberately NOT part of the Tailwind build.
 * Once tailwind.css's @source scan emits transform/gradient utilities, the v4
 * pipeline injects its @property registrations into the stream and drops any
 * authored CSS that follows. Keeping components in their own sheet is immune to
 * that, is never purged, and wins the cascade over utilities (intended — a
 * .btn-primary shouldn't be overridable by a stray bg-* utility).
 *
 * Loaded AFTER tailwind.css (see _head_styles.html): it consumes the --color-*
 * tokens tailwind.css emits to :root from @theme, and owns its own radius /
 * elevation / stacking scales below (Tailwind manages the radius and z-index
 * namespaces, so those aren't reliably emitted from @theme). Cache-busted via
 * COMPONENTS_VERSION (web/main.py).
 * ───────────────────────────────────────────────────────────────────────── */

:root {
  --radius-control: 10px;   /* buttons, inputs, chips */
  --radius-surface: 14px;   /* cards, panels */
  --radius-overlay: 16px;   /* modals */
  --radius-pill: 9999px;

  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-raised: 0 10px 28px rgba(0, 0, 0, 0.45);
  --shadow-overlay: 0 25px 60px rgba(0, 0, 0, 0.55);

  --z-dropdown: 40;
  --z-overlay: 50;
  --z-modal: 60;
  --z-toast: 70;
}

/* ── Button ─────────────────────────────────────────────────────────────────
   .btn base + variant (primary/secondary/ghost/danger) + optional size
   (sm/lg/icon/block) + optional .btn-hero gradient + .is-loading spinner. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9375rem;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  padding: 0.625rem 1.1rem;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}
.btn:focus-visible {
  outline: 2px solid var(--color-ring);
  outline-offset: 2px;
}
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
.btn:active:not(:disabled) {
  transform: translateY(0.5px);
}
.btn svg {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-bg-muted);
  color: var(--color-text-heading);
}
.btn-secondary:hover:not(:disabled) {
  background: #3f3f46; /* zinc-700 */
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-body);
  border-color: var(--color-border-default);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(245, 245, 244, 0.05);
  border-color: var(--color-border-emphasis);
  color: var(--color-text-heading);
}

.btn-danger {
  background: var(--color-danger-strong);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #B91C1C; /* red-700 */
}

/* Sizes / shape modifiers */
.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
}
.btn-lg {
  padding: 0.8rem 1.4rem;
  font-size: 1rem;
}
.btn-icon {
  padding: 0.55rem;
  aspect-ratio: 1 / 1;
}
.btn-block {
  display: flex;
  width: 100%;
}

/* Hero gradient — folds the landing .cta-button into the one system. */
.btn-hero {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  border-radius: var(--radius-pill);
  box-shadow: 0 8px 24px rgba(13, 148, 136, 0.2);
}
.btn-hero:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 12px 30px rgba(13, 148, 136, 0.28);
}

/* Loading — a centered spinner; label is hidden while active. */
.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 1.05em;
  height: 1.05em;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: nh-btn-spin 0.6s linear infinite;
}
@keyframes nh-btn-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Card ───────────────────────────────────────────────────────────────────
   One surface. Replaces .card (payments), .settings-section, .profile-section,
   .generation-card — all the same "subtle fill + hairline + radius" idea. */
.card {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-surface);
}
.card--hover {
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.card--hover:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-raised);
}
.card-body {
  padding: 1.25rem;
}

/* ── Modal ──────────────────────────────────────────────────────────────────
   Native <dialog>. The element itself is a transparent, centered positioning
   container; .modal-panel is the visible card. Opened with .showModal() (see
   web/static/js/modal.js) which gives focus-trap, Esc, background inert, and
   focus-return for free. ::backdrop replaces the old bg-black/50 overlay. */
.modal {
  margin: auto; /* center in the top layer */
  width: calc(100% - 2rem);
  max-width: 28rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--color-text-body);
  overflow: visible;
}
.modal::backdrop {
  background: rgba(9, 9, 11, 0.62);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.modal-lg {
  max-width: 34rem;
}
.modal-panel {
  position: relative;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-overlay);
  box-shadow: var(--shadow-overlay);
  padding: 2rem;
  /* Scroll a tall panel internally: the page is scroll-locked while a modal is
     open, and the UA clamps the dialog to the viewport, so without this a modal
     taller than the viewport (e.g. signup at 200% zoom) would be unreachable. */
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}
/* Scroll-lock — the "one line". Only engages while a modal <dialog> is open. */
html:has(dialog.modal[open]) {
  overflow: hidden;
}
/* Subtle entrance for the panel + backdrop. */
.modal[open] .modal-panel {
  animation: nh-modal-in 0.18s ease-out;
}
.modal[open]::backdrop {
  animation: nh-modal-backdrop-in 0.18s ease-out;
}
@keyframes nh-modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
@keyframes nh-modal-backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Reduced-motion: keep the components, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  .btn,
  .card--hover {
    transition: none;
  }
  .btn-hero:hover:not(:disabled) {
    transform: none;
  }
  .btn.is-loading::after {
    animation-duration: 1.2s;
  }
  .modal[open] .modal-panel {
    animation: none;
  }
}
