/* ==========================================================================
   Numlytix Design System (numlytix-ds.css)
   Single source of truth for CSS variables, typography, light/dark themes,
   and the shared single-row header component (#nx-header).
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&family=Rajdhani:wght@500;600;700&display=swap');

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

:root {
  /* ── Surface & Border Tokens (Dark Default) ── */
  --bg0: #080c12;
  --bg1: #0d1117;
  --bg2: #111820;
  --bg3: #141c26;
  --bg4: #1a2333;
  --b1:  #1e2d40;
  --b2:  #253347;

  /* ── Brand & Module Accents ── */
  --cyan:   #00d4ff;
  --green:  #00e88a;
  --orange: #ff6b35;
  --purple: #a855f7;
  --yellow: #f0c060;
  --red:    #ff4d6a;

  /* ── Text Hierarchy ── */
  --t1: #d0dce8;
  --t2: #8ca0b8;
  --t3: #4a6380;

  /* ── Typography Families ── */
  --ff: 'IBM Plex Sans', sans-serif;
  --fd: 'Rajdhani', sans-serif;
  --fm: 'JetBrains Mono', monospace;
  --fb: var(--ff); /* legacy alias */

  /* ── Shared Typography Scale ── */
  --fs-xs:  11px;
  --fs-sm:  12px;
  --fs-md:  13px; /* base body size */
  --fs-lg:  15px;
  --fs-xl:  18px;
  --fs-2xl: 24px;
  --fs-3xl: 32px;

  /* ── Shared Header Metrics ── */
  --nx-header-h:   58px;
  --nx-logo-h:     36px;
  --nx-header-px:  16px;
  --nx-header-gap: 10px;
}


/* ── Gray Theme Overrides ── */
body.gray-theme {
  --bg0: #22262e;
  --bg1: #2a2f38;
  --bg2: #323842;
  --bg3: #3a414d;
  --bg4: #454d5b;
  --b1:  #4e5766;
  --b2:  #647082;

  --cyan:   #38bdf8;
  --green:  #34d399;
  --orange: #fb923c;
  --purple: #c084fc;
  --yellow: #fbbf24;
  --red:    #f87171;

  --t1: #f1f5f9;
  --t2: #cbd5e1;
  --t3: #94a3b8;
}

body.gray-theme #nx-header {
  background: var(--bg1);
  border-bottom-color: var(--b1);
}

/* ── Light Theme Overrides ── */
body.light-theme {
  --bg0: #f0f4f8;
  --bg1: #e8edf3;
  --bg2: #ffffff;
  --bg3: #f5f7fa;
  --bg4: #edf1f7;
  --b1:  #d0d9e4;
  --b2:  #b8c4d4;

  --cyan:   #0077aa;
  --green:  #1a8a50;
  --orange: #d44000;
  --purple: #7c3aed;
  --yellow: #b45a00;
  --red:    #d6264a;

  --t1: #1a2535;
  --t2: #3d5068;
  --t3: #7a90aa;
}

/* ── Semantic Aliases (resolved on body so light theme updates them cleanly) ── */
body {
  --bg:     var(--bg0);
  --border: var(--b1);
  --gold:   var(--yellow);

  font-family: var(--ff);
  font-size: var(--fs-md);
  line-height: 1.5;
  background: var(--bg0);
  color: var(--t1);
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ==========================================================================
   Shared Header Component (#nx-header)
   ========================================================================== */
#nx-header {
  background: var(--bg0);
  border-bottom: 1px solid var(--b1);
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  height: var(--nx-header-h);
  padding: 0 var(--nx-header-px);
  gap: var(--nx-header-gap);
  position: sticky;
  top: 0;
  z-index: 1100;
  flex-shrink: 0;
  user-select: none;
}

#nx-header .nx-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}

#nx-header .nav-logo-img {
  height: var(--nx-logo-h);
  max-height: var(--nx-logo-h);
  width: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

body.light-theme #nx-header {
  background: #f5f7fa;
  border-bottom-color: var(--b1);
}

body.light-theme #nx-header .nav-logo-img {
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.12));
}

/* ── Navigation Strip ── */
#nx-header .nx-nav {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 2px;
}

#nx-header .nx-nav::-webkit-scrollbar {
  display: none;
}

#nx-header .nx-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--fd);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 0 9px;
  height: 38px;
  flex-shrink: 0;
  white-space: nowrap;
  color: var(--t2);
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
  border-radius: 4px 4px 0 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#nx-header .nx-tab:hover {
  color: var(--t1);
  background: rgba(255, 255, 255, 0.05);
}

body.light-theme #nx-header .nx-tab[data-key="hydro"] { color: #0284c7; }

body.light-theme #nx-header .nx-tab:hover {
  background: rgba(0, 0, 0, 0.04);
}

#nx-header .nx-divider {
  width: 1px;
  height: 18px;
  background: var(--b2);
  margin: 0 4px;
  flex-shrink: 0;
}

/* ── Module Tab Accents ── */
#nx-header .nx-tab[data-key="pricing"],
#nx-header .nx-tab[data-key="tol"]   { color: var(--yellow); }
#nx-header .nx-tab[data-key="stat"]  { color: var(--cyan); }
#nx-header .nx-tab[data-key="pd"]    { color: var(--orange); }
#nx-header .nx-tab[data-key="gdt"]   { color: var(--purple); }
#nx-header .nx-tab[data-key="hydro"] { color: #38bdf8; }
#nx-header .nx-tab[data-key="learn"] { color: var(--green); }

/* ── Active Tab State ── */
#nx-header .nx-tab.is-active {
  border-bottom-color: currentColor;
  background: rgba(127, 127, 127, 0.10);
}

#nx-header .nx-tab[data-key="home"].is-active {
  color: var(--t1);
  border-bottom-color: var(--cyan);
}

/* ── Right Controls & Page Slot ── */
#nx-header .nx-right {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

#nx-header .nx-slot-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#nx-header .nx-theme-btn {
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.28);
  color: var(--cyan);
  padding: 5px 12px;
  height: 32px;
  cursor: pointer;
  border-radius: 6px;
  font-family: var(--fd);
  font-size: var(--fs-md);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

#nx-header .nx-theme-btn:hover {
  background: rgba(0, 212, 255, 0.16);
}

/* ── Shared Header Utility Buttons (Auth / Admin / Gates) ── */
.nav-login-btn {
  padding: 6px 14px;
  background: var(--cyan);
  color: #000;
  border: none;
  border-radius: 5px;
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
  font-family: var(--fd);
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.nav-login-btn:hover { opacity: 0.85; }
.nav-login-btn-signup {
  background: transparent;
  color: var(--cyan);
  border: 1px solid var(--cyan);
}
.nav-login-btn-signup:hover {
  background: rgba(0, 212, 255, 0.1);
  opacity: 1;
}
.nav-user-badge {
  font-size: var(--fs-sm);
  color: #000;
  font-weight: 800;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--cyan);
  border-radius: 50%;
  cursor: default;
  flex-shrink: 0;
}
.nav-admin-btn {
  padding: 4px 9px;
  font-size: var(--fs-xs);
  font-family: var(--fd);
  font-weight: 700;
  background: rgba(168, 85, 247, 0.2);
  color: var(--purple);
  border: 1px solid var(--purple);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-signout-btn {
  padding: 4px 9px;
  font-size: var(--fs-xs);
  font-family: var(--fd);
  font-weight: 700;
  background: transparent;
  color: var(--t3);
  border: 1px solid var(--b2);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.nav-signout-btn:hover {
  color: var(--orange);
  border-color: var(--orange);
}
.nav-gates-btn {
  padding: 4px 9px;
  font-size: var(--fs-xs);
  font-family: var(--fd);
  font-weight: 700;
  background: rgba(240, 192, 96, 0.15);
  color: var(--yellow);
  border: 1px solid rgba(240, 192, 96, 0.3);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Responsive & Print ── */
@media (max-width: 1280px) {
  #nx-header .nx-tab {
    font-size: 12.5px;
    padding: 0 7px;
  }
}

@media (max-width: 1024px) {
  #nx-header .nx-tab {
    font-size: 12px;
    padding: 0 6px;
  }
}

@media (max-width: 820px) {
  #nx-header {
    padding: 0 12px;
    gap: 8px;
  }
  #nx-header .nx-theme-label {
    display: none;
  }
}

@media print {
  #nx-header {
    display: none !important;
  }
}

/* ── Unified Auth Controls in #nx-header ── */
#nx-header .nx-auth-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#nx-header .nx-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--cyan);
  color: #000000;
  font-family: var(--ff);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex-shrink: 0;
  cursor: default;
  user-select: none;
}

body.light-theme #nx-header .nx-user-avatar {
  color: #ffffff;
}

#nx-header .nx-user-avatar.is-guest {
  background: var(--bg3);
  color: var(--t2);
  border: 1px solid var(--b2);
}

/* ── Shared Page Search Bar in #nx-header (used by Tolerance Stackup & GD&T) ── */
#nx-header .nx-search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

#nx-header .nx-search-input {
  width: 100px;
  height: 30px;
  background: var(--bg1);
  border: 1px solid var(--b2);
  border-radius: 15px;
  padding: 4px 10px;
  color: var(--t1);
  font-family: var(--ff);
  font-size: var(--fs-sm);
  outline: none;
  transition: width 0.18s ease, border-color 0.15s ease;
}

#nx-header .nx-search-input::placeholder {
  color: var(--t3);
}

#nx-header .nx-search-input:focus {
  width: 150px;
  border-color: var(--cyan);
}

body.light-theme #nx-header .nx-search-input {
  background: var(--bg2);
}

#nx-header .nx-search-results {
  display: none;
  position: absolute;
  top: 36px;
  right: 0;
  width: 380px;
  max-width: 90vw;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg2);
  border: 1px solid var(--b2);
  border-top: 2px solid var(--cyan);
  border-radius: 6px;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
  z-index: 9100;
  padding: 4px;
}

#nx-header .nx-search-opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 6px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: var(--fs-md);
  color: var(--t1);
}

#nx-header .nx-search-opt:hover,
#nx-header .nx-search-opt.is-sel {
  background: var(--bg4);
}

#nx-header .nx-search-opt em {
  color: var(--cyan);
  font-style: normal;
  font-weight: 700;
}

#nx-header .nx-search-cat {
  color: var(--t3);
  font-size: var(--fs-xs);
  white-space: nowrap;
  font-family: var(--fm);
  flex-shrink: 0;
}

#nx-header .nx-search-empty {
  padding: 10px;
  color: var(--t3);
  font-size: var(--fs-sm);
}

.nx-search-flash {
  animation: nxSearchFlash 1.5s ease;
}

@keyframes nxSearchFlash {
  0%, 55% { box-shadow: 0 0 0 2px var(--cyan); background: rgba(0, 212, 255, 0.12); }
  100%    { box-shadow: none; }
}

@media (max-width: 1120px) {
  #nx-header .nx-search-input {
    width: 96px;
  }
  #nx-header .nx-search-input:focus {
    width: 150px;
  }
}

@media (max-width: 820px) {
  #nx-header .nx-search-input {
    width: 82px;
  }
}
