/* ==========================================================================
   Mastering APIs With Python - Chapter Styles v3
   Clean, modern styling for all 30 chapters
   ========================================================================== */


/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Code syntax highlighting */
    --code-bg: #272a2c;
    --code-fg: #E0E0E0;
    --comment: #7FB366;
    --keyword: #C586C0;
    --string: #CE9178;
    --number: #B5CEA8;
    --builtin: #5EA4E0;
    --function: #DCDCAA;
    --operator: #D4D4D4;
    --variable: #9CDCFE;
    --boolean: #569CD6;
    --punctuation: #D4D4D4;

    /* Color scheme */
    --code-heading-color: #4e9a61;
    --text-primary: #E0E0E0;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #6366f1;
    --success-green: #28a745;

    /* Neutral colors */
    --border-light: #2a2a2a;
    --bg-light: #1c1c1e;
}


/* ============================================
   BASE & RESET
   ============================================ */
body {
    background: #131314 !important;
    color: #E0E0E0;
    line-height: 1.6;
}

html {
    scroll-behavior: smooth;
}


/* ============================================
   LAYOUT — CHAPTER CONTAINER
   ============================================ */
.chapter-container {
    max-width: 66ch;
    margin: 0 auto;
    padding: 2rem 1.25rem;
    background: #131314;
}


/* ============================================
   CHAPTER HEADER
   ============================================ */
.chapter-header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px;
    background: #4F46E5;
    color: white;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.chapter-header h1 {
    margin: 0;
    font-size: 2.6em;
    font-weight: 400;
    font-family: 'Open Sans', sans-serif;
}

.chapter-header p {
    margin: 10px 0 0 0;
    font-size: 1.2em;
    opacity: 0.9;
    color: white;
}

.chapter-header h4 {
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-weight: 300;
    font-size: 1.1em;
    font-family: 'Open Sans', sans-serif;
    color: white;
}


/* ============================================
   SECTIONS
   ============================================ */
.section {
    background: transparent;
    margin-bottom: 25px;
    margin-top: 25px;
    padding: 0;
}

.section-header {
    background: #4F46E5;
    color: white;
    padding: 30px 25px 20px 40px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0px;
    border-radius: 5px 5px 0 0;
}

.section-header h2 {
    margin: 0;
    font-weight: 400;
    font-size: 1.7em;
    font-family: 'Open Sans', sans-serif;
}

.section-content {
    padding: 0;
    margin: 0px 0 60px 0;
}


/* ============================================
   SUBSECTIONS
   ============================================ */
.subsection {
    background: transparent;
    margin: 2rem 0 2rem 0;
    max-width: 86ch;
}

.subsection-header {
    padding: 22px 25px 14px 25px;
    border-bottom: 1px solid #2a2a2a;
    margin-bottom: 20px;
    position: relative;
}

.subsection-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 25px;
    width: 60px;
    height: 2px;
    background: var(--accent);
}

.subsection-header h3 {
    margin: 0;
    color: #E0E0E0;
    font-size: 1.4em;
    font-weight: 600;
    line-height: 1.3;
    font-family: 'Open Sans', sans-serif;
}

.subsection-header .subsection-subtitle {
    margin: 8px 0 2px 0;
    color: #9ca3af;
    font-size: 1.0em;
    font-weight: 400;
    line-height: 1.5;
}

.subsection-content {
    padding: 0px 25px 0px 30px;
}


/* ============================================
   TYPOGRAPHY
   ============================================ */

/* H4 headings - used for checklists and subsection organization */
h4 {
    color: #E0E0E0;
    font-weight: 600;
    font-size: 1.1em;
    margin: 1.75rem 0 0.75rem 0;
    font-family: 'Open Sans', sans-serif;
    line-height: 1.3;
}

p {
    margin: 0 0 1.25em 0;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
    font-size: 1.0rem;
}

strong {
    font-weight: 500;
    color: #959de6;
}

.body-strong-heading {
    font-weight: 600;
    color: #959de6;
    margin-top: 2.5rem;
    margin-bottom: 1rem;
}

.heading-inline {
    font-weight: 600;
    color: #c9cad6;
    margin-bottom: 1.5rem;
}

code.code-heading {
    color: #81c995;
    padding: 0.15em 0.15em;
    border-radius: 3px;
    font-family: 'Roboto Mono', monospace;
    font-size: 1.0em;
    font-weight: normal;
}

code.inline-code {
    color: #9ca3af;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.92em;
    background: #1a1a1a;
    padding: 0.1em 0.35em;
    border-radius: 3px;
    word-break: break-all;
}

/* Concept Heading - Thematic markers within subsections */
.concept-heading {
    font-size: 1.05em;
    font-weight: 600;
    color: var(--text-primary);
    margin: 2rem 0 1rem 0;
    padding-left: 1rem;
    border-left: 4px solid #667eea;
    line-height: 1.4;
}

h5.concept-heading {
    color: #959de6;
    font-weight: 700;
    border-left: 4px solid #667eea;
    padding-left: 1rem;
    margin: 2rem 0 1rem 0;
}


/* ============================================
   LISTS
   ============================================ */
.chapter-container ul,
.section-content ul,
.subsection-content ul,
.explanation-box ul,
.description-box ul,
.tip-box ul,
.warning-box ul,
.milestone-box ul {
    margin: 14px 0;
    padding-left: 30px;
    list-style-type: none;
}

/* Reduce bottom margin for ul/ol inside boxes */
.explanation-box ul,
.description-box ul,
.tip-box ul,
.warning-box ul,
.milestone-box ul,
.explanation-box ol,
.description-box ol,
.tip-box ol,
.warning-box ol,
.milestone-box ol {
    margin-bottom: 0.5rem;
}

.chapter-container li,
.section-content li,
.subsection-content li,
.explanation-box li,
.description-box li,
.tip-box li,
.warning-box li,
.milestone-box li {
    margin: 5px 0;
    color: var(--text-primary);
    position: relative;
    padding-left: 0.5rem;
}

.chapter-container li::before,
.section-content li::before,
.subsection-content li::before,
.explanation-box li::before,
.description-box li::before,
.tip-box li::before,
.warning-box li::before,
.milestone-box li::before {
    content: "→";
    position: absolute;
    left: -1.55rem;
    color: #959de6;
    font-weight: 600;
}

ul.spaced-list {
    margin: 1em 0;
    padding-left: 1.5em;
}

ul.spaced-list li {
    margin-bottom: 0.75em;
    font-family: 'Open Sans', sans-serif;
}

ul.spaced-list-last li:last-child {
    margin-bottom: 0;
}

ul.spaced-list-last,
ol.spaced-list-last {
    margin-bottom: 3.5em;
}

/* Spacing when spaced-list is followed by paragraphs */
ul.spaced-list + p,
ul.spaced-list + p.body-strong-heading,
ol.spaced-list + p,
ol.spaced-list + p.body-strong-heading {
    margin-top: 2rem;
}

/* Add extra spacing when boxes follow spaced-list */
ul.spaced-list + .explanation-box,
ul.spaced-list + .description-box,
ul.spaced-list + .tip-box,
ul.spaced-list + .warning-box,
ul.spaced-list + .key-takeaway-box,
ul.spaced-list + .recommendation-box,
ul.spaced-list + .milestone-box,
ol.spaced-list + .explanation-box,
ol.spaced-list + .description-box,
ol.spaced-list + .tip-box,
ol.spaced-list + .warning-box,
ol.spaced-list + .key-takeaway-box,
ol.spaced-list + .recommendation-box,
ol.spaced-list + .milestone-box {
    margin-top: 3rem;
}

/* Ordered lists - use numbers instead of arrows */
.explanation-box ol,
.description-box ol,
.tip-box ol,
.warning-box ol,
.milestone-box ol,
.subsection-content ol {
    margin: 14px 0;
    padding-left: 30px;
    list-style-position: outside;
}

.explanation-box ol li,
.description-box ol li,
.tip-box ol li,
.warning-box ol li,
.milestone-box ol li,
.subsection-content ol li {
    margin: 5px 0;
    color: var(--text-primary);
    position: relative;
    padding-left: 0.5rem;
}

.explanation-box ol li::before,
.description-box ol li::before,
.tip-box ol li::before,
.warning-box ol li::before,
.milestone-box ol li::before,
.subsection-content ol li::before {
    content: none; /* Remove the arrow for ordered lists */
}

ol.spaced-list {
    list-style-type: decimal;
}

.explanation-box ol,
.tip-box ol {
    font-family: 'Open Sans', sans-serif;
}

/* Override the 3.5em default for lists inside boxes */
.explanation-box ul.spaced-list-last,
.explanation-box ol.spaced-list-last,
.tip-box ul.spaced-list-last,
.tip-box ol.spaced-list-last,
.description-box ul.spaced-list-last,
.description-box ol.spaced-list-last,
.key-takeaway-box ul.spaced-list-last,
.key-takeaway-box ol.spaced-list-last {
    margin-bottom: 1.5em;
}

/* When the list is the last child in a box, remove bottom margin */
.explanation-box ul.spaced-list-last:last-child,
.explanation-box ol.spaced-list-last:last-child,
.tip-box ul.spaced-list-last:last-child,
.tip-box ol.spaced-list-last:last-child,
.description-box ul.spaced-list-last:last-child,
.description-box ol.spaced-list-last:last-child,
.key-takeaway-box ul.spaced-list-last:last-child,
.key-takeaway-box ol.spaced-list-last:last-child {
    margin-bottom: 1.5;
}

/* List item headings and descriptions */
.list-item-heading {
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.list-item-description {
    font-weight: normal;
}


/* ============================================
   PROGRAM TITLES
   ============================================ */
.program-title {
    font-weight: 600;
    color: #E0E0E0;
    margin: 2.75rem 0 0.5rem 0;
    font-size: 1.05em;
    font-family: 'Open Sans', sans-serif;
}

p + .program-title {
    margin-top: 2.75rem;
}


/* ============================================
   CODE BLOCKS — WRAPPER & PRE
   ============================================ */
.code-block-wrapper {
    position: relative;
    margin: 2rem 0;
}

.code-block-wrapper pre {
    background: var(--code-bg);
    color: var(--code-fg);
    padding: 1.65rem 1.5625rem 2.1875rem 1.875rem;
    border-radius: 0 0 8px 8px;
    line-height: 1.75;
    white-space: pre;
    overflow-x: auto;
    margin: 0;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.95em;
}

.code-block-wrapper pre code {
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 1em;
    line-height: inherit;
    color: inherit;
    background: none;
}

.code-block-wrapper pre.soft-wrap,
.code-block-wrapper pre.soft-wrap code {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Code blocks inside explanation/tip boxes */
.explanation-box pre,
.tip-box pre {
    margin: 1rem 0;
}

.explanation-box pre code,
.tip-box pre code {
    display: block;
    background: var(--code-bg);
    color: var(--code-fg);
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    overflow-x: auto;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.95em;
    line-height: 1.7;
}


/* ============================================
   CODE BLOCKS — SCROLLBAR
   ============================================ */
.code-block-wrapper pre::-webkit-scrollbar {
    height: 12px;
}

.code-block-wrapper pre::-webkit-scrollbar-track {
    background: #1a1a1a; 
    border-radius: 0 0 6px 0;
}

.code-block-wrapper pre::-webkit-scrollbar-thumb {
    background: #4a5568;
    border-radius: 6px;
    border: 2px solid #1a1d1f;
}

.code-block-wrapper pre::-webkit-scrollbar-thumb:hover {
    background: #a47dcf;
}

.code-block-wrapper pre {
    scrollbar-width: thin;
    scrollbar-color: #4a5568 #1a1d1f;
}

pre.diagram {
    background: var(--code-bg);
    color: var(--code-fg);
    font-family: 'Roboto Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    padding: 1.5rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1rem 0;
}



/* ============================================
   CODE BLOCKS — HEADER BAR
   ============================================ */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .9rem 2rem 0.6rem 2rem;
    background-color: #303336;
    border-radius: 8px 8px 0 0;
    font-family: 'Open Sans', sans-serif;
}

.code-label {
    font-family: 'Open Sans', sans-serif;
    font-size: 0.875rem;
    font-weight: normal;
    color: #a0a0a0;
    letter-spacing: 0.5px;
    margin: 0;
}

/* Section headings inside boxes */
.explanation-box .section-heading,
.description-box .section-heading,
.tip-box .section-heading {
    font-weight: 600;
    margin: 1.15rem 0 0.4rem 0;
}

.explanation-box .section-heading:first-child,
.description-box .section-heading:first-child,
.tip-box .section-heading:first-child {
    margin-top: 0;
}


/* ============================================
   CODE BLOCKS — COPY BUTTON
   ============================================ */
.copy-button {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    background-color: #303336;
    border: 0px solid #303336;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    color: #a0a0a0;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.copy-button:hover {
    background-color: #c6cace;
    border-color: #c6cace;
}

.copy-button:active {
    background-color: #e9ecef;
}

.copy-button.copied {
    background-color: #dafbe1;
    border-color: #2da44e;
    color: #1a7f37;
}

.copy-icon {
    width: 11px;
    height: 11px;
    color: currentColor;
    flex-shrink: 0;
    transition: color 0.3s ease;
}

.copy-button.copied .copy-icon {
    color: #1a7f37;
}

.copy-text {
    font-family: 'Open Sans', sans-serif;
    display: inline-block;
    transition: color 0.2s ease;
}


/* ============================================
   CODE BLOCKS — WRAP TOGGLE BUTTON
   ============================================ */
.wrap-toggle-button {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.1rem 0.5rem;
    background-color: #303336;
    border: 0px solid #303336;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    color: #a0a0a0;
    cursor: pointer;
    transition: all 0.2s ease;
}

.wrap-toggle-button:hover {
    background-color: #c6cace;
    border-color: #c6cace;
}

.wrap-toggle-button.active {
    background-color: #4a5568;
    color: #e2e8f0;
}

.wrap-icon {
    font-size: 0.75rem;
}

.wrap-text {
    font-weight: 500;
}


/* ============================================
   CODE BLOCKS — SYNTAX HIGHLIGHTING TOKENS
   ============================================ */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
    color: var(--comment);
}

.token.keyword {
    color: var(--keyword);
}

.token.string {
    color: var(--string);
}

.token.number {
    color: var(--number);
}

.token.builtin,
.token.class-name {
    color: var(--builtin);
}

.token.function {
    color: var(--function);
}

.token.operator {
    color: var(--operator);
}

.token.variable {
    color: var(--variable);
}

.token.boolean {
    color: var(--boolean);
}

.token.punctuation {
    color: var(--punctuation);
}


/* ============================================
   DISPLAY BLOCKS — HTTP HEADER BLOCK
   ============================================ */
.http-header-block {
    background: var(--code-bg);
    color: var(--code-fg);
    font-family: 'Courier New', Consolas, Monaco, monospace;
    padding: 1rem 1.5rem;
    border-left: 4px solid var(--accent);
    border-radius: 0 4px 4px 0;
    margin: 1.5rem 0;
    font-size: 0.95em;
    line-height: 1.75;
    overflow-x: auto;
}


/* ============================================
   DISPLAY BLOCKS — TERMINAL BLOCK
   ============================================ */
.terminal-block {
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 0.85rem 1.25rem;
    margin: 1.5rem 0;
    font-family: 'Courier New', Consolas, Monaco, monospace;
    font-size: 0.92em;
    color: var(--code-fg);
    line-height: 1.6;
}

.terminal-block .prompt {
    color: var(--accent);
    font-weight: 600;
    margin-right: 0.6rem;
    user-select: none;
}


/* ============================================
   CHAPTER NAVIGATION
   ============================================ */
.chapter-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
}

.nav-button {
    display: inline-flex;
    align-items: center;
    padding: 0.8rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    text-decoration: none !important;
    transition: all 0.2s ease;
    font-family: 'Open Sans', sans-serif;
}

/* Green "Next" Button */
.nav-button.next {
    background-color: var(--success-green);
    color: white !important;
}

.nav-button.next:hover {
    background-color: #218838;
    transform: translateX(3px);
}

/* Gray "Previous" Button */
.nav-button.prev {
    background-color: #1a1a1a;
    color: #9ca3af !important;
    border: 1px solid #2a2a2a;
}

.nav-button.prev:hover {
    background-color: #2a2a2a;
    transform: translateX(-3px);
}

/* "Go to Top" center link */
.nav-top-link {
    font-size: 0.9rem;
    color: var(--text-muted);
    text-decoration: none;
}

.nav-top-link:hover {
    color: var(--accent);
}

@media (max-width: 600px) {
    .chapter-navigation {
        flex-direction: column;
        gap: 1.5rem;
    }

    .nav-button {
        width: 100%;
        justify-content: center;
    }
}


/* ============================================
   CALLOUT BOXES — EXPLANATION BOX (Blue)
   ============================================ */
.explanation-box {
    background: #0d1117;
    border: 1px solid #1e3a5f;
    border-left: 4px solid #4793df;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 2rem 0;
    border-radius: 8px;
}

.explanation-box p {
    margin: 0.5rem 0;
}

.explanation-box p:last-child {
    margin-bottom: 0;
}


/* ============================================
   CALLOUT BOXES — DESCRIPTION BOX (Amber)
   ============================================ */
.description-box {
    background: #1a1200;
    border: 1px solid #3d2e00;
    border-left: 4px solid #f59e0b;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 2rem 0;
    border-radius: 8px;
}


/* ============================================
   CALLOUT BOXES — TIP BOX (Slate)
   ============================================ */
.tip-box {
    background: #0f1117;
    border-left: 4px solid #64748b;
    padding: 1.5rem 1.25rem 2.5rem 1.25rem;
    margin: 3rem 0 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 0.125rem 0.375rem rgba(0, 0, 0, 0.3);
}

.tip-box .tip-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 1em;
    color: #E0E0E0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #2a3a4a;
    font-family: 'Open Sans', sans-serif;
}

.tip-box p {
    margin: 0.5rem 0;
}

.tip-box p:last-child {
    margin-bottom: 0;
}

/* Shared tip-heading style (used across multiple box types) */
.tip-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 1em;
    color: #E0E0E0;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #2a2a2a;
    font-family: 'Open Sans', sans-serif;
}


/* ============================================
   CALLOUT BOXES — MILESTONE BOX (Blue border)
   ============================================ */
.milestone-box {
    background: #0a1628;
    border: 2px solid #3b82f6;
    border-radius: 8px;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 1.5rem 0 2.5rem 0;
}

.milestone-box h4 {
    color: #93c5fd;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 1rem;
    font-size: 1.15em;
    font-family: 'Open Sans', sans-serif;
}

.milestone-box p {
    margin: 0 0 1em 0;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.milestone-box p:last-child {
    margin-bottom: 0;
}


/* ============================================
   CALLOUT BOXES — WARNING BOX (Amber border)
   ============================================ */
.warning-box {
    background: #1a0e00;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 1.5rem 0 2.5rem 0;
}

.warning-box .tip-heading {
    color: #fbbf24;
    border-bottom: 1px solid #3d2600;
}

.warning-box p {
    margin: 0 0 1em 0;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.warning-box p:last-child {
    margin-bottom: 0;
}


/* ============================================
   CALLOUT BOXES — RECOMMENDATION BOX (Green)
   ============================================ */
.recommendation-box {
    background: #0a1a12;
    border: 1px solid #2d6a4f;
    border-radius: 8px;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 1.5rem 0 2.5rem 0;
}

.recommendation-box .tip-heading {
    color: #6ee7b7;
    border-bottom: 1px solid #1a3d2a;
}

.recommendation-box p {
    margin: 0 0 1em 0;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.recommendation-box p:last-child {
    margin-bottom: 0;
}


/* ============================================
   CALLOUT BOXES — KEY TAKEAWAY BOX (Teal)
   ============================================ */
.key-takeaway-box {
    background: #0d1f15;
    border: 1px solid #1a3d28;
    border-left: 4px solid #5bbb9f;
    padding: 1.5rem 1.5rem 2.5rem 1.5rem;
    margin: 2rem 0;
    border-radius: 8px;
}

.key-takeaway-box .tip-heading {
    color: #6ee7b7;
    border-bottom: 1px solid #1a3d28;
}

.key-takeaway-box p {
    margin: 0 0 1em 0;
    font-family: 'Open Sans', sans-serif;
    color: var(--text-primary);
}

.key-takeaway-box p:last-child {
    margin-bottom: 0;
}


/* ============================================
   NUMBERED HEADING BLOCKS
   ============================================ */
.numbered-heading-block {
    display: flex;
    align-items: baseline;
    gap: 0.9rem;
    margin: 1.5rem 0;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-light);
}

.numbered-heading-block > .number {
    margin-top: 0;
    min-width: 1.6rem;
    text-align: right;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
    color: #5b6bc4;
    background: none;
    border-radius: 0;
    padding: 0;
}

.numbered-heading-block-last {
    border-bottom: none;
    padding-bottom: 0;
}

.numbered-heading-block .content {
    flex: 1;
    min-width: 0; /* Allow flex child to shrink */
}

.numbered-heading-block .content p:first-child {
    margin-top: 0;
}

.numbered-heading-block .content p:last-child {
    margin-bottom: 0;
}

.numbered-heading-block .content .code-block-wrapper {
    max-width: 100%;
    overflow: hidden;
}

/* Extra top margin when boxes follow numbered heading blocks */
.numbered-heading-block-last + .recommendation-box,
.numbered-heading-block-last + .key-takeaway-box,
.numbered-heading-block-last + .description-box,
.numbered-heading-block-last + .warning-box,
.numbered-heading-block-last + .explanation-box,
.numbered-heading-block-last + .tip-box,
.numbered-heading-block-last + .milestone-box {
    margin-top: 3rem;
}


/* ============================================
   TABLES
   ============================================ */
.styled-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 1.5rem 0 2rem 0;
    font-size: 16px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.styled-table caption {
    font-size: 1.1em;
    font-weight: 600;
    text-align: left;
    padding: 1.5rem 0;
    color: #E0E0E0;
    caption-side: top;
}

.styled-table thead th {
    background: #3730a3;
    color: white;
    font-weight: 600;
    padding: 15px 12px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 14px;
}

.styled-table tbody tr {
    background-color: #1c1c1e;
    border-bottom: 1px solid #2a2a2a;
}

.styled-table tbody tr:nth-child(even) {
    background-color: #1a1a1a;
}

.styled-table tbody tr:last-child {
    border-bottom: none;
}

.styled-table tbody td {
    padding: 14px 12px;
    color: #E0E0E0;
    line-height: 1.4;
}

.styled-table .code-heading {
    font-size: 1em;
}

.styled-table tbody tr:hover {
    background: #1e1e3a;
    cursor: default;
}

/* Spacing when boxes follow tables */
.styled-table + .explanation-box,
.styled-table + .tip-box,
.styled-table + .warning-box,
.styled-table + .recommendation-box,
.styled-table + .key-takeaway-box,
.styled-table + .milestone-box {
    margin-top: 2.75rem;
}


/* ============================================
   TABLES — HORIZONTAL SCROLLING
   ============================================ */

/* Prevent code elements inside table cells from wrapping */
.styled-table td code.code-heading,
.styled-table th code.code-heading {
    white-space: pre-wrap;
    display: inline;
}

/* Scroll container */
div[style*="overflow-x: auto"] {
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    padding-bottom: 1rem;
    margin: 1.5rem 0 2rem 0;
}

/* Tables inside scroll containers */
div[style*="overflow-x: auto"] .styled-table {
    margin: 0;
    box-shadow: none;
}


/* ============================================
   CHECKPOINT QUIZ & COLLAPSIBLE DETAILS
   ============================================ */
.checkpoint-quiz {
    margin: 2rem 0;
}

.checkpoint-quiz-heading {
    font-weight: 600;
    color: #E0E0E0;
    margin-bottom: 1rem;
}

.troubleshooting-details {
    background: #1c1c1e;
    border: 1px solid var(--border-light);
    border-radius: 0.5rem;
    margin: 0.75rem 0;
    overflow: hidden;
    transition: all 0.2s ease;
}

.troubleshooting-details:hover {
    box-shadow: 0 0.125rem 0.375rem rgba(0, 0, 0, 0.05);
}

.troubleshooting-details summary {
    padding: 1rem 1.25rem 1rem 3rem;
    cursor: pointer;
    font-weight: 500;
    color: #E0E0E0;
    list-style: none;
    user-select: none;
    position: relative;
}

.troubleshooting-details summary::before {
    content: '▶';
    position: absolute;
    left: 1.25rem;
    color: #6b7280;
    transition: transform 0.2s ease;
}

/* Allow code elements in summary to wrap naturally */
.troubleshooting-details summary code {
    white-space: pre-wrap;
}

.troubleshooting-details summary::-webkit-details-marker {
    display: none;
}

.troubleshooting-details[open] summary::before {
    transform: rotate(90deg);
}

.troubleshooting-details summary:hover {
    background: #1a1a1a;
}

.troubleshooting-content {
    padding: 0 1.25rem 1.25rem 3rem;
    color: var(--text-secondary);
}

.troubleshooting-content p {
    margin: 0.5rem 0;
}

.troubleshooting-content p:last-child {
    margin-bottom: 0;
}

/* Info Details - Simple collapsible content */
.info-details {
    margin: 0.75rem 0;
}

.info-details summary {
    cursor: pointer;
    user-select: none;
}

.info-details summary:hover {
    background: #1a1a1a;
}

.details-content {
    padding-top: 1rem;
}

.details-content p {
    margin: 0.5rem 0;
}

.details-content p:first-child {
    margin-top: 0;
}

.details-content p:last-child {
    margin-bottom: 0;
}


/* ============================================
   ROADMAP TIMELINE
   ============================================ */
.roadmap-timeline {
    position: relative;
    max-width: 90%;
    margin: 3rem auto 3.5rem auto;
    padding-left: 1rem;
}

/* Vertical connecting line */
.roadmap-timeline::before {
    content: '';
    position: absolute;
    top: 15px;
    bottom: 0;
    left: 24px;
    width: 2px;
    background: #2a2a2a;
    z-index: 0;
}

.roadmap-item {
    position: relative;
    display: flex;
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    z-index: 1;
}

.roadmap-item:last-child {
    margin-bottom: 0;
}

/* Number circle */
.roadmap-marker {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    background: #000000;
    border: 2px solid var(--accent);
    color: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    font-family: 'Open Sans', sans-serif;
    box-shadow: 0 0 0 4px #000000;
}

/* Active/filled marker variant */
.roadmap-marker.active {
    background: var(--accent);
    color: white;
}

.roadmap-content {
    flex: 1;
    padding-top: 0.2rem;
}

.roadmap-title {
    margin: 0 0 0.35rem 0;
    font-size: 1.15rem;
    color: #E0E0E0;
    font-weight: 700;
}

.roadmap-meta {
    display: inline-block;
    font-family: 'Open Sans', sans-serif;
    font-size: 0.85rem;
    color: var(--accent);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    margin-bottom: 0.6rem;
}

.roadmap-content p {
    margin: 0 0 1rem 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Tags */
.roadmap-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.roadmap-tags span {
    background: #1a1a1a;
    color: #9ca3af;
    padding: 0.2rem 0.65rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: 'Open Sans', sans-serif;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

/* Hover interactions */
.roadmap-item:hover .roadmap-marker {
    background: var(--accent);
    color: white;
    transform: scale(1.1);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.roadmap-item:hover .roadmap-tags span {
    background: #2a2a2a;
    border-color: #3a3a3a;
    box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

@media (max-width: 600px) {
    .roadmap-timeline::before {
        left: 15px;
    }

    .roadmap-timeline {
        padding-left: 0;
        margin-bottom: 4rem;
    }

    .roadmap-item {
        gap: 1rem;
    }
}


/* ============================================
   FLOW DIAGRAMS
   ============================================ */
.flow-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 2rem auto;
    align-items: center;
    max-width: 400px;
}

.flow-block {
    background: #6366f1;
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    width: 100%;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.flow-block p {
    margin: 0;
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    line-height: 1.4;
}

.flow-block strong {
    display: block;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: white;
}

.green-block {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.15);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.transparent-flow-block {
    background: rgba(15, 23, 42, 0.2);
    border: 2px dashed rgba(148, 163, 184, 0.25);
    box-shadow: none;
    padding: 1rem 1.5rem;
}

.transparent-flow-block p {
    margin: 0;
    color: rgba(255, 255, 255, 0.95);
    font-size: 0.9rem;
    line-height: 1.4;
}

.transparent-flow-block strong {
    display: block;
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: white;
}

.arrow {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 40px;
    color: white;
    font-size: 1.5rem;
    line-height: 1;
    margin: -0.15rem 0;
}

.arrow::after {
    content: '↓';
}


/* ============================================
   HORIZONTAL RULES
   ============================================ */
hr {
    border: none;
    height: 1px;
    background: var(--border-light);
    margin: 2rem 0;
}


/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 768px) {
    .chapter-container {
        padding: 1rem 0.75rem;
    }

    .chapter-header h1 {
        font-size: 2em;
    }

    .section-content,
    .subsection-content {
        padding: 0 5px;
    }

    .subsection-header {
        padding: 22px 5px 14px 5px;
    }

    .subsection-header::after {
        left: 5px;
    }

    .code-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .numbered-heading-block {
        gap: 0.5rem;
    }

    .numbered-heading-block > .number {
        min-width: 1.2rem;
        font-size: 0.9rem;
    }

    .code-block-wrapper {
        margin-left: 0;
        margin-right: 0;
    }

    .styled-table {
        width: 100%;
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 0.95rem;
    }

    .chapter-header {
        padding: 20px;
    }

    .chapter-header h1 {
        font-size: 1.75em;
    }

    .code-block-wrapper pre {
        padding: 1rem;
        font-size: 0.875em;
    }
}


/* ============================================
   ACCESSIBILITY & FOCUS STATES
   ============================================ */
:focus-visible {
    outline: 3px solid rgba(79, 70, 229, 0.5);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}


/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    * {
        box-shadow: none !important;
        text-shadow: none !important;
    }

    body {
        color: #111;
        background: #fff !important;
    }

    .chapter-container {
        background: #fff;
    }

    a {
        color: #000;
        text-decoration: none;
    }

    .chapter-header,
    .section-header {
        background: #fff !important;
        color: #000 !important;
        border: 2px solid #000;
    }

    pre {
        background: #f5f5f5 !important;
        color: #000 !important;
        border: 1px solid #ccc;
        page-break-inside: avoid;
    }

    .styled-table,
    pre,
    .tip-box,
    .explanation-box {
        page-break-inside: avoid;
    }

    h2,
    h3 {
        page-break-after: avoid;
    }

    .copy-button,
    .wrap-toggle-button {
        display: none;
    }
}

/* ============================================
   CHAPTER 20: DEPLOYMENT COMPONENTS
   ============================================ */

/* --- CI/CD Pipeline Tracker --- */
.pipeline-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin: 2.5rem 0;
    padding: 1.5rem;
    background-color: var(--bg-light);
    border-radius: 12px;
    border: 1px dashed var(--border-light);
}

.pipeline-step {
    flex: 1;
    text-align: center;
    position: relative;
}

.step-number {
    width: 32px;
    height: 32px;
    line-height: 32px;
    margin: 0 auto 0.75rem;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
}

.step-label {
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.step-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.pipeline-arrow {
    font-size: 1.5rem;
    color: var(--text-muted);
    padding-top: 0.5rem;
}

@media (max-width: 768px) {
    .pipeline-container {
        flex-direction: column;
        align-items: center;
    }
    .pipeline-arrow {
        transform: rotate(90deg);
        padding: 1rem 0;
    }
}

/* --- Storage Architecture Diagram --- */
.storage-diagram {
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--bg-light);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid var(--border-light);
    margin: 2rem 0;
    gap: 1rem;
}

.storage-box {
    flex: 1;
    padding: 1.5rem;
    border-radius: 8px;
    text-align: center;
    border: 2px solid;
}

.ephemeral {
    border-color: #ff6b6b;
    background-color: #2a1215;
}

.persistent {
    border-color: #51cf66;
    background-color: #0d2818;
}

.box-label {
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-size: 0.85rem;
    text-transform: uppercase;
}

.status-tag {
    margin-top: 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
}

.wipe { background: #3d1518; color: #ff6b6b; }
.save { background: #0d2818; color: #51cf66; }

.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.file-list li {
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 2px 0;
    font-family: var(--code-font, monospace);
}

.db-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.file-name {
    color: var(--text-primary);
    font-family: var(--code-font, monospace);
    font-size: 0.85rem;
}

.path-label {
    color: var(--text-secondary);
    font-family: var(--code-font, monospace);
}

.mount-arrow {
    flex: 0.5;
    text-align: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.arrow-line {
    height: 2px;
    background: repeating-linear-gradient(to right, var(--text-muted), var(--text-muted) 5px, transparent 5px, transparent 10px);
    margin-top: 5px;
}

@media (max-width: 600px) {
    .storage-diagram { flex-direction: column; }
    .mount-arrow { transform: rotate(90deg); margin: 1rem 0; }
}

/* --- README Anatomy Map (GitHub Dark Theme) --- */
.readme-map {
    background-color: #0d1117;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid #30363d;
    color: #c9d1d9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

.readme-block {
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 6px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    position: relative;
}

.readme-block.low-priority {
    opacity: 0.6;
    border-style: dashed;
}

.block-tag {
    position: absolute;
    top: -12px;
    right: 15px;
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.p1-tag { background: #238636; }
.p2-tag { background: #1f6feb; }
.p3-tag { background: #8957e5; }
.p4-tag { background: #6e7681; }

.readme-block h4 {
    color: #58a6ff;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

.readme-block .primary { border-left: 4px solid #238636; }

.readme-link {
    color: #58a6ff;
}

.screenshot-placeholder {
    background: #0d1117;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: #8b949e;
    font-style: italic;
    margin-top: 1rem;
    border: 2px dashed #30363d;
}

.annotation {
    color: #ff7b72;
    font-weight: 800;
    margin-left: 5px;
}

.mini-list {
    color: #c9d1d9;
    font-size: 0.9rem;
    line-height: 1.6;
}
