/* uSort-M Documentation Stylesheet */

:root {
  /* Light mode (default) */
  --color-bg: #fafafa;
  --color-sidebar: #f5f5f5;
  --color-border: #e5e5e5;
  --color-text: #333;
  --color-text-muted: #666;
  --color-text-light: #999;
  --color-link: #2563eb;
  --color-link-hover: #1d4ed8;
  --color-accent: #2563eb;
  --color-accent-light: #e0f2fe;
  --color-success: #059669;
  --color-success-light: #dcfce7;
  --color-success-dark: #166534;
  --color-warning: #d97706;
  --color-card-bg: white;
  --color-code-bg: #f6f8fa;
  --color-code-text: #24292f;
  --color-code-border: #d0d7de;
  --sidebar-width: 260px;
  --content-max-width: 900px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;
  --method-img-filter: none;
}

/* Dark mode */
[data-theme="dark"] {
  --color-bg: #1a1a2e;
  --color-sidebar: #16213e;
  --color-border: #2d3748;
  --color-text: #e2e8f0;
  --color-text-muted: #a0aec0;
  --color-text-light: #718096;
  --color-link: #60a5fa;
  --color-link-hover: #93c5fd;
  --color-accent: #60a5fa;
  --color-accent-light: #1e3a5f;
  --color-success: #34d399;
  --color-success-light: #86efac;
  --color-success-dark: #14532d;
  --color-card-bg: #1e293b;
  --color-code-bg: #0d1117;
  --color-code-text: #c9d1d9;
  --color-code-border: #30363d;
  --method-img-filter: invert(0.88) hue-rotate(180deg);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
}

/* Smooth transitions for all theme-affected elements */
*, *::before, *::after {
  transition: background-color 0.2s ease-in-out,
              border-color 0.2s ease-in-out,
              box-shadow 0.2s ease-in-out,
              fill 0.2s ease-in-out,
              stroke 0.2s ease-in-out;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
  text-decoration: none;
  color: var(--color-text);
}

.sidebar-header img {
  width: 48px;
  height: 48px;
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

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

.sidebar-nav li {
  margin-bottom: 0.25rem;
}

.sidebar-nav a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9375rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav a:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.sidebar-nav a.active {
  background: var(--color-card-bg);
  color: var(--color-text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.sidebar-section {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-light);
  margin: 1.5rem 0 0.5rem 0.75rem;
}

/* Theme toggle - positioned at top right */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  cursor: pointer;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  transition: background 0.2s, border-color 0.2s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.theme-toggle:hover {
  background: var(--color-sidebar);
  transform: scale(1.05);
}

.theme-toggle-icon {
  font-size: 1.125rem;
  line-height: 1;
}

/* Hide theme label - icon only */
#theme-label {
  display: none;
}

/* Main content */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 2rem 3rem;
}

.content {
  max-width: var(--content-max-width);
  margin: 0 auto;
  animation: fadeIn 0.3s ease-in-out;
}

/* Smooth page load animation */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Typography */
h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.3;
  margin-top: 2rem;
  margin-bottom: 1rem;
  border: none;
  border-bottom: none;
}

h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1rem; }

/* Ensure sections don't add borders */
section {
  border: none;
  border-bottom: none;
}

p {
  margin: 0 0 1rem;
}

a {
  color: var(--color-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Hero section */
.hero {
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid var(--color-border);
}

.hero-image {
  width: 200px;
  flex-shrink: 0;
}

.hero-image img {
  width: 100%;
  height: auto;
}

.hero-content h1 {
  margin-bottom: 0.5rem;
}

.hero-content .tagline {
  font-size: 1.25rem;
  color: var(--color-text-muted);
  margin-bottom: 1rem;
}

/* Method overview figure */
.method-figure {
  margin: 2rem 0;
  text-align: center;
}

.method-figure img {
  max-width: 68%;
  height: auto;
  border: none;
  border-radius: 8px;
  filter: var(--method-img-filter);
  will-change: filter;
}

.method-figure figcaption {
  margin-top: 0.75rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Input sentence styling */
.input-sentence {
  font-size: 1.25rem;
  line-height: 2.5;
  margin: 2rem 0;
}

.input-sentence .inline-input {
  display: inline-block;
  vertical-align: baseline;
}

.input-sentence input[type="number"] {
  width: 90px;
  padding: 0.375rem 0.5rem;
  font-size: 1.375rem;
  font-weight: 600;
  text-align: center;
  border: 2px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-card-bg);
  color: var(--color-accent);
  transition: width 0.2s ease, border-color 0.15s, background 0.3s;
}

.input-sentence input[type="number"]:focus {
  outline: none;
  border-color: var(--color-accent);
}

/* Cost visualization container */
.cost-chart {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

/* Results panel */
.results-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.result-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
}

.result-card .label {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.result-card .value {
  font-size: 1.75rem;
  font-weight: 600;
}

.result-card .value.accent {
  color: var(--color-accent);
}

.result-card .value.success {
  color: var(--color-success);
}

.result-card .subtext {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9375rem;
}

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

th {
  font-weight: 600;
  background: var(--color-sidebar);
}

tr:hover td {
  background: var(--color-sidebar);
}

/* Code blocks - darker grey theme */
code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-code-bg);
  color: var(--color-code-text);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
}

pre {
  background: var(--color-code-bg);
  color: var(--color-code-text);
  padding: 1.25rem 1.5rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.9rem;
  line-height: 1.6;
  border: 1px solid var(--color-code-border);
  position: relative;
}

/* Add subtle shadow for light mode */
:root pre {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] pre {
  box-shadow: none;
}

pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Syntax highlighting colors - Light mode (GitHub-inspired) */
:root pre .hljs-comment, :root pre .hljs-quote { color: #6e7781; }
:root pre .hljs-keyword, :root pre .hljs-selector-tag { color: #cf222e; }
:root pre .hljs-string, :root pre .hljs-doctag { color: #0a3069; }
:root pre .hljs-number, :root pre .hljs-literal { color: #0550ae; }
:root pre .hljs-built_in, :root pre .hljs-type { color: #953800; }
:root pre .hljs-function .hljs-title { color: #8250df; }
:root pre .hljs-variable, :root pre .hljs-attr { color: #0550ae; }
:root pre .hljs-params { color: #24292f; }
:root pre .hljs-meta { color: #8250df; }

/* Syntax highlighting colors - Dark mode (GitHub-inspired) */
[data-theme="dark"] pre .hljs-comment, [data-theme="dark"] pre .hljs-quote { color: #8b949e; }
[data-theme="dark"] pre .hljs-keyword, [data-theme="dark"] pre .hljs-selector-tag { color: #ff7b72; }
[data-theme="dark"] pre .hljs-string, [data-theme="dark"] pre .hljs-doctag { color: #a5d6ff; }
[data-theme="dark"] pre .hljs-number, [data-theme="dark"] pre .hljs-literal { color: #79c0ff; }
[data-theme="dark"] pre .hljs-built_in, [data-theme="dark"] pre .hljs-type { color: #ffa657; }
[data-theme="dark"] pre .hljs-function .hljs-title { color: #d2a8ff; }
[data-theme="dark"] pre .hljs-variable, [data-theme="dark"] pre .hljs-attr { color: #79c0ff; }
[data-theme="dark"] pre .hljs-params { color: #c9d1d9; }
[data-theme="dark"] pre .hljs-meta { color: #d2a8ff; }

/* Override any highlight.js default backgrounds and ensure proper text rendering */
pre .hljs,
pre [class*="hljs-"] {
  background: none !important;
  padding: 0;
  margin: 0;
}

/* Copy button for code blocks */
.code-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.2s, background 0.2s, color 0.2s;
  font-family: var(--font-sans);
}

pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  background: var(--color-accent-light);
  color: var(--color-accent);
  border-color: var(--color-accent);
}

.code-copy-btn:active {
  transform: scale(0.95);
}

.code-copy-btn.copied {
  color: var(--color-success);
  border-color: var(--color-success);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  text-decoration: none;
  border-radius: 6px;
  transition: background 0.15s, transform 0.1s;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--color-accent);
  color: white;
}

.btn-primary:hover {
  background: var(--color-link-hover);
}

.btn-secondary {
  background: var(--color-sidebar);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-border);
}

/* Feature grid */
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.feature-card {
  background: var(--color-card-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.5rem;
}

.feature-card h3 {
  margin-top: 0;
  font-size: 1.125rem;
}

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

/* Timeline */
.timeline {
  margin: 1.5rem 0;
  padding-left: 1rem;
  border-left: 2px solid var(--color-border);
}

.timeline-item {
  position: relative;
  padding: 0 0 1.5rem 1.5rem;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -0.5rem;
  top: 0.375rem;
  width: 0.75rem;
  height: 0.75rem;
  background: var(--color-accent);
  border-radius: 50%;
  border: 2px solid var(--color-bg);
}

.timeline-item .day {
  font-weight: 600;
  color: var(--color-text);
}

.timeline-item .task {
  color: var(--color-text-muted);
}

/* Callout/info boxes */
.callout {
  background: var(--color-accent-light);
  border-left: 4px solid var(--color-accent);
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin: 1.5rem 0;
  font-size: 0.9375rem;
}

.callout strong {
  color: var(--color-accent);
}

.callout code {
  background: var(--color-sidebar);
  color: var(--color-text);
  font-size: 0.875em;
}

/* Footer */
.footer {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

/* Mobile responsive */
@media (max-width: 900px) {
  .sidebar {
    width: 100%;
    position: fixed;
    height: auto;
    max-height: 100vh;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding: 1rem;
    overflow-y: auto;
    z-index: 90;
  }

  .sidebar-header {
    margin-bottom: 1rem;
    padding-right: 3rem; /* Make room for theme toggle */
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .sidebar-nav li {
    margin-bottom: 0;
  }

  .sidebar-nav a {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
  }

  .sidebar-section {
    display: none;
  }

  .theme-toggle {
    /* Keep fixed positioning from main style */
    top: 1rem;
    right: 1rem;
  }

  .main {
    margin-left: 0;
    margin-top: calc(100px + 1rem); /* Account for fixed sidebar height */
    padding: 1.5rem 1rem;
  }
  
  .hero {
    flex-direction: column;
    gap: 1rem;
  }
  
  .hero-image {
    width: 100px;
  }
  
  .method-figure img {
    max-width: 100%;
  }
  
  .input-sentence {
    font-size: 1.125rem;
    line-height: 2;
  }
  
  .input-sentence input[type="number"] {
    font-size: 1.125rem;
    width: 80px;
  }
  
  .cost-section {
    grid-template-columns: 1fr !important;
  }
  
  .quick-stats {
    grid-template-columns: 1fr !important;
  }
  
  .feature-grid {
    grid-template-columns: 1fr;
  }
  
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
}

@media (max-width: 480px) {
  .main {
    padding: 1rem 0.75rem;
  }
  
  pre {
    font-size: 0.8rem;
    padding: 1rem;
  }
  
  .btn {
    display: block;
    text-align: center;
    margin-bottom: 0.5rem;
  }
}