/**
 * Article Content Styles
 *
 * Handles the styling of HTML content rendered from article sections.
 * Targets elements inside .kb-article-section-content which contains
 * user-generated HTML from the CMS (headings, paragraphs, lists, images,
 * videos, iframes, code blocks, tables, etc.)
 */

/* ==========================================================================
   Container overflow guard — catches wide tables, pre blocks, or images
   that exceed the content width without needing a wrapper div.
   ========================================================================== */

.kb-article-section-content {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ==========================================================================
   Base Typography
   ========================================================================== */

.kb-article-section-content p {
    margin: 0 0 1rem 0;
}

.kb-article-section-content p:last-child {
    margin-bottom: 0;
}

.kb-article-section-content strong,
.kb-article-section-content b {
    font-weight: 600;
    color: var(--text-primary);
}

.kb-article-section-content em,
.kb-article-section-content i {
    font-style: italic;
}

.kb-article-section-content u {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.kb-article-section-content s,
.kb-article-section-content strike {
    text-decoration: line-through;
}

/* Links */
.kb-article-section-content a {
    color: var(--brand-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.kb-article-section-content a:hover {
    color: var(--brand-primary-hover);
    text-decoration: underline;
}

/* Ensure spans within links inherit link styling (e.g., c-mrkdwn__highlight from rich text editors) */
.kb-article-section-content a span,
.kb-article-section-content a .c-mrkdwn__highlight {
    color: inherit;
    background-color: transparent;
}

/* Headings within content (nested/additional headings) */
/* h2 - Normalize to match kb-article-section-subtitle for consistency */
.kb-article-section-content h2 {
    margin: 2rem 0 1rem 0;
    font-size: 1.375rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-secondary);
}

.kb-article-section-content h2:first-child {
    margin-top: 0;
}

.kb-article-section-content h3 {
    margin: 1.5rem 0 0.75rem 0;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
}

.kb-article-section-content h4 {
    margin: 1.25rem 0 0.625rem 0;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
}

.kb-article-section-content h5,
.kb-article-section-content h6 {
    margin: 1rem 0 0.5rem 0;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
}

.kb-article-section-content h3:first-child,
.kb-article-section-content h4:first-child,
.kb-article-section-content h5:first-child,
.kb-article-section-content h6:first-child {
    margin-top: 0;
}

/* ==========================================================================
   Lists
   ========================================================================== */

.kb-article-section-content ul,
.kb-article-section-content ol {
    margin: 0 0 1rem 0;
    padding-left: 1.5rem;
}

.kb-article-section-content ul {
    list-style-type: disc;
}

.kb-article-section-content ol {
    list-style-type: decimal;
}

.kb-article-section-content li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.kb-article-section-content li:last-child {
    margin-bottom: 0;
}

/* Nested lists */
.kb-article-section-content ul ul,
.kb-article-section-content ol ol,
.kb-article-section-content ul ol,
.kb-article-section-content ol ul {
    margin: 0.5rem 0 0 0;
}

.kb-article-section-content ul ul {
    list-style-type: circle;
}

.kb-article-section-content ul ul ul {
    list-style-type: square;
}

/* ==========================================================================
   Images
   ========================================================================== */

.kb-article-section-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    display: block;
    cursor: zoom-in;
}

.kb-article-section-content img:first-child {
    margin-top: 0;
}

.kb-article-section-content img:last-child {
    margin-bottom: 0;
}

/* Image with caption */
.kb-article-section-content figure {
    margin: 1.5rem 0;
    padding: 0;
}

.kb-article-section-content figure img {
    margin: 0;
}

.kb-article-section-content figcaption {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    text-align: center;
}

/* ==========================================================================
   Videos and Iframes
   ========================================================================== */

.kb-article-section-content video {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-md);
    margin: 1rem 0;
    display: block;
}

/* Responsive iframe container */
.kb-article-section-content iframe {
    max-width: 100%;
    border: none;
    border-radius: var(--radius-md);
    margin: 1rem 0;
}

/* Responsive video wrapper - for embedding YouTube, Vimeo, etc. */
.kb-article-section-content .video-wrapper,
.kb-article-section-content .embed-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    margin: 1.5rem 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background-color: var(--bg-tertiary);
}

.kb-article-section-content .video-wrapper iframe,
.kb-article-section-content .embed-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: 0;
}

/* ==========================================================================
   Code Blocks
   ========================================================================== */

/* Inline code */
.kb-article-section-content code {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Mono', 'Droid Sans Mono', 'Source Code Pro', monospace;
    font-size: 0.875em;
    padding: 0.125rem 0.375rem;
    background-color: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    word-break: break-word;
}

/* Code blocks */
.kb-article-section-content pre {
    margin: 1.25rem 0 1.5rem 0;
    padding: 1rem 1.25rem;
    background-color: var(--bg-code);
    border-radius: var(--radius-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    min-width: 0; /* Critical for flex containers - allows shrinking below content size */
}

.kb-article-section-content pre code {
    display: block;
    padding: 0;
    background: none;
    border-radius: 0;
    font-size: 0.8125rem;
    line-height: 1.6;
    color: var(--text-code);
    white-space: pre;
    word-break: normal;
}

/* Code block wrappers (e.g., Hugo/Chroma highlight) */
.kb-article-section-content .highlight_wrap,
.kb-article-section-content .highlight {
    max-width: 100%;
    min-width: 0; /* Allow shrinking in flex context */
}

/* Ensure all spans within code blocks inherit styling */
.kb-article-section-content pre code span,
.kb-article-section-content pre .line,
.kb-article-section-content pre .cl {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

/* Code block with line numbers */
.kb-article-section-content pre.line-numbers {
    padding-left: 3.5rem;
    position: relative;
}

.kb-article-section-content pre.line-numbers::before {
    content: attr(data-line-numbers);
    position: absolute;
    left: 0;
    top: 1rem;
    width: 2.5rem;
    padding-right: 0.5rem;
    text-align: right;
    color: var(--text-muted);
    font-size: 0.8125rem;
    line-height: 1.6;
    white-space: pre-line;
    border-right: 1px solid var(--border-secondary);
}

/* ==========================================================================
   Blockquotes
   ========================================================================== */

.kb-article-section-content blockquote {
    margin: 1.25rem 0;
    padding: 1rem 1.25rem;
    background-color: var(--bg-secondary);
    border-left: 4px solid var(--brand-primary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.kb-article-section-content blockquote p {
    margin: 0;
    font-style: italic;
    color: var(--text-secondary);
}

.kb-article-section-content blockquote p + p {
    margin-top: 0.75rem;
}

/* Nested blockquotes */
.kb-article-section-content blockquote blockquote {
    margin: 0.75rem 0 0 0;
    border-left-color: var(--text-muted);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.kb-article-section-content table {
    width: 100%;
    margin: 1.25rem 0;
    border-collapse: collapse;
    font-size: 0.9375rem;
}

.kb-article-section-content thead {
    background-color: var(--bg-tertiary);
}

.kb-article-section-content th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-secondary);
}

.kb-article-section-content td {
    padding: 0.75rem 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-tertiary, var(--border-secondary));
}

.kb-article-section-content tbody tr:last-child td {
    border-bottom: none;
}

.kb-article-section-content tbody tr:hover {
    background-color: var(--hover-bg);
}

/* Responsive table wrapper */
.kb-article-section-content .table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1.25rem 0;
}

.kb-article-section-content .table-wrapper table {
    margin: 0;
}

/* ==========================================================================
   Horizontal Rules
   ========================================================================== */

.kb-article-section-content hr {
    margin: 2rem 0;
    border: none;
    border-top: 1px solid var(--border-secondary);
}

/* ==========================================================================
   Callouts / Notes / Alerts
   ========================================================================== */

.kb-article-section-content .callout,
.kb-article-section-content .note,
.kb-article-section-content .alert {
    margin: 1.25rem 0;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    font-size: 0.9375rem;
    line-height: 1.6;
}

/* Info callout */
.kb-article-section-content .callout-info,
.kb-article-section-content .note-info {
    background-color: var(--info-bg);
    border: 1px solid var(--info-border);
    color: var(--info-text);
}

/* Success callout */
.kb-article-section-content .callout-success,
.kb-article-section-content .note-success {
    background-color: var(--success-bg);
    border: 1px solid var(--success-border);
    color: var(--success-text);
}

/* Warning callout */
.kb-article-section-content .callout-warning,
.kb-article-section-content .note-warning {
    background-color: var(--warning-bg);
    border: 1px solid var(--warning-border);
    color: var(--warning-text);
}

/* Danger callout */
.kb-article-section-content .callout-danger,
.kb-article-section-content .note-danger,
.kb-article-section-content .callout-error,
.kb-article-section-content .note-error {
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-text);
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media screen and (max-width: 768px) {
    .kb-article-section-content h2 {
        font-size: 1.25rem;
        margin: 1.5rem 0 0.875rem 0;
        padding-bottom: 0.375rem;
    }

    .kb-article-section-content h3 {
        font-size: 1.0625rem;
        margin: 1.25rem 0 0.625rem 0;
    }

    .kb-article-section-content h4 {
        font-size: 0.9375rem;
    }

    .kb-article-section-content ul,
    .kb-article-section-content ol {
        padding-left: 1.25rem;
    }

    .kb-article-section-content li {
        margin-bottom: 0.375rem;
    }

    .kb-article-section-content img {
        margin: 0.875rem 0;
    }

    .kb-article-section-content figure {
        margin: 1.25rem 0;
    }

    .kb-article-section-content figcaption {
        font-size: 0.8125rem;
    }

    .kb-article-section-content pre {
        padding: 0.875rem 1rem;
        margin: 1rem 0;
    }

    .kb-article-section-content pre code {
        font-size: 0.75rem;
    }

    .kb-article-section-content blockquote {
        padding: 0.875rem 1rem;
        margin: 1rem 0;
    }

    .kb-article-section-content table {
        font-size: 0.875rem;
    }

    .kb-article-section-content th,
    .kb-article-section-content td {
        padding: 0.625rem 0.75rem;
    }

    .kb-article-section-content .callout,
    .kb-article-section-content .note,
    .kb-article-section-content .alert {
        padding: 0.875rem 1rem;
        font-size: 0.875rem;
    }
}

@media screen and (max-width: 480px) {
    .kb-article-section-content h2 {
        font-size: 1.125rem;
        margin: 1.25rem 0 0.75rem 0;
        padding-bottom: 0.25rem;
    }

    .kb-article-section-content h3 {
        font-size: 1rem;
        margin: 1rem 0 0.5rem 0;
    }

    .kb-article-section-content h4 {
        font-size: 0.875rem;
    }

    .kb-article-section-content ul,
    .kb-article-section-content ol {
        padding-left: 1rem;
    }

    .kb-article-section-content li {
        margin-bottom: 0.25rem;
        line-height: 1.5;
    }

    .kb-article-section-content img {
        margin: 0.75rem 0;
        border-radius: var(--radius-sm);
    }

    .kb-article-section-content figure {
        margin: 1rem 0;
    }

    .kb-article-section-content figcaption {
        font-size: 0.75rem;
    }

    .kb-article-section-content .video-wrapper,
    .kb-article-section-content .embed-wrapper {
        margin: 1rem 0;
    }

    .kb-article-section-content code {
        font-size: 0.8125em;
        padding: 0.0625rem 0.25rem;
    }

    .kb-article-section-content pre {
        padding: 0.75rem;
        margin: 0.875rem 0;
        border-radius: var(--radius-sm);
    }

    .kb-article-section-content pre code {
        font-size: 0.6875rem;
        line-height: 1.5;
    }

    .kb-article-section-content blockquote {
        padding: 0.75rem;
        margin: 0.875rem 0;
        border-left-width: 3px;
    }

    .kb-article-section-content table {
        font-size: 0.8125rem;
    }

    .kb-article-section-content th,
    .kb-article-section-content td {
        padding: 0.5rem 0.625rem;
    }

    .kb-article-section-content hr {
        margin: 1.5rem 0;
    }

    .kb-article-section-content .callout,
    .kb-article-section-content .note,
    .kb-article-section-content .alert {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }
}
