/**
 * UNIFIED NEPHROLOGY EDUCATION STYLES
 * Consolidated CSS for Urine Nephrology Now
 *
 * CONSOLIDATION NOTES:
 * - Merged nephrology-styles.css (UDPA lectures) + textbook styles.css
 * - Changed from institution-specific colors to neutral medical education palette
 * - Unified theme approach: [data-theme="dark"] attribute (removed .dark-mode class)
 * - Improved link readability: #1d4ed8 (light) / #60a5fa (dark) with font-weight: 500
 * - Combined all component styles (cards, buttons, tables, navigation, etc.)
 * - Maintained WCAG AA contrast compliance
 * - Print styles with proper attribution for Andrew Bland, MD
 *
 * COLOR PHILOSOPHY:
 * - Primary: Professional navy blue (#2c5282) - authoritative, medical
 * - Gradients: Subtle purple-blue blend for visual interest
 * - Neutrals: High-contrast grays for accessibility
 * - Accent colors: Color-coded boxes for clinical significance
 */

/* ============================================
   RESET & BASE STYLES
   ============================================ */

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

/* ============================================
   CSS VARIABLES - LIGHT MODE
   ============================================ */

:root {
    /* Primary Palette - Neutral Professional Medical Education Colors */
    --primary-color: #2c5282;
    --secondary-color: #3d5a96;
    --accent-color: #1e3a5f;

    /* Background & Surface */
    --background-color: #ffffff;
    --background: #ffffff;
    --surface-color: #f8f9fa;
    --background-elevated: #f8f9fa;

    /* Text Colors */
    --text-color: #2d3748;
    --text-secondary: #718096;

    /* Link Colors - High Readability */
    --link-color: #1d4ed8;
    --link-hover: #1e40af;

    /* Borders & Shadows */
    --border-color: #e2e8f0;
    --shadow-color: rgba(44, 82, 130, 0.1);

    /* Semantic Colors */
    --white: #ffffff;
    --gray-light: #f8f9fa;
    --gray: #e9ecef;
    --gray-dark: #6c757d;
}

/* ============================================
   CSS VARIABLES - DARK MODE
   ============================================ */

[data-theme="dark"] {
    /* Primary Palette - Dark Mode */
    --primary-color: #63b3ed;
    --secondary-color: #7ac1f5;
    --accent-color: #90cdf4;

    /* Background & Surface */
    --background-color: #121212;
    --background: #121212;
    --surface-color: #1e1e1e;
    --background-elevated: #2d3748;

    /* Text Colors - Enhanced for readability */
    --text-color: #ffffff;
    --text-secondary: #a0aec0;

    /* Link Colors - High Readability */
    --link-color: #60a5fa;
    --link-hover: #93c5fd;

    /* Borders & Shadows */
    --border-color: #4a5568;
    --shadow-color: rgba(255, 255, 255, 0.1);

    /* Semantic Colors */
    --white: #e2e8f0;
    --gray-light: #2d3748;
    --gray: #4a5568;
    --gray-dark: #cbd5e1;
}

/* ============================================
   BODY & CONTAINER
   ============================================ */

body {
    font-family: 'Georgia', serif;
    line-height: 1.6;
    color: var(--text-color);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    transition: background 0.3s ease, color 0.3s ease;
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: var(--background-color);
    box-shadow: 0 10px 30px var(--shadow-color);
    border-radius: 15px;
    transition: background-color 0.3s, box-shadow 0.3s;
}

/* ============================================
   HEADER & NAVIGATION
   ============================================ */

.header {
    text-align: center;
    color: var(--white);
    margin-bottom: 30px;
    padding: 30px 0;
    position: relative;
    border-bottom: 3px solid var(--primary-color);
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
    color: var(--white);
}

[data-theme="dark"] .header h1 {
    color: var(--primary-color);
}

.header p,
.header .subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
    font-style: italic;
    color: var(--text-secondary);
}

.author {
    color: var(--primary-color);
    font-size: 1.1em;
    font-weight: bold;
    margin-top: 10px;
}

/* Navigation Header */
.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

/* Top Navigation Bar (Global) */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--background);
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-nav .brand {
    font-weight: 800;
    color: var(--primary-color);
    text-decoration: none;
}

.top-nav .nav-links {
    display: flex;
    gap: 12px;
}

.top-nav .nav-links a,
.nav-links a {
    color: var(--link-color);
    text-decoration: none;
    margin: 0 10px;
    padding: 6px 10px;
    border-radius: 8px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.top-nav .nav-links a:hover,
.nav-links a:hover {
    background-color: var(--background-elevated);
    text-decoration: underline;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-color);
}

@media (max-width: 820px) {
    .nav-toggle {
        display: block;
    }
    .nav-links {
        display: none;
        flex-direction: column;
        gap: 8px;
        padding: 10px 0;
    }
    .nav-links.open {
        display: flex;
    }
}

/* Theme Toggle Button */
.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255,255,255,0.25);
    border: 2px solid rgba(255,255,255,0.4);
    color: #ffffff;
    padding: 10px 15px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.35);
    transform: translateY(-2px);
}

[data-theme="dark"] .theme-toggle {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.25);
    color: #ffffff;
}

/* ============================================
   CONTENT SECTIONS
   ============================================ */

.content {
    background: var(--background-color);
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px var(--shadow-color);
    margin-bottom: 20px;
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section {
    margin-bottom: 40px;
    padding: 20px;
    border-radius: 8px;
    background: var(--background-color);
    border-left: 4px solid var(--primary-color);
    overflow: auto;
}

.section.subtle {
    background: var(--background-elevated);
    border-radius: 12px;
    padding: 24px;
}

/* Section Headings */
.section h2 {
    color: var(--primary-color);
    font-size: 2em;
    margin-bottom: 25px;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 10px;
}

.section h3 {
    color: var(--text-color);
    font-size: 1.6em;
    margin: 25px 0 15px 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.section h4 {
    color: var(--text-color);
    font-size: 1.3em;
    margin: 20px 0 10px 0;
}

.section h5 {
    color: var(--text-color);
    font-size: 1.1em;
    margin: 15px 0 10px 0;
    font-style: italic;
}

/* Kicker Headings */
.kicker {
    color: var(--text-secondary);
    margin: 8px 0 4px;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Hero Section */
.hero {
    text-align: center;
    padding: 32px 0;
}

.hero .sub {
    opacity: 0.8;
    margin-top: 8px;
}

/* ============================================
   GRID & CARD LAYOUTS
   ============================================ */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.card {
    background: var(--background-elevated);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 15px var(--shadow-color);
    transition: transform 0.3s ease;
    border-left: 4px solid var(--primary-color);
}

.card:hover {
    transform: translateY(-5px);
}

.card h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}

.card ul {
    list-style: none;
    padding-left: 0;
}

.card li {
    margin: 8px 0;
    padding-left: 20px;
    position: relative;
    color: var(--text-secondary);
}

.card li::before {
    content: "🔑";
    position: absolute;
    left: 0;
}

.card li strong {
    color: var(--text-color);
}

/* Readable Links on Cards */
.card a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.card a:hover {
    text-decoration: underline;
}

/* Multi-Column Layout */
.cols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px 24px;
}

.cols a {
    display: block;
    color: var(--link-color);
    text-decoration: none;
    margin: 2px 0;
    font-weight: 500;
}

.cols a:hover {
    text-decoration: underline;
}

/* ============================================
   BUTTONS & NAVIGATION ELEMENTS
   ============================================ */

/* Floating Back Button (Universal) */
.back-button-floating {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 1000;
    background: var(--primary-color);
    color: #fff !important;
    text-decoration: none;
    padding: 10px 14px;
    border-radius: 9999px;
    font-weight: 600;
    box-shadow: 0 6px 18px rgba(0,0,0,0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.back-button-floating:hover,
.back-button-floating:focus-visible {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(0,0,0,0.25);
    background: var(--secondary-color);
    outline: none;
}

.back-button-floating:active {
    transform: translateY(0);
}

/* Back to Top Button */
.back-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary-color);
    color: white;
    padding: 12px 16px;
    border-radius: 50%;
    text-decoration: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    transition: opacity 0.3s, transform 0.3s;
    display: none;
    z-index: 1000;
    opacity: 0;
    transform: translateY(100px);
}

.back-to-top.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.back-to-section-top {
    font-style: italic;
    color: var(--link-color);
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
}

.back-to-section-top:hover {
    text-decoration: underline;
}

.section-footer-links {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 20px;
    margin-top: 25px;
    width: 100%;
}

/* Navigation Buttons */
.nav-buttons {
    display: flex;
    gap: 15px;
    margin: 20px 0;
    flex-wrap: wrap;
    justify-content: center;
}

.nav-button {
    background: var(--secondary-color);
    color: var(--white);
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px var(--shadow-color);
    font-size: 14px;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.nav-button:hover {
    background: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--shadow-color);
}

.nav-button.home {
    background: linear-gradient(135deg, #00b894, #00a085);
}

.nav-button.theme {
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(10px);
    border: 2px solid rgba(255,255,255,0.3);
}

/* CTA Buttons */
.cta-row {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 12px 0 8px;
}

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    text-decoration: none;
    color: var(--text-color);
    background: var(--background);
    font-weight: 500;
    transition: background 0.3s ease;
}

.btn:hover {
    background: var(--background-elevated);
}

.btn-primary {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.btn-primary:hover {
    filter: brightness(0.95);
}

/* Print Button */
.print-button {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
    color: var(--white);
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 10px;
}

.print-button:hover {
    background: linear-gradient(135deg, #c0392b, #a93226);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(231, 76, 60, 0.4);
}

.print-button:before {
    content: "🖨️";
}

/* Chips & Quick Links */
.chip {
    display: inline-block;
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--background-elevated);
    border: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-color);
    margin: 4px;
    font-weight: 500;
}

.quick-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* UDPA Quickbar */
.udpa-quickbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 8px;
    background: var(--background-elevated);
    border-radius: 12px;
    margin: 8px 0 16px;
}

.udpa-quickbar a {
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--background);
    border: 1px solid var(--border-color);
    color: var(--link-color);
    font-weight: 500;
}

.udpa-quickbar a:hover {
    background: var(--background-elevated);
}

/* ============================================
   TABLES
   ============================================ */

table,
.correction-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: 14px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border-radius: 10px;
    overflow: hidden;
    background: var(--background-color);
}

th {
    background: var(--primary-color);
    color: white;
    padding: 15px;
    text-align: center;
    font-weight: 600;
}

td {
    padding: 12px;
    text-align: left;
    border: 1px solid var(--border-color);
    vertical-align: top;
    color: var(--text-color);
}

.correction-table td {
    text-align: center;
}

tr:nth-child(even) {
    background: var(--background-elevated);
}

/* Risk Stratification Colors */
.risk-low {
    background-color: #dcfce7;
    color: #166534;
    font-weight: bold;
}

.risk-moderate {
    background-color: #ffedd5;
    color: #9a3412;
    font-weight: bold;
}

.risk-high {
    background-color: #fee2e2;
    color: #991b1b;
    font-weight: bold;
}

.risk-very-high {
    background-color: #ef4444;
    color: white;
    font-weight: bold;
}

[data-theme="dark"] .risk-low {
    background-color: #1c4532;
    color: #a7f3d0;
}

[data-theme="dark"] .risk-moderate {
    background-color: #6b3e1a;
    color: #fed7aa;
}

[data-theme="dark"] .risk-high {
    background-color: #7f1d1d;
    color: #fecaca;
}

[data-theme="dark"] .risk-very-high {
    background-color: #b91c1c;
    color: #fee2e2;
}

/* ============================================
   CLINICAL BOXES & CALLOUTS
   ============================================ */

.highlight-box,
.warning-box,
.info-box,
.clinical-pearl,
.stage-box,
.algorithm-step,
.medication-box {
    padding: 15px 15px 15px 25px;
    margin: 20px 0;
    border-radius: 6px;
}

.highlight-box ul,
.highlight-box ol,
.warning-box ul,
.warning-box ol,
.info-box ul,
.info-box ol,
.clinical-pearl ul,
.clinical-pearl ol,
.stage-box ul,
.stage-box ol,
.algorithm-step ul,
.algorithm-step ol {
    padding-left: 25px;
}

.highlight-box {
    background: #e0f2fe;
    border-left: 5px solid #0284c7;
}

.warning-box {
    background: #feefee;
    border-left: 5px solid #ef4444;
}

.info-box {
    background: #f0fdf4;
    border-left: 5px solid #22c55e;
}

.clinical-pearl {
    background: #fefce8;
    border-left: 5px solid #eab308;
}

.stage-box {
    border: 2px solid var(--primary-color);
    background: var(--background-elevated);
}

.medication-box {
    background: #fefce8;
    border: 1px solid #fde047;
}

.algorithm-step {
    background: #eef2ff;
    border-left: 5px solid #4f46e5;
}

/* Dark Mode Variants */
[data-theme="dark"] .highlight-box {
    background: #2c5282;
    border-left-color: #63b3ed;
    color: var(--text-color);
}

[data-theme="dark"] .warning-box {
    background: #742a2a;
    border-left-color: #fc8181;
    color: var(--text-color);
}

[data-theme="dark"] .info-box {
    background: #2f5d44;
    border-left-color: #68d391;
    color: var(--text-color);
}

[data-theme="dark"] .clinical-pearl {
    background: #746f36;
    border-left-color: #faf089;
    color: var(--text-color);
}

[data-theme="dark"] .stage-box {
    background: #374151;
    border-color: var(--primary-color);
}

[data-theme="dark"] .algorithm-step {
    background: #3c366b;
    border-left-color: #a78bfa;
    color: var(--text-color);
}

/* Formula & Normal Values Boxes */
.formula {
    background: #334155;
    color: white;
    padding: 15px;
    border-radius: 6px;
    font-family: 'Courier New', monospace;
    margin: 20px 0;
}

[data-theme="dark"] .formula {
    background: #1a202c;
}

.normal-values {
    background: #f0fdfa;
    border: 1px solid #99f6e4;
    padding: 15px;
    border-radius: 6px;
    margin: 20px 0;
}

[data-theme="dark"] .normal-values {
    background: #134e4a;
    border-color: #5eead4;
}

/* ============================================
   TREATMENT PROTOCOLS
   ============================================ */

.treatment-protocol {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--white);
    padding: 25px;
    border-radius: 15px;
    margin: 20px 0;
}

.protocol-step {
    background: rgba(255,255,255,0.95);
    color: #333;
    padding: 15px;
    margin: 10px 0;
    border-radius: 10px;
    border-left: 5px solid var(--accent-color);
    font-weight: 600;
}

.step-number {
    background: var(--accent-color);
    color: var(--white);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 15px;
    font-weight: bold;
}

/* ============================================
   INTERACTIVE ELEMENTS
   ============================================ */

.interactive-demo {
    background: var(--background-elevated);
    border-radius: 10px;
    padding: 20px;
    margin: 20px 0;
}

.slider-container {
    margin: 15px 0;
}

.slider {
    width: 100%;
    height: 5px;
    border-radius: 5px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
}

.result-display {
    background: var(--primary-color);
    color: var(--white);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
    margin-top: 15px;
    font-weight: bold;
}

/* ============================================
   TABLE OF CONTENTS
   ============================================ */

.toc {
    background: var(--background-elevated);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
}

.toc h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    text-align: center;
}

.toc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
    column-gap: 25px;
}

.toc-chapter {
    margin-bottom: 15px;
}

.toc-chapter-title {
    font-weight: bold;
    color: var(--text-color);
    margin-bottom: 5px;
    font-size: 1.1em;
}

.toc-chapter a {
    color: var(--link-color);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 4px;
    transition: background-color 0.3s;
    display: block;
    font-size: 0.95em;
    font-weight: 500;
}

.toc-chapter a:hover {
    background-color: var(--background-elevated);
    text-decoration: underline;
}

/* ============================================
   SEARCH
   ============================================ */

.search-container {
    margin-bottom: 30px;
    text-align: center;
}

.search-box {
    display: flex;
    justify-content: center;
    margin: 8px 0 16px;
}

.search-box input {
    width: min(800px, 92%);
    max-width: 400px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    background-color: var(--background-color);
    color: var(--text-color);
    transition: border-color 0.3s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

[data-theme="dark"] .search-box input {
    background-color: var(--surface-color);
}

[data-theme="dark"] .search-box input::placeholder {
    color: var(--text-secondary);
}

.search-hit {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Tool Links List */
.tool-links {
    list-style: none;
    padding: 0;
    margin: 8px 0 0 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 6px 12px;
}

.tool-links a {
    text-decoration: none;
    color: var(--link-color);
    font-weight: 500;
}

.tool-links a:hover {
    text-decoration: underline;
}

/* ============================================
   IMAGES & FIGURES
   ============================================ */

.skeleton-key-figure {
    text-align: center;
    margin: 12px 0 28px;
}

.skeleton-key-img {
    max-width: min(100%, 900px);
    height: auto;
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow-color);
    border: 1px solid var(--border-color);
    background: var(--background);
}

/* ============================================
   FOOTER
   ============================================ */

.site-footer {
    border-top: 1px solid var(--border-color);
    padding: 20px 0;
    margin-top: 24px;
    text-align: center;
}

.site-footer nav {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    margin-bottom: 6px;
}

.muted {
    color: var(--text-secondary);
}

.small {
    font-size: 0.9rem;
}

.print-footer {
    display: none;
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.page-break-before {
    page-break-before: always;
}

.page-break-after {
    page-break-after: always;
}

.no-page-break {
    page-break-inside: avoid;
}

/* Safeguards for hardcoded light backgrounds in dark mode */
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background: #ffffff"],
[data-theme="dark"] [style*="background:#ffffff"] {
    color: #111 !important;
}

/* ============================================
   TEXT CONTRAST FIXES
   Fix washed out text across the site
   ============================================ */

/* Footer text - remove opacity, ensure readability */
.site-footer p,
footer p {
    opacity: 1 !important;
    color: var(--text-secondary) !important;
}

/* Fix pale pink text (#ffecec) - make it white or properly contrasted */
[style*="color: #ffecec"],
[style*="color:#ffecec"] {
    color: #ffffff !important;
}

/* Fix yellow/gold text (#ffeb3b, #ffd700) - ensure proper contrast */
[style*="color: #ffeb3b"],
[style*="color:#ffeb3b"],
[style*="color: #ffd700"],
[style*="color:#ffd700"] {
    color: #1a202c !important;
    font-weight: 600 !important;
}

[data-theme="dark"] [style*="color: #ffeb3b"],
[data-theme="dark"] [style*="color:#ffeb3b"],
[data-theme="dark"] [style*="color: #ffd700"],
[data-theme="dark"] [style*="color:#ffd700"] {
    color: #fbbf24 !important;
    font-weight: 600 !important;
}

/* Fix light gray arrows and decorative elements */
.flow-arrow {
    color: var(--text-secondary) !important;
    font-weight: bold !important;
}

/* Fix cream/pale yellow text colors */
[style*="color: #fff3cd"],
[style*="color:#fff3cd"],
[style*="color: #ecf0f1"],
[style*="color:#ecf0f1"] {
    color: var(--text-color) !important;
}

/* Quick reference boxes - ensure visibility */
[style*="background: #ecf0f1"],
[style*="background:#ecf0f1"] {
    background: var(--background-elevated) !important;
    border: 2px solid var(--border-color) !important;
}

/* Ensure all subtitle and secondary text is readable */
.subtitle,
.sub,
.header p,
.header .subtitle {
    color: var(--text-secondary) !important;
    opacity: 1 !important;
    font-weight: 500 !important;
}

[data-theme="dark"] .subtitle,
[data-theme="dark"] .sub,
[data-theme="dark"] .header p,
[data-theme="dark"] .header .subtitle {
    color: var(--text-secondary) !important;
    opacity: 1 !important;
}

/* Fix ODS classification colors for better contrast */
.ods-low {
    background: #78350f !important;
    color: #fef3c7 !important;
}

.ods-moderate {
    background: #7c2d12 !important;
    color: #fed7aa !important;
}

.ods-high {
    background: #7f1d1d !important;
    color: #fecaca !important;
}

/* Ensure strong/bold text is always visible */
strong, b {
    color: var(--text-color);
    font-weight: 700;
}

[data-theme="dark"] strong,
[data-theme="dark"] b {
    color: var(--text-color);
}

/* Fix nav button theme variant */
.nav-button.theme {
    background: rgba(255,255,255,0.25);
    border: 2px solid rgba(255,255,255,0.4);
    color: #ffffff;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

[data-theme="dark"] .nav-button.theme {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.25);
}

/* ============================================
   FIX LIGHT BACKGROUNDS IN DARK MODE
   Override inline styles with light backgrounds
   ============================================ */

/* Light yellow/cream backgrounds - most common issue */
[data-theme="dark"] [style*="background: #fff3cd"],
[data-theme="dark"] [style*="background:#fff3cd"],
[data-theme="dark"] [style*="background: #fff3e0"],
[data-theme="dark"] [style*="background:#fff3e0"],
[data-theme="dark"] [style*="background: #fff8e1"],
[data-theme="dark"] [style*="background:#fff8e1"],
[data-theme="dark"] [style*="background: #fefce8"],
[data-theme="dark"] [style*="background:#fefce8"],
[data-theme="dark"] [style*="background: #fef3c7"],
[data-theme="dark"] [style*="background:#fef3c7"],
[data-theme="dark"] [style*="background: #fef9c3"],
[data-theme="dark"] [style*="background:#fef9c3"],
[data-theme="dark"] [style*="background: #fffacd"],
[data-theme="dark"] [style*="background:#fffacd"],
[data-theme="dark"] [style*="background: #fffbeb"],
[data-theme="dark"] [style*="background:#fffbeb"],
[data-theme="dark"] [style*="background: #fef5e7"],
[data-theme="dark"] [style*="background:#fef5e7"],
[data-theme="dark"] [style*="background: #fef9e7"],
[data-theme="dark"] [style*="background:#fef9e7"] {
    background: #78350f !important;
    color: #fef3c7 !important;
}

/* Light pink/red backgrounds */
[data-theme="dark"] [style*="background: #ffeaea"],
[data-theme="dark"] [style*="background:#ffeaea"],
[data-theme="dark"] [style*="background: #ffebee"],
[data-theme="dark"] [style*="background:#ffebee"],
[data-theme="dark"] [style*="background: #ffe6e6"],
[data-theme="dark"] [style*="background:#ffe6e6"],
[data-theme="dark"] [style*="background: #fee2e2"],
[data-theme="dark"] [style*="background:#fee2e2"],
[data-theme="dark"] [style*="background: #fef2f2"],
[data-theme="dark"] [style*="background:#fef2f2"],
[data-theme="dark"] [style*="background: #fff3f3"],
[data-theme="dark"] [style*="background:#fff3f3"],
[data-theme="dark"] [style*="background: #fff5f5"],
[data-theme="dark"] [style*="background:#fff5f5"] {
    background: #7f1d1d !important;
    color: #fecaca !important;
}

/* Fix all child elements in light pink/red backgrounds */
[data-theme="dark"] [style*="background: #ffeaea"] *,
[data-theme="dark"] [style*="background:#ffeaea"] *,
[data-theme="dark"] [style*="background: #ffebee"] *,
[data-theme="dark"] [style*="background:#ffebee"] *,
[data-theme="dark"] [style*="background: #ffe6e6"] *,
[data-theme="dark"] [style*="background:#ffe6e6"] *,
[data-theme="dark"] [style*="background: #fee2e2"] *,
[data-theme="dark"] [style*="background:#fee2e2"] *,
[data-theme="dark"] [style*="background: #fef2f2"] *,
[data-theme="dark"] [style*="background:#fef2f2"] *,
[data-theme="dark"] [style*="background: #fff3f3"] *,
[data-theme="dark"] [style*="background:#fff3f3"] *,
[data-theme="dark"] [style*="background: #fff5f5"] *,
[data-theme="dark"] [style*="background:#fff5f5"] * {
    color: #fecaca !important;
}

/* Light blue backgrounds */
[data-theme="dark"] [style*="background: #eff6ff"],
[data-theme="dark"] [style*="background:#eff6ff"],
[data-theme="dark"] [style*="background: #f0f8ff"],
[data-theme="dark"] [style*="background:#f0f8ff"],
[data-theme="dark"] [style*="background: #e0f2fe"],
[data-theme="dark"] [style*="background:#e0f2fe"],
[data-theme="dark"] [style*="background: #e0e7ff"],
[data-theme="dark"] [style*="background:#e0e7ff"] {
    background: #1e3a8a !important;
    color: #dbeafe !important;
}

/* Light green backgrounds */
[data-theme="dark"] [style*="background: #f0fdf4"],
[data-theme="dark"] [style*="background:#f0fdf4"],
[data-theme="dark"] [style*="background: #f0fdfa"],
[data-theme="dark"] [style*="background:#f0fdfa"] {
    background: #065f46 !important;
    color: #d1fae5 !important;
}

/* Fix all child elements in light yellow/cream backgrounds */
[data-theme="dark"] [style*="background: #fff3cd"] *,
[data-theme="dark"] [style*="background:#fff3cd"] *,
[data-theme="dark"] [style*="background: #fff3e0"] *,
[data-theme="dark"] [style*="background:#fff3e0"] *,
[data-theme="dark"] [style*="background: #fff8e1"] *,
[data-theme="dark"] [style*="background:#fff8e1"] *,
[data-theme="dark"] [style*="background: #fefce8"] *,
[data-theme="dark"] [style*="background:#fefce8"] *,
[data-theme="dark"] [style*="background: #fef3c7"] *,
[data-theme="dark"] [style*="background:#fef3c7"] *,
[data-theme="dark"] [style*="background: #fef9c3"] *,
[data-theme="dark"] [style*="background:#fef9c3"] *,
[data-theme="dark"] [style*="background: #fffacd"] *,
[data-theme="dark"] [style*="background:#fffacd"] *,
[data-theme="dark"] [style*="background: #fffbeb"] *,
[data-theme="dark"] [style*="background:#fffbeb"] *,
[data-theme="dark"] [style*="background: #fef5e7"] *,
[data-theme="dark"] [style*="background:#fef5e7"] *,
[data-theme="dark"] [style*="background: #fef9e7"] *,
[data-theme="dark"] [style*="background:#fef9e7"] * {
    color: #fef3c7 !important;
}

/* Fix all child elements in light blue backgrounds */
[data-theme="dark"] [style*="background: #eff6ff"] *,
[data-theme="dark"] [style*="background:#eff6ff"] *,
[data-theme="dark"] [style*="background: #f0f8ff"] *,
[data-theme="dark"] [style*="background:#f0f8ff"] *,
[data-theme="dark"] [style*="background: #e0f2fe"] *,
[data-theme="dark"] [style*="background:#e0f2fe"] *,
[data-theme="dark"] [style*="background: #e0e7ff"] *,
[data-theme="dark"] [style*="background:#e0e7ff"] * {
    color: #dbeafe !important;
}

/* Fix all child elements in light green backgrounds */
[data-theme="dark"] [style*="background: #f0fdf4"] *,
[data-theme="dark"] [style*="background:#f0fdf4"] *,
[data-theme="dark"] [style*="background: #f0fdfa"] *,
[data-theme="dark"] [style*="background:#f0fdfa"] * {
    color: #d1fae5 !important;
}

/* Fix table rows with light backgrounds */
[data-theme="dark"] tr[style*="background: #fff"],
[data-theme="dark"] tr[style*="background:#fff"],
[data-theme="dark"] td[style*="background: #fff"],
[data-theme="dark"] td[style*="background:#fff"] {
    background: var(--surface-color) !important;
    color: var(--text-color) !important;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    /* Reset body styling for print */
    body {
        background: white !important;
        color: black !important;
        font-family: 'Times New Roman', serif !important;
        font-size: 12pt;
        line-height: 1.4;
        margin: 0;
        padding: 0;
    }

    /* Hide interactive elements */
    .nav-buttons,
    .print-button,
    .theme-toggle,
    button,
    .interactive-demo,
    .slider-container,
    .search-container,
    .back-to-top,
    .back-to-section-top,
    .back-button-floating,
    #printBtn,
    #darkModeToggle,
    .nav-header,
    .top-nav {
        display: none !important;
    }

    /* Page setup */
    @page {
        size: letter;
        margin: 1in 0.75in 1.25in 0.75in;

        @top-right {
            content: "Copyright 2025 Andrew Bland MD";
            font-family: 'Times New Roman', serif;
            font-size: 9pt;
        }

        @top-center {
            content: "Nephrology Education - Andrew Bland MD";
            font-family: 'Times New Roman', serif;
            font-size: 10pt;
            font-weight: bold;
        }

        @bottom-left {
            content: "Andrew Bland MD";
            font-family: 'Times New Roman', serif;
            font-size: 9pt;
        }

        @bottom-center {
            content: "For Educational Use Only";
            font-family: 'Times New Roman', serif;
            font-size: 9pt;
            font-style: italic;
            font-weight: bold;
        }

        @bottom-right {
            content: "Page " counter(page);
            font-family: 'Times New Roman', serif;
            font-size: 9pt;
        }
    }

    /* Container and content styling */
    .container {
        max-width: none !important;
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
    }

    .header {
        background: none !important;
        color: black !important;
        text-align: center;
        margin-bottom: 20pt;
        padding: 0 !important;
        border-bottom: 2pt solid #2c5282;
        page-break-after: avoid;
    }

    .header h1 {
        font-size: 18pt !important;
        font-weight: bold;
        margin-bottom: 6pt;
        color: #2c5282 !important;
        text-shadow: none !important;
    }

    .header p,
    .header .subtitle {
        font-size: 12pt !important;
        margin-bottom: 12pt;
        color: black !important;
        opacity: 1 !important;
    }

    .content,
    .section {
        background: white !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 0 12pt 0 !important;
        page-break-inside: avoid;
    }

    /* Headings */
    h1 {
        font-size: 16pt !important;
        font-weight: bold;
        margin: 16pt 0 8pt 0;
        color: #2c5282 !important;
        page-break-after: avoid;
    }

    h2 {
        font-size: 14pt !important;
        font-weight: bold;
        margin: 14pt 0 6pt 0;
        color: #2c5282 !important;
        page-break-after: avoid;
    }

    h3 {
        font-size: 12pt !important;
        font-weight: bold;
        margin: 12pt 0 4pt 0;
        color: #2c5282 !important;
        page-break-after: avoid;
    }

    h4, h5, h6 {
        font-size: 11pt !important;
        font-weight: bold;
        margin: 10pt 0 3pt 0;
        color: #2c5282 !important;
        page-break-after: avoid;
    }

    /* Cards and grids */
    .grid {
        display: block !important;
        margin: 12pt 0 !important;
        page-break-after: always;
    }

    .grid:last-child {
        page-break-after: auto;
    }

    .card {
        background: white !important;
        border: 1pt solid #2c5282 !important;
        border-radius: 0 !important;
        padding: 8pt !important;
        margin: 6pt 0 !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        border-left: 3pt solid #2c5282 !important;
    }

    .card h3 {
        color: #2c5282 !important;
        border-bottom: 1pt solid #2c5282 !important;
        padding-bottom: 3pt !important;
        margin-bottom: 6pt !important;
    }

    /* Lists */
    ul, ol {
        margin: 6pt 0 6pt 18pt !important;
        padding: 0 !important;
    }

    li {
        margin: 3pt 0 !important;
        line-height: 1.3 !important;
        color: black !important;
    }

    .card li::before {
        content: "• " !important;
        font-weight: bold;
        color: #2c5282 !important;
    }

    /* Tables */
    table {
        width: 100% !important;
        border-collapse: collapse !important;
        margin: 12pt 0 !important;
        font-size: 10pt !important;
        page-break-inside: avoid;
        background: white !important;
    }

    th {
        background: #f0f0f0 !important;
        color: black !important;
        border: 1pt solid #2c5282 !important;
        padding: 6pt !important;
        font-weight: bold !important;
        text-align: center !important;
    }

    td {
        border: 1pt solid #2c5282 !important;
        padding: 6pt !important;
        background: white !important;
        color: black !important;
    }

    /* Treatment protocols */
    .treatment-protocol {
        background: #f8f9fa !important;
        border: 2pt solid #2c5282 !important;
        color: black !important;
        padding: 12pt !important;
        margin: 12pt 0 !important;
        border-radius: 0 !important;
        page-break-inside: avoid;
    }

    .protocol-step {
        background: white !important;
        color: black !important;
        padding: 8pt !important;
        margin: 6pt 0 !important;
        border-left: 3pt solid #2c5282 !important;
        border-radius: 0 !important;
    }

    .step-number {
        background: #2c5282 !important;
        color: white !important;
        display: inline-block !important;
        width: 18pt !important;
        height: 18pt !important;
        text-align: center !important;
        line-height: 18pt !important;
        border-radius: 50% !important;
        margin-right: 6pt !important;
        font-size: 9pt !important;
        font-weight: bold !important;
    }

    /* Links */
    a {
        color: #2c5282 !important;
        text-decoration: underline !important;
    }

    a:after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666;
    }

    /* Strong emphasis */
    strong, b {
        font-weight: bold !important;
        color: #2c5282 !important;
    }

    /* Ensure proper spacing */
    p {
        margin: 6pt 0 !important;
        text-align: justify !important;
    }

    /* Print footer */
    .print-footer {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        text-align: center;
        padding: 5px;
        font-size: 10pt;
        color: #666;
        border-top: 1px solid #ccc;
    }

    .dynamic-print-footer {
        display: block !important;
        visibility: visible !important;
    }

    /* Clinical boxes in print */
    .highlight-box,
    .warning-box,
    .info-box,
    .clinical-pearl,
    .stage-box,
    .algorithm-step {
        background: white !important;
        border: 1pt solid #2c5282 !important;
        color: black !important;
        page-break-inside: avoid;
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .grid,
    .toc-grid {
        grid-template-columns: 1fr;
    }

    .theme-toggle {
        position: static;
        margin: 10px auto;
        display: block;
    }

    .nav-buttons {
        flex-direction: column;
        align-items: center;
    }

    .nav-button {
        width: 200px;
        justify-content: center;
    }

    .print-button {
        width: 180px;
        justify-content: center;
    }
}
