/* Modern, Clean, Clinical but Warm Theme */
:root {
    --primary-color: #0e7490;
    /* Cyan 700 - Professional Teal */
    --secondary-color: #155e75;
    /* Cyan 800 */
    --accent-color: #06b6d4;
    /* Cyan 500 */
    --text-main: #334155;
    /* Slate 700 */
    --text-light: #64748b;
    /* Slate 500 */
    --bg-body: #f8fafc;
    /* Slate 50 */
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    /* Slate 200 */
    --font-heading: 'Merriweather', serif;
    --font-body: 'Inter', sans-serif;
    --spacing-unit: 1rem;
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    color: var(--text-main);
    background-color: var(--bg-body);
    line-height: 1.7;
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    font-family: var(--font-heading);
    color: var(--secondary-color);
    margin-bottom: 1rem;
    line-height: 1.3;
}

h1 {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 2rem;
    color: var(--primary-color);
}

h2 {
    font-size: 2.25rem;
    margin-top: 3rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--accent-color);
}

h3 {
    font-size: 1.5rem;
    margin-top: 2rem;
    color: var(--primary-color);
}

p {
    margin-bottom: 1.5rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Global Image Safety */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

.sidebar img {
    display: inline-block;
}

.image-wrapper {
    width: 100%;
    margin: 2rem 0;
    display: block;
    clear: both;
}

/* Layout */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
    background: var(--bg-card);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    min-height: 100vh;
}

/* Sidebar Navigation (Hidden on Print) */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    background: white;
    padding: 2rem;
    overflow-y: auto;
    border-right: 1px solid var(--border-color);
}

.sidebar ul {
    list-style: none;
}

.sidebar li {
    margin-bottom: 0.5rem;
}

.sidebar a {
    display: block;
    padding: 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.9rem;
}

.sidebar a:hover {
    background: var(--bg-body);
}

.main-content {
    margin-left: 250px;
    /* Offset for sidebar */
    padding: 4rem;
    max-width: 1000px;
}

/* Components */
.cover-page {
    height: 90vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    margin-bottom: 4rem;
    border-bottom: none;
}

.cover-image {
    max-width: 100%;
    height: auto;
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    margin: 2rem 0;
}

.chapter-header-image {
    width: 100%;
    height: auto;
    /* Allow full height to avoid cropping */
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    display: block;
    /* Ensure no inline-block gaps */
}


blockquote {
    border-left: 4px solid var(--accent-color);
    padding: 1rem 1.5rem;
    background: #ecfeff;
    /* Cyan 50 */
    margin-bottom: 1.5rem;
    border-radius: 0 0.5rem 0.5rem 0;
    font-style: italic;
    color: var(--text-main);
    /* Ensure contrast */
}

/* Diagrams High Contrast */
.mermaid-container {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: 0.5rem;
    border: 2px solid var(--primary-color);
    /* Thicker border */
    margin: 2rem 0;
    text-align: center;
}

/* Ensure Mermaid text is legible - will be handled by Mermaid config in HTML but container helps */

/* Print Styles */
@media print {
    body {
        background: white;
        font-size: 12pt;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        margin: 0;
        padding: 1cm;
        box-shadow: none;
        max-width: 100%;
    }

    .container {
        box-shadow: none;
        max-width: 100%;
        padding: 0;
        margin: 0;
    }

    h2 {
        page-break-before: always;
    }

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

    /* Evitar que las imágenes se corten entre páginas */
    img {
        page-break-inside: avoid;
        page-break-before: auto;
        page-break-after: auto;
        max-width: 100%;
        max-height: 90vh;
    }

    .image-wrapper {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .chapter-header-image {
        page-break-inside: avoid;
        break-inside: avoid;
        max-height: 40vh;
        width: auto;
        margin-bottom: 1rem;
    }

    .cover-image {
        page-break-inside: avoid;
        max-height: 60vh;
    }

    figure, .mermaid-container {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    blockquote {
        page-break-inside: avoid;
    }

    p {
        orphans: 3;
        widows: 3;
    }

    /* Start chapters on new pages */
    a {
        text-decoration: none;
        color: black;
    }

    .cover-page {
        height: 100vh;
        page-break-after: always;
    }
}

/* Mobile */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin: 0;
        padding: 1.5rem;
    }
}