/**
 * ALLSCANTOOL — Enterprise Design System Primitives
 * WP-02 — Section 2 of 5 — Enterprise Design System
 *
 * Depends on: assets/design-tokens.css (link tokens first).
 * Opt-in classes only (.ast-*). Does not rename page IDs or alter JS hooks.
 * Does not redesign existing page layouts.
 */

/* —— Base (opt-in) —— */
.ast-ds-root,
.ast-ds-root body {
  font-family: var(--ast-font-sans);
  font-size: var(--ast-font-size-base);
  line-height: var(--ast-line-height-body);
  color: var(--ast-color-text);
  background: var(--ast-color-bg);
}

/* —— Accessibility focus (opt-in root + standalone controls) —— */
.ast-ds-root a:focus-visible,
.ast-ds-root button:focus-visible,
.ast-ds-root input:focus-visible,
.ast-ds-root select:focus-visible,
.ast-ds-root textarea:focus-visible,
.ast-btn:focus-visible,
.ast-card:focus-visible,
.ast-form-control:focus-visible,
.ast-badge:focus-visible,
.ast-nav-link:focus-visible {
  outline: 3px solid var(--ast-color-focus-outline);
  outline-offset: 3px;
}

.ast-skip-link {
  position: absolute;
  top: -60px;
  left: 12px;
  z-index: 1000;
  background: var(--ast-color-blue);
  color: var(--ast-color-white);
  padding: 10px 16px;
  border-radius: 0 0 var(--ast-radius-md) var(--ast-radius-md);
  font-size: 14px;
  font-weight: var(--ast-font-weight-bold);
}

.ast-skip-link:focus {
  top: 0;
}

/* —— Grid / layout utilities —— */
.ast-container {
  max-width: var(--ast-max-width);
  margin: 0 auto;
  padding: 0 var(--ast-gutter);
}

.ast-section {
  padding: var(--ast-section-y) 0;
}

.ast-grid {
  display: grid;
  gap: var(--ast-grid-gap);
  grid-template-columns: repeat(var(--ast-col-count), minmax(0, 1fr));
}

.ast-grid--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.ast-grid--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ast-grid--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.ast-stack {
  display: flex;
  flex-direction: column;
  gap: var(--ast-space-4);
}

.ast-stack--sm {
  gap: var(--ast-space-2);
}

.ast-stack--lg {
  gap: var(--ast-space-6);
}

.ast-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ast-space-4);
  align-items: center;
}

/* —— Typography —— */
.ast-label {
  text-transform: uppercase;
  font-size: var(--ast-text-xs);
  letter-spacing: var(--ast-letter-spacing-label);
  color: var(--ast-color-text-muted);
  font-weight: var(--ast-font-weight-semibold);
}

.ast-h1 {
  font-size: var(--ast-h1-size);
  font-weight: var(--ast-font-weight-extrabold);
  line-height: var(--ast-line-height-tight);
  color: var(--ast-color-text);
}

.ast-h2,
.ast-title {
  font-size: var(--ast-h2-size);
  font-weight: var(--ast-font-weight-bold);
  line-height: var(--ast-line-height-tight);
  color: var(--ast-color-text);
}

.ast-h3 {
  font-size: var(--ast-h3-size);
  font-weight: var(--ast-font-weight-bold);
  line-height: var(--ast-line-height-snug);
  color: var(--ast-color-text);
}

.ast-h4 {
  font-size: var(--ast-h4-size);
  font-weight: var(--ast-font-weight-semibold);
  line-height: var(--ast-line-height-snug);
  color: var(--ast-color-text);
}

.ast-lead {
  font-size: var(--ast-text-lg);
  color: var(--ast-color-text-muted);
  max-width: var(--ast-content-reading);
  line-height: var(--ast-line-height-body);
}

.ast-body {
  font-size: var(--ast-text-base);
  line-height: var(--ast-line-height-body);
  color: var(--ast-color-text);
}

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

.ast-mono {
  font-family: var(--ast-font-mono);
}

/* —— Buttons —— */
.ast-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ast-space-2);
  min-height: var(--ast-touch-min);
  padding: 12px 28px;
  border-radius: var(--ast-radius-md);
  font-weight: var(--ast-font-weight-semibold);
  font-size: var(--ast-text-md);
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  border: 2px solid transparent;
  text-decoration: none;
  background: transparent;
  color: var(--ast-color-text);
  transition:
    background var(--ast-transition),
    border-color var(--ast-transition),
    color var(--ast-transition),
    box-shadow var(--ast-transition),
    opacity var(--ast-transition);
}

.ast-btn:hover {
  text-decoration: none;
}

.ast-btn:active {
  transform: translateY(0.5px);
}

.ast-btn--primary {
  background: var(--ast-color-blue);
  color: var(--ast-color-white);
}

.ast-btn--primary:hover {
  background: var(--ast-color-blue-hover);
}

.ast-btn--primary:active {
  background: var(--ast-color-blue-active);
}

.ast-btn--secondary {
  background: var(--ast-color-bg-muted);
  color: var(--ast-color-text);
  border-color: var(--ast-color-border);
}

.ast-btn--secondary:hover {
  background: var(--ast-color-border);
}

.ast-btn--secondary:active {
  background: var(--ast-color-border-strong);
}

.ast-btn--teal {
  background: var(--ast-color-teal);
  color: var(--ast-color-white);
}

.ast-btn--teal:hover {
  background: var(--ast-color-teal-hover);
}

.ast-btn--teal:active {
  background: var(--ast-color-teal-active);
}

.ast-btn--outline {
  background: transparent;
  color: var(--ast-color-text);
  border-color: var(--ast-color-border);
}

.ast-btn--outline:hover {
  border-color: var(--ast-color-text);
  background: var(--ast-color-bg-alt);
}

.ast-btn--outline:active {
  background: var(--ast-color-bg-muted);
}

.ast-btn--text {
  background: transparent;
  color: var(--ast-color-blue);
  border-color: transparent;
  padding-left: 12px;
  padding-right: 12px;
}

.ast-btn--text:hover {
  background: var(--ast-color-blue-subtle);
}

.ast-btn--text:active {
  background: var(--ast-color-info-bg);
}

.ast-btn--large {
  padding: 16px 40px;
  font-size: var(--ast-text-lg);
}

.ast-btn--small {
  min-height: 36px;
  padding: 8px 16px;
  font-size: var(--ast-text-sm);
}

.ast-btn--block {
  width: 100%;
}

.ast-btn:disabled,
.ast-btn[aria-disabled="true"],
.ast-btn--disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

/* —— Forms —— */
.ast-form-group {
  display: flex;
  flex-direction: column;
  gap: var(--ast-space-2);
  margin-bottom: var(--ast-space-4);
}

.ast-form-label {
  font-size: var(--ast-text-sm);
  font-weight: var(--ast-font-weight-semibold);
  color: var(--ast-color-text);
}

.ast-form-control {
  min-height: var(--ast-control-height);
  padding: 10px 14px;
  border: 1px solid var(--ast-color-border);
  border-radius: var(--ast-radius-md);
  font: inherit;
  color: var(--ast-color-text);
  background: var(--ast-color-white);
  transition: border-color var(--ast-transition-fast), box-shadow var(--ast-transition-fast);
}

select.ast-form-control {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ast-color-text-muted) 50%),
    linear-gradient(135deg, var(--ast-color-text-muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.ast-form-control:hover {
  border-color: var(--ast-color-border-strong);
}

.ast-form-control:focus {
  border-color: var(--ast-color-blue);
  box-shadow: var(--ast-shadow-focus);
  outline: none;
}

.ast-form-control--success,
.ast-form-group--success .ast-form-control {
  border-color: var(--ast-color-success-border);
}

.ast-form-control--warning,
.ast-form-group--warning .ast-form-control {
  border-color: var(--ast-color-warning-border);
}

.ast-form-control--error,
.ast-form-group--error .ast-form-control {
  border-color: var(--ast-color-error);
}

.ast-form-control--error:focus,
.ast-form-group--error .ast-form-control:focus {
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.25);
}

.ast-form-help {
  font-size: var(--ast-text-sm);
  color: var(--ast-color-text-muted);
}

.ast-form-error {
  font-size: var(--ast-text-sm);
  color: var(--ast-color-error);
}

.ast-form-success {
  font-size: var(--ast-text-sm);
  color: var(--ast-color-success);
}

textarea.ast-form-control {
  min-height: 120px;
  resize: vertical;
}

.ast-check,
.ast-radio {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--ast-space-2);
  font-size: var(--ast-text-md);
  color: var(--ast-color-text);
  cursor: pointer;
}

.ast-check input,
.ast-radio input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--ast-color-blue);
  flex: none;
}

.ast-check input:focus-visible,
.ast-radio input:focus-visible {
  outline: 3px solid var(--ast-color-focus-outline);
  outline-offset: 2px;
}

/* —— Cards —— */
.ast-card {
  background: var(--ast-color-white);
  border: 1px solid var(--ast-color-border);
  border-radius: var(--ast-radius-xl);
  padding: var(--ast-space-8) var(--ast-space-6);
  box-shadow: var(--ast-shadow-xs);
}

.ast-card--alt {
  background: var(--ast-color-bg-alt);
}

.ast-card--muted {
  background: var(--ast-color-bg-muted);
}

.ast-card--featured {
  border: 2px solid var(--ast-color-blue);
  box-shadow: var(--ast-shadow-card);
}

.ast-card--pricing {
  display: flex;
  flex-direction: column;
  gap: var(--ast-space-4);
  height: 100%;
}

.ast-card--community {
  padding: var(--ast-space-6);
}

.ast-card--panel {
  border-radius: var(--ast-radius-lg);
  box-shadow: var(--ast-shadow-sm);
}

.ast-card--report {
  border-left: 4px solid var(--ast-color-blue);
}

.ast-card__title {
  font-size: var(--ast-text-base);
  font-weight: var(--ast-font-weight-extrabold);
  margin-bottom: var(--ast-space-2);
  color: var(--ast-color-text);
}

.ast-card__body {
  font-size: 0.88rem;
  color: var(--ast-color-text-muted);
  line-height: var(--ast-line-height-body);
}

.ast-card__footer {
  margin-top: auto;
  padding-top: var(--ast-space-4);
}

/* —— Badges —— */
.ast-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: var(--ast-radius-pill);
  font-size: var(--ast-text-xs);
  font-weight: var(--ast-font-weight-semibold);
  letter-spacing: 0.02em;
  line-height: 1.2;
  border: 1px solid transparent;
  white-space: nowrap;
}

.ast-badge--neutral {
  background: var(--ast-color-bg-muted);
  color: var(--ast-color-text);
  border-color: var(--ast-color-border);
}

.ast-badge--info {
  background: var(--ast-color-info-bg);
  color: var(--ast-color-info);
  border-color: var(--ast-color-info-border);
}

.ast-badge--success {
  background: var(--ast-color-success-bg);
  color: var(--ast-color-success);
  border-color: var(--ast-color-success-border);
}

.ast-badge--warning {
  background: var(--ast-color-warning-bg);
  color: var(--ast-color-warning);
  border-color: var(--ast-color-warning-border);
}

.ast-badge--error {
  background: var(--ast-color-error-bg);
  color: var(--ast-color-error);
  border-color: var(--ast-color-error-border);
}

.ast-badge--brand {
  background: var(--ast-color-blue-subtle);
  color: var(--ast-color-blue);
  border-color: var(--ast-color-focus-ring);
}

/* —— Alerts —— */
.ast-alert {
  display: flex;
  gap: var(--ast-space-3);
  align-items: flex-start;
  padding: var(--ast-space-4) var(--ast-space-5);
  border-radius: var(--ast-radius-lg);
  border: 1px solid var(--ast-color-border);
  background: var(--ast-color-bg-alt);
  color: var(--ast-color-text);
  font-size: var(--ast-text-md);
  line-height: var(--ast-line-height-body);
}

.ast-alert--info {
  background: var(--ast-color-info-bg);
  border-color: var(--ast-color-info-border);
  color: var(--ast-color-info);
}

.ast-alert--success {
  background: var(--ast-color-success-bg);
  border-color: var(--ast-color-success-border);
  color: var(--ast-color-success);
}

.ast-alert--warning {
  background: var(--ast-color-warning-bg);
  border-color: var(--ast-color-warning-border);
  color: var(--ast-color-warning);
}

.ast-alert--error {
  background: var(--ast-color-error-bg);
  border-color: var(--ast-color-error-border);
  color: var(--ast-color-error);
}

.ast-alert__title {
  font-weight: var(--ast-font-weight-bold);
  margin-bottom: 2px;
}

/* —— Tables —— */
.ast-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--ast-color-border);
  border-radius: var(--ast-radius-lg);
}

.ast-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ast-text-md);
}

.ast-table th,
.ast-table td {
  padding: var(--ast-space-3) var(--ast-space-4);
  border-bottom: 1px solid var(--ast-color-border);
  text-align: left;
  vertical-align: top;
}

.ast-table th {
  font-weight: var(--ast-font-weight-bold);
  color: var(--ast-color-text);
  background: var(--ast-color-bg-alt);
}

.ast-table td {
  color: var(--ast-color-text);
}

.ast-table tr:last-child td {
  border-bottom: none;
}

.ast-table tr:hover td {
  background: rgba(248, 250, 252, 0.8);
}

/* —— Responsive foundation —— */
@media (max-width: 1024px) {
  .ast-grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .ast-grid--2,
  .ast-grid--3,
  .ast-grid--4 {
    grid-template-columns: 1fr;
  }

  .ast-h1 {
    font-size: var(--ast-text-4xl);
  }

  .ast-h2,
  .ast-title {
    font-size: var(--ast-text-2xl);
  }

  .ast-container {
    padding: 0 var(--ast-gutter-sm);
  }

  .ast-section {
    padding: var(--ast-section-y-sm) 0;
  }
}

@media (max-width: 480px) {
  .ast-btn--large {
    width: 100%;
  }

  .ast-card {
    padding: var(--ast-space-6) var(--ast-space-5);
  }

  .ast-row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ast-btn,
  .ast-form-control {
    transition: none;
  }

  .ast-btn:active {
    transform: none;
  }
}
