/*
 * AH Digital — Core Components
 *
 * Reusable UI primitives only.
 * Page-specific composition belongs in templates/section styles later.
 */

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

.ah-button {
  --ah-button-bg: var(--ah-color-brand);
  --ah-button-bg-hover: var(--ah-color-brand-hover);
  --ah-button-bg-active: var(--ah-color-brand-active);
  --ah-button-text: var(--ah-color-text-inverse);
  --ah-button-border: transparent;

  position: relative;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  gap: var(--ah-space-3);
  overflow: hidden;
  border: 1px solid var(--ah-button-border);
  border-radius: var(--ah-radius-md);
  background: var(--ah-button-bg);
  color: var(--ah-button-text);
  font-weight: 650;
  line-height: 1;
  padding: 0.9rem 1.2rem;
  text-align: center;
  text-decoration: none;
  transition:
    transform var(--ah-duration-fast) var(--ah-ease-standard),
    background-color var(--ah-duration-base) var(--ah-ease-standard),
    border-color var(--ah-duration-base) var(--ah-ease-standard),
    color var(--ah-duration-base) var(--ah-ease-standard),
    box-shadow var(--ah-duration-base) var(--ah-ease-standard);
}

.ah-button:hover {
  background: var(--ah-button-bg-hover);
  color: var(--ah-button-text);
  transform: translateY(-1px);
}

.ah-button:active {
  background: var(--ah-button-bg-active);
  transform: translateY(0);
}

.ah-button:focus-visible {
  outline-offset: 4px;
}

.ah-button[aria-disabled="true"],
.ah-button:disabled {
  opacity: 0.55;
  pointer-events: none;
}

.ah-button__label,
.ah-button__icon {
  position: relative;
  z-index: 1;
}

.ah-button__icon {
  display: inline-flex;
  flex: 0 0 auto;
  transition: transform var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-button:hover .ah-button__icon {
  transform: translateX(3px);
}

.ah-button--secondary {
  --ah-button-bg: var(--ah-color-surface);
  --ah-button-bg-hover: var(--ah-color-surface-soft);
  --ah-button-bg-active: var(--ah-color-surface-soft);
  --ah-button-text: var(--ah-color-text);
  --ah-button-border: var(--ah-color-border);
}

.ah-button--ghost {
  --ah-button-bg: transparent;
  --ah-button-bg-hover: var(--ah-color-surface-soft);
  --ah-button-bg-active: var(--ah-color-surface-soft);
  --ah-button-text: var(--ah-color-text);
  --ah-button-border: transparent;
}

.ah-button--dark {
  --ah-button-bg: var(--ah-color-dark-surface);
  --ah-button-bg-hover: #182139;
  --ah-button-bg-active: #202B47;
  --ah-button-text: #F8FAFC;
  --ah-button-border: var(--ah-color-dark-border);
}

.ah-button--sm {
  min-height: 40px;
  border-radius: var(--ah-radius-sm);
  font-size: var(--ah-font-size-sm);
  padding: 0.72rem 1rem;
}

.ah-button--lg {
  min-height: 54px;
  padding: 1rem 1.35rem;
}

/* Signal Sweep: high-value primary CTAs only. */

.ah-button--signal::after {
  position: absolute;
  inset: -40% auto -40% -45%;
  width: 34%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.38),
    transparent
  );
  content: "";
  pointer-events: none;
  transform: skewX(-18deg);
  transition: left var(--ah-duration-medium) var(--ah-ease-emphasis);
}

.ah-button--signal:hover::after,
.ah-button--signal:focus-visible::after {
  left: 115%;
}

/* -------------------------------------------------------------------------- */
/* Text links                                                                 */
/* -------------------------------------------------------------------------- */

.ah-link {
  display: inline-flex;
  align-items: center;
  gap: var(--ah-space-2);
  color: var(--ah-color-text);
  font-weight: 650;
  text-decoration: none;
}

.ah-link__icon {
  transition: transform var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-link:hover {
  color: var(--ah-color-brand);
}

.ah-link:hover .ah-link__icon,
.ah-link:focus-visible .ah-link__icon {
  transform: translateX(3px);
}

/* -------------------------------------------------------------------------- */
/* Badges / labels                                                            */
/* -------------------------------------------------------------------------- */

.ah-badge {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  gap: var(--ah-space-2);
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-pill);
  background: var(--ah-color-surface);
  color: var(--ah-color-text-secondary);
  font-family: var(--ah-font-mono);
  font-size: var(--ah-font-size-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 0.48rem 0.7rem;
  text-transform: uppercase;
}

.ah-badge--brand {
  border-color: color-mix(in srgb, var(--ah-color-brand) 28%, var(--ah-color-border));
  background: color-mix(in srgb, var(--ah-color-brand) 8%, var(--ah-color-surface));
  color: var(--ah-color-brand);
}

.ah-badge--signal {
  border-color: color-mix(in srgb, var(--ah-color-signal) 55%, var(--ah-color-border));
  background: color-mix(in srgb, var(--ah-color-signal) 13%, var(--ah-color-surface));
  color: var(--ah-color-text);
}

/* -------------------------------------------------------------------------- */
/* Section heading                                                            */
/* -------------------------------------------------------------------------- */

.ah-section-heading {
  display: grid;
  gap: var(--ah-space-4);
  max-width: 860px;
}

.ah-section-heading--center {
  margin-inline: auto;
  text-align: center;
}

.ah-section-heading--center > * {
  margin-inline: auto;
}

.ah-section-heading__eyebrow {
  color: var(--ah-color-brand);
  font-family: var(--ah-font-mono);
  font-size: var(--ah-font-size-xs);
  font-weight: 600;
  letter-spacing: 0.1em;
  line-height: 1.4;
  text-transform: uppercase;
}

.ah-section-heading__title {
  max-width: 18ch;
}

.ah-section-heading__copy {
  max-width: 66ch;
  color: var(--ah-color-text-secondary);
  font-size: var(--ah-font-size-body-lg);
}

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

.ah-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-lg);
  background: var(--ah-color-surface);
  color: var(--ah-color-text);
}

.ah-card--interactive {
  transition:
    transform var(--ah-duration-base) var(--ah-ease-standard),
    border-color var(--ah-duration-base) var(--ah-ease-standard),
    box-shadow var(--ah-duration-base) var(--ah-ease-standard);
}

.ah-card--interactive:hover {
  border-color: var(--ah-color-border-strong);
  box-shadow: var(--ah-shadow-md);
  transform: translateY(-2px);
}

.ah-card__body {
  padding: clamp(22px, 3vw, 32px);
}

.ah-card__header {
  display: grid;
  gap: var(--ah-space-3);
}

.ah-card__title {
  font-size: var(--ah-font-size-h4);
  letter-spacing: -0.025em;
}

.ah-card__copy {
  margin-block-start: var(--ah-space-4);
}

.ah-card__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--ah-space-4);
  margin-block-start: var(--ah-space-6);
}

/* Functional Card */

.ah-card--functional .ah-card__body {
  display: flex;
  min-height: 100%;
  flex-direction: column;
}

.ah-card--functional .ah-card__footer {
  margin-block-start: auto;
  padding-block-start: var(--ah-space-6);
}

/* Product Card */

.ah-card--product {
  background:
    linear-gradient(
      180deg,
      color-mix(in srgb, var(--ah-color-brand) 3%, var(--ah-color-surface)) 0%,
      var(--ah-color-surface) 38%
    );
}

.ah-card--product .ah-card__media {
  border-block-end: 1px solid var(--ah-color-border);
  background: var(--ah-color-surface-soft);
}

/* Signal Card */

.ah-card--signal {
  border-color: color-mix(in srgb, var(--ah-color-brand) 24%, var(--ah-color-border));
}

.ah-card--signal::before {
  position: absolute;
  inset-block-start: 0;
  inset-inline-start: 0;
  width: 72px;
  height: 2px;
  background: linear-gradient(
    90deg,
    var(--ah-color-brand),
    var(--ah-color-intelligence)
  );
  content: "";
}

/* -------------------------------------------------------------------------- */
/* Metric                                                                     */
/* -------------------------------------------------------------------------- */

.ah-metric {
  display: grid;
  gap: var(--ah-space-2);
}

.ah-metric__value {
  color: var(--ah-color-text);
  font-size: clamp(1.75rem, 3vw, 3rem);
  font-weight: 750;
  letter-spacing: -0.045em;
  line-height: 1;
}

.ah-metric__label {
  color: var(--ah-color-text-secondary);
  font-size: var(--ah-font-size-sm);
}

/* -------------------------------------------------------------------------- */
/* Browser / product frame                                                    */
/* -------------------------------------------------------------------------- */

.ah-browser-frame {
  overflow: hidden;
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-xl);
  background: var(--ah-color-surface);
  box-shadow: var(--ah-shadow-feature);
}

.ah-browser-frame__bar {
  display: flex;
  min-height: 48px;
  align-items: center;
  gap: var(--ah-space-3);
  border-block-end: 1px solid var(--ah-color-border);
  background: var(--ah-color-surface-soft);
  padding-inline: var(--ah-space-5);
}

.ah-browser-frame__dots {
  display: flex;
  gap: 6px;
}

.ah-browser-frame__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ah-color-border-strong);
}

.ah-browser-frame__address {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--ah-color-text-muted);
  font-family: var(--ah-font-mono);
  font-size: var(--ah-font-size-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ah-browser-frame__content {
  position: relative;
  min-height: 220px;
  background: var(--ah-color-surface);
}

/* -------------------------------------------------------------------------- */
/* Forms                                                                      */
/* -------------------------------------------------------------------------- */

.ah-field {
  display: grid;
  gap: var(--ah-space-2);
}

.ah-field__label {
  color: var(--ah-color-text);
  font-size: var(--ah-font-size-sm);
  font-weight: 650;
}

.ah-field__hint {
  color: var(--ah-color-text-muted);
  font-size: var(--ah-font-size-sm);
}

.ah-field input,
.ah-field textarea,
.ah-field select {
  min-height: 48px;
  transition:
    border-color var(--ah-duration-fast) var(--ah-ease-standard),
    box-shadow var(--ah-duration-fast) var(--ah-ease-standard),
    background-color var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-field textarea {
  min-height: 140px;
}

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

.ah-field input:focus,
.ah-field textarea:focus,
.ah-field select:focus {
  border-color: var(--ah-color-brand);
  outline: none;
  box-shadow: var(--ah-focus-ring);
}

.ah-field.is-error input,
.ah-field.is-error textarea,
.ah-field.is-error select {
  border-color: #C93B45;
}

.ah-field__error {
  color: #B4232C;
  font-size: var(--ah-font-size-sm);
}

html[data-theme="dark"] .ah-field__error {
  color: #FF9DA4;
}

@media (prefers-color-scheme: dark) {
  html[data-theme="system"] .ah-field__error {
    color: #FF9DA4;
  }
}

.ah-field.is-success input,
.ah-field.is-success textarea,
.ah-field.is-success select {
  border-color: #16835A;
}

.ah-form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ah-space-4);
}

/* -------------------------------------------------------------------------- */
/* Navigation primitives                                                      */
/* -------------------------------------------------------------------------- */

.ah-nav {
  display: flex;
  align-items: center;
}

.ah-nav__list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: clamp(16px, 2vw, 28px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ah-nav__link {
  position: relative;
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  color: var(--ah-color-text-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: color var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-nav__link::after {
  position: absolute;
  inset-inline: 0;
  inset-block-end: 3px;
  height: 2px;
  border-radius: var(--ah-radius-pill);
  background: var(--ah-color-brand);
  content: "";
  opacity: 0;
  transform: scaleX(0.45);
  transform-origin: center;
  transition:
    opacity var(--ah-duration-fast) var(--ah-ease-standard),
    transform var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-nav__link:hover,
.ah-nav__link:focus-visible,
.ah-nav__link[aria-current="page"] {
  color: var(--ah-color-text);
}

.ah-nav__link:hover::after,
.ah-nav__link:focus-visible::after,
.ah-nav__link[aria-current="page"]::after {
  opacity: 1;
  transform: scaleX(1);
}

/* -------------------------------------------------------------------------- */
/* Theme toggle                                                               */
/* -------------------------------------------------------------------------- */

.ah-theme-toggle {
  display: inline-flex;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-pill);
  background: var(--ah-color-surface);
  color: var(--ah-color-text);
  transition:
    background-color var(--ah-duration-fast) var(--ah-ease-standard),
    border-color var(--ah-duration-fast) var(--ah-ease-standard),
    transform var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-theme-toggle:hover {
  border-color: var(--ah-color-border-strong);
  background: var(--ah-color-surface-soft);
  transform: translateY(-1px);
}

.ah-theme-toggle:active {
  transform: translateY(0);
}

.ah-theme-toggle__icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
}

/* -------------------------------------------------------------------------- */
/* Tabs / selectable controls                                                 */
/* -------------------------------------------------------------------------- */

.ah-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ah-space-2);
}

.ah-tab {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-pill);
  background: var(--ah-color-surface);
  color: var(--ah-color-text-secondary);
  font-size: var(--ah-font-size-sm);
  font-weight: 650;
  padding: 0.65rem 0.9rem;
  transition:
    background-color var(--ah-duration-fast) var(--ah-ease-standard),
    border-color var(--ah-duration-fast) var(--ah-ease-standard),
    color var(--ah-duration-fast) var(--ah-ease-standard);
}

.ah-tab:hover {
  border-color: var(--ah-color-border-strong);
  color: var(--ah-color-text);
}

.ah-tab[aria-selected="true"],
.ah-tab.is-active {
  border-color: var(--ah-color-brand);
  background: var(--ah-color-brand);
  color: var(--ah-color-text-inverse);
}

/* -------------------------------------------------------------------------- */
/* Status / node primitives                                                   */
/* -------------------------------------------------------------------------- */

.ah-status {
  display: inline-flex;
  align-items: center;
  gap: var(--ah-space-2);
  color: var(--ah-color-text-secondary);
  font-family: var(--ah-font-mono);
  font-size: var(--ah-font-size-xs);
}

.ah-status__dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--ah-color-border-strong);
}

.ah-status.is-active .ah-status__dot {
  background: var(--ah-color-signal);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ah-color-signal) 16%, transparent);
}

.ah-node {
  display: inline-flex;
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid var(--ah-color-border-strong);
  border-radius: 50%;
  background: var(--ah-color-surface);
}

.ah-node.is-active {
  border-color: var(--ah-color-brand);
  background: var(--ah-color-brand);
}

.ah-node.is-intelligence {
  border-color: var(--ah-color-intelligence);
  background: var(--ah-color-intelligence);
}

.ah-node.is-signal {
  border-color: var(--ah-color-signal);
  background: var(--ah-color-signal);
}

/* -------------------------------------------------------------------------- */
/* Dividers                                                                   */
/* -------------------------------------------------------------------------- */

.ah-divider {
  width: 100%;
  height: 1px;
  border: 0;
  background: var(--ah-color-border);
}

.ah-divider--gradient {
  background: linear-gradient(
    90deg,
    transparent,
    var(--ah-color-border-strong),
    transparent
  );
}

/* -------------------------------------------------------------------------- */
/* Empty / notice states                                                      */
/* -------------------------------------------------------------------------- */

.ah-notice {
  display: grid;
  gap: var(--ah-space-3);
  border: 1px solid var(--ah-color-border);
  border-radius: var(--ah-radius-md);
  background: var(--ah-color-surface-soft);
  padding: var(--ah-space-5);
}

.ah-notice__title {
  color: var(--ah-color-text);
  font-weight: 700;
}

.ah-notice__copy {
  color: var(--ah-color-text-secondary);
  font-size: var(--ah-font-size-sm);
}

/* -------------------------------------------------------------------------- */
/* Dark section compatibility                                                 */
/* -------------------------------------------------------------------------- */

.ah-section--dark .ah-card,
.ah-section--dark .ah-badge,
.ah-section--dark .ah-browser-frame,
.ah-section--dark .ah-theme-toggle,
.ah-section--dark .ah-tab {
  background: var(--ah-color-surface);
}

.ah-section--dark .ah-button--secondary {
  --ah-button-bg: transparent;
  --ah-button-bg-hover: var(--ah-color-surface-soft);
  --ah-button-bg-active: var(--ah-color-surface-soft);
  --ah-button-text: var(--ah-color-text);
  --ah-button-border: var(--ah-color-border);
}

/* -------------------------------------------------------------------------- */
/* Fallbacks                                                                  */
/* -------------------------------------------------------------------------- */

@supports not (color: color-mix(in srgb, black, white)) {
  .ah-badge--brand {
    border-color: var(--ah-color-border-strong);
    background: var(--ah-color-surface-soft);
  }

  .ah-badge--signal {
    border-color: var(--ah-color-border-strong);
    background: var(--ah-color-surface-soft);
  }

  .ah-card--product {
    background: var(--ah-color-surface);
  }

  .ah-card--signal {
    border-color: var(--ah-color-border-strong);
  }

  .ah-status.is-active .ah-status__dot {
    box-shadow: none;
  }
}

/* -------------------------------------------------------------------------- */
/* Small-screen component behavior                                            */
/* -------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .ah-button {
    min-height: 46px;
  }

  .ah-button--lg {
    min-height: 50px;
  }

  .ah-section-heading {
    gap: var(--ah-space-3);
  }

  .ah-card__body {
    padding: 22px;
  }

  .ah-browser-frame {
    border-radius: var(--ah-radius-lg);
  }

  .ah-browser-frame__bar {
    min-height: 44px;
    padding-inline: var(--ah-space-4);
  }

  .ah-form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .ah-form-actions .ah-button {
    width: 100%;
  }
}

/* -------------------------------------------------------------------------- */
/* Reduced motion                                                             */
/* -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .ah-button,
  .ah-button__icon,
  .ah-link__icon,
  .ah-card--interactive,
  .ah-nav__link,
  .ah-nav__link::after,
  .ah-theme-toggle,
  .ah-tab {
    transition: none;
  }

  .ah-button--signal::after {
    display: none;
  }

  .ah-button:hover,
  .ah-card--interactive:hover,
  .ah-theme-toggle:hover {
    transform: none;
  }
}
