/* ============================================================
   ConstructMate AI — Design System
   Layer 1 of 2. Tokens, reset, typography, primitives.
   Everything is a CSS custom property so you can rebrand the
   whole site by editing the :root block below and nothing else.
   ============================================================ */

/* ------------------------------------------------------------
   1. DESIGN TOKENS
   ------------------------------------------------------------ */
:root {
  /* --- Brand palette ------------------------------------- */
  --c-primary:        #0F172A;   /* Midnight Navy   */
  --c-secondary:      #00C2A8;   /* Emerald Aqua    */
  --c-accent:         #FF6B35;   /* Vibrant Orange  */
  --c-highlight:      #7C3AED;   /* Modern Purple   */
  --c-bg:             #F8FAFC;
  --c-surface:        #FFFFFF;
  --c-success:        #10B981;
  --c-warning:        #F59E0B;
  --c-error:          #EF4444;

  /* --- Derived tints (used for soft backgrounds, borders) -- */
  --c-primary-900:    #020617;
  --c-primary-800:    #0F172A;
  --c-primary-700:    #1E293B;
  --c-primary-600:    #334155;
  --c-primary-500:    #475569;
  --c-primary-400:    #64748B;
  --c-primary-300:    #94A3B8;
  --c-primary-200:    #CBD5E1;
  --c-primary-100:    #E2E8F0;
  --c-primary-50:     #F1F5F9;

  /* Darkened from #009e89 so link/eyebrow text clears WCAG AA (4.5:1)
     on every light surface in the system: page bg, white cards, the
     aqua tint, and both sunken/alt greys. Worst case 4.68:1. */
  --c-secondary-dark: #007A6A;
  --c-secondary-soft: #E6FAF7;
  --c-accent-dark:    #E8501A;
  --c-accent-text:    #B84D26;   /* accent as TEXT on light backgrounds (AA) */
  --c-accent-soft:    #FFF0EA;
  --c-highlight-dark: #6425D0;
  --c-highlight-soft: #F1EAFE;
  --c-success-soft:   #E7F8F1;
  --c-warning-soft:   #FEF5E6;
  --c-error-soft:     #FDECEC;

  /* --- Text ---------------------------------------------- */
  --c-text:           #0F172A;
  --c-text-muted:     #475569;
  --c-text-subtle:    #606F85;   /* AA on white, page bg and both tinted surfaces */
  --c-text-invert:    #F8FAFC;

  /* --- Lines & surfaces ---------------------------------- */
  --c-border:         #E2E8F0;
  --c-border-strong:  #CBD5E1;
  --c-surface-alt:    #F1F5F9;
  --c-surface-sunken: #EEF2F7;

  /* --- Signature gradients (the brand's fingerprint) ------ */
  --grad-hero:    linear-gradient(135deg, #0F172A 0%, #16233F 38%, #1B2E5B 66%, #2A1F63 100%);
  --grad-aqua:    linear-gradient(135deg, #00C2A8 0%, #12A8C9 100%);
  --grad-violet:  linear-gradient(135deg, #7C3AED 0%, #4F46E5 100%);
  --grad-ember:   linear-gradient(135deg, #FF6B35 0%, #F59E0B 100%);
  --grad-mixed:   linear-gradient(120deg, #00C2A8 0%, #7C3AED 55%, #FF6B35 100%);
  --grad-sheen:   linear-gradient(180deg, rgba(255,255,255,.14) 0%, rgba(255,255,255,0) 100%);

  /* --- Typography scale (fluid, clamp-based) -------------- */
  --font-sans: 'Plus Jakarta Sans', 'Segoe UI', system-ui, -apple-system,
               'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo,
               Consolas, monospace;

  --fs-2xs:  0.6875rem;                              /* 11px  */
  --fs-xs:   0.75rem;                                /* 12px  */
  --fs-sm:   0.875rem;                               /* 14px  */
  --fs-base: 1rem;                                   /* 16px  */
  --fs-lg:   1.125rem;                               /* 18px  */
  --fs-xl:   clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
  --fs-2xl:  clamp(1.5rem, 1.3rem + 1.0vw, 2rem);
  --fs-3xl:  clamp(1.875rem, 1.5rem + 1.7vw, 2.75rem);
  --fs-4xl:  clamp(2.25rem, 1.6rem + 3.0vw, 4rem);
  --fs-5xl:  clamp(2.75rem, 1.8rem + 4.2vw, 5rem);

  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semi:    600;
  --fw-bold:    700;
  --fw-black:   800;

  --lh-tight: 1.15;
  --lh-snug:  1.3;
  --lh-base:  1.6;
  --lh-loose: 1.75;

  --ls-tight: -0.02em;
  --ls-snug:  -0.01em;
  --ls-wide:  0.04em;
  --ls-caps:  0.08em;

  /* --- Spacing scale (4px base) --------------------------- */
  --sp-1:  0.25rem;   --sp-2:  0.5rem;    --sp-3:  0.75rem;
  --sp-4:  1rem;      --sp-5:  1.25rem;   --sp-6:  1.5rem;
  --sp-8:  2rem;      --sp-10: 2.5rem;    --sp-12: 3rem;
  --sp-16: 4rem;      --sp-20: 5rem;      --sp-24: 6rem;
  --sp-32: 8rem;

  /* Section rhythm shrinks on phones, opens up on desktop */
  --sp-section: clamp(3rem, 2rem + 5vw, 7rem);

  /* --- Radii ---------------------------------------------- */
  --r-xs:   6px;
  --r-sm:   10px;
  --r-md:   14px;
  --r-lg:   20px;
  --r-xl:   28px;
  --r-2xl:  36px;
  --r-pill: 999px;

  /* --- Elevation (navy-tinted, never plain black) --------- */
  --sh-xs:  0 1px 2px rgba(15, 23, 42, .06);
  --sh-sm:  0 2px 6px rgba(15, 23, 42, .07);
  --sh-md:  0 6px 18px -4px rgba(15, 23, 42, .10), 0 2px 6px -2px rgba(15, 23, 42, .06);
  --sh-lg:  0 16px 40px -12px rgba(15, 23, 42, .16), 0 4px 12px -4px rgba(15, 23, 42, .08);
  --sh-xl:  0 28px 64px -20px rgba(15, 23, 42, .24), 0 8px 20px -8px rgba(15, 23, 42, .10);
  --sh-aqua:   0 12px 32px -10px rgba(0, 194, 168, .50);
  --sh-ember:  0 12px 32px -10px rgba(255, 107, 53, .48);
  --sh-violet: 0 12px 32px -10px rgba(124, 58, 237, .46);

  /* --- Motion --------------------------------------------- */
  --ease-out:    cubic-bezier(.25, .8, .35, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .5, 1);
  --t-fast:   140ms;
  --t-base:   240ms;
  --t-slow:   420ms;

  /* --- Layout --------------------------------------------- */
  --container:      1280px;
  --container-wide: 1520px;
  --container-text: 720px;
  --gutter: clamp(1rem, 0.5rem + 2.2vw, 2.5rem);

  --h-header:     64px;
  --h-bottomnav:  68px;
  --w-sidebar:    264px;
  --w-sidebar-sm: 76px;

  --z-base: 1;  --z-sticky: 100;  --z-header: 200;
  --z-drawer: 300;  --z-modal: 400;  --z-toast: 500;

  --focus-ring: 0 0 0 3px rgba(0, 194, 168, .45);
}

/* ------------------------------------------------------------
   2. DARK MODE
   Follows the OS by default; [data-theme] on <html> overrides.
   ------------------------------------------------------------ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-bg:            #0B1220;
    --c-surface:       #131C2E;
    --c-surface-alt:   #1A2438;
    --c-surface-sunken: #0F1729;
    --c-text:          #E8EEF7;
    --c-text-muted:    #A9B7CC;
    --c-text-subtle:   #8496AE;
    --c-border:        #24314A;
    --c-border-strong: #33425F;
    --c-primary-50:    #131C2E;
    --c-primary-100:   #1A2438;
    --c-secondary-soft: #062F2A;
    --c-accent-soft:   #3A1B0E;
    --c-highlight-soft: #241546;
    --c-success-soft:  #06281F;
    --c-warning-soft:  #33240A;
    --c-error-soft:    #3A1414;
    --sh-md: 0 6px 18px -4px rgba(0, 0, 0, .55), 0 2px 6px -2px rgba(0, 0, 0, .40);
    --sh-lg: 0 16px 40px -12px rgba(0, 0, 0, .65), 0 4px 12px -4px rgba(0, 0, 0, .45);
    --sh-xl: 0 28px 64px -20px rgba(0, 0, 0, .75);
  }
}

:root[data-theme="dark"] {
  --c-bg:            #0B1220;
  --c-surface:       #131C2E;
  --c-surface-alt:   #1A2438;
  --c-surface-sunken: #0F1729;
  --c-text:          #E8EEF7;
  --c-text-muted:    #A9B7CC;
  --c-text-subtle:   #8496AE;
  --c-border:        #24314A;
  --c-border-strong: #33425F;
  --c-primary-50:    #131C2E;
  --c-primary-100:   #1A2438;
  --c-secondary-soft: #062F2A;
  --c-accent-soft:   #3A1B0E;
  --c-highlight-soft: #241546;
  --c-success-soft:  #06281F;
  --c-warning-soft:  #33240A;
  --c-error-soft:    #3A1414;
  --sh-md: 0 6px 18px -4px rgba(0, 0, 0, .55), 0 2px 6px -2px rgba(0, 0, 0, .40);
  --sh-lg: 0 16px 40px -12px rgba(0, 0, 0, .65), 0 4px 12px -4px rgba(0, 0, 0, .45);
  --sh-xl: 0 28px 64px -20px rgba(0, 0, 0, .75);
}

/* ------------------------------------------------------------
   3. HIGH CONTRAST / FORCED COLORS
   ------------------------------------------------------------ */
@media (prefers-contrast: more) {
  :root {
    --c-text-muted:  #1E293B;
    --c-text-subtle: #1E293B;
    --c-border:      #64748B;
    --c-border-strong: #334155;
    --focus-ring: 0 0 0 4px #0F172A;
  }
}

@media (forced-colors: active) {
  .btn, .card, .input { border: 1px solid CanvasText; }
  .kpi-ring, .chart-svg { forced-color-adjust: none; }
}

/* ------------------------------------------------------------
   4. RESET
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--h-header) + var(--sp-4));
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-base);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img, picture, video, canvas, svg { display: block; max-width: 100%; }
svg { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
ul, ol { list-style: none; padding: 0; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

/* ------------------------------------------------------------
   5. TYPOGRAPHY
   ------------------------------------------------------------ */
h1, .h1 {
  font-size: var(--fs-4xl); font-weight: var(--fw-black);
  line-height: var(--lh-tight); letter-spacing: var(--ls-tight);
}
h2, .h2 {
  font-size: var(--fs-3xl); font-weight: var(--fw-bold);
  line-height: var(--lh-tight); letter-spacing: var(--ls-tight);
}
h3, .h3 {
  font-size: var(--fs-2xl); font-weight: var(--fw-bold);
  line-height: var(--lh-snug); letter-spacing: var(--ls-snug);
}
h4, .h4 {
  font-size: var(--fs-xl); font-weight: var(--fw-semi);
  line-height: var(--lh-snug);
}
h5, .h5 { font-size: var(--fs-lg); font-weight: var(--fw-semi); }
h6, .h6 { font-size: var(--fs-base); font-weight: var(--fw-semi); }

.lead { font-size: var(--fs-lg); color: var(--c-text-muted); line-height: var(--lh-loose); }
.small { font-size: var(--fs-sm); }
.tiny  { font-size: var(--fs-xs); }
.muted { color: var(--c-text-muted); }
.subtle { color: var(--c-text-subtle); }
.mono  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.nums  { font-variant-numeric: tabular-nums; }

.eyebrow {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
  letter-spacing: var(--ls-caps); text-transform: uppercase;
  color: var(--c-secondary-dark);
}
.eyebrow--invert { color: var(--c-secondary); }

/* Gradient text — the brand's signature headline treatment */
.text-gradient {
  background: var(--grad-mixed);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.text-gradient-aqua {
  background: var(--grad-aqua);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}

.balance { text-wrap: balance; }
.measure { max-width: var(--container-text); }

/* ------------------------------------------------------------
   6. LAYOUT PRIMITIVES
   ------------------------------------------------------------ */
.container {
  width: 100%; max-width: var(--container);
  margin-inline: auto; padding-inline: var(--gutter);
}
.container--wide { max-width: var(--container-wide); }
.container--text { max-width: var(--container-text); }

.section { padding-block: var(--sp-section); }
.section--tight { padding-block: clamp(2rem, 1.5rem + 3vw, 4rem); }

.stack > * + * { margin-top: var(--flow, var(--sp-4)); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-8); }

.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.row--top { align-items: flex-start; }
.spacer { flex: 1 1 auto; }

/* Auto-fit grid: one column on phones, more as space allows.
   No media queries needed — it responds to container width. */
.grid { display: grid; gap: var(--sp-5); }
.grid--auto  { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
.grid--auto-sm { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.grid--auto-lg { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.grid--2 { grid-template-columns: 1fr; }
.grid--3 { grid-template-columns: 1fr; }
.grid--4 { grid-template-columns: repeat(2, 1fr); }

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

/* Sidebar + content, collapsing to a single column on small screens */
.shell { display: block; }
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: var(--w-sidebar) minmax(0, 1fr); }
}

/* ------------------------------------------------------------
   7. ACCESSIBILITY HELPERS
   ------------------------------------------------------------ */
.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;
}

.skip-link {
  position: absolute; left: var(--sp-4); top: -100px;
  z-index: var(--z-toast);
  background: var(--c-primary); color: #fff;
  padding: var(--sp-3) var(--sp-5); border-radius: var(--r-sm);
  font-weight: var(--fw-semi); box-shadow: var(--sh-lg);
  transition: top var(--t-base) var(--ease-out);
}
.skip-link:focus { top: var(--sp-4); }

:focus-visible {
  outline: 2px solid var(--c-secondary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
/* Keyboard users get the ring; mouse users don't. */
:focus:not(:focus-visible) { outline: none; }

/* ------------------------------------------------------------
   8. MOTION — every animation is opt-out safe
   ------------------------------------------------------------ */
@keyframes fade-up {
  from { opacity: 0; transform: translate3d(0, 18px, 0); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scale-in {
  from { opacity: 0; transform: scale(.95); }
  to   { opacity: 1; transform: none; }
}
@keyframes slide-in-right {
  from { transform: translate3d(100%, 0, 0); }
  to   { transform: none; }
}
@keyframes float-y {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50%      { transform: translate3d(0, -12px, 0); }
}
@keyframes shimmer {
  from { background-position: -600px 0; }
  to   { background-position: 600px 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(0, 194, 168, .45); }
  70%  { box-shadow: 0 0 0 14px rgba(0, 194, 168, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 194, 168, 0); }
}

/* Scroll-reveal: set by JS via IntersectionObserver.
   Without JS the content is visible — never hidden permanently. */
.reveal {
  opacity: 0;
  transform: translate3d(0, 20px, 0);
  transition: opacity var(--t-slow) var(--ease-out),
              transform var(--t-slow) var(--ease-out);
  will-change: opacity, transform;
}
.reveal.is-visible { opacity: 1; transform: none; }
.no-js .reveal { opacity: 1; transform: none; }

.reveal-d1 { transition-delay: 70ms; }
.reveal-d2 { transition-delay: 140ms; }
.reveal-d3 { transition-delay: 210ms; }
.reveal-d4 { transition-delay: 280ms; }
.reveal-d5 { transition-delay: 350ms; }

.animate-float { animation: float-y 6s var(--ease-out) infinite; }
.animate-fade-up { animation: fade-up var(--t-slow) var(--ease-out) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
}

/* ------------------------------------------------------------
   9. UTILITIES
   ------------------------------------------------------------ */
.hide { display: none !important; }
@media (max-width: 767.98px)  { .hide-mobile  { display: none !important; } }
@media (min-width: 768px)     { .show-mobile  { display: none !important; } }
@media (max-width: 1023.98px) { .hide-tablet  { display: none !important; } }
@media (min-width: 1024px)    { .show-tablet-down { display: none !important; } }

.text-center { text-align: center; }
.text-right  { text-align: right; }
.w-full { width: 100%; }
.relative { position: relative; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.mt-12 { margin-top: var(--sp-12); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-8 { margin-bottom: var(--sp-8); }

.c-secondary { color: var(--c-secondary-dark); }
.c-accent    { color: var(--c-accent-text); }
.c-highlight { color: var(--c-highlight); }
.c-success   { color: var(--c-success); }
.c-warning   { color: #B45309; }
.c-error     { color: var(--c-error); }

/* Blueprint grid — the brand motif. A construction nod that
   isn't yellow hazard tape. Used behind heroes and empty states. */
.bg-blueprint {
  background-image:
    linear-gradient(rgba(255,255,255,.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.055) 1px, transparent 1px);
  background-size: 44px 44px;
}
.bg-blueprint-light {
  background-image:
    linear-gradient(rgba(15,23,42,.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15,23,42,.045) 1px, transparent 1px);
  background-size: 36px 36px;
}

/* Print: drop chrome, keep the estimate */
@media print {
  .site-header, .bottom-nav, .sidebar, .no-print, footer { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #CBD5E1; break-inside: avoid; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 10px; }
}
