/* ReadBrain Design System — Dark editorial theme */
:root {
  /* Backgrounds */
  --bg-primary: #0D1117;
  --bg-secondary: #161B22;
  --bg-elevated: #21262D;
  --bg-overlay: rgba(13, 17, 23, 0.85);

  /* Accents */
  --accent-warm: #E6A817;
  --accent-warm-dim: #9B6F0E;
  --accent-warm-glow: rgba(230, 168, 23, 0.15);

  /* Text */
  --text-primary: #E6EDF3;
  --text-secondary: #8B949E;
  --text-dim: #484F58;

  /* Borders */
  --border: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(230, 168, 23, 0.3);

  /* Layout */
  --sidebar-width: 280px;
  --notes-width: 380px;
  --notes-panel-width: 380px;
  --header-height: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius: 12px;
  --radius-lg: 18px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  --glow-warm: 0 0 20px rgba(230, 168, 23, 0.3);

  /* Typography */
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "DM Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", monospace;

  /* Animation */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-fast: 150ms;
  --duration-normal: 250ms;
  --duration-slow: 400ms;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --duration-fast: 0ms;
    --duration-normal: 0ms;
    --duration-slow: 0ms;
    --ease-spring: linear;
    --ease-smooth: linear;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
}

/* Grain overlay */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  z-index: 9999;
}

/* Layout */
.app-layout {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr var(--notes-width);
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.header-icon-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.25rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
}

.header-icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

@media (max-width: 768px) {
  .header-icon-btn {
    display: flex;
  }
}

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

.logo-icon {
  color: var(--accent-warm);
  font-size: 1.25rem;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
}

.search-wrapper {
  flex: 1;
  max-width: 400px;
  position: relative;
}

.search-wrapper input {
  width: 100%;
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease-smooth);
}

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

.search-wrapper input::placeholder {
  color: var(--text-dim);
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.search-dropdown.hidden {
  display: none;
}

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

.header-btn {
  padding: 0.375rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--duration-fast), color var(--duration-fast);
}

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

.header-btn.active {
  color: var(--accent-warm);
  border-color: var(--border-accent);
}

.header-stats {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  font-family: var(--font-display);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.book-list {
  padding: 0 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.book-card {
  padding: 1rem 1rem 1rem 1.25rem;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  border-left: 4px solid var(--border);
  cursor: pointer;
  animation: sidebarItemIn var(--duration-slow) var(--ease-smooth) backwards;
  transition:
    transform var(--duration-fast) var(--ease-smooth),
    background var(--duration-fast) var(--ease-smooth),
    box-shadow var(--duration-fast) var(--ease-smooth);
}

@keyframes sidebarItemIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.book-card:hover {
  transform: translateY(-2px);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-md);
}

.book-card[data-color] {
  border-left-color: attr(data-color color);
}

.book-card-header {
  cursor: pointer;
  outline: none;
}

.book-card-header:focus-visible {
  outline: 2px solid var(--accent-warm);
  outline-offset: 2px;
}

.book-card-title-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.book-expand-icon {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  transition: transform var(--duration-fast);
}

.book-card.expanded .book-expand-icon {
  transform: rotate(90deg);
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-chapters {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.book-chapters.hidden {
  display: none;
}

.chapter-item {
  display: block;
  width: 100%;
  padding: 0.375rem 0.5rem;
  font-family: var(--font-body);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  text-align: left;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.chapter-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.book-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.book-author {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.book-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.book-rating {
  color: var(--accent-warm);
  font-size: 0.75rem;
}

.book-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.5rem;
}

.book-tag {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  padding: 0.125rem 0.5rem;
  background: transparent;
  border: 1px solid var(--border-accent);
  border-radius: 4px;
  color: var(--text-secondary);
}

.book-tag.concept-chip {
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast), color var(--duration-fast);
}

.book-tag.concept-chip:hover {
  background: var(--accent-warm-glow);
  border-color: var(--accent-warm);
  color: var(--accent-warm);
}

/* Mindmap canvas */
.mindmap-canvas {
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

.mindmap-canvas svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Notes panel */
.notes-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.notes-panel.collapsed {
  transform: translateX(100%);
  position: absolute;
  right: 0;
  top: var(--header-height);
  bottom: 0;
  width: var(--notes-width);
  z-index: 50;
}

.panel-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--duration-fast), background var(--duration-fast);
  z-index: 10;
}

.panel-close:hover {
  color: var(--text-primary);
  background: var(--bg-elevated);
}

.notes-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 2rem;
}

/* Notes panel content */
.notes-breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.notes-breadcrumb .book-title {
  font-style: italic;
}

.notes-breadcrumb .book-title-link {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color var(--duration-fast);
}

.notes-breadcrumb .book-title-link:hover {
  color: var(--accent-warm);
}

.chapter-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.chapter-nav-btn {
  padding: 0.375rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--duration-fast), color var(--duration-fast);
}

.chapter-nav-btn:hover {
  color: var(--accent-warm);
  border-color: var(--border-accent);
}

.chapter-nav-indicator {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.chapter-nav-placeholder {
  min-width: 4rem;
}

.notes-chapter-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.notes-meta-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ai-badge {
  padding: 0.125rem 0.5rem;
  background: var(--accent-warm-glow);
  border: 1px solid var(--border-accent);
  border-radius: 4px;
  color: var(--accent-warm);
  font-size: 0.6875rem;
}

.ai-card {
  padding: 1rem;
  margin-bottom: 1.5rem;
  background: var(--accent-warm-glow);
  border-left: 2px solid var(--accent-warm);
  border-radius: var(--radius-sm);
  position: relative;
}

.ai-card-label {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--accent-warm);
}

.notes-body {
  font-size: 0.9375rem;
  line-height: 1.6;
}

.notes-body h1,
.notes-body h2,
.notes-body h3 {
  font-family: var(--font-display);
  margin-top: 1.25rem;
  margin-bottom: 0.5rem;
}

.notes-body ul,
.notes-body ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.notes-body p {
  margin: 0.5rem 0;
}

.actionable-list {
  list-style: none;
  padding-left: 0;
  margin: 1rem 0;
}

.actionable-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.actionable-list li::before {
  content: "☐";
  font-size: 1rem;
  font-weight: 500;
  color: var(--accent-warm);
}

.connected-ideas {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 1rem 0;
}

.idea-chip {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--duration-fast), color var(--duration-fast);
}

.idea-chip:hover {
  border-color: var(--border-accent);
  color: var(--accent-warm);
}

.notes-tags {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.notes-tags .book-tags {
  margin-top: 0.5rem;
}

/* Search result item */
.search-result-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--duration-fast);
}

.search-result-item:hover {
  background: var(--bg-primary);
}

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

.search-result-book {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

.search-result-title {
  font-family: var(--font-display);
  font-size: 0.875rem;
}

/* Responsive */
@media (max-width: 1200px) {
  .notes-panel {
    position: absolute;
    right: 0;
    top: var(--header-height);
    bottom: 0;
    width: var(--notes-width);
    z-index: 50;
    transform: translateX(100%);
    transition: transform var(--duration-normal) var(--ease-smooth);
  }

  .notes-panel.open {
    transform: translateX(0);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.4);
  }

  .app-layout {
    grid-template-columns: var(--sidebar-width) 1fr;
  }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--header-height);
  background: rgba(0, 0, 0, 0.5);
  z-index: 35;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-smooth);
}

@media (max-width: 768px) {
  .sidebar-overlay.visible {
    display: block;
    opacity: 1;
  }

  .sidebar {
    position: absolute;
    left: 0;
    top: var(--header-height);
    bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-smooth);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
  }

  .app-layout {
    grid-template-columns: 1fr;
  }
}
