:root {
  --bg-primary: #0f0f1a;
  --bg-sidebar: #1a1a2e;
  --bg-hover: #2a2a4a;
  --bg-active: #3a3a6a;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --text-accent: #6c8cff;
  --border: #2a2a3e;
  --sidebar-width: 280px;
  --header-height: 48px;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

.header {
  height: var(--header-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}

.header-title span {
  color: var(--text-accent);
}

.layout {
  display: flex;
  height: calc(100% - var(--header-height));
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

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

.sidebar-tab.active {
  color: var(--text-accent);
  border-bottom-color: var(--text-accent);
}

.tab-panel {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
}

.sidebar-search {
  padding: 12px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
}

.sidebar-search input:focus {
  border-color: var(--text-accent);
}

.sidebar-search input::placeholder {
  color: var(--text-secondary);
}

.chapter-list {
  list-style: none;
  padding: 4px 0;
}

.chapter-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.15s;
  gap: 12px;
}

.chapter-item:hover {
  background: var(--bg-hover);
}

.chapter-item.active {
  background: var(--bg-active);
}

.chapter-code {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-accent);
  min-width: 32px;
  font-family: "SF Mono", "Fira Code", monospace;
}

.chapter-title {
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-item.active .chapter-title {
  color: #fff;
}

.search-results {
  padding: 4px 0;
  flex: 1;
  overflow-y: auto;
}

.search-group {
  border-bottom: 1px solid var(--border);
}

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

.search-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 4px;
}

.search-result-code {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-accent);
  font-family: "SF Mono", "Fira Code", monospace;
  min-width: 28px;
}

.search-group-title {
  font-size: 12px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.search-group-count {
  font-size: 10px;
  color: var(--text-secondary);
  background: var(--bg-hover);
  padding: 1px 6px;
  border-radius: 8px;
  flex-shrink: 0;
}

.search-match {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 16px 3px 36px;
  cursor: pointer;
  transition: background 0.1s;
}

.search-match:hover {
  background: var(--bg-hover);
}

.search-match-page {
  font-size: 10px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--text-secondary);
  flex-shrink: 0;
  min-width: 24px;
}

.search-match-snippet {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-match-snippet mark {
  background: rgba(108, 140, 255, 0.3);
  color: var(--text-primary);
  padding: 0 1px;
  border-radius: 2px;
}

.search-match-more {
  padding: 3px 16px 6px 36px;
  font-size: 11px;
  color: var(--text-secondary);
}

.search-empty {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

.viewer-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.viewer-container iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
}

@media (max-width: 768px) {
  .hamburger {
    display: block;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 60;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }

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

  .overlay.open {
    display: block;
  }

  .viewer-container {
    width: 100%;
  }
}
