/* ============================================================
   PepRecon shared stylesheet
   Used by root domain + all 5 calculator subdomains
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  /* Light theme (Clinical) — default */
  --bg:            #f7f8fa;
  --bg-elevated:   #ffffff;
  --bg-subtle:     #eef0f4;
  --border:        #e3e6ec;
  --border-strong: #c9cfd9;
  --text:          #1a1f2b;
  --text-muted:    #5a6478;
  --text-faint:    #8a93a4;
  --accent:        #0891a8;
  --accent-hover:  #0a7d92;
  --accent-soft:   #e6f4f7;
  --accent-text:   #ffffff;
  --shadow-sm:     0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md:     0 4px 6px rgba(15, 23, 42, 0.05), 0 10px 20px rgba(15, 23, 42, 0.06);
  --focus-ring:    0 0 0 3px rgba(8, 145, 168, 0.25);
  --danger:        #b91c1c;
  --danger-soft:   #fef2f2;
  --success:       #047857;
  --success-soft:  #ecfdf5;
}

[data-theme="dark"] {
  /* Dark theme (Tech) */
  --bg:            #0d1117;
  --bg-elevated:   #161b22;
  --bg-subtle:     #1c232c;
  --border:        #2a323d;
  --border-strong: #3a4554;
  --text:          #e6edf3;
  --text-muted:    #9ba7b6;
  --text-faint:    #6b7785;
  --accent:        #2dd4bf;
  --accent-hover:  #5eead4;
  --accent-soft:   #042f2e;
  --accent-text:   #0d1117;
  --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md:     0 4px 6px rgba(0, 0, 0, 0.35), 0 10px 20px rgba(0, 0, 0, 0.5);
  --focus-ring:    0 0 0 3px rgba(45, 212, 191, 0.3);
  --danger:        #f87171;
  --danger-soft:   #2a1414;
  --success:       #34d399;
  --success-soft:  #0c2620;
}

/* Auto mode follows system preference */
@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg:            #0d1117;
    --bg-elevated:   #161b22;
    --bg-subtle:     #1c232c;
    --border:        #2a323d;
    --border-strong: #3a4554;
    --text:          #e6edf3;
    --text-muted:    #9ba7b6;
    --text-faint:    #6b7785;
    --accent:        #2dd4bf;
    --accent-hover:  #5eead4;
    --accent-soft:   #042f2e;
    --accent-text:   #0d1117;
    --shadow-sm:     0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md:     0 4px 6px rgba(0, 0, 0, 0.35), 0 10px 20px rgba(0, 0, 0, 0.5);
    --focus-ring:    0 0 0 3px rgba(45, 212, 191, 0.3);
    --danger:        #f87171;
    --danger-soft:   #2a1414;
    --success:       #34d399;
    --success-soft:  #0c2620;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: 'Inter Tight', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background-color: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}
a:hover { color: var(--accent-hover); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  padding: 56px 0 16px;
  text-align: center;
}

.wordmark {
  font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
  font-weight: 600;
  font-size: clamp(2rem, 5vw, 2.75rem);
  letter-spacing: -0.04em;
  margin: 0;
  color: var(--text);
}

.wordmark .accent { color: var(--accent); }

/* Generic accent text — usable in any heading */
.accent { color: var(--accent); }

.tagline {
  margin: 8px 0 0;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

/* ---------- Theme switcher ---------- */
.theme-switcher {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 50;
  display: inline-flex;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow-sm);
}

.theme-switcher button {
  background: transparent;
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 999px;
  transition: color 0.15s ease, background-color 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1;
}

.theme-switcher button:hover {
  color: var(--text);
}

.theme-switcher button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
}

.theme-switcher button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.theme-switcher svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- App grid (root page) ---------- */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 40px 0 48px;
}

.app-card {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  row-gap: 4px;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  overflow: hidden;
}

.app-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.25s ease;
}

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

.app-card:hover::before { transform: scaleX(1); }

.app-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: var(--accent);
}

.app-card .app-icon {
  grid-column: 1;
  grid-row: 1;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 9px;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.app-card:hover .app-icon {
  transform: scale(1.05);
}

.app-card .app-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-card .app-title {
  grid-column: 2;
  grid-row: 1;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}

.app-card .app-desc {
  grid-column: 1 / -1;
  grid-row: 2;
  margin: 6px 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ---------- Calculator pages — form layout ---------- */
.calc-shell {
  max-width: 640px;
  margin: 32px auto 48px;
  padding: 0 24px;
}

.calc-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

.calc-card h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.calc-card .calc-sub {
  margin: 0 0 24px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -moz-appearance: textfield;
}

.field input[type="number"]::-webkit-outer-spin-button,
.field input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

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

.field .field-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* Inline unit selector (e.g. mcg / mg toggle) */
.field-row {
  display: flex;
  gap: 8px;
}
.field-row > *:first-child { flex: 1; }
.field-row select {
  width: auto;
  min-width: 90px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  line-height: 1;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover {
  background: var(--bg-subtle);
}

.btn-block { width: 100%; }

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Result display */
.result {
  margin-top: 24px;
  padding: 20px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  border-left: 3px solid var(--accent);
}

.result.hidden { display: none; }

.result-label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.result-value {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  letter-spacing: -0.01em;
}

.result-detail {
  margin: 4px 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.result + .result { margin-top: 12px; }

.result.error {
  background: var(--danger-soft);
  border-left-color: var(--danger);
}
.result.error .result-value,
.result.error .result-label { color: var(--danger); }

/* ---------- Hamburger nav (used by calculator pages, not root) ---------- */
.nav-toggle {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 50;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease;
}

.nav-toggle:hover { background: var(--bg-subtle); }

.nav-toggle:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.nav-toggle svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 99;
}

.nav-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.nav-drawer {
  position: fixed;
  top: 0;
  left: -280px;
  width: 260px;
  height: 100%;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  transition: left 0.25s ease;
  z-index: 100;
  padding: 64px 20px 20px;
}

.nav-drawer.active { left: 0; }

.nav-drawer .nav-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 22px;
  border-radius: 6px;
}
.nav-drawer .nav-close:hover { background: var(--bg-subtle); color: var(--text); }

.nav-drawer ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-drawer li { margin: 0; }

.nav-drawer a {
  display: block;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: 6px;
  transition: background-color 0.12s ease;
}

.nav-drawer a:hover {
  background: var(--bg-subtle);
  color: var(--accent);
}

.nav-drawer a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-drawer .nav-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 4px 6px;
  list-style: none;
}

.nav-drawer .nav-section span {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  white-space: nowrap;
}

.nav-drawer .nav-section::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: auto;
  padding: 24px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
}

.site-footer a {
  color: var(--text-muted);
}

.site-footer a:hover { color: var(--accent); }

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

.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .container { padding: 0 16px; }
  .site-header { padding: 80px 0 12px; }
  .calc-shell { padding: 0 16px; margin-top: 80px; }
  .calc-card { padding: 20px; }
  .result-value { font-size: 1.25rem; }

  /* Force 2-column tile grid on mobile so cards stay card-shaped */
  .app-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 28px 0 36px;
  }
  .app-card {
    padding: 16px;
    column-gap: 10px;
  }
  .app-card .app-icon {
    width: 32px;
    height: 32px;
  }
  .app-card .app-icon svg { width: 18px; height: 18px; }
  .app-card .app-title { font-size: 1rem; }
  .app-card .app-desc {
    font-size: 0.8rem;
    line-height: 1.4;
    margin-top: 4px;
  }
}

/* Very small screens — even tighter */
@media (max-width: 360px) {
  .app-card .app-desc { display: none; }
  .app-card { padding: 14px; }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
