/* =============================================
   DevOps for Everyone
   Shared Stylesheet
   ============================================= */

:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --accent: #f59e0b;
  --accent-dark: #d97706;
  --success: #16a34a;
  --text: #1f2937;
  --text-light: #6b7280;
  --text-muted: #9ca3af;
  --bg: #ffffff;
  --bg-soft: #f9fafb;
  --bg-sidebar: #f3f4f6;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --sidebar-width: 290px;
  --content-max: 760px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.75;
  font-size: 17px;
}

/* ---- Layout ---- */
.layout {
  display: flex;
  min-height: 100vh;
}

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

.sidebar-header {
  background: var(--primary);
  color: white;
  padding: 1.25rem 1.5rem;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 10;
}

.sidebar-header a {
  color: white;
  text-decoration: none;
  display: block;
}

.sidebar-header .book-title {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-transform: none;
  line-height: 1.3;
}

.sidebar-header .book-subtitle {
  font-size: 0.75rem;
  opacity: 0.8;
  font-weight: 400;
  margin-top: 0.2rem;
  text-transform: none;
  letter-spacing: 0;
}

.sidebar nav {
  padding: 1rem 0;
}

.nav-part {
  margin-bottom: 0.25rem;
}

.nav-part-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0.75rem 1.5rem 0.3rem;
}

.sidebar nav a {
  display: block;
  padding: 0.35rem 1.5rem 0.35rem 1.75rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover {
  background: var(--border);
  color: var(--primary);
}

.sidebar nav a.active {
  background: #ccfbf1;
  color: var(--primary-dark);
  border-left-color: var(--primary);
  font-weight: 600;
}

/* ---- Main Content ---- */
.content-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

.content {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 3rem 2.5rem 5rem;
}

/* ---- Typography ---- */
h1 {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 2.5rem;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--border);
}

h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-top: 1.75rem;
  margin-bottom: 0.5rem;
}

h4 {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

p {
  margin-bottom: 1.1rem;
  color: var(--text);
}

ul, ol {
  padding-left: 1.5rem;
  margin-bottom: 1.1rem;
}

li {
  margin-bottom: 0.4rem;
}

strong { font-weight: 700; }
em { font-style: italic; color: var(--text); }

a {
  color: var(--primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover { color: var(--primary-dark); }

code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  background: #f0fdf4;
  color: #065f46;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-size: 0.88em;
  border: 1px solid #bbf7d0;
}

pre {
  background: #0d1117;
  color: #c9d1d9;
  padding: 1.5rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 1.5rem 0;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  box-shadow: var(--shadow-md);
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* Syntax color hints */
.kw   { color: #ff7b72; }
.fn   { color: #79c0ff; }
.str  { color: #a5d6ff; }
.num  { color: #f2cc60; }
.cmt  { color: #8b949e; font-style: italic; }
.var  { color: #c9d1d9; }
.op   { color: #ffa657; }
.flag { color: #7ee787; }

/* ---- Chapter Header ---- */
.chapter-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.chapter-tag {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.3rem 0.75rem;
  border-radius: 100px;
  margin-bottom: 0.75rem;
}

.chapter-tag.part-1 { background: #7c3aed; }
.chapter-tag.part-2 { background: #0891b2; }
.chapter-tag.part-3 { background: #2563eb; }
.chapter-tag.part-4 { background: #16a34a; }
.chapter-tag.part-5 { background: #d97706; }
.chapter-tag.part-6 { background: #dc2626; }
.chapter-tag.part-7 { background: #0f766e; }

.chapter-intro {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-top: 0.5rem;
  font-style: italic;
}

/* ---- Special Boxes ---- */
.box {
  padding: 1.25rem 1.5rem;
  border-radius: var(--radius);
  margin: 1.75rem 0;
}

.box-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.6rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.analogy { background: #fffbeb; border-left: 4px solid var(--accent); }
.analogy .box-title { color: var(--accent-dark); }

.key-term { background: #f0fdf4; border-left: 4px solid #16a34a; }
.key-term .box-title { color: #15803d; }

.tip { background: #f0fdfa; border-left: 4px solid var(--primary); }
.tip .box-title { color: var(--primary-dark); }

.warning { background: #fff7ed; border-left: 4px solid #ea580c; }
.warning .box-title { color: #c2410c; }

.fun-fact { background: #fdf4ff; border-left: 4px solid #a855f7; }
.fun-fact .box-title { color: #7e22ce; }

.learn-box {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
}
.learn-box h4 { margin-top: 0; color: var(--primary); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.07em; }
.learn-box ul { margin-bottom: 0; }
.learn-box li::marker { color: var(--primary); }

/* ---- Exercises ---- */
.exercises {
  background: #f5f3ff;
  border: 2px solid #7c3aed;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 2.5rem;
}

.exercises h3 { color: #5b21b6; margin-top: 0; margin-bottom: 1rem; font-size: 1.1rem; }

.exercise {
  background: white;
  border-radius: 6px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  border: 1px solid #ddd6fe;
}

.exercise-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: #7c3aed;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.exercise p { margin-bottom: 0.5rem; }
.exercise p:last-child { margin-bottom: 0; }

.interactive-exercise {
  background: white;
  border: 2px solid #7c3aed;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1rem 0;
}

.interactive-exercise textarea,
.interactive-exercise input[type="text"] {
  width: 100%;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.875rem;
  padding: 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  margin: 0.5rem 0;
  background: #0d1117;
  color: #c9d1d9;
  resize: vertical;
}

.interactive-exercise button {
  background: #7c3aed;
  color: white;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  transition: background 0.15s;
}

.interactive-exercise button:hover { background: #5b21b6; }

.exercise-output {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: #f1f5f9;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.875rem;
  min-height: 2.5rem;
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

.exercise-output.success { color: #16a34a; background: #f0fdf4; border-color: #bbf7d0; }
.exercise-output.error   { color: #dc2626; background: #fef2f2; border-color: #fecaca; }

/* ---- Chapter Navigation ---- */
.chapter-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 3rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.chapter-nav a {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  padding: 0.75rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 45%;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: white;
}

.chapter-nav a:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
}

.chapter-nav .nav-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.chapter-nav .nav-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.3;
}

.chapter-nav .next { text-align: right; margin-left: auto; }

/* ---- Home / Index ---- */
.hero {
  background: linear-gradient(135deg, #042f2e 0%, #0d9488 100%);
  color: white;
  padding: 3.5rem 2.5rem;
  margin: -3rem -2.5rem 3rem;
}

.hero h1 { color: white; font-size: 2.75rem; line-height: 1.15; }

.hero p {
  color: rgba(255,255,255,0.85);
  font-size: 1.1rem;
  max-width: 560px;
  margin-top: 1rem;
}

.hero .badge {
  display: inline-block;
  background: var(--accent);
  color: #1c1917;
  padding: 0.3rem 0.75rem;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.parts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin: 2rem 0;
}

.part-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
  background: white;
  display: block;
}

.part-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--text);
}

.part-card .part-emoji { font-size: 2rem; margin-bottom: 0.75rem; }
.part-card h3 { font-size: 1rem; margin-top: 0; margin-bottom: 0.25rem; color: var(--primary); }
.part-card p { font-size: 0.875rem; color: var(--text-light); margin: 0; }

.toc-list { list-style: none; padding: 0; }
.toc-list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; align-items: baseline; gap: 0.75rem; }
.toc-list .ch-num { font-size: 0.75rem; color: var(--text-muted); min-width: 3rem; font-weight: 600; }
.toc-list a { text-decoration: none; font-size: 0.925rem; }
.toc-list a:hover { text-decoration: underline; }

/* ---- Diagram ---- */
.diagram {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  margin: 1.5rem 0;
  font-family: monospace;
  font-size: 0.875rem;
  line-height: 1.8;
  overflow-x: auto;
}

/* ---- Summary Box ---- */
.summary {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-top: 2rem;
}

.summary h4 { color: var(--text); margin-top: 0; font-size: 0.875rem; }
.summary ul { margin-bottom: 0; }

/* ---- Horizontal Rule ---- */
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; margin: 1.5rem 0; font-size: 0.9rem; }
th { background: var(--bg-soft); font-weight: 700; text-align: left; padding: 0.6rem 1rem; border: 1px solid var(--border); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); }
td { padding: 0.6rem 1rem; border: 1px solid var(--border); }
tr:nth-child(even) td { background: var(--bg-soft); }

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: translateX(0); }
  .content-wrapper { margin-left: 0; }
  .content { padding: 2rem 1.25rem 4rem; }
  h1 { font-size: 1.9rem; }
  h2 { font-size: 1.35rem; }
  .hero { padding: 2rem 1.25rem; margin: -2rem -1.25rem 2rem; }
  .hero h1 { font-size: 2rem; }

  .menu-btn {
    display: flex;
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 3rem;
    height: 3rem;
    font-size: 1.25rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(13,148,136,.4);
    z-index: 200;
  }
}

@media (min-width: 901px) { .menu-btn { display: none; } }

/* ---- Dark Mode ---- */
[data-theme="dark"] {
  --primary: #2dd4bf;
  --primary-dark: #5eead4;
  --accent: #fbbf24;
  --accent-dark: #f59e0b;
  --success: #4ade80;
  --text: #e2e8f0;
  --text-light: #94a3b8;
  --text-muted: #64748b;
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --bg-sidebar: #1e293b;
  --border: #334155;
  --border-strong: #475569;
}

[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] code { background: #1e293b; color: #6ee7b7; border-color: #334155; }
[data-theme="dark"] .chapter-nav a { background: #1e293b; color: var(--text); }
[data-theme="dark"] .exercise { background: #1e293b; border-color: #4c1d95; }
[data-theme="dark"] .exercises { background: #1a1033; }
[data-theme="dark"] .interactive-exercise { background: #1e293b; border-color: #6d28d9; }
[data-theme="dark"] .part-card { background: #1e293b; color: var(--text); }
[data-theme="dark"] .summary { background: #1e293b; }
[data-theme="dark"] .learn-box { background: #1e293b; }
[data-theme="dark"] .diagram { background: #1e293b; }
[data-theme="dark"] .analogy { background: #1c1708; }
[data-theme="dark"] .key-term { background: #0a1f10; }
[data-theme="dark"] .tip { background: #042f2e; }
[data-theme="dark"] .warning { background: #1f0f08; }
[data-theme="dark"] .fun-fact { background: #1a0a2e; }
[data-theme="dark"] .sidebar nav a.active { background: #134e4a; color: var(--primary-dark); }
[data-theme="dark"] .sidebar nav a:hover { background: #334155; }
[data-theme="dark"] th { background: #1e293b; color: var(--text-light); }
[data-theme="dark"] tr:nth-child(even) td { background: #1e293b; }
[data-theme="dark"] td { border-color: var(--border); }

/* Dark mode toggle */
.dark-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 0.25rem 0.65rem;
  border-radius: 100px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 0.65rem;
  transition: background 0.15s;
  letter-spacing: 0.02em;
  font-family: inherit;
  width: fit-content;
}
.dark-toggle:hover { background: rgba(255,255,255,0.22); }

/* ---- Print ---- */
@media print {
  .sidebar, .chapter-nav, .menu-btn { display: none !important; }
  .content-wrapper { margin-left: 0; }
  .content { padding: 1rem 2rem; max-width: 100%; }
  pre { page-break-inside: avoid; }
  .exercises { page-break-inside: avoid; }
  h2 { page-break-before: auto; }
  .chapter-header { page-break-after: avoid; }
  @page { margin: 2.5cm 2cm; size: A4; }
}
