/* CSS Variables for consistent theming - matching app styles */
:root {
  --screenshot-max-height: 400px;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #3b82f6;
  --secondary: #64748b;
  --secondary-hover: #475569;
  --accent: #f59e0b;
  --accent-hover: #d97706;
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --warning-hover: #d97706;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-dark: #f1f5f9;
  --surface-darker: #e2e8f0;
  --border: #e2e8f0;
  --border-dark: #cbd5e1;
  --border-focus: #3b82f6;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md:
    0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg:
    0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl:
    0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --radius: 0.375rem;
  --radius-lg: 0.5rem;
  --transition: all 0.2s ease-in-out;
  --text-primary: var(--text);
}

/* Dark theme variables */
[data-theme='dark'] {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #60a5fa;
  --secondary: #94a3b8;
  --secondary-hover: #cbd5e1;
  --accent: #fbbf24;
  --accent-hover: #f59e0b;
  --success: #34d399;
  --success-hover: #10b981;
  --warning: #fbbf24;
  --warning-hover: #f59e0b;
  --danger: #f87171;
  --danger-hover: #ef4444;
  --background: #0f172a;
  --surface: #1e293b;
  --surface-dark: #334155;
  --surface-darker: #475569;
  --border: #334155;
  --border-dark: #475569;
  --border-focus: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md:
    0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg:
    0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
  --shadow-xl:
    0 20px 25px -5px rgba(0, 0, 0, 0.3), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
  --text-primary: var(--text);
}

/* Improved dark mode styles */
[data-theme='dark'] {
  color-scheme: dark;
}

/* Base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Smooth theme transitions */
*,
*::before,
*::after {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.3s ease;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}

/* App container */

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}


/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-left h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
  display: flex;
  align-items: center;
}

.app-logo {
  height: 2rem;
  width: 2rem;
  margin-right: 0.5rem;
}

.header-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Dropdown component */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  background: none;
  border: none;
  cursor: pointer;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  z-index: 1000;
  display: none;
  min-width: 200px;
  padding: 0.5rem 0;
  margin: 0.125rem 0 0;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.dropdown.active .dropdown-menu {
  display: block !important;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
}

.dropdown-item:hover {
  background: var(--surface-dark);
}

/* Navigation */
.main-nav {
  display: flex;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  background: var(--surface-dark);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 73px; /* Height of header (padding + content) */
  z-index: 9;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  text-decoration: none;
  color: var(--text-muted);
  border-radius: var(--radius);
  transition: var(--transition);
  white-space: nowrap;
  font-weight: 500;
}

.nav-link:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-link.active {
  background: var(--primary);
  color: white;
}

.nav-link i {
  font-size: 1rem;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 2rem 1.5rem;
}

.content-section {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
}

.content-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-header {
  margin-bottom: 2rem;
}

.section-header h2 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0;
}

.section-content {
  max-width: 900px;
  position: relative;
}

/* Ensure reference section content works with TOC */
#reference .section-content {
  width: 100%;
}

/* Table of Contents */
.section-with-toc {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}

.section-content-wrapper {
  flex: 1;
  min-width: 0;
  max-width: 900px;
  display: flex;
  flex-direction: column;
}

.toc-container {
  position: sticky;
  top: var(--sticky-offset, 145px); /* Use CSS custom property synced with JS */
  width: 250px;
  flex-shrink: 0;
  max-height: calc(100vh - var(--sticky-offset, 145px) - 20px);
  overflow-y: auto;
  padding: 1rem;
  background: var(--surface-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.toc-container h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.75rem 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

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

.toc-list li {
  margin: 0;
  padding: 0;
}

.toc-list a {
  display: block;
  padding: 0.375rem 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  border-radius: var(--radius);
  transition: var(--transition);
}

.toc-list a:hover {
  color: var(--primary);
  background: var(--surface);
}

.toc-list a.active {
  color: var(--primary);
  background: var(--surface);
  font-weight: 500;
}

.toc-list .toc-level-2 {
  padding-left: 0.5rem;
}

.toc-list .toc-level-3 {
  padding-left: 1rem;
  font-size: 0.8125rem;
  color: var(--text-light);
}

.toc-list .toc-level-4 {
  padding-left: 1.5rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Add anchor IDs to headings */
.content-section h2,
.content-section h3,
.content-section h4,
.content-section h5 {
  scroll-margin-top: var(--sticky-offset, 145px); /* Use CSS custom property synced with JS */
}

.content-section h2[id],
.content-section h3[id],
.content-section h4[id] {
  position: relative;
}

/* Responsive: Hide TOC on smaller screens */
@media (max-width: 1200px) {
  .section-with-toc {
    flex-direction: column;
  }
  
  .toc-container {
    position: relative;
    top: 0;
    width: 100%;
    max-height: none;
    margin-top: 2rem;
    order: -1;
  }
}

@media (max-width: 768px) {
  .toc-container {
    display: none;
  }
  
  .section-content-wrapper {
    max-width: 100%;
  }
}

/* Intro card */
.intro-card {
  background: var(--surface-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 3rem;
  text-align: center;
}

.intro-card .lead {
  font-size: 1.25rem;
  color: var(--text);
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
}

/* Features grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.feature-card {
  background: var(--surface-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  transition: var(--transition);
}

.feature-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.feature-icon {
  width: 60px;
  height: 60px;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}

.feature-card p {
  color: var(--text-muted);
  line-height: 1.6;
}

/* Guide content */
.guide-content {
  background: var(--surface-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.guide-content h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary);
  margin-top: 2rem;
  margin-bottom: 1rem;
}

.guide-content h3:first-child {
  margin-top: 0;
}

.guide-content p {
  color: var(--text);
  margin-bottom: 1.5rem;
  line-height: 1.8;
}

.guide-list {
  margin-left: 2rem;
  margin-bottom: 2rem;
  color: var(--text);
}

.guide-list li {
  margin-bottom: 1rem;
  line-height: 1.8;
}

/* Code blocks */
.code-block {
  background: var(--surface-darker);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
  font-family: 'Courier New', Consolas, 'Monaco', monospace;
  font-size: 0.875rem;
  line-height: 1.6;
}

.code-block code {
  color: var(--primary);
  background: transparent;
  padding: 0;
  border: none;
  font-family: inherit;
}

[data-theme='dark'] .code-block {
  background: var(--surface-darker);
  border-color: var(--border-dark);
}

[data-theme='dark'] .code-block code {
  color: var(--primary-light);
}

/* Screenshot styling */
.screenshot {
  display: block;
  width: min(100%, calc(var(--screenshot-max-height, 400px) * 16 / 9));
  aspect-ratio: 16 / 9;
  height: auto;
  max-height: var(--screenshot-max-height, 400px);
  margin: 1.5rem auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  background: var(--surface-dark);
  object-fit: contain;
}

[data-theme='dark'] .screenshot {
  border-color: var(--border-dark);
  box-shadow: var(--shadow-lg);
}

/* Command categories */
.command-categories {
  margin: 1.5rem 0;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Reference tabs */
.reference-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border);
}

.reference-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: -2px;
}

.reference-tab:hover {
  color: var(--text);
  background: var(--surface-dark);
}

.reference-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: transparent;
}

.reference-tab i {
  font-size: 0.875rem;
}

.reference-tab-content {
  display: none;
  animation: fadeIn 0.3s ease-in-out;
  width: 100%;
}

.reference-tab-content.active {
  display: block;
}

/* Reference callout box */
.reference-callout {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
  background: #e0f2fe;
  border: 1px solid #7dd3fc;
  border-radius: var(--radius-lg);
  width: 100%;
}

.reference-callout i {
  color: #0369a1;
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.reference-callout p {
  margin: 0;
  color: #0c4a6e;
  line-height: 1.6;
  font-size: 0.9375rem;
}

[data-theme='dark'] .reference-callout {
  background: #1e3a5f;
  border-color: #3b82f6;
}

[data-theme='dark'] .reference-callout i {
  color: #60a5fa;
}

[data-theme='dark'] .reference-callout p {
  color: #bfdbfe;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  min-height: 35px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

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

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

.btn-icon {
  padding: 0.5rem;
  min-width: 2.5rem;
}

/* Footer */
.app-footer {
  background: var(--surface-dark);
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  margin-top: auto;
}

.footer-content {
  text-align: center;
  color: var(--text-muted);
}

.footer-content p {
  margin-bottom: 0.5rem;
}

.footer-link {
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
}

.footer-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Footer nav links shouldn't have nav-link default styles */
.footer-link.nav-link {
  display: inline;
  padding: 0;
  background: none;
  border: none;
  font-size: inherit;
  font-weight: inherit;
  gap: 0;
}

.footer-link.nav-link:hover {
  background: none;
}

.footer-link.nav-link.active {
  color: var(--text-muted);
  background: none;
}

.footer-content a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}

.footer-content a:hover {
  text-decoration: underline;
}

.footer-content i {
  margin-right: 0.5rem;
  color: var(--primary);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--surface-dark);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) var(--surface-dark);
}

/* Responsive design */
@media (max-width: 768px) {
  .app-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .header-right {
    order: 3;
    width: 100%;
    justify-content: flex-end;
  }

  .main-nav {
    padding: 0.75rem 1rem;
  }

  .nav-link {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }

  .main-content {
    padding: 1.5rem 1rem;
  }

  .section-header h2 {
    font-size: 1.5rem;
  }

  .features-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .intro-card {
    padding: 1.5rem;
  }

  .guide-content {
    padding: 1.5rem;
  }
}

@media (max-width: 480px) {
  .header-left h1 {
    font-size: 1.25rem;
  }

  .nav-link span {
    display: none;
  }

  .nav-link {
    padding: 0.75rem;
    min-width: 48px;
    justify-content: center;
  }
}
