/**
 * CodiCraft Theme Presentation Contract v1
 * =========================================
 *
 * Diese Datei gehört zum FRONTEND-THEME.
 *
 * Sie ist die gemeinsame Design-Schnittstelle zwischen:
 *
 *   aktives Frontend-Theme
 *          ↕
 *   Page-Builder-Canvas
 *          ↕
 *   semantisches builder_json
 *
 * Der Builder speichert weiterhin nur Rollen wie:
 *
 *   text_color = accent
 *   spacing = large
 *   width = wide
 *   background = dark
 *   button_variant = outline
 *
 * Die tatsächlichen Designwerte kommen ausschließlich aus dieser Datei.
 *
 * Vertrag:
 * - keine Werte aus dem Admin-Theme
 * - kein Parsing von style.css
 * - keine Hex-Farben im builder_json
 * - jedes Frontend-Theme definiert seine Tokenwerte selbst
 */

/* ==========================================================================
   1. THEME TOKENS
   ========================================================================== */

:root {
    /*
     * Contract-Marker.
     *
     * JavaScript kann damit erkennen, ob die Datei tatsächlich geladen ist.
     */
    --cc-theme-presentation-version: 1;

    /* Textrollen ---------------------------------------------------------- */

    --cc-theme-text-default: #334155;
    --cc-theme-text-muted: #64748b;
    --cc-theme-text-accent: #4f46e5;
    --cc-theme-text-light: #f8fafc;
    --cc-theme-text-dark: #0f172a;

    /* Hintergrundrollen -------------------------------------------------- */

    --cc-theme-bg-default: transparent;

    --cc-theme-bg-light:
        linear-gradient(
            180deg,
            rgba(248, 250, 252, 0.98),
            rgba(241, 245, 249, 0.92)
        );

    --cc-theme-bg-dark:
        radial-gradient(
            circle at top right,
            rgba(99, 102, 241, 0.20),
            transparent 38%
        ),
        #0f172a;

    --cc-theme-bg-accent:
        linear-gradient(
            135deg,
            #4f46e5 0%,
            #7c3aed 100%
        );

    /* Abstände ----------------------------------------------------------- */

    /*
     * Absichtlich px-basiert:
     * Das Admin-Theme verwendet eine andere rem-Basis als das Frontend.
     * Pixelwerte sorgen dafür, dass die sichtbare Builder-Vorschau denselben
     * absoluten Tokenwert verwendet.
     */
    --cc-theme-space-none: 0px;
    --cc-theme-space-small: 16px;
    --cc-theme-space-normal: 32px;
    --cc-theme-space-large: 64px;

    /*
     * Strukturblöcke dürfen eigene semantische Rhythmuswerte besitzen.
     */
    --cc-theme-section-space-none: 0px;
    --cc-theme-section-space-small: 28px;
    --cc-theme-section-space-normal: 54px;
    --cc-theme-section-space-large: 84px;

    --cc-theme-container-space-none: 0px;
    --cc-theme-container-space-small: 12px;
    --cc-theme-container-space-normal: 20px;
    --cc-theme-container-space-large: 36px;

    /* Breiten ------------------------------------------------------------ */

    --cc-theme-width-default: 820px;
    --cc-theme-width-wide: 1200px;
    --cc-theme-width-full: 100%;
    --cc-theme-site-gutter: clamp(16px, 4vw, 40px);

    /* Buttons ------------------------------------------------------------ */

    --cc-theme-button-primary-color: #ffffff;
    --cc-theme-button-primary-bg:
        linear-gradient(
            135deg,
            #4f46e5,
            #6d5dfc
        );
    --cc-theme-button-primary-border: rgba(67, 56, 202, 0.15);

    --cc-theme-button-secondary-color: #ffffff;
    --cc-theme-button-secondary-bg: #0f172a;
    --cc-theme-button-secondary-border: #0f172a;

    --cc-theme-button-outline-color: #4f46e5;
    --cc-theme-button-outline-bg: transparent;
    --cc-theme-button-outline-border: #4f46e5;

    /*
     * Alias-Zuordnung für das Default-Theme. style.css konsumiert diese
     * Variablennamen; presentation.css definiert ihre Werte als
     * Theme-Source-of-Truth.
     */
    --accent: var(--cc-theme-text-accent);
    --text-main: var(--cc-theme-text-default);
    --text-muted: var(--cc-theme-text-muted);
    --text-inverse: var(--cc-theme-text-light);
    --text-strong: var(--cc-theme-text-dark);

    --space-sm: var(--cc-theme-space-small);
    --space-md: var(--cc-theme-space-normal);
    --space-lg: var(--cc-theme-space-large);

    --content-width: var(--cc-theme-width-default);
    --wide-width: var(--cc-theme-width-wide);
    --site-gutter: var(--cc-theme-site-gutter);
}

/* ==========================================================================
   2. ALIGNMENT
   ========================================================================== */

.cc-heading.cc-align--left,
.cc-richtext.cc-align--left {
    text-align: left;
}

.cc-heading.cc-align--center,
.cc-richtext.cc-align--center {
    text-align: center;
}

.cc-heading.cc-align--right,
.cc-richtext.cc-align--right {
    text-align: right;
}

.cc-button.cc-align--left,
.cc-button.cc-align--center,
.cc-button.cc-align--right {
    display: flex;
    width: max-content;
    max-width: 100%;
}

.cc-button.cc-align--left {
    margin-left: 0;
    margin-right: auto;
}

.cc-button.cc-align--center {
    margin-left: auto;
    margin-right: auto;
}

.cc-button.cc-align--right {
    margin-left: auto;
    margin-right: 0;
}

/* ==========================================================================
   3. TEXT COLORS
   ========================================================================== */

.cc-heading.cc-text--default,
.cc-richtext.cc-text--default {
    color: var(--cc-theme-text-default);
}

.cc-heading.cc-text--muted,
.cc-richtext.cc-text--muted {
    color: var(--cc-theme-text-muted);
}

.cc-heading.cc-text--accent,
.cc-richtext.cc-text--accent {
    color: var(--cc-theme-text-accent);
}

.cc-heading.cc-text--light,
.cc-richtext.cc-text--light {
    color: var(--cc-theme-text-light);
}

.cc-heading.cc-text--dark,
.cc-richtext.cc-text--dark {
    color: var(--cc-theme-text-dark);
}

/*
 * RichText-interne Überschriften folgen bei expliziter Blockfarbe
 * derselben semantischen Rolle.
 */
.cc-richtext.cc-text--default :is(h2, h3, h4),
.cc-richtext.cc-text--muted :is(h2, h3, h4),
.cc-richtext.cc-text--accent :is(h2, h3, h4),
.cc-richtext.cc-text--light :is(h2, h3, h4),
.cc-richtext.cc-text--dark :is(h2, h3, h4) {
    color: inherit;
}

/* --------------------------------------------------------------------------
   3.1 INLINE RICH-TEXT TOKENS
   -------------------------------------------------------------------------- */

.cc-inline-text--muted {
    color: var(--cc-theme-text-muted);
}

.cc-inline-text--accent {
    color: var(--cc-theme-text-accent);
}

.cc-inline-text--light {
    color: var(--cc-theme-text-light);
}

.cc-inline-text--dark {
    color: var(--cc-theme-text-dark);
}

.cc-inline-highlight {
    padding: 0 0.12em;
    color: inherit;
    background:
        color-mix(
            in srgb,
            var(--cc-theme-text-accent) 18%,
            transparent
        );
    border-radius: 0.2em;
}

.cc-richtext code {
    padding: 0.12em 0.35em;
    color: var(--cc-theme-text-dark);
    background:
        color-mix(
            in srgb,
            var(--cc-theme-text-muted) 12%,
            transparent
        );
    border-radius: 0.3em;
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 0.92em;
}

.cc-richtext pre {
    margin: 1.1em 0;
    padding: 1em 1.1em;
    overflow-x: auto;
    color: var(--cc-theme-text-light);
    background: var(--cc-theme-text-dark);
    border-radius: 0.7em;
    white-space: pre;
}

.cc-richtext pre code {
    padding: 0;
    color: inherit;
    background: transparent;
    border-radius: 0;
}

/* ==========================================================================
   4. SPACING
   ========================================================================== */

.cc-section.cc-spacing--none {
    --cc-section-space:
        var(--cc-theme-section-space-none);
}

.cc-section.cc-spacing--small {
    --cc-section-space:
        var(--cc-theme-section-space-small);
}

.cc-section.cc-spacing--normal {
    --cc-section-space:
        var(--cc-theme-section-space-normal);
}

.cc-section.cc-spacing--large {
    --cc-section-space:
        var(--cc-theme-section-space-large);
}

/*
 * Falls ein Theme keine vorhandene cc-section-Basisregel besitzt, bleibt
 * der Contract trotzdem funktionsfähig.
 */
.cc-section.cc-spacing--none,
.cc-section.cc-spacing--small,
.cc-section.cc-spacing--normal,
.cc-section.cc-spacing--large {
    padding-block:
        var(
            --cc-section-space,
            var(--cc-theme-section-space-normal)
        );
}

.cc-container.cc-spacing--none,
.cc-column.cc-spacing--none {
    padding-block:
        var(--cc-theme-container-space-none);
}

.cc-container.cc-spacing--small,
.cc-column.cc-spacing--small {
    padding-block:
        var(--cc-theme-container-space-small);
}

.cc-container.cc-spacing--normal,
.cc-column.cc-spacing--normal {
    padding-block:
        var(--cc-theme-container-space-normal);
}

.cc-container.cc-spacing--large,
.cc-column.cc-spacing--large {
    padding-block:
        var(--cc-theme-container-space-large);
}

:is(
    .cc-heading,
    .cc-richtext,
    .cc-image,
    .cc-button,
    .cc-divider,
    .cc-columns
).cc-spacing--none {
    margin-block:
        var(--cc-theme-space-none);
}

:is(
    .cc-heading,
    .cc-richtext,
    .cc-image,
    .cc-button,
    .cc-divider,
    .cc-columns
).cc-spacing--small {
    margin-block:
        var(--cc-theme-space-small);
}

:is(
    .cc-heading,
    .cc-richtext,
    .cc-image,
    .cc-button,
    .cc-divider,
    .cc-columns
).cc-spacing--normal {
    margin-block:
        var(--cc-theme-space-normal);
}

:is(
    .cc-heading,
    .cc-richtext,
    .cc-image,
    .cc-button,
    .cc-divider,
    .cc-columns
).cc-spacing--large {
    margin-block:
        var(--cc-theme-space-large);
}

/* ==========================================================================
   5. WIDTH
   ========================================================================== */

.cc-width--default {
    width:
        min(
            calc(
                100%
                - (
                    2
                    * var(--cc-theme-site-gutter)
                )
            ),
            var(--cc-theme-width-default)
        );
    margin-inline: auto;
}

.cc-width--wide {
    width:
        min(
            calc(
                100%
                - (
                    2
                    * var(--cc-theme-site-gutter)
                )
            ),
            var(--cc-theme-width-wide)
        );
    margin-inline: auto;
}

.cc-width--full {
    width: var(--cc-theme-width-full);
    max-width: none;
    margin-inline: 0;
}

:is(
    .cc-heading,
    .cc-richtext
).cc-width--full {
    padding-inline:
        var(--cc-theme-site-gutter);
}

/* ==========================================================================
   6. BACKGROUNDS
   ========================================================================== */

.cc-bg--default {
    background:
        var(--cc-theme-bg-default);
}

.cc-bg--light {
    color:
        var(--cc-theme-text-default);

    background:
        var(--cc-theme-bg-light);
}

.cc-bg--dark {
    color:
        var(--cc-theme-text-light);

    background:
        var(--cc-theme-bg-dark);
}

.cc-bg--accent {
    color:
        var(--cc-theme-text-light);

    background:
        var(--cc-theme-bg-accent);
}

/*
 * Explizite text_color-Rollen gewinnen weiterhin gegen den Parent-Kontext.
 */
:is(
    .cc-bg--dark,
    .cc-bg--accent
)
:is(
    .cc-heading,
    .cc-richtext
):not(
    .cc-text--default,
    .cc-text--muted,
    .cc-text--accent,
    .cc-text--light,
    .cc-text--dark
) {
    color: inherit;
}

/* ==========================================================================
   7. BUTTON VARIANTS
   ========================================================================== */

.cc-button.cc-button--primary {
    color:
        var(--cc-theme-button-primary-color);

    background:
        var(--cc-theme-button-primary-bg);

    border-color:
        var(--cc-theme-button-primary-border);
}

.cc-button.cc-button--secondary {
    color:
        var(--cc-theme-button-secondary-color);

    background:
        var(--cc-theme-button-secondary-bg);

    border-color:
        var(--cc-theme-button-secondary-border);
}

.cc-button.cc-button--outline {
    color:
        var(--cc-theme-button-outline-color);

    background:
        var(--cc-theme-button-outline-bg);

    border-color:
        var(--cc-theme-button-outline-border);

    box-shadow: none;
}

/* PB-R1.4: semantische Rich-Text-Tabellen */
.cc-richtext-table-wrap {
    max-width: 100%;
    margin: 1.5rem 0;
    overflow-x: auto;
}

.cc-richtext-table {
    width: 100%;
    min-width: 32rem;
    border-collapse: collapse;
}

.cc-richtext-table th,
.cc-richtext-table td {
    padding: 0.8rem 0.9rem;
    vertical-align: top;
    border: 1px solid currentColor;
    border-color: color-mix(in srgb, currentColor 20%, transparent);
}

.cc-richtext-table th {
    font-weight: 700;
    background: color-mix(in srgb, currentColor 5%, transparent);
}

.cc-richtext-table th > p,
.cc-richtext-table td > p {
    margin: 0;
}

/* PB-R1.6: Core-Datei-/Download-Block */
.cc-file {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.1rem;
    border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
    border-radius: 0.75rem;
}

.cc-file-content {
    min-width: 0;
}

.cc-file-title,
.cc-file-description,
.cc-file-meta {
    display: block;
}

.cc-file-description,
.cc-file-meta {
    margin: 0.35rem 0 0;
}

.cc-file-meta {
    opacity: 0.72;
    font-size: 0.9em;
}

.cc-file-download {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.6rem;
    padding: 0.65rem 0.9rem;
    border: 1px solid currentColor;
    border-radius: 0.55rem;
    color: inherit;
    text-decoration: none;
    font-weight: 700;
}

.cc-file-download:hover {
    text-decoration: none;
}

@media (max-width: 620px) {
    .cc-file {
        align-items: stretch;
        flex-direction: column;
    }

    .cc-file-download {
        width: 100%;
    }
}

