/* Interactive code blocks */
.code-preview {
    position: relative;
    border-radius: 3px;
    background-color: var(--terra-color-carbon-5);
    margin-bottom: 1.5rem;
}

.code-preview__preview {
    position: relative;
    border: solid 1px var(--terra-color-carbon-20);
    border-bottom: none;
    border-top-left-radius: 3px;
    border-top-right-radius: 3px;
    background-color: var(--terra-color-carbon-5);
    min-width: 20rem;
    max-width: 100%;
    padding: 1.5rem 3.25rem 1.5rem 1.5rem;
}

/* Block the preview while dragging to prevent iframes from intercepting drag events */
.code-preview__preview--dragging:after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: ew-resize;
}

.code-preview__resizer {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 1.75rem;
    font-size: 20px;
    color: var(--terra-color-carbon-60);
    background-color: var(--terra-color-carbon-5);
    border-left: solid 1px var(--terra-color-carbon-20);
    border-top-right-radius: 3px;
    cursor: ew-resize;
}

@media screen and (max-width: 600px) {
    .code-preview__preview {
        padding-right: 1.5rem;
    }

    .code-preview__resizer {
        display: none;
    }
}

.code-preview__source {
    border: solid 1px var(--terra-color-carbon-20);
    border-bottom: none;
    border-radius: 0 !important;
    display: none;
}

.code-preview--expanded .code-preview__source {
    display: block;
}

.code-preview__source pre {
    margin: 0;
}

.code-preview__buttons {
    position: relative;
    border: solid 1px var(--terra-color-carbon-20);
    border-bottom-left-radius: 3px;
    border-bottom-right-radius: 3px;
    display: flex;
}

.code-preview__button {
    flex: 0 0 auto;
    height: 2.5rem;
    min-width: 2.5rem;
    border: none;
    border-radius: 0;
    background: var(--terra-color-carbon-5);
    font: inherit;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    color: var(--terra-color-carbon-60);
    padding: 0 1rem;
    cursor: pointer;
}

.code-preview__button:not(:last-of-type) {
    border-right: solid 1px var(--terra-color-carbon-20);
}

.code-preview__button--html,
.code-preview__button--react,
.code-preview__button--jupyter {
    width: 70px;
    display: flex;
    place-items: center;
    justify-content: center;
}

.code-preview__button--selected {
    font-weight: 700;
    color: var(--terra-color-primary-600);
}

.code-preview__button--codepen {
    display: flex;
    place-items: center;
    width: 6rem;
}

.code-preview__button:first-of-type {
    border-bottom-left-radius: 3px;
}

.code-preview__button:last-of-type {
    border-bottom-right-radius: 3px;
}

.code-preview__button:hover,
.code-preview__button:active {
    box-shadow: 0 0 0 1px var(--terra-color-primary-400);
    border-right-color: transparent;
    background-color: var(--terra-color-primary-50);
    color: var(--terra-color-primary-600);
    z-index: 1;
}

.code-preview__button:focus-visible {
    outline: none;
    outline: var(--terra-focus-ring);
    z-index: 2;
}

.code-preview__toggle {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    width: 100%;
    color: var(--terra-color-carbon-60);
    cursor: pointer;
}

.code-preview__toggle svg {
    width: 1em;
    height: 1em;
    margin-left: 0.25rem;
}

.code-preview--expanded .code-preview__toggle svg {
    transform: rotate(180deg);
}

/* We can apply data-flavor="html|react|jupyter" to any element on the page to toggle it when the flavor changes */
.flavor-html [data-flavor]:not([data-flavor='html']) {
    display: none;
}

.flavor-react [data-flavor]:not([data-flavor='react']) {
    display: none;
}

.flavor-jupyter [data-flavor]:not([data-flavor='jupyter']) {
    display: none;
}

/* Preview content switching */
.code-preview__preview-content {
    width: 100%;
}

.code-preview__preview-content:not([data-flavor='html']):not(
        [data-flavor='jupyter']
    ) {
    display: none;
}

/* Jupyter banner styling */
.code-preview__jupyter-banner {
    background-color: var(--terra-color-primary-50);
    border: 1px solid var(--terra-color-primary-200);
    border-radius: 3px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.code-preview__jupyter-banner p {
    margin: 0;
    font-size: 0.875rem;
    color: var(--terra-color-primary-700);
    line-height: 1.5;
}

/* Jupyter iframe styling - only in preview area */
.code-preview__preview-content[data-flavor='jupyter'] iframe {
    width: 100%;
    height: 600px;
    border: none;
    display: block;
}
