/* Documentation Markdown Styles - Mobile First Approach */

/* Base styles for mobile (default) */
.markdown-body {
    font-size: 1rem; /* 16px on mobile for better readability */
    line-height: 1.7;
    color: #334155;
    width: 100%; /* Explicit width for flex child */
    max-width: 100% !important; /* Override Tailwind's max-w-none */
    overflow-wrap: break-word;
    word-wrap: break-word;
}

/* Headings - Mobile first */
.markdown-body h1 {
    font-size: 1.75rem; /* 28px */
    font-weight: 700;
    color: #0f172a;
    margin-top: 1.5rem;
    margin-bottom: 1rem;
    line-height: 1.3;
}

.markdown-body h2 {
    font-size: 1.5rem; /* 24px */
    font-weight: 700;
    color: #0f172a;
    margin-top: 1.5rem;
    margin-bottom: 0.875rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #e2e8f0;
    line-height: 1.3;
}

.markdown-body h3 {
    font-size: 1.25rem; /* 20px */
    font-weight: 600;
    color: #1e293b;
    margin-top: 1.25rem;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.markdown-body h4 {
    font-size: 1.125rem; /* 18px */
    font-weight: 600;
    color: #1e293b;
    margin-top: 1rem;
    margin-bottom: 0.625rem;
    line-height: 1.4;
}

.markdown-body h5,
.markdown-body h6 {
    font-size: 1rem;
    font-weight: 600;
    color: #475569;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* Paragraphs */
.markdown-body p {
    margin-bottom: 1rem;
    line-height: 1.7;
}

/* Links */
.markdown-body a {
    color: #4751EB;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
}

.markdown-body a:hover {
    border-bottom-color: #4751EB;
}

/* Lists */
.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.markdown-body ul {
    list-style-type: disc;
}

.markdown-body ol {
    list-style-type: decimal;
}

.markdown-body li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.markdown-body li > p {
    margin-bottom: 0.5rem;
}

.markdown-body ul ul,
.markdown-body ol ul,
.markdown-body ul ol,
.markdown-body ol ol {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

/* Blockquotes */
.markdown-body blockquote {
    margin: 1rem 0;
    padding: 0.75rem 1rem;
    border-left: 4px solid #4751EB;
    background-color: #f8fafc;
    color: #475569;
    font-style: italic;
}

.markdown-body blockquote p:last-child {
    margin-bottom: 0;
}

/* Inline code */
.markdown-body code {
    background-color: #f1f5f9;
    color: #be123c;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: 'Courier New', Courier, monospace;
}

/* Code blocks */
.markdown-body pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 0.5rem;
    overflow-x: auto;
    margin-bottom: 1rem;
    -webkit-overflow-scrolling: touch;
}

.markdown-body pre code {
    background-color: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* 1. The Wrapper: Force it to respect the parent's width */
.markdown-body .codehilite {
    display: grid;           /* Grid children are better at respecting boundaries */
    width: 100%;             /* Occupy full width of article */
    max-width: 100%;
    min-width: 0;            /* CRITICAL: Allows grid item to shrink below content size */
    margin-bottom: 1.5rem;
    border-radius: 0.5rem;
    overflow: hidden;        /* Clip the pre's corners if needed */
}

/* 2. The Pre: The element that will actually scroll */
.markdown-body .codehilite pre {
    display: block;
    width: 100%;
    overflow-x: auto;        /* Enable the horizontal scrollbar */
    margin: 0;
    padding: 1.25rem;        /* Slightly more breathing room */
    
    /* Formatting */
    white-space: pre;        /* Keep lines long for scrolling */
    word-spacing: normal;
    word-break: normal;
    
    /* Theme */
    background-color: #1e293b;
    color: #e2e8f0;
    
    /* Mobile optimization */
    -webkit-overflow-scrolling: touch;
}

/* 3. The Code: Ensure background and text span the full scrollable width */
.markdown-body .codehilite pre code {
    display: inline-block;   /* Allows code to be wider than the pre container */
    min-width: 100%;         /* Ensure background color doesn't cut off */
    padding: 0;
    background-color: transparent;
    color: inherit;
    white-space: pre;        /* Inherit the pre's non-wrapping behavior */
}


/* Tables - Responsive wrapper */
.markdown-body .table-wrapper {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden; /* Hide overflow by default */
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
}

.markdown-body .table-wrapper table {
    max-width: 100%; /* Responsive minimum width for mobile devices */
    border-collapse: collapse;
    margin: 0;
    overflow-x: auto
}

.markdown-body .table-wrapper th,
.markdown-body .table-wrapper td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.markdown-body .table-wrapper th {
    background-color: #f8fafc;
    font-weight: 600;
    color: #0f172a;
    border-bottom: 2px solid #cbd5e1;
}

.markdown-body .table-wrapper tr:last-child td {
    border-bottom: none;
}

.markdown-body .table-wrapper tr:hover {
    background-color: #f8fafc;
}

/* Images */
.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin: 1rem 0;
    display: block;
}

/* Horizontal rule */
.markdown-body hr {
    border: none;
    border-top: 2px solid #e2e8f0;
    margin: 2rem 0;
}

/* Strong and emphasis */
.markdown-body strong {
    font-weight: 700;
    color: #0f172a;
}

.markdown-body em {
    font-style: italic;
}

/* Tablet styles (641px to 1024px) */
@media (min-width: 641px) and (max-width: 1024px) {
    .markdown-body {
        font-size: 0.9375rem; /* 15px */
    }

    .markdown-body h1 {
        font-size: 1.625rem; /* 26px */
    }

    .markdown-body h2 {
        font-size: 1.375rem; /* 22px */
    }

    .markdown-body h3 {
        font-size: 1.125rem; /* 18px */
    }

    .markdown-body h4 {
        font-size: 1rem; /* 16px */
    }

    .markdown-body pre code {
        font-size: 0.8125rem;
    }
}

/* Desktop styles (1025px and above) */
@media (min-width: 1025px) {
    .markdown-body {
        font-size: 0.875rem; /* 14px */
    }

    .markdown-body h1 {
        font-size: 1.5rem; /* 24px */
    }

    .markdown-body h2 {
        font-size: 1.25rem; /* 20px */
    }

    .markdown-body h3 {
        font-size: 1.125rem; /* 18px */
    }

    .markdown-body h4 {
        font-size: 1rem; /* 16px */
    }

    .markdown-body pre code {
        font-size: 0.8125rem;
    }

    .markdown-body th,
    .markdown-body td {
        padding: 0.625rem;
    }
}

/* Table of Contents specific styles */
.toc {
    font-size: 0.875rem;
}

.toc ul {
    list-style: none;
    padding-left: 0;
    margin: 0;
}

.toc li {
    margin-bottom: 0.5rem;
}

.toc a {
    color: #475569;
    text-decoration: none;
    display: block;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.toc a:hover {
    color: #4751EB;
    background-color: #f1f5f9;
    border-bottom: none;
}

.toc ul ul {
    padding-left: 1rem;
    margin-top: 0.25rem;
}

/* Floating TOC Button */
.floating-toc-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    background-color: #4751EB;
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(71, 81, 235, 0.3), 0 2px 6px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 40;
}

.floating-toc-btn:hover {
    background-color: #3640d4;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(71, 81, 235, 0.4), 0 3px 8px rgba(0, 0, 0, 0.15);
}

.floating-toc-btn:active {
    transform: scale(0.95);
}

/* Backdrop overlay */
.toc-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    z-index: 45;
}

.toc-backdrop.active {
    opacity: 1;
    visibility: visible;
}

/* TOC Modal */
.toc-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 500px;
    max-height: 60vh;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.toc-modal.active {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}

.toc-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.toc-modal-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Make TOC links in modal look good */
.toc-modal-content .toc ul {
    list-style: none;
    padding-left: 0;
}

.toc-modal-content .toc li {
    margin-bottom: 0.5rem;
}

.toc-modal-content .toc a {
    color: #475569;
    text-decoration: none;
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.toc-modal-content .toc a:hover {
    color: #4751EB;
    background-color: #f1f5f9;
    border-bottom: none;
}

.toc-modal-content .toc ul ul {
    padding-left: 1rem;
    margin-top: 0.25rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .floating-toc-btn {
        width: 48px;
        height: 48px;
        bottom: 16px;
        right: 16px;
    }
    
    .toc-modal {
        width: 95%;
        max-height: 65vh;
    }
    
    .toc-modal-header {
        padding: 1rem;
    }
    
    .toc-modal-content {
        padding: 1rem;
    }
}
