/**
 * OpenGist Block — Frontend Styles
 *
 * Matches the theme's terminal-style <pre><code> blocks, adding:
 * - Header: Ubuntu dots (left) + collapse/expand toggle (center) + filename link (right)
 * - Collapsible code container
 * - Footer: collapse/expand toggle (center) + filename link (right)
 */

/* --- Base container --- */
.atareao-opengist {
    margin: 1.5rem 0;
}

.atareao-opengist + .atareao-opengist {
    margin-top: 1rem;
}

/* --- Per-file wrapper --- */
.atareao-opengist-file {
    border-radius: 0.5rem;
    overflow: hidden;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* === HEADER === */
.atareao-opengist-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    height: 32px;
    padding: 0 0.75rem;
    background: linear-gradient(to bottom, #3c0a2a, #2a0820);
    border-bottom: 1px solid #1a0510;
}

/* Left: Ubuntu terminal dots */
.atareao-opengist-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: start;
}

.atareao-opengist-dot {
    display: block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

.atareao-opengist-dot-red {
    background: #ee5f57;
}

.atareao-opengist-dot-yellow {
    background: #f5bd4f;
}

.atareao-opengist-dot-green {
    background: #61c554;
}

/* Center: toggle button */
.atareao-opengist-header .atareao-opengist-toggle {
    justify-self: center;
}

/* Right: filename link */
.atareao-opengist-header .atareao-opengist-filename {
    justify-self: end;
}

/* === TOGGLE BUTTON (shared header + footer) === */
.atareao-opengist-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.2rem 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.25rem;
    color: rgba(255, 255, 255, 0.65);
    font-family: var(--font-mono, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace);
    font-size: 0.6875rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    outline: none;
    line-height: 1;
    white-space: nowrap;
    flex-shrink: 0;
}

.atareao-opengist-toggle:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
}

.atareao-opengist-toggle:focus-visible {
    outline: 2px solid #61c554;
    outline-offset: 2px;
}

.atareao-opengist-toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
    font-size: 0.5625rem;
    line-height: 1;
}

.atareao-opengist-toggle.expanded .atareao-opengist-toggle-icon {
    transform: rotate(180deg);
}

.atareao-opengist-toggle-text {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.625rem;
}

/* === FILENAME LINK (shared header + footer) === */
.atareao-opengist-filename {
    font-family: var(--font-mono, 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace);
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: color 0.2s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 40%;
}

.atareao-opengist-filename:hover {
    color: #ffffff;
    text-decoration: underline;
}

/* === CODE CONTAINER (collapsible wrapper around <pre>) === */
.atareao-opengist-code-container {
    position: relative;
    max-height: 100px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.atareao-opengist-code-container.expanded {
    max-height: none;
}

/* Gradient fade at bottom when collapsed */
.atareao-opengist-code-container::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: linear-gradient(to bottom, transparent, #300a24);
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.atareao-opengist-code-container.expanded::after {
    opacity: 0;
}

/* === <pre> — let theme styles apply, remove title bar extras === */
.atareao-opengist-code {
    margin: 0 !important;
    /* Remove theme's title bar padding (32px) since header is separate */
    padding: 0.75rem 1.5rem 1.5rem !important;
    border-top: none !important;
    border-top-left-radius: 0 !important;
    border-top-right-radius: 0 !important;
}

/* Remove theme's terminal buttons and title bar pseudo-elements */
.atareao-opengist-code::before,
.atareao-opengist-code::after {
    display: none !important;
    content: none !important;
}

.atareao-opengist-code code {
    display: block;
}

/* === FOOTER === */
.atareao-opengist-footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0.3rem 0.75rem;
    background: linear-gradient(to bottom, #2a0820, #1a0510);
    border-top: 1px solid #1a0510;
    min-height: 28px;
}

.atareao-opengist-footer .atareao-opengist-toggle {
    justify-self: center;
}

.atareao-opengist-footer .atareao-opengist-filename {
    justify-self: end;
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.5);
}

/* --- Placeholder (when config is incomplete) --- */
.atareao-opengist-placeholder {
    padding: 1.5rem;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    border: 1px dashed #1a0510;
    border-radius: 0.5rem;
    background: #300a24;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .atareao-opengist {
        margin: 1rem -1rem;
    }

    .atareao-opengist-file {
        border-radius: 0;
    }

    .atareao-opengist-header {
        height: 28px;
        padding: 0 0.5rem;
    }

    .atareao-opengist-dot {
        width: 10px;
        height: 10px;
    }

    .atareao-opengist-header-left {
        gap: 6px;
    }

    .atareao-opengist-toggle {
        padding: 0.15rem 0.375rem;
        font-size: 0.625rem;
    }

    .atareao-opengist-filename {
        font-size: 0.6875rem;
    }

    .atareao-opengist-code {
        padding: 0.625rem 1rem 1rem !important;
    }

    .atareao-opengist-footer {
        padding: 0.25rem 0.5rem;
    }
}

/* --- Dark mode --- */
@media (prefers-color-scheme: dark) {
    .atareao-opengist-code-container::after {
        background: linear-gradient(to bottom, transparent, #1a0510);
    }

    .atareao-opengist-placeholder {
        background: #1a0510;
        border-color: #0a0005;
    }
}

/* Embed fallback (script mode) */
.atareao-opengist opengist-embed {
    display: block;
    min-height: 100px;
}