/* ============================================================
   Engerman — Base Styles & Component Library
   Performance-first: no framework, minimal repaints,
   reserved layout space for CLS prevention.
   ============================================================ */

@import url('design-tokens.css');

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-surface);
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
a { color: var(--color-link); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-link-hover); }

/* Focus visible for keyboard nav (WCAG 2.2 AA) */
:focus-visible {
  outline: 2px solid var(--color-blue-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Skip link for accessibility */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--color-navy-800);
  color: var(--color-white);
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}
.skip-link:focus { top: var(--space-4); }

/* ── Layout ─────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-6);
}
.container--narrow { max-width: var(--container-narrow); }
.container--wide { max-width: var(--container-wide); }

.section {
  padding: var(--space-20) 0;
}
.section--sm { padding: var(--space-12) 0; }
.section--lg { padding: var(--space-24) 0; }

/* ── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  color: var(--color-navy-800);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
}

h1 { font-size: var(--text-4xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-3xl); letter-spacing: -0.015em; }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }

p { margin-bottom: var(--space-4); }
.text-sm { font-size: var(--text-sm); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-secondary { color: var(--color-text-secondary); }
.text-center { text-align: center; }

/* Overline label */
.overline {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-blue-600);
  margin-bottom: var(--space-2);
}

/* ── Navigation ─────────────────────────────────────────── */
.nav {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border-light);
  height: 64px;
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.nav__logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: var(--weight-bold);
  font-size: var(--text-xl);
  color: var(--color-navy-800);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.nav__logo-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

.nav__logo img {
  height: 40px;
  width: auto;
}

.nav__links {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  list-style: none;
}

.nav__links a {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-gray-700);
  transition: color var(--transition-fast);
  white-space: nowrap;
}

.nav__links a:hover,
.nav__links a[aria-current="page"] {
  color: var(--color-navy-800);
}

.nav__cta {
  display: inline-flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  background: var(--color-navy-800);
  color: var(--color-white) !important;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  transition: background var(--transition-fast);
}

.nav__cta:hover {
  background: var(--color-navy-700);
  color: var(--color-white) !important;
  transform: translateY(-1px);
}

/* Mobile hamburger */
.nav__toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-2);
  color: var(--color-navy-800);
}

.nav__toggle svg { width: 24px; height: 24px; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn--primary {
  background: var(--color-navy-800);
  color: var(--color-white);
}
.btn:hover {
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}

.btn--primary:hover {
  background: var(--color-navy-700);
  color: var(--color-white);
}

.btn--secondary {
  background: transparent;
  color: var(--color-navy-800);
  border-color: var(--color-navy-800);
}
.btn--secondary:hover {
  background: var(--color-navy-800);
  color: var(--color-white);
}

.btn--ghost {
  background: transparent;
  color: var(--color-blue-600);
  padding: var(--space-2) var(--space-3);
}
.btn--ghost:hover {
  background: var(--color-blue-50);
  color: var(--color-blue-700);
}

.btn--lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--text-lg);
}

.btn--sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
}

/* Disabled state */
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card--elevated {
  border: none;
  box-shadow: var(--shadow-sm);
}
.card--elevated:hover {
  box-shadow: var(--shadow-lg);
}

/* ── Tabs ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
}

.tab {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab:hover {
  color: var(--color-navy-800);
}

.tab[aria-selected="true"],
.tab.active {
  color: var(--color-navy-800);
  font-weight: var(--weight-semibold);
  border-bottom-color: var(--color-blue-600);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Badge / Tag ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  line-height: 1;
}

.badge--green  { background: var(--color-green-100); color: var(--color-green-600); }
.badge--amber  { background: var(--color-amber-100); color: var(--color-amber-600); }
.badge--red    { background: var(--color-red-100);   color: var(--color-red-600); }
.badge--blue   { background: var(--color-blue-100);  color: var(--color-blue-600); }
.badge--gray   { background: var(--color-gray-100);  color: var(--color-gray-600); }

/* ── Grid helpers ───────────────────────────────────────── */
.grid { display: grid; gap: var(--space-6); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

.flex { display: flex; }
.flex--center { align-items: center; justify-content: center; }
.flex--between { align-items: center; justify-content: space-between; }

/* ── Tables ─────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}

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

.table th {
  background: var(--color-gray-50);
  font-weight: var(--weight-semibold);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  color: var(--color-gray-700);
  white-space: nowrap;
}

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

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

/* ── Footer ─────────────────────────────────────────────── */
.footer {
  background: var(--color-navy-800);
  color: var(--color-gray-300);
  padding: var(--space-16) 0 var(--space-8);
}

.footer__grid {
  display: grid;
  grid-template-columns: 2fr repeat(3, 1fr);
  gap: var(--space-10);
  margin-bottom: var(--space-12);
}

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

.footer__brand img { height: 32px; width: auto; }
.footer__brand .nav__logo-mark { width: 32px; height: 32px; }
.footer__brand p { font-size: var(--text-sm); color: var(--color-gray-400); max-width: 280px; }

.footer__col h4 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-white);
  margin-bottom: var(--space-4);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.footer__col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.footer__col a {
  font-size: var(--text-sm);
  color: var(--color-gray-400);
  transition: color var(--transition-fast);
}

.footer__col a:hover { color: var(--color-white); }

.footer__bottom {
  border-top: 1px solid var(--color-navy-700);
  padding-top: var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--color-gray-500);
}

/* ── Scroll Reveal ─────────────────────────────────────── */
.scroll-fade {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.7s var(--ease-out-expo), transform 0.7s var(--ease-out-expo);
}

.scroll-fade.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.scroll-stagger > * {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.5s var(--ease-out-expo), transform 0.5s var(--ease-out-expo);
}

.scroll-stagger.is-visible > * {
  opacity: 1;
  transform: translateY(0);
}

.scroll-stagger.is-visible > :nth-child(2) { transition-delay: 0.1s; }
.scroll-stagger.is-visible > :nth-child(3) { transition-delay: 0.15s; }
.scroll-stagger.is-visible > :nth-child(4) { transition-delay: 0.2s; }

@media (prefers-reduced-motion: reduce) {
  .scroll-fade,
  .scroll-stagger > * {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
}

/* ── Utility ────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.bg-alt   { background: var(--color-surface-alt); }
.bg-navy  { background: var(--color-navy-800); color: var(--color-text-invert); }
.bg-navy h2, .bg-navy h3, .bg-navy h4 { color: var(--color-white); }
.bg-navy .overline { color: var(--color-blue-300); }

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

@media (max-width: 768px) {
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }

  .section { padding: var(--space-12) 0; }

  .grid--2, .grid--3, .grid--4 {
    grid-template-columns: 1fr;
  }

  .footer__grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8);
  }

  /* Mobile nav */
  .nav__links {
    display: none;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--color-white);
    flex-direction: column;
    padding: var(--space-4) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    gap: var(--space-1);
  }

  .nav__links.open { display: flex; }

  .nav__links li { width: 100%; }

  .nav__links a {
    display: block;
    padding: var(--space-3) 0;
    font-size: var(--text-base);
  }

  .nav__toggle { display: flex; }
}

@media (max-width: 480px) {
  h1 { font-size: var(--text-2xl); }
  .container { padding: 0 var(--space-4); }
  .section { padding: var(--space-10) 0; }

  .footer__grid { grid-template-columns: 1fr; }
}
