/* RESET & VARIABLES */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ICON STYLES */
.icon {
  width: 20px;
  height: 20px;
  vertical-align: middle;
  display: inline-block;
}

.icon-large {
  width: 24px;
  height: 24px;
}

.icon-small {
  width: 16px;
  height: 16px;
}

/* Icon in sidebar nav */
.sidebar nav a .icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Icon in search modal */
.search-header .icon {
  width: 24px;
  height: 24px;
}

.search-close-btn .icon {
  width: 20px;
  height: 20px;
}

/* Icon in mobile menu buttons */
.mobile-menu-btn .icon {
  width: 20px;
  height: 20px;
}

/* Icon in header search button */
.header-search-btn .icon {
  width: 20px;
  height: 20px;
}

/* Icon in result category badges */
.result-category .icon {
  width: 16px;
  height: 16px;
  margin-right: 0.4rem;
  vertical-align: middle;
}

/* Icon in suggestions */
.suggestion-item .icon {
  width: 16px;
  height: 16px;
  margin-right: 0.75rem;
  flex-shrink: 0;
}

/* Icon color inversion for light theme */
/* For SVG icons with white/light strokes, invert to dark on light theme */
[data-theme="light"] .icon,
[data-theme="light"] .logo img {
  filter: brightness(0) saturate(100%);
}

/* Specific adjustments for icons that need different treatment */
[data-theme="light"] .result-category .icon {
  filter: none; /* Keep category icons as-is since they have specific colors */
}

:root[data-theme="light"] {
  --text: #0f161a;
  --text-light: #47535c;
  --background: #e5edf5;
  --background-secondary: #d1dbe6;
  --card-bg: #f5f7fa;
  --primary: #194c6b;
  --secondary: #75bff0;
  --accent: #194c6b;
  --border: #b8c5d1;
  --highlight-bg: #028fed;
  --highlight-text: #ffffff;
  --error-color: #e74c3c;
  --header-height: 70px;
  --footer-height: 120px;
  --hover-bg: rgba(2, 143, 237, 0.1);
}

:root[data-theme="dark"] {
  --text: #e5ecf0;
  --text-light: #94a3b1;
  --background: #0a121a;
  --background-secondary: #141e29;
  --card-bg: #1a2530;
  --primary: #94c6e6;
  --secondary: #0f598a;
  --accent: #129ffd;
  --border: #1f3a4d;
  --highlight-bg: #129ffd;
  --highlight-text: #ffffff;
  --error-color: #ff6b6b;
  --header-height: 70px;
  --footer-height: 120px;
  --hover-bg: rgba(18, 159, 253, 0.15);
}

:root {
  --text: #e5ecf0;
  --text-light: #94a3b1;
  --background: #0a121a;
  --background-secondary: #141e29;
  --card-bg: #1a2530;
  --primary: #94c6e6;
  --secondary: #0f598a;
  --accent: #129ffd;
  --border: #1f3a4d;
  --highlight-bg: #129ffd;
  --highlight-text: #ffffff;
  --error-color: #ff6b6b;
  --header-height: 70px;
  --footer-height: 120px;
  --hover-bg: rgba(18, 159, 253, 0.15);
}

body {
  font-family: 'IBM Plex Sans', sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

/* LAYOUT CONTAINER */
.container {
  display: grid;
  grid-template-columns: 250px 1fr 280px;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "header header header"
    "sidebar main toc"
    "footer footer footer";
  min-height: 100vh;
  gap: 0;
}

/* HEADER */
header {
  grid-area: header;
  background: var(--background-secondary);
  border-bottom: 0.5px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  height: var(--header-height);
  justify-content: space-between;
  position: sticky;
  top: 0; 
  z-index: 100; 
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text);
  font-size: 1.5rem;
  font-weight: bold;
}

.logo img {
  width: 32px;
  height: 32px;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: 0.5px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.mobile-menu-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* HEADER SEARCH BUTTON */
.header-search-btn {
  background: none;
  border: 0.5px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.75rem;
  font-size: 1rem;
}

.header-search-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* SIDEBAR (LEFT) */
.sidebar {
  grid-area: sidebar;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  background: var(--background-secondary);
  border-right: 0.5px solid var(--border);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar nav ul {
  list-style: none;
  flex: 1;
}

.sidebar nav li {
  margin: 0.5rem 1rem;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  text-decoration: none;
  color: var(--text);
  border: 0.5px solid transparent;
  background: transparent;
  transition: all 0.2s ease;
}

.sidebar nav a:hover {
  background: var(--background-secondary);
  border: 0.5px solid var(--accent);
  border-radius: 8px;
}

.sidebar nav a.active {
  background: var(--background-secondary);
  border: 0.5px solid var(--primary);
  border-radius: 8px;
  color: var(--accent);
  font-weight: 600;
}

.search-box {
  padding: 1rem;
  border-top: 0.5px solid var(--border);
  margin-top: auto;
}

.search-box input {
  width: 100%;
  padding: 0.75rem;
  background: var(--background-secondary);
  border: 0.5px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.2);
}

/* SIDEBAR SEARCH (Desktop) */
.sidebar-search {
  padding: 1rem;
  border-top: 0.5px solid var(--border);
  margin-top: auto;
}

.sidebar-search input {
  width: 100%;
  padding: 0.75rem;
  background: var(--background-secondary);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

.sidebar-search input:hover {
  border-color: var(--accent);
  border-radius: 8px;
}

/* Header search button hidden on desktop */
.header-search-btn {
  display: none;
}

/* MAIN CONTENT */
.main-content {
  grid-area: main;
  padding: 2rem;
  background: var(--background);
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
  overflow-x: hidden;
}

.content-box {
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  padding: 2rem;
  min-height: 800px;
  width: 100%;
}

/* Markdown Content Styling */
#content {
  line-height: 1.7;
}

#content h1 {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  color: var(--accent);
  border-bottom: 0.5px solid var(--border);
  padding-bottom: 0.5rem;
}

#content h2 {
  font-size: 2rem;
  margin: 1.5rem 0 1rem 0;
  color: var(--text);
}

#content h3 {
  font-size: 1.5rem;
  margin: 1.25rem 0 0.75rem 0;
  color: var(--text);
  padding-left: 0.5rem;
  border-left: 0.5px solid var(--accent);

}

#content h4 {
  font-size: 1.25rem;
  margin: 1rem 0 0.5rem 0;
  color: var(--text-light);
}

#content p {
  margin-bottom: 1rem;
}

#content ul, #content ol {
  margin: 0 0 1rem 1.5rem;
}

#content li {
  margin-bottom: 0.5rem;
}

#content a {
  color: var(--accent);
  text-decoration: none;
}

#content a:hover {
  text-decoration: underline;
}

#content code {
  background: var(--background-secondary);
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

#content pre {
  background: var(--background-secondary);
  border: 0.5px solid var(--border);
  padding: 1rem;
  overflow-x: auto;
  margin: 1rem 0;
}

#content pre code {
  background: transparent;
  padding: 0;
}

#content blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 1rem;
  margin: 1rem 0;
  color: var(--text-light);
}

#content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

#content th, #content td {
  border: 2px solid var(--border);
  padding: 0.5rem;
  text-align: left;
}

#content th {
  background: var(--background-secondary);
  font-weight: 600;
}

#content .highlight {
  background-color: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 0.1rem 0.2rem;
  border-radius: 2px;
}

#content .loading, #content .error {
  text-align: center;
  padding: 3rem;
}

#content .error {
  color: var(--error-color);
}

/* TOC SIDEBAR (RIGHT) */
.toc-sidebar {
  grid-area: toc;
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  background: var(--background-secondary);
  border-left: 0.5x solid var(--border);
  padding: 1.5rem;
  overflow-y: auto;
}

.toc-title {
  font-size: 1.2rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--accent);
  font-weight: 500;
}

.toc-nav ul {
  list-style: none;
}

.toc-nav li {
  margin-bottom: 0.5rem;
}

.toc-nav a {
  display: block;
  padding: 0.5rem 0.75rem;
  color: var(--text-light);
  text-decoration: none;
  border-left: 0.5px solid transparent;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.toc-nav a:hover {
  color: var(--text);
  border-left: 0.5px solid var(--accent);
  padding-left: 1rem;
}

.toc-nav a.active {
  color: var(--accent);
  border-left: 0.5px solid var(--accent);
  font-weight: 500;
  background-color: var(--hover-bg);
}

/* FOOTER */
footer {
  grid-area: footer;
  background: var(--background-secondary);
  border-top: 0.5px solid var(--border);
  padding: 1.5rem;
  text-align: center;
}

footer p {
  color: var(--text-light);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

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

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

.footer-links {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

/* SEARCH MODAL STYLES */
.search-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  backdrop-filter: blur(4px);
  padding: 1rem;
}

.search-modal.active {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10vh;
}

.search-modal-content {
  background: var(--card-bg);
  border: 0.5px solid var(--border);
  border-radius: 8px;
  width: 100%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Search Header */
.search-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  background: var(--background-secondary);
}

.search-icon {
  color: var(--text-light);
  font-size: 1.25rem;
}

#searchModalInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  padding: 0.5rem 0;
}

#searchModalInput:focus {
  outline: none;
}

#searchModalInput::placeholder {
  color: var(--text-light);
}

.search-close-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.5rem;
  transition: color 0.2s ease;
}

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

/* Search Suggestions */
.search-suggestions {
  display: none;
  border-bottom: 0.5px solid var(--border);
  background: var(--background-secondary);
  max-height: 200px;
  overflow-y: auto;
}

.search-suggestions.active {
  display: block;
}

.suggestion-item {
  padding: 0.75rem 1.25rem;
  cursor: pointer;
  transition: background 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text);
}

.suggestion-item:hover,
.suggestion-item.selected {
  background: var(--hover-bg);
}

.suggestion-item i {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Search Results */
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.search-results:empty {
  display: none;
}

.search-results.has-results {
  padding: 0.5rem 0;
}

.search-result-item {
  padding: 1rem 1.25rem;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-result-item:hover,
.search-result-item.selected {
  background: var(--hover-bg);
  border-left: 1.5px solid var(--accent);
  padding-left: calc(1.25rem - 3px);
}

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

.result-category {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 0.25rem 0.5rem;
  border-radius: 2px;
  background: var(--accent);
  color: #fff;
  width: fit-content;
}

.result-category.film { background: #e74c3c; }
.result-category.music { background: #9b59b6; }
.result-category.tools { background: #3498db; }
.result-category.books { background: #27ae60; }

.result-section {
  font-size: 0.85rem;
  color: var(--text-light);
  font-weight: 500;
}

.result-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
}

.result-text mark {
  background: var(--highlight-bg);
  color: var(--highlight-text);
  padding: 0.1rem 0.2rem;
  border-radius: 2px;
  font-weight: 600;
}

/* Show More Button */
.show-more-btn {
  display: block;
  width: calc(100% - 2.5rem);
  margin: 0.75rem 1.25rem;
  padding: 0.75rem;
  background: var(--background-secondary);
  border: 0.5px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border-radius: 4px;
}

.show-more-btn:hover {
  border-color: var(--accent);
  background: var(--hover-bg);
}

/* No Results State */
.no-results {
  padding: 2rem;
  text-align: center;
  color: var(--text-light);
}

.no-results i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.no-results h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.no-results p {
  font-size: 0.9rem;
}

/* Search Footer */
.search-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-top: 0.5px solid var(--border);
  background: var(--background-secondary);
  font-size: 0.8rem;
  color: var(--text-light);
}

.search-shortcuts {
  display: flex;
  gap: 1rem;
}

.search-shortcuts span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.search-shortcuts kbd {
  background: var(--border);
  border: 0.5px solid #333;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-family: inherit;
  font-size: 0.75rem;
}

.search-status {
  font-style: italic;
}

.search-status.ready {
  color: #27ae60;
}

/* Sidebar Search Trigger */
.search-box {
  padding: 1rem;
  border-top: 0.5px solid var(--border);
  margin-top: auto;
  cursor: pointer;
}

.search-trigger-input {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--background-secondary);
  border: 0.5px solid var(--border);
  border-radius: 4px;
  color: var(--text-light);
  transition: all 0.2s ease;
}

.search-box:hover .search-trigger-input {
  border-color: var(--accent);
  color: var(--text);
}

.search-trigger-input i {
  font-size: 0.9rem;
}

.search-trigger-input span {
  font-size: 0.9rem;
}

/* MOBILE RESPONSIVE */
@media (max-width: 1024px) {
  .container {
    grid-template-columns: 1fr;
    grid-template-areas: 
      "header"
      "main"
      "footer";
  }
  
  .sidebar,
  .toc-sidebar {
    position: fixed;
    top: 0;
    height: 100vh;
    z-index: 1000;
    display: none;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  }
  
  .sidebar {
    left: 0;
    width: 280px;
    border-right: 0.5px solid var(--border);
  }
  
  .toc-sidebar {
    right: 0;
    width: 280px;
    border-left: 0.5px solid var(--border);
  }
  
  .sidebar.active,
  .toc-sidebar.active {
    display: flex;
    flex-direction: column;
  }
  
  .mobile-menu-btn {
    display: block;
  }
  
  .overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 999;
  }
  
  .overlay.active {
    display: block;
  }
  
  .mobile-controls {
    display: flex;
    gap: 0.5rem;
    margin-right: 0.5rem;
  }
  
  .main-content {
    margin-left: 0;
    margin-right: 0;
    padding: 1.5rem;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
  }
  
  /* Mobile: Show header search button, hide sidebar search */
  .header-search-btn {
    display: flex;
    background: none;
    border: 0.5px solid var(--border);
    color: var(--text);
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.2s ease;
    align-items: center;
    justify-content: center;
    margin-left: 0.75rem;
    font-size: 1rem;
  }
  
  .header-search-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
  
  .sidebar-search {
    display: none;
  }
}

@media (max-width: 768px) {
  .main-content {
    padding: 1rem;
  }
  
  .content-box {
    padding: 1.5rem;
    max-width: 100%;
  }
  
  #content h1 {
    font-size: 2rem;
  }
  
  #content h2 {
    font-size: 1.75rem;
  }
  
  #content h3 {
    font-size: 1.5rem;
  }
  
  .sidebar,
  .toc-sidebar {
    width: 100%;
    max-width: 320px;
  }
}

@media (max-width: 480px) {
  .container {
    min-height: 100vh;
  }
  
  header {
    padding: 1rem;
    position: sticky;
    top: 0;
  }
  
  .logo span {
    font-size: 1.25rem;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .content-box {
    padding: 1rem;
  }
  
  .footer-links img {
    max-width: 88px;
    height: auto;
  }
}

/* Mobile Responsive for Search Modal */
@media (max-width: 768px) {
  .search-modal {
    padding: 0;
  }
  
  .search-modal.active {
    padding-top: 0;
    align-items: stretch;
  }
  
  .search-modal-content {
    max-width: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  
  .search-header {
    padding: 1rem;
  }
  
  #searchModalInput {
    font-size: 1rem;
  }
  
  .search-shortcuts {
    display: none;
  }
  
  .search-footer {
    justify-content: center;
  }
  
  .search-result-item {
    padding: 0.875rem 1rem;
  }
  
  .result-text {
    font-size: 0.9rem;
  }
}

/* THEME TOGGLE BUTTON */
.theme-toggle {
  background: none;
  border: 0.5px solid var(--border);
  color: var(--text);
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 0.75rem;
  font-size: 1rem;
  border-radius: 4px;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.theme-toggle .icon {
  width: 20px;
  height: 20px;
}

/* Mobile theme toggle */
@media (max-width: 1024px) {
  .theme-toggle {
    display: flex;
  }
}

/* Dark theme icons */
[data-theme="dark"] .theme-toggle .sun-icon {
  display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
  display: none;
}

/* Light theme icons */
[data-theme="light"] .theme-toggle .sun-icon {
  display: none;
}

[data-theme="light"] .theme-toggle .moon-icon {
  display: block;
}
