/* Awesome Data Engineering BR — Ebook Library Styles */
:root {
  --color-primary: #004aad;
  --color-primary-dark: #003580;
  --color-primary-light: #e8f0fe;
  --color-bg: #ffffff;
  --color-bg-secondary: #f8f9fb;
  --color-bg-tertiary: #f0f2f5;
  --color-text: #1a1a2e;
  --color-text-secondary: #5a6270;
  --color-text-muted: #8b939e;
  --color-border: #e2e6ed;
  --color-border-light: #eef1f5;
  --color-success: #0d7a4a;
  --color-warning: #b45309;
  --color-danger: #c0392b;
  --color-info: #0369a1;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  --sidebar-width: 280px;
  --header-height: 56px;
  --toc-width: 240px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --transition: 150ms ease;
  --content-max-width: 780px;
  --font-size-base: 16px;
  --line-height: 1.7;
}

[data-theme="dark"] {
  --color-primary: #4d8fff;
  --color-primary-dark: #3b7ae8;
  --color-primary-light: #1a2744;
  --color-bg: #0f1117;
  --color-bg-secondary: #161922;
  --color-bg-tertiary: #1e2230;
  --color-text: #e8eaed;
  --color-text-secondary: #a0a8b8;
  --color-text-muted: #6b7385;
  --color-border: #2a2f3d;
  --color-border-light: #222733;
  --color-success: #34d399;
  --color-warning: #fbbf24;
  --color-danger: #f87171;
  --color-info: #60a5fa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.5);
}

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

html {
  scroll-behavior: smooth;
  font-size: var(--font-size-base);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary-dark); text-decoration: underline; }
a:focus-visible, button:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Skip link */
.skip-link {
  position: absolute; top: -100%; left: 16px; z-index: 9999;
  padding: 8px 16px; background: var(--color-primary); color: #fff;
  border-radius: var(--radius); font-weight: 600;
}
.skip-link:focus { top: 16px; }

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-height);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  display: flex; align-items: center; padding: 0 16px; gap: 12px;
}
.site-header__logo {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: .95rem; color: var(--color-text);
  text-decoration: none; white-space: nowrap;
}
.site-header__logo:hover { text-decoration: none; color: var(--color-primary); }
.site-header__logo svg { width: 28px; height: 28px; flex-shrink: 0; }
.site-header__search { flex: 1; max-width: 400px; position: relative; }
.site-header__search input {
  width: 100%; padding: 8px 12px 8px 36px;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-bg-secondary); color: var(--color-text);
  font-size: .875rem; transition: border-color var(--transition);
}
.site-header__search input:focus { border-color: var(--color-primary); outline: none; }
.site-header__search svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--color-text-muted); pointer-events: none;
}
.site-header__actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: none; border-radius: var(--radius);
  background: transparent; color: var(--color-text-secondary);
  cursor: pointer; transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--color-bg-secondary); color: var(--color-text); }
.btn-icon svg { width: 18px; height: 18px; }

/* Progress bar */
.reading-progress {
  position: fixed; top: var(--header-height); left: 0; right: 0;
  height: 3px; z-index: 99; background: var(--color-border-light);
}
.reading-progress__bar {
  height: 100%; width: 0; background: var(--color-primary);
  transition: width 100ms linear;
}

/* Layout */
.layout { display: flex; min-height: calc(100vh - var(--header-height)); }
.layout--catalog { flex-direction: column; max-width: 1200px; margin: 0 auto; padding: 32px 24px; }

.sidebar {
  width: var(--sidebar-width); flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-secondary);
  overflow-y: auto; position: sticky;
  top: var(--header-height); height: calc(100vh - var(--header-height));
  padding: 16px 0;
}
.sidebar__title {
  padding: 0 16px 8px; font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; color: var(--color-text-muted);
}
.sidebar__nav a {
  display: block; padding: 6px 16px; font-size: .875rem;
  color: var(--color-text-secondary); text-decoration: none;
  border-left: 3px solid transparent; transition: all var(--transition);
}
.sidebar__nav a:hover { color: var(--color-text); background: var(--color-bg-tertiary); text-decoration: none; }
.sidebar__nav a.active {
  color: var(--color-primary); font-weight: 600;
  border-left-color: var(--color-primary); background: var(--color-primary-light);
}
.sidebar__nav a .level-2 { padding-left: 12px; font-size: .8125rem; }

.content-wrapper { flex: 1; display: flex; min-width: 0; }
.main-content {
  flex: 1; max-width: var(--content-max-width);
  padding: 32px 40px 80px; margin: 0 auto; width: 100%;
}
.toc-float {
  width: var(--toc-width); flex-shrink: 0;
  position: sticky; top: calc(var(--header-height) + 24px);
  height: fit-content; max-height: calc(100vh - var(--header-height) - 48px);
  overflow-y: auto; padding: 16px 16px 16px 0;
}
.toc-float__title {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--color-text-muted); margin-bottom: 8px;
}
.toc-float nav a {
  display: block; padding: 4px 0; font-size: .8125rem;
  color: var(--color-text-secondary); text-decoration: none;
  border-left: 2px solid transparent; padding-left: 12px;
  transition: all var(--transition);
}
.toc-float nav a:hover { color: var(--color-primary); }
.toc-float nav a.active { color: var(--color-primary); border-left-color: var(--color-primary); font-weight: 600; }
.toc-float nav a[data-level="3"] { padding-left: 24px; font-size: .75rem; }

/* Typography */
.main-content h1 {
  font-size: 2.25rem; font-weight: 800; line-height: 1.2;
  margin-bottom: 8px; letter-spacing: -.02em;
}
.main-content h2 {
  font-size: 1.5rem; font-weight: 700; margin-top: 48px; margin-bottom: 16px;
  padding-bottom: 8px; border-bottom: 1px solid var(--color-border);
  scroll-margin-top: calc(var(--header-height) + 16px);
}
.main-content h3 {
  font-size: 1.125rem; font-weight: 600; margin-top: 32px; margin-bottom: 12px;
  scroll-margin-top: calc(var(--header-height) + 16px);
}
.main-content h4 { font-size: 1rem; font-weight: 600; margin-top: 24px; margin-bottom: 8px; }
.main-content p { margin-bottom: 16px; }
.main-content ul, .main-content ol { margin-bottom: 16px; padding-left: 24px; }
.main-content li { margin-bottom: 6px; }
.main-content strong { font-weight: 600; }
.main-content hr { border: none; border-top: 1px solid var(--color-border); margin: 32px 0; }

.ebook-meta {
  display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 24px;
  font-size: .875rem; color: var(--color-text-secondary);
}
.ebook-meta span { display: flex; align-items: center; gap: 6px; }
.ebook-meta svg { width: 16px; height: 16px; }

.lead {
  font-size: 1.125rem; color: var(--color-text-secondary);
  line-height: 1.6; margin-bottom: 32px;
}

/* Tables */
.table-wrapper { overflow-x: auto; margin-bottom: 24px; border-radius: var(--radius); border: 1px solid var(--color-border); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead { background: var(--color-bg-secondary); }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--color-border); }
th { font-weight: 600; font-size: .8125rem; text-transform: uppercase; letter-spacing: .03em; color: var(--color-text-secondary); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--color-bg-secondary); }

/* Callouts */
.callout {
  padding: 16px 16px 16px 48px; border-radius: var(--radius);
  margin-bottom: 20px; position: relative; font-size: .9375rem;
  border: 1px solid var(--color-border);
}
.callout__icon {
  position: absolute; left: 16px; top: 16px; width: 20px; height: 20px;
}
.callout--tip { background: #f0fdf4; border-color: #bbf7d0; }
.callout--tip .callout__icon { color: var(--color-success); }
.callout--warning { background: #fffbeb; border-color: #fde68a; }
.callout--warning .callout__icon { color: var(--color-warning); }
.callout--info { background: var(--color-primary-light); border-color: #bfdbfe; }
.callout--info .callout__icon { color: var(--color-info); }
.callout--reference { background: var(--color-bg-secondary); }
.callout--reference .callout__icon { color: var(--color-primary); }
[data-theme="dark"] .callout--tip { background: #052e16; border-color: #166534; }
[data-theme="dark"] .callout--warning { background: #422006; border-color: #854d0e; }
[data-theme="dark"] .callout--info { background: #1a2744; border-color: #1e40af; }

/* Quote */
blockquote {
  border-left: 4px solid var(--color-primary); padding: 12px 20px;
  margin-bottom: 20px; background: var(--color-bg-secondary);
  border-radius: 0 var(--radius) var(--radius) 0; font-style: italic;
  color: var(--color-text-secondary);
}
blockquote cite { display: block; margin-top: 8px; font-style: normal; font-size: .875rem; font-weight: 600; }

/* Checklist */
.checklist { list-style: none; padding-left: 0; }
.checklist li {
  padding: 8px 0 8px 32px; position: relative;
  border-bottom: 1px solid var(--color-border-light);
}
.checklist li::before {
  content: ""; position: absolute; left: 0; top: 12px;
  width: 18px; height: 18px; border: 2px solid var(--color-border);
  border-radius: 4px; transition: all var(--transition);
}
.checklist li.checked::before {
  background: var(--color-primary); border-color: var(--color-primary);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3'%3E%3Cpath d='M5 13l4 4L19 7'/%3E%3C/svg%3E");
  background-size: 14px; background-repeat: no-repeat; background-position: center;
}

/* Cards */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; margin-bottom: 32px; }
.card {
  border: 1px solid var(--color-border); border-radius: var(--radius-lg);
  padding: 24px; background: var(--color-bg); transition: box-shadow var(--transition), border-color var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--color-primary); }
.card__category {
  font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--color-primary); margin-bottom: 8px;
}
.card__title { font-size: 1.125rem; font-weight: 700; margin-bottom: 8px; }
.card__title a { color: var(--color-text); text-decoration: none; }
.card__title a:hover { color: var(--color-primary); }
.card__desc { font-size: .875rem; color: var(--color-text-secondary); margin-bottom: 12px; line-height: 1.5; }
.card__meta { font-size: .8125rem; color: var(--color-text-muted); display: flex; gap: 12px; }

/* FAQ */
.faq-item { border-bottom: 1px solid var(--color-border); }
.faq-item summary {
  padding: 16px 0; font-weight: 600; cursor: pointer;
  list-style: none; display: flex; justify-content: space-between; align-items: center;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after { content: "+"; font-size: 1.25rem; color: var(--color-text-muted); }
.faq-item[open] summary::after { content: "−"; }
.faq-item .faq-answer { padding-bottom: 16px; color: var(--color-text-secondary); font-size: .9375rem; }

/* Definition list */
dl.definitions { margin-bottom: 24px; }
dl.definitions dt { font-weight: 700; margin-top: 12px; color: var(--color-primary); }
dl.definitions dd { margin-left: 0; padding-left: 16px; border-left: 2px solid var(--color-border); color: var(--color-text-secondary); }

/* References */
.references { font-size: .875rem; }
.references ol { padding-left: 20px; }
.references li { margin-bottom: 8px; word-break: break-all; }

/* Breadcrumb */
.breadcrumb {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: .8125rem; color: var(--color-text-muted); margin-bottom: 16px;
}
.breadcrumb a { color: var(--color-text-secondary); }
.breadcrumb span[aria-current] { color: var(--color-text); font-weight: 500; }

/* Toolbar */
.ebook-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px;
  padding: 12px; background: var(--color-bg-secondary);
  border-radius: var(--radius); border: 1px solid var(--color-border);
}
.ebook-toolbar button, .ebook-toolbar a.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: .8125rem; font-weight: 500;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: var(--color-bg); color: var(--color-text);
  cursor: pointer; text-decoration: none; transition: all var(--transition);
}
.ebook-toolbar button:hover, .ebook-toolbar a.btn:hover {
  border-color: var(--color-primary); color: var(--color-primary); text-decoration: none;
}

/* Navigation between ebooks */
.ebook-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-top: 48px; padding-top: 32px; border-top: 1px solid var(--color-border);
}
.ebook-nav a {
  padding: 16px; border: 1px solid var(--color-border); border-radius: var(--radius);
  text-decoration: none; transition: border-color var(--transition);
}
.ebook-nav a:hover { border-color: var(--color-primary); text-decoration: none; }
.ebook-nav__label { font-size: .75rem; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .05em; }
.ebook-nav__title { font-weight: 600; color: var(--color-text); margin-top: 4px; }
.ebook-nav .next { text-align: right; }

/* Footer */
.site-footer {
  border-top: 1px solid var(--color-border); padding: 32px 24px;
  text-align: center; font-size: .8125rem; color: var(--color-text-muted);
  background: var(--color-bg-secondary);
}
.site-footer a { color: var(--color-text-secondary); }

/* Back to top */
.back-to-top {
  position: fixed; bottom: 24px; right: 24px; z-index: 50;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--color-primary); color: #fff; border: none;
  cursor: pointer; box-shadow: var(--shadow-md);
  opacity: 0; visibility: hidden; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.back-to-top.visible { opacity: 1; visibility: visible; }
.back-to-top:hover { background: var(--color-primary-dark); }
.back-to-top svg { width: 20px; height: 20px; }

/* Search results */
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  max-height: 320px; overflow-y: auto; display: none; z-index: 200;
}
.search-results.active { display: block; }
.search-results a {
  display: block; padding: 10px 14px; font-size: .875rem;
  color: var(--color-text); text-decoration: none;
  border-bottom: 1px solid var(--color-border-light);
}
.search-results a:hover { background: var(--color-bg-secondary); text-decoration: none; }
.search-results a small { display: block; color: var(--color-text-muted); font-size: .75rem; margin-top: 2px; }

/* Hero (catalog) */
.hero { text-align: center; padding: 48px 0 32px; }
.hero h1 { font-size: 2.5rem; font-weight: 800; margin-bottom: 12px; letter-spacing: -.02em; }
.hero p { font-size: 1.125rem; color: var(--color-text-secondary); max-width: 600px; margin: 0 auto 24px; }
.hero__stats { display: flex; justify-content: center; gap: 32px; font-size: .875rem; color: var(--color-text-muted); }
.hero__stats strong { display: block; font-size: 1.5rem; color: var(--color-primary); }

/* Cover page (print) */
.cover-page { display: none; }

/* Reading mode */
body.reading-mode .sidebar,
body.reading-mode .toc-float,
body.reading-mode .site-header__search { display: none; }
body.reading-mode .main-content { max-width: 680px; }

/* Mobile sidebar toggle */
.sidebar-toggle { display: none; }

/* Responsive */
@media (max-width: 1024px) {
  .toc-float { display: none; }
  .main-content { padding: 24px 24px 64px; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 100%; }
  .sidebar {
    position: fixed; left: -100%; top: var(--header-height);
    width: 85%; max-width: 320px; z-index: 150;
    transition: left var(--transition); box-shadow: var(--shadow-lg);
  }
  .sidebar.open { left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 140; display: none;
  }
  .sidebar-overlay.active { display: block; }
  .main-content { padding: 20px 16px 64px; }
  .main-content h1 { font-size: 1.75rem; }
  .ebook-nav { grid-template-columns: 1fr; }
  .ebook-nav .next { text-align: left; }
  .card-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}

/* Print / PDF */
@media print {
  .site-header, .sidebar, .toc-float, .ebook-toolbar,
  .back-to-top, .reading-progress, .ebook-nav, .skip-link,
  .sidebar-toggle, .sidebar-overlay { display: none !important; }
  .cover-page {
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    min-height: 100vh; text-align: center; page-break-after: always;
    padding: 48px;
  }
  .cover-page h1 { font-size: 2.5rem; color: #004aad; margin-bottom: 16px; }
  .cover-page .cover-subtitle { font-size: 1.25rem; color: #666; margin-bottom: 32px; }
  .cover-page .cover-meta { font-size: .875rem; color: #888; }
  .cover-page .cover-qr { margin-top: 32px; }
  .main-content { max-width: 100%; padding: 0; }
  body { font-size: 11pt; color: #000; }
  a { color: #004aad; }
  a[href^="http"]::after { content: " (" attr(href) ")"; font-size: 8pt; color: #666; }
  h2 { page-break-after: avoid; }
  .callout, table, .faq-item { page-break-inside: avoid; }
  @page { margin: 2cm; @bottom-center { content: counter(page); } }
  .print-footer {
    display: block; position: fixed; bottom: 0; left: 0; right: 0;
    text-align: center; font-size: 8pt; color: #888;
    border-top: 1px solid #ddd; padding-top: 8px;
  }
}

.print-footer { display: none; }
