/* 
  TraceForge Technical Engineering Blog & Case Study Stylesheet
  Design Standard: Restrained, publication-quality technical journalism
  Accessibility Target: WCAG 2.2 AA compliant
*/

:root {
  /* Palette: Dark Theme (Default) */
  --bg-primary: #0b0f17;
  --bg-secondary: #121824;
  --bg-tertiary: #1b2234;
  --bg-elevated: #222b40;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-inverse: #0f172a;
  
  --brand-primary: #ff5722;      /* Ember Orange */
  --brand-primary-hover: #f4511e;
  --brand-light: #ff8a65;
  --brand-dim: rgba(255, 87, 34, 0.15);
  
  --accent-cyan: #00e5ff;
  --accent-cyan-dim: rgba(0, 229, 255, 0.12);
  --accent-emerald: #10b981;
  --accent-emerald-dim: rgba(16, 185, 129, 0.12);
  --accent-amber: #f59e0b;
  --accent-amber-dim: rgba(245, 158, 11, 0.12);
  --accent-rose: #ef4444;
  --accent-rose-dim: rgba(239, 68, 68, 0.12);
  
  --border-subtle: #1e293b;
  --border-medium: #334155;
  --border-strong: #475569;
  
  --code-bg: #0d1117;
  --code-header-bg: #161b22;
  --code-text: #e6edf3;
  --code-keyword: #ff7b72;
  --code-string: #a5d6ff;
  --code-number: #79c0ff;
  --code-comment: #8b949e;
  --code-function: #d2a8ff;
  
  /* Typography Stack - Robust system fallback stack */
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, "Liberation Mono", monospace;
  
  /* Layout & Spacing */
  --container-max: 1200px;
  --article-max: 760px;
  --nav-height: 4rem;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  /* Focus & Motion */
  --focus-ring: 0 0 0 3px rgba(255, 87, 34, 0.4);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

/* Light Theme Override */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --bg-elevated: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #f8fafc;
  
  --brand-primary: #e64a19;
  --brand-primary-hover: #d84315;
  --brand-light: #ff7043;
  --brand-dim: rgba(230, 74, 25, 0.10);
  
  --accent-cyan: #0284c7;
  --accent-cyan-dim: rgba(2, 132, 199, 0.08);
  --accent-emerald: #059669;
  --accent-emerald-dim: rgba(5, 150, 105, 0.08);
  --accent-amber: #d97706;
  --accent-amber-dim: rgba(217, 119, 6, 0.08);
  --accent-rose: #dc2626;
  --accent-rose-dim: rgba(220, 38, 38, 0.08);
  
  --border-subtle: #e2e8f0;
  --border-medium: #cbd5e1;
  --border-strong: #94a3b8;
  
  --code-bg: #1e293b;
  --code-header-bg: #0f172a;
  --code-text: #f8fafc;
  
  --focus-ring: 0 0 0 3px rgba(230, 74, 25, 0.35);
}

/* Base Resets & Global Behavior */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-sans);
  font-size: 100%;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Accessibility Focus Ring */
:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 1rem;
  background: var(--brand-primary);
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  z-index: 9999;
  font-weight: 600;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 1rem;
}

/* Header & Navigation */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background-color: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color var(--transition-normal);
}

[data-theme="light"] .site-header {
  background-color: rgba(255, 255, 255, 0.88);
}

.nav-container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.125rem;
}

.brand-icon {
  width: 28px;
  height: 28px;
  background: linear-gradient(135deg, var(--brand-primary), var(--accent-amber));
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 0.875rem;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.theme-toggle-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}

/* Reading Progress Bar */
.progress-container {
  position: fixed;
  top: var(--nav-height);
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  z-index: 99;
}

.progress-bar {
  height: 100%;
  background: var(--brand-primary);
  width: 0%;
  transition: width 0.1s linear;
}

/* Article Layout */
.page-wrapper {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem 1.5rem;
  width: 100%;
}

.article-header {
  max-width: var(--article-max);
  margin: 0 auto 3.5rem auto;
}

.category-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--brand-primary);
  background: var(--brand-dim);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  border: 1px solid rgba(255, 87, 34, 0.3);
  margin-bottom: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.article-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
  color: var(--text-primary);
}

.article-subtitle {
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--text-secondary);
  margin-bottom: 2rem;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  padding: 1rem 0;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

/* Main Layout Grid with Table of Contents */
.content-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 3rem;
}

@media (min-width: 1024px) {
  .content-grid {
    grid-template-columns: 240px 1fr;
    align-items: start;
  }
}

/* Sticky Sidebar Table of Contents */
.toc-sidebar {
  display: none;
}

@media (min-width: 1024px) {
  .toc-sidebar {
    display: block;
    position: sticky;
    top: calc(var(--nav-height) + 2rem);
    max-height: calc(100vh - var(--nav-height) - 4rem);
    overflow-y: auto;
    padding-right: 1rem;
    border-right: 1px solid var(--border-subtle);
  }
}

.toc-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  font-size: 0.875rem;
}

.toc-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition-fast);
  line-height: 1.35;
  display: block;
}

.toc-link:hover, .toc-link.active {
  color: var(--brand-primary);
  font-weight: 600;
}

/* Article Body Typography */
.article-body {
  max-width: var(--article-max);
  margin: 0 auto;
  font-size: 1.0625rem;
  line-height: 1.75;
  color: var(--text-primary);
}

.article-body h2 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.015em;
  margin: 3rem 0 1.25rem 0;
  color: var(--text-primary);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.article-body h3 {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 2.25rem 0 1rem 0;
  color: var(--text-primary);
}

.article-body p {
  margin-bottom: 1.5rem;
  color: var(--text-primary);
}

.article-body p strong {
  color: var(--text-primary);
  font-weight: 600;
}

.article-body ul, .article-body ol {
  margin: 0 0 1.5rem 1.5rem;
  padding: 0;
}

.article-body li {
  margin-bottom: 0.5rem;
}

/* Callout Box Component */
.callout {
  padding: 1.25rem 1.5rem;
  margin: 2rem 0;
  border-radius: var(--radius-md);
  border-left: 4px solid var(--border-strong);
  background: var(--bg-secondary);
  font-size: 1rem;
}

.callout-title {
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.callout-info {
  border-left-color: var(--accent-cyan);
  background: var(--accent-cyan-dim);
}
.callout-info .callout-title { color: var(--accent-cyan); }

.callout-warning {
  border-left-color: var(--accent-amber);
  background: var(--accent-amber-dim);
}
.callout-warning .callout-title { color: var(--accent-amber); }

.callout-success {
  border-left-color: var(--accent-emerald);
  background: var(--accent-emerald-dim);
}
.callout-success .callout-title { color: var(--accent-emerald); }

.callout-danger {
  border-left-color: var(--accent-rose);
  background: var(--accent-rose-dim);
}
.callout-danger .callout-title { color: var(--accent-rose); }

/* Custom Code Block Component */
.code-block {
  margin: 2rem 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-medium);
  background-color: var(--code-bg);
}

.code-header {
  background-color: var(--code-header-bg);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.code-copy-btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
}

.code-copy-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.code-content {
  padding: 1.25rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--code-text);
  tab-size: 2;
}

.code-content pre {
  margin: 0;
  white-space: pre;
}

/* Data Table Component */
.table-wrapper {
  overflow-x: auto;
  margin: 2rem 0;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9375rem;
}

.data-table th, .data-table td {
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

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

.data-table td.number {
  font-family: var(--font-mono);
  text-align: right;
}

.data-table th.number {
  text-align: right;
}

.text-danger {
  color: var(--accent-rose);
  font-weight: 700;
}

.text-success {
  color: var(--accent-emerald);
  font-weight: 700;
}

.badge-ship {
  display: inline-block;
  background: var(--accent-emerald-dim);
  color: var(--accent-emerald);
  border: 1px solid var(--accent-emerald);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
}

/* SVG & Screenshot Image Containers */
.diagram-container {
  margin: 2.5rem 0;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

.diagram-caption {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.diagram-svg {
  width: 100%;
  height: auto;
  display: block;
}

/* Telemetry Screenshot Gallery Component */
.gallery-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin: 2.5rem 0;
}

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

.screenshot-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.screenshot-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand-primary);
}

.screenshot-img {
  width: 100%;
  height: auto;
  display: block;
  border-bottom: 1px solid var(--border-subtle);
  background: #000;
}

.screenshot-body {
  padding: 1.25rem;
}

.screenshot-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.screenshot-desc {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Metric Interactive Switcher Component */
.interactive-widget {
  margin: 2.5rem 0;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
}

.widget-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.tab-btn {
  background: transparent;
  border: 1px solid var(--border-medium);
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--brand-dim);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}

/* Section Footer & Call to Action */
.cta-box {
  margin: 4rem 0 2rem 0;
  padding: 2.5rem 2rem;
  background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  text-align: center;
}

.cta-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.cta-desc {
  color: var(--text-secondary);
  max-width: 600px;
  margin: 0 auto 1.5rem auto;
}

.cta-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--brand-primary);
  color: #ffffff;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  text-decoration: none;
  transition: background var(--transition-fast);
}

.cta-btn:hover {
  background: var(--brand-primary-hover);
}

/* Site Footer */
.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
  padding: 2.5rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer-container {
  max-width: var(--container-max);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1.5rem;
}

/* Reduced Motion Override */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
