/* ===== MLX-Tune Documentation - Design System ===== */

/* --- CSS Custom Properties (Theming) --- */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f6f8fa;
  --bg-tertiary: #eef1f5;
  --bg-nav: rgba(255, 255, 255, 0.85);
  --text-primary: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #888888;
  --accent: #0066cc;
  --accent-hover: #0052a3;
  --accent-subtle: rgba(0, 102, 204, 0.08);
  --border: #e0e0e0;
  --border-light: #f0f0f0;
  --card-bg: #ffffff;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.1);
  --code-bg: #f6f8fa;
  --code-inline-bg: #f0f2f5;
  --nav-height: 64px;
  --sidebar-width: 260px;
  --content-max-width: 860px;
  --page-max-width: 1200px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-nav: rgba(13, 17, 23, 0.85);
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --accent-subtle: rgba(88, 166, 255, 0.08);
  --border: #30363d;
  --border-light: #21262d;
  --card-bg: #161b22;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  --card-shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.4);
  --code-bg: #161b22;
  --code-inline-bg: #1c2128;
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--nav-height) + 24px);
}

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.7;
  color: var(--text-primary);
  background: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.3;
  color: var(--text-primary);
  margin-bottom: 0.5em;
}

h1 { font-size: 2.5rem; letter-spacing: -0.03em; }
h2 { font-size: 1.75rem; letter-spacing: -0.02em; margin-top: 2.5rem; }
h3 { font-size: 1.25rem; margin-top: 2rem; }
h4 { font-size: 1.1rem; margin-top: 1.5rem; }

p { margin-bottom: 1rem; color: var(--text-secondary); }

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

strong { color: var(--text-primary); }

/* --- Navigation --- */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-nav);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

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

.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.nav-logo:hover { text-decoration: none; color: var(--text-primary); }
.nav-logo img {
  height: 28px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.nav-links a {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.nav-links a:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
  text-decoration: none;
}
.nav-links a.active {
  color: var(--accent);
  background: var(--accent-subtle);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  transition: all var(--transition);
  display: flex;
  align-items: center;
}
.theme-toggle:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
}

.github-link {
  display: flex;
  align-items: center;
  color: var(--text-secondary);
  transition: color var(--transition);
}
.github-link:hover { color: var(--text-primary); text-decoration: none; }
.github-link svg { width: 22px; height: 22px; fill: currentColor; }

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
}

/* --- Page Layout --- */
.page-wrapper {
  display: flex;
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding-top: var(--nav-height);
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  top: var(--nav-height);
  left: max(0px, calc((100vw - var(--page-max-width)) / 2));
  width: var(--sidebar-width);
  height: calc(100vh - var(--nav-height));
  padding: 24px 16px 24px 24px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg-primary);
  transition: background var(--transition), border-color var(--transition);
}

.sidebar-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-left: 12px;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav a {
  display: block;
  padding: 6px 12px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  transition: all var(--transition);
}
.sidebar-nav a:hover {
  color: var(--text-primary);
  background: var(--accent-subtle);
  text-decoration: none;
}
.sidebar-nav a.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: var(--accent-subtle);
}

.sidebar-nav .sub-item a {
  padding-left: 24px;
  font-size: 0.825rem;
}

.content {
  flex: 1;
  min-width: 0;
  max-width: var(--content-max-width);
  margin-left: var(--sidebar-width);
  padding: 40px 48px 80px;
}

/* No sidebar layout (home page) */
.content.full-width {
  margin-left: 0;
  max-width: 100%;
  padding: 0;
}

/* --- Hero Section --- */
.hero {
  text-align: center;
  padding: 80px 24px 60px;
  max-width: 800px;
  margin: 0 auto;
}

.hero-logo {
  width: 280px;
  max-width: 80%;
  margin-bottom: 24px;
}

.hero-tagline {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

.hero-install {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 32px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.hero-install:hover {
  border-color: var(--accent);
}
.hero-install .copy-icon {
  color: var(--text-muted);
  transition: color var(--transition);
}
.hero-install:hover .copy-icon {
  color: var(--accent);
}
.hero-install .copied-tooltip {
  position: absolute;
  top: -32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--bg-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font-body);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.hero-install .copied-tooltip.show {
  opacity: 1;
}

.hero-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
  cursor: pointer;
  border: none;
}
.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  border-color: var(--text-muted);
  background: var(--accent-subtle);
}

/* --- Feature Cards --- */
.features {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

.feature-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  transition: all var(--transition);
}
.feature-card:hover {
  box-shadow: var(--card-shadow-hover);
  border-color: var(--text-muted);
}

.feature-icon {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.feature-card h3 {
  font-size: 1rem;
  margin-top: 0;
  margin-bottom: 8px;
}

.feature-card p {
  font-size: 0.9rem;
  margin-bottom: 0;
  color: var(--text-secondary);
}

/* --- Sections --- */
.section {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 24px;
}

.section + .section {
  border-top: 1px solid var(--border-light);
}

.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 8px;
}

/* --- Code Blocks --- */
pre[class*="language-"] {
  background: #1e1e2e !important;
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin: 16px 0 24px;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.6;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

code[class*="language-"] {
  font-family: var(--font-mono);
  font-size: 0.875rem;
}

code:not([class*="language-"]) {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--code-inline-bg);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-primary);
}

.code-block-wrapper {
  position: relative;
}

.code-block-wrapper .copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: var(--font-body);
  transition: all var(--transition);
  opacity: 0;
}
.code-block-wrapper:hover .copy-btn { opacity: 1; }
.code-block-wrapper .copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.8);
}

/* Side-by-side code comparison */
.code-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 16px 0 24px;
}

.code-compare-panel {
  min-width: 0;
}

.code-compare-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 4px;
}

.code-compare pre[class*="language-"] {
  margin: 0;
  font-size: 0.8rem;
}

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

th {
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-secondary);
  font-size: 0.85rem;
}

td { color: var(--text-secondary); }

tr:hover td { background: var(--accent-subtle); }

/* --- Example Cards --- */
.example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin: 16px 0;
}

.example-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: all var(--transition);
}
.example-card:hover {
  box-shadow: var(--card-shadow-hover);
}

.example-card h4 {
  margin-top: 0;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.example-card p {
  font-size: 0.85rem;
  margin-bottom: 12px;
}

.example-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.example-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-subtle);
  color: var(--accent);
}

.example-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font-body);
}
.example-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.example-code {
  display: none;
  margin-top: 12px;
}
.example-code.open {
  display: block;
}

/* --- API Reference --- */
.api-module {
  margin-bottom: 40px;
}

.api-module-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
  cursor: pointer;
}

.api-module-header h2 {
  margin: 0;
  font-size: 1.3rem;
}

.api-module-header .module-path {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.api-entry {
  margin-bottom: 32px;
  padding-bottom: 32px;
  border-bottom: 1px solid var(--border-light);
}
.api-entry:last-child {
  border-bottom: none;
}

.api-signature {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 12px;
  overflow-x: auto;
  line-height: 1.5;
}

.api-signature .api-name {
  font-weight: 700;
  color: var(--accent);
}

.api-signature .api-param {
  color: var(--text-secondary);
}

.api-signature .api-default {
  color: var(--text-muted);
}

.api-decorator {
  display: block;
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 4px;
}

.api-description {
  margin-bottom: 12px;
}

.api-params {
  font-size: 0.85rem;
}

.api-params th {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.api-example {
  margin-top: 12px;
}

.api-example-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* --- Collapsible Sections --- */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.collapsible-header .chevron {
  transition: transform var(--transition);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.collapsible-header.open .chevron {
  transform: rotate(90deg);
}

.collapsible-content {
  display: none;
}
.collapsible-content.open {
  display: block;
}

/* --- Footer --- */
.footer {
  text-align: center;
  padding: 40px 24px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

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

/* --- Utility Classes --- */
.container {
  max-width: var(--page-max-width);
  margin: 0 auto;
  padding: 0 24px;
}

.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }

/* --- Callout / Note --- */
.callout {
  background: var(--accent-subtle);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 16px 20px;
  margin: 16px 0;
  font-size: 0.9rem;
}

.callout p { margin-bottom: 0; }

.callout-title {
  font-weight: 700;
  color: var(--accent);
  font-size: 0.85rem;
  margin-bottom: 4px;
}

/* --- Workflow Steps --- */
.workflow-steps {
  display: flex;
  gap: 20px;
  margin: 24px 0;
}

.workflow-step {
  flex: 1;
  text-align: center;
  padding: 24px 16px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  position: relative;
}

.workflow-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  border-radius: 50%;
  margin-bottom: 12px;
}

.workflow-step h4 {
  margin-top: 0;
  font-size: 0.95rem;
}

.workflow-step p {
  font-size: 0.85rem;
  margin-bottom: 0;
}

.workflow-arrow {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  font-size: 1.5rem;
  flex-shrink: 0;
}

/* --- Diff Viewer --- */
.diff-viewer {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 16px 0 24px;
  font-family: var(--font-mono);
  font-size: 0.825rem;
  line-height: 1.7;
}

.diff-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.diff-header .diff-file {
  color: var(--text-primary);
}

.diff-body {
  background: #1e1e2e;
  padding: 0;
  overflow-x: auto;
}

.diff-line {
  display: flex;
  padding: 0 16px;
  min-height: 1.7em;
  white-space: pre;
}

.diff-line-num {
  width: 36px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 12px;
  color: rgba(255, 255, 255, 0.25);
  user-select: none;
}

.diff-line-content {
  flex: 1;
  color: rgba(255, 255, 255, 0.75);
}

.diff-line.diff-remove {
  background: rgba(248, 81, 73, 0.15);
}
.diff-line.diff-remove .diff-line-content {
  color: #ffa198;
}
.diff-line.diff-remove .diff-line-content::before {
  content: '- ';
  color: #f85149;
  font-weight: 700;
}

.diff-line.diff-add {
  background: rgba(63, 185, 80, 0.15);
}
.diff-line.diff-add .diff-line-content {
  color: #7ee787;
}
.diff-line.diff-add .diff-line-content::before {
  content: '+ ';
  color: #3fb950;
  font-weight: 700;
}

.diff-line.diff-context .diff-line-content::before {
  content: '  ';
}

.diff-separator {
  padding: 4px 16px;
  background: rgba(88, 166, 255, 0.08);
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.75rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* --- Responsive --- */
@media (max-width: 1024px) {
  .sidebar {
    left: 0;
  }
}

@media (max-width: 768px) {
  h1 { font-size: 1.8rem; }
  h2 { font-size: 1.4rem; }

  .nav-links { display: none; }
  .mobile-toggle { display: block; }

  .nav-links.mobile-open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: var(--nav-height);
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    gap: 4px;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    width: 100%;
    height: auto;
    max-height: 60vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    z-index: 50;
    padding: 16px;
  }
  .sidebar.mobile-open {
    display: block;
  }

  .content {
    margin-left: 0;
    padding: 24px 16px 60px;
  }

  .features {
    grid-template-columns: 1fr;
    padding: 0 16px 40px;
  }

  .hero {
    padding: 40px 16px;
  }

  .hero-tagline { font-size: 1.2rem; }
  .hero-subtitle { font-size: 1rem; }

  .code-compare {
    grid-template-columns: 1fr;
  }

  .workflow-steps {
    flex-direction: column;
  }

  .workflow-arrow {
    transform: rotate(90deg);
    justify-content: center;
  }

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

  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 8px 10px;
  }
}

@media (max-width: 480px) {
  .hero-install {
    font-size: 0.8rem;
    padding: 10px 14px;
  }

  .hero-buttons {
    flex-direction: column;
    align-items: center;
  }
}
