/* ============================================
   OwnRules Documentation — Unified Dark Theme
   Centered Layout: Top Bar + Sidebar + Content
   ============================================ */

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

:root {
  --sidebar-width: 260px;
  --topbar-height: 56px;
  --bg: #101014;
  --bg-elevated: #18181c;
  --bg-surface: #1e1e24;
  --text-primary: #e4e4e8;
  --text-secondary: #8e8e96;
  --text-heading: #ffffff;
  --text-muted: #6e6e78;
  --link-color: #5b9ef5;
  --link-hover: #7db8ff;
  --accent: #5b9ef5;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.1);
  --code-bg: #16161a;
  --inline-code-bg: rgba(255, 255, 255, 0.08);
  --content-max-width: 820px;
  --active-bg: rgba(91, 158, 245, 0.1);
  --active-border: #5b9ef5;
  --layout-max-width: 1200px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Oxygen, Ubuntu, sans-serif;
  color: var(--text-primary);
  background: var(--bg);
  line-height: 1.7;
  min-height: 100vh;
}

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

a:hover {
  color: var(--link-hover);
}

/* ==========================================
   TOP HEADER BAR — Fixed, full width
   ========================================== */
.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 300;
}

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

.top-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  align-items: center;
}

.sidebar-toggle:hover {
  color: var(--text-heading);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-heading);
  text-decoration: none;
}

.header-brand:hover {
  color: var(--text-heading);
}

.header-logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.header-brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.3px;
}

.header-brand-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* --- Header Right (Search + Fab Link) --- */
.top-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-fab-link {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  transition: color 0.15s;
}

.header-fab-link:hover {
  color: var(--text-heading);
}

.header-search {
  position: relative;
  width: 280px;
}

.search-wrapper {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  padding: 7px 12px 7px 34px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  color: var(--text-heading);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

#search-input::placeholder {
  color: var(--text-muted);
}

#search-input:focus {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: 10px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 400;
  display: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.search-results.visible {
  display: block;
}

.search-result-item {
  display: block;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--active-bg);
  color: var(--text-heading);
}

.search-result-title {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-heading);
  margin-bottom: 2px;
}

.search-result-snippet {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.search-no-results {
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ==========================================
   PAGE WRAPPER — Centers sidebar + content
   ========================================== */
.page-wrapper {
  display: flex;
  max-width: var(--layout-max-width);
  margin: 0 auto;
  padding-top: var(--topbar-height);
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ==========================================
   SIDEBAR — Sticky inside centered wrapper
   ========================================== */
.sidebar {
  position: sticky;
  top: var(--topbar-height);
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: calc(100vh - var(--topbar-height));
  background: var(--bg);
  color: var(--text-secondary);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-subtle);
}

/* --- Sidebar Navigation --- */
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0 0 4px;
}

.nav-section-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 20px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  transition: color 0.15s;
}

.nav-section-toggle:hover {
  color: var(--text-primary);
}

.nav-section.open .nav-section-toggle {
  color: var(--text-primary);
}

.nav-chevron {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.nav-section.open .nav-chevron {
  transform: rotate(90deg);
}

.nav-list {
  list-style: none;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.nav-section.open .nav-list {
  max-height: 500px;
}

.nav-item a {
  display: block;
  padding: 5px 20px 5px 40px;
  font-size: 0.88rem;
  color: var(--text-secondary);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.nav-item a:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.03);
}

.nav-item.active a {
  color: var(--text-heading);
  background: var(--active-bg);
  border-left-color: var(--active-border);
  font-weight: 500;
}

/* --- Sidebar Footer --- */
.sidebar-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.8rem;
}

.sidebar-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.sidebar-footer a:hover {
  color: var(--text-primary);
}

/* --- Sidebar Overlay (Mobile) --- */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 150;
}

/* ==========================================
   CONTENT AREA — Fills remaining space
   ========================================== */
.content-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content-container {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 40px 48px;
  flex: 1;
  width: 100%;
}

/* ==========================================
   HOME PAGE
   ========================================== */
.home-hero {
  padding: 40px 0 32px;
}

.home-hero h1 {
  font-size: 2.2rem;
  font-weight: 400;
  color: var(--text-heading);
  line-height: 1.3;
}

.home-hero h1 strong {
  font-weight: 700;
}

.home-subtitle {
  margin-top: 12px;
  font-size: 1.1rem;
  color: var(--text-secondary);
}

.home-products {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  padding: 20px 0;
}

.product-card {
  display: block;
  padding: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.2s;
}

.product-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 24px rgba(91, 158, 245, 0.1);
  transform: translateY(-2px);
}

.product-card-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}

.product-card-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.product-card-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.product-card-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.product-card-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.product-card-page {
  display: inline-block;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.product-card-link {
  font-size: 0.88rem;
  color: var(--accent);
  font-weight: 500;
}

/* --- Particles Background --- */
#particles-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ==========================================
   DOCUMENTATION CONTENT
   ========================================== */
.doc-content {
  max-width: 100%;
}

.doc-content h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-heading);
  margin-bottom: 8px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.doc-content h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-top: 40px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}

.doc-content h3 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-top: 28px;
  margin-bottom: 8px;
}

.doc-content h4 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-heading);
  margin-top: 20px;
  margin-bottom: 8px;
}

.doc-content p {
  margin-bottom: 16px;
}

.doc-content ul, .doc-content ol {
  margin-bottom: 16px;
  padding-left: 28px;
}

.doc-content li {
  margin-bottom: 4px;
}

.doc-content li > ul, .doc-content li > ol {
  margin-top: 4px;
  margin-bottom: 4px;
}

/* Inline Code */
.doc-content code {
  background: var(--inline-code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', 'Menlo', monospace;
  color: #e4e4e8;
}

/* Code Blocks */
.doc-content pre.hljs {
  background: var(--code-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 20px;
  overflow-x: auto;
  line-height: 1.5;
}

.doc-content pre.hljs code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.85rem;
}

/* Blockquotes */
.doc-content blockquote {
  margin: 0 0 16px;
  padding: 12px 20px;
  border-left: 4px solid var(--accent);
  background: rgba(91, 158, 245, 0.06);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.doc-content blockquote p:last-child {
  margin-bottom: 0;
}

/* Tables */
.doc-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.doc-content th, .doc-content td {
  padding: 8px 14px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.doc-content th {
  background: var(--bg-elevated);
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-heading);
}

.doc-content td {
  font-size: 0.9rem;
}

.doc-content tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}

/* Images */
.doc-content img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  margin: 8px 0 16px;
}

/* Horizontal Rule */
.doc-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 32px 0;
}

/* Heading Anchors */
.doc-content .header-anchor {
  color: var(--text-secondary);
  text-decoration: none;
  margin-left: 8px;
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.2s;
}

.doc-content h1:hover .header-anchor,
.doc-content h2:hover .header-anchor,
.doc-content h3:hover .header-anchor,
.doc-content h4:hover .header-anchor {
  opacity: 0.6;
}

.doc-content .header-anchor:hover {
  opacity: 1;
  color: var(--link-color);
}

/* --- Doc Footer (sticky at bottom) --- */
.doc-footer {
  margin-top: auto;
  padding: 20px 48px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: var(--content-max-width);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.doc-footer-links {
  margin-bottom: 8px;
}

.doc-footer-links a {
  color: var(--text-muted);
  font-size: 0.82rem;
  transition: color 0.15s;
}

.doc-footer-links a:hover {
  color: var(--text-primary);
}

.doc-footer-sep {
  color: var(--text-muted);
  margin: 0 8px;
  opacity: 0.5;
}

/* ==========================================
   404 ERROR PAGE
   ========================================== */
.error-page {
  text-align: center;
  padding: 80px 20px;
}

.error-page h1 {
  font-size: 6rem;
  font-weight: 800;
  color: var(--border-medium);
  line-height: 1;
}

.error-page p {
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin: 16px 0 32px;
}

.error-home-link {
  display: inline-block;
  padding: 10px 24px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.2s;
}

.error-home-link:hover {
  background: #7db8ff;
  color: white;
}

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
  }

  .header-search {
    width: 180px;
  }

  .page-wrapper {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100vh;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .content-container {
    padding: 24px 20px;
  }

  .doc-footer {
    padding: 20px;
  }

  .home-hero h1 {
    font-size: 1.6rem;
  }

  .home-products {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 480px) {
  .header-brand-name {
    font-size: 0.9rem;
  }

  .header-brand-sub {
    display: none;
  }

  .header-fab-link {
    display: none;
  }

  .header-search {
    width: 140px;
  }

  .content-container {
    padding: 20px 16px;
  }

  .doc-content h1 {
    font-size: 1.5rem;
  }

  .doc-content h2 {
    font-size: 1.2rem;
  }

  .doc-content pre.hljs {
    padding: 12px;
    font-size: 0.8rem;
  }
}
