/* shade/css/styles.css */

/* --- Variables --- */
:root {
  --nav-height: 3.8rem;
  /* Slightly taller for modern feel */
  --sidebar-width: 17rem;
  --font-sans: ui-sans-serif, 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;
}

/* --- Global Reset --- */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-color);
  color: var(--text-color);
  line-height: 1.5;
  transition: background 0.2s, color 0.2s;
  -webkit-font-smoothing: antialiased;
  /* Crisp text on Mac */
}

/* --- Icons --- */
.sp-icon {
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

/* --- Header --- */
.sp-header {
  height: var(--nav-height);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  position: fixed;
  top: 0;
  width: 100%;
  background: var(--bg-color);
  z-index: 50;
  backdrop-filter: blur(8px);
  /* subtle blur if bg has opacity */
}

.sp-logo {
  font-weight: 700;
  font-size: 1.25rem;
  margin-right: auto;
  letter-spacing: -0.025em;
}

.nav-link {
  margin-left: 1.5rem;
  text-decoration: none;
  color: var(--subtext-color);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color 0.2s;
}

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

/* --- Layout --- */
.sp-layout {
  display: flex;
  padding-top: var(--nav-height);
  position: relative;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sp-sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border-color);
  background: var(--sidebar-bg);
  position: fixed;
  height: calc(100vh - var(--nav-height));
  overflow-y: auto;
  padding: 2rem 1rem;
  left: 0;
  bottom: 0;
  z-index: 40;
}

.sidebar-group {
  margin-bottom: 2rem;
}

.sidebar-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  width: 100%;
  background: none;
  border: none;
  padding: 0.25rem 0.5rem;
  color: var(--text-color);
  text-align: left;
}

.sidebar-group-header:hover {
  color: var(--primary-color);
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.chevron-icon {
  width: 1rem;
  height: 1rem;
  transition: transform 0.2s;
  opacity: 0.5;
}

.sidebar-group.collapsed .chevron-icon {
  transform: rotate(-90deg);
}

.sidebar-list {
  list-style: none;
  padding: 0.5rem 0 0 0;
  margin: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.sidebar-group.collapsed .sidebar-list {
  max-height: 0;
  display: none;
}

.sidebar-link {
  display: block;
  padding: 0.4rem 0.5rem;
  color: var(--subtext-color);
  text-decoration: none;
  font-size: 0.95rem;
  border-radius: 6px;
  transition: all 0.2s;
}

.sidebar-link:hover {
  color: var(--primary-color);
  background: rgba(127, 127, 127, 0.05);
}

.sidebar-link.active {
  color: var(--primary-color);
  background: rgba(127, 127, 127, 0.1);
  font-weight: 600;
}

.sidebar-mobile-nav,
.sidebar-divider {
  display: none;
}

/* --- Content Area --- */
.sp-content {
  margin-left: var(--sidebar-width);
  padding: 3rem 5rem;
  flex-grow: 1;
  min-width: 0;
  max-width: 100%;
}

/* --- MARKDOWN BODY (The Core Fixes) --- */
.markdown-body {
  font-size: 1.05rem;
  line-height: 1.75;
  /* Readability boost */
  color: var(--text-color);
}

.markdown-body h1 {
  font-size: 2.5rem;
  font-weight: 800;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 2.5rem;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.markdown-body h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-top: 3.5rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.markdown-body h3 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

.markdown-body p {
  margin-bottom: 1.5rem;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

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

/* INLINE CODE (Soft & Clean) */
.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background-color: var(--sidebar-bg);
  /* Subtle bg */
  border: 1px solid var(--border-color);
  /* Definition without loud color */
  border-radius: 4px;
  padding: 0.2em 0.4em;
  color: var(--primary-color);
  white-space: nowrap;
}

/* BLOCK CODE (The Bug Fix) */
/* This specific selector overrides the inline style above for code inside pre */
.markdown-body pre code {
  background-color: transparent;
  border: none;
  padding: 0;
  border-radius: 0;
  color: inherit;
  white-space: pre;
  /* Essential for code blocks */
  font-size: 1em;
}

.markdown-body pre {
  background-color: var(--code-block-bg);
  padding: 1.25rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  overflow-x: auto;
  margin: 1.5rem 0;
  position: relative;
  line-height: 1.5;
  font-size: 0.9em;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.markdown-body blockquote {
  border-left: 4px solid var(--primary-color);
  background: var(--sidebar-bg);
  padding: 1rem 1.5rem;
  margin: 2rem 0;
  border-radius: 0 8px 8px 0;
  font-style: italic;
  color: var(--subtext-color);
}

.markdown-body a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

.markdown-body a:hover {
  text-decoration: underline;
}

/* --- Table of Contents --- */
.sp-toc {
  width: 16rem;
  position: fixed;
  right: 0;
  top: var(--nav-height);
  bottom: 0;
  padding: 3rem 1.5rem;
  overflow-y: auto;
  border-left: 1px solid var(--border-color);
  background: var(--bg-color);
  z-index: 30;
}

.toc-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
  color: var(--text-color);
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 0.85rem;
}

.toc-link {
  display: block;
  color: var(--subtext-color);
  text-decoration: none;
  padding: 0.25rem 0;
  border-left: 2px solid transparent;
  padding-left: 1rem;
  transition: all 0.2s;
}

.toc-link:hover {
  color: var(--text-color);
}

.toc-link.active {
  color: var(--primary-color);
  border-left-color: var(--primary-color);
}

.toc-link.depth-3 {
  padding-left: 2rem;
}

/* --- Helpers --- */
.loading {
  text-align: center;
  padding: 4rem;
  color: var(--subtext-color);
}

.copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  color: var(--subtext-color);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s;
}

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

.copy-btn:hover {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

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

/* --- Pagination --- */
.sp-pagination {
  margin-top: 5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 1rem;
}

.page-link {
  border: 1px solid var(--border-color);
  padding: 1.5rem;
  border-radius: 8px;
  width: 50%;
  text-decoration: none;
  transition: all 0.2s;
}

.page-link:hover {
  border-color: var(--primary-color);
  transform: translateY(-2px);
}

.page-link span {
  display: block;
  font-size: 0.8rem;
  color: var(--subtext-color);
  margin-bottom: 0.25rem;
}

.page-link div {
  font-weight: 600;
  color: var(--primary-color);
  font-size: 1.1rem;
}

.page-link.next {
  text-align: right;
  margin-left: auto;
}

/* --- Search UI --- */
.search-trigger-wrapper {
  flex-grow: 1;
  display: flex;
  justify-content: flex-end;
  margin-right: 2rem;
}

.search-btn {
  background: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  color: var(--subtext-color);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  width: 200px;
  transition: all 0.2s;
}

.search-btn:hover {
  border-color: var(--primary-color);
  color: var(--text-color);
}

.search-key {
  margin-left: auto;
  font-size: 0.75rem;
  border: 1px solid var(--border-color);
  padding: 0.1rem 0.3rem;
  border-radius: 4px;
}

#theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--subtext-color);
  transition: color 0.2s;
  padding: 0.5rem;
}

#theme-toggle:hover {
  color: var(--primary-color);
}

#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-color);
  cursor: pointer;
}

/* --- Search Modal --- */
.search-modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 8vh;
  backdrop-filter: blur(4px);
}

.search-modal-backdrop.open {
  display: flex;
}

.search-modal-content {
  background: var(--bg-color);
  width: 100%;
  max-width: 600px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.search-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
}

#search-input {
  width: 100%;
  background: transparent;
  border: none;
  font-size: 1.1rem;
  color: var(--text-color);
  outline: none;
  height: 2rem;
}

#close-search {
  background: var(--sidebar-bg);
  border: 1px solid var(--border-color);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: var(--subtext-color);
  cursor: pointer;
  font-size: 0.75rem;
}

.search-results {
  padding: 1rem;
  overflow-y: auto;
}

.search-result-item {
  display: block;
  padding: 1rem;
  background: var(--sidebar-bg);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  text-decoration: none;
  border: 1px solid transparent;
  transition: all 0.2s;
}

.search-result-item:hover {
  border-color: var(--primary-color);
  transform: translateX(4px);
}

.search-result-title {
  color: var(--primary-color);
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 0.25rem;
  display: block;
}

.search-result-excerpt {
  color: var(--subtext-color);
  font-size: 0.85rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.search-footer {
  padding: 0.8rem;
  border-top: 1px solid var(--border-color);
  text-align: right;
  font-size: 0.75rem;
  color: var(--subtext-color);
}

.search-empty {
  text-align: center;
  color: var(--subtext-color);
  padding: 2rem;
}

/* --- Admonitions --- */
.admonition {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border-left: 4px solid;
  border-radius: 0 8px 8px 0;
  background: var(--sidebar-bg);
}

.admonition-title {
  font-weight: 800;
  margin: 0 0 0.5rem 0;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.admonition.info {
  border-color: #89b4fa;
  background: rgba(137, 180, 250, 0.08);
}

.admonition.info .admonition-title {
  color: #89b4fa;
}

.admonition.tip {
  border-color: #a6e3a1;
  background: rgba(166, 227, 161, 0.08);
}

.admonition.tip .admonition-title {
  color: #a6e3a1;
}

.admonition.warning {
  border-color: #f9e2af;
  background: rgba(249, 226, 175, 0.08);
}

.admonition.warning .admonition-title {
  color: #f9e2af;
}

.admonition.danger {
  border-color: #f38ba8;
  background: rgba(243, 139, 168, 0.08);
}

.admonition.danger .admonition-title {
  color: #f38ba8;
}

/* --- Edit Link --- */
.edit-link-wrapper {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px dashed var(--border-color);
  text-align: right;
}

.edit-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--subtext-color);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}

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

.edit-icon {
  width: 1em;
  height: 1em;
}

/* --- Responsive --- */
@media (max-width: 1200px) {
  .sp-toc {
    display: none;
  }

  .sp-content {
    padding-right: 3rem;
    margin-right: 0;
  }
}

@media (min-width: 1201px) {
  .sp-content {
    margin-right: 16rem;
  }
}

@media (max-width: 768px) {
  #menu-toggle {
    display: block;
  }

  .sp-sidebar {
    transform: translateX(-100%);
    width: 85%;
    max-width: 320px;
    height: 100vh;
    top: 0;
    box-shadow: 5px 0 15px rgba(0, 0, 0, 0.3);
  }

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

  .sp-content {
    margin-left: 0;
    padding: 2rem 1.25rem;
  }

  .sp-nav {
    display: none;
  }

  .sidebar-mobile-nav,
  .sidebar-divider {
    display: block;
  }

  .mobile-nav-link {
    display: block;
    padding: 0.5rem 0.5rem;
    color: var(--text-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 1rem;
    border-radius: 6px;
  }

  .mobile-nav-link:hover {
    background: var(--sidebar-bg);
  }

  .sp-pagination {
    flex-direction: column;
    gap: 1rem;
  }

  .page-link {
    width: 100%;
  }

  .search-btn {
    width: auto;
    padding: 0.4rem;
  }

  .search-placeholder,
  .search-key {
    display: none;
  }

  .search-modal-backdrop {
    padding-top: 0;
  }

  .search-modal-content {
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  /* Reset content margins on mobile */
  .sp-content {
    margin-right: 0 !important;
  }
}
