/* KI-Bilder – Eingabefeld für alle Designer (Aussehen wie im Druckdesigner 1.13.0, passt zum Bootstrap-Theme) */

.bb-ai-panel {
    position: relative;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    /* füllt die Höhe des Containers, wenn der Designer eine vorgibt (sonst wie bisher nach Inhalt) */
    min-height: calc(100% - 8px);
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--bb-ai-accent, var(--bs-primary, #0b6bcb));
    border-radius: 8px;
    background: var(--bb-ai-panel-bg, var(--bb-ai-surface, #fff));
    color: var(--bb-ai-text-color, inherit);
    font-family: var(--bb-ai-font-family, inherit);
    text-align: left;
}

/* Leicht getönter Hintergrund in der Akzentfarbe (nur Browser mit color-mix, sonst Fläche) */
@supports (background: color-mix(in srgb, red 5%, white)) {
    .bb-ai-panel {
        background: var(--bb-ai-panel-bg, color-mix(in srgb, var(--bb-ai-accent, var(--bs-primary, #0b6bcb)) 5%, var(--bb-ai-surface, #fff)));
    }
}

.bb-ai-panel [hidden] {
    display: none !important;
}

.bb-ai-head {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 4px 8px;
    margin-bottom: 4px;
}

.bb-ai-label {
    margin: 0;
    font-family: var(--bb-ai-heading-font-family, inherit);
    font-size: .82rem;
    font-weight: 600;
}

/* Tipps als kleiner Textlink rechts neben der Überschrift, nur per Klick */
.bb-ai-tip-wrap {
    margin-left: auto;
    text-align: right;
}

.bb-ai-tip-link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--bb-ai-accent, var(--bs-primary, #0b6bcb));
    font-size: .72rem;
    font-weight: 500;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.bb-ai-tip-link[aria-expanded="true"] {
    text-decoration: none;
}

.bb-ai-tips {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 60vh;
    overflow: auto;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--bb-ai-tips-bg, #22272e);
    color: var(--bb-ai-tips-color, #fff);
    font-size: .78rem;
    line-height: 1.45;
    white-space: pre-line;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
    cursor: pointer;
}

.bb-ai-prompt {
    display: block;
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    margin-bottom: 8px;
    font-family: inherit;
    font-size: .9rem;
}

/* Hinweis zu verbotenen Inhalten – direkt unter dem Prompt */
.bb-ai-content {
    margin: 0 0 8px;
    padding: 6px 8px;
    border-left: 3px solid var(--bb-ai-warning-color, #c0392b);
    border-radius: 4px;
    background: var(--bb-ai-warning-bg, rgba(192, 57, 43, .06));
    font-size: .74rem;
    line-height: 1.4;
    white-space: pre-line;
}

.bb-ai-privacy {
    margin: 0 0 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--bb-ai-note-bg, rgba(0, 0, 0, .04));
    font-size: .74rem;
    line-height: 1.4;
    color: var(--bb-ai-note-color, var(--bs-secondary-color, #5c6670));
    white-space: pre-line;
}

.bb-ai-privacy a {
    color: inherit;
    text-decoration: underline;
}

/* Unter dem Knopf: Restanzeige links, Hinweis des Designers (Option footerText) rechts */
.bb-ai-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
}

.bb-ai-footer {
    color: var(--bb-ai-muted, #6b7280);
    font-size: .74rem;
    line-height: 1.4;
    text-align: right;
}

.bb-ai-hint {
    margin: 0 0 8px;
    color: var(--bb-ai-muted, #6b7280);
    font-size: .76rem;
}

.bb-ai-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.bb-ai-info {
    font-size: .82rem;
    font-weight: 600;
}

.bb-ai-info.is-empty {
    color: var(--bb-ai-danger, var(--bs-danger, #c0392b));
}

/* Knopf „Bild erstellen“ über die ganze Breite des Felds (ab 1.0.23) */
.bb-ai-go {
    width: 100%;
}

/* Ladeanzeige (nur wenn der Designer keine eigene hat) */
.bb-ai-busy {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: .82rem;
    color: var(--bb-ai-muted, #6b7280);
}

.bb-ai-spinner {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: bb-ai-spin .8s linear infinite;
}

@keyframes bb-ai-spin {
    to {
        transform: rotate(360deg);
    }
}

.bb-ai-panel.is-busy .bb-ai-prompt {
    opacity: .7;
}

/* Meldung (nur wenn der Designer keine eigene hat) */
.bb-ai-message {
    margin-top: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: var(--bb-ai-danger-bg, rgba(192, 57, 43, .08));
    color: var(--bb-ai-danger, var(--bs-danger, #c0392b));
    font-size: .8rem;
}

/* KI-Credits */
.bb-ai-credits {
    margin-top: .6rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .75rem;
    font-size: .875rem;
}

.bb-ai-credits.is-needed {
    padding: .65rem .75rem;
    border: 1px solid var(--bb-ai-accent, var(--bs-primary, #0d6efd));
    border-radius: .5rem;
    background: var(--bb-ai-box-bg, rgba(13, 110, 253, .05));
}

.bb-ai-credits-text {
    flex: 1 1 12rem;
}

.bb-ai-credits.is-needed .bb-ai-credits-text {
    flex-basis: 100%;
    font-weight: 600;
}

.bb-ai-credits-hint {
    flex-basis: 100%;
    color: var(--bb-ai-muted, #6b7280);
    font-size: .85rem;
}

.bb-ai-credits .btn-link {
    padding: 0;
}

/* Stilvorschläge */
.bb-ai-styles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin: 8px 0 4px;
}

.bb-ai-styles-label {
    margin-right: 2px;
    font-size: .78rem;
    font-weight: 600;
}

.bb-ai-style {
    min-height: 32px;
    padding: 4px 12px;
    border: 1px solid var(--bb-ai-accent, var(--bs-primary, #0b6bcb));
    border-radius: 16px;
    background: var(--bb-ai-surface, #fff);
    color: var(--bb-ai-accent, var(--bs-primary, #0b6bcb));
    font-size: .8rem;
    line-height: 1.2;
    cursor: pointer;
}

.bb-ai-style.is-active {
    background: var(--bb-ai-accent, var(--bs-primary, #0b6bcb));
    color: var(--bb-ai-on-accent, #fff);
}

/* Tooltip der Stil-Knöpfe (ab 1.0.21): Sprechblase bei Maus/Tastatur, Erklärung des gewählten Stils darunter */
.bb-ai-style.has-tooltip {
    position: relative;
}

.bb-ai-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    z-index: 20;
    width: max-content;
    max-width: 240px;
    box-sizing: border-box;
    padding: 6px 9px;
    border-radius: 6px;
    background: var(--bb-ai-tooltip-bg, #222);
    color: var(--bb-ai-tooltip-color, #fff);
    font-size: .75rem;
    font-weight: 400;
    line-height: 1.35;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
    pointer-events: none;
    display: none;
    transform: translateX(-50%);
}

.bb-ai-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    border: 5px solid transparent;
    border-top-color: var(--bb-ai-tooltip-bg, #222);
    transform: translateX(-50%);
}

@media (hover: hover) {
    .bb-ai-style.has-tooltip:hover .bb-ai-tooltip {
        display: block;
    }
}

.bb-ai-style.has-tooltip:focus-visible .bb-ai-tooltip {
    display: block;
}

.bb-ai-style-desc {
    margin: 2px 0 4px;
    color: var(--bb-ai-desc-color, #6c757d);
    font-size: .75rem;
    line-height: 1.35;
}

.bb-ai-style-desc[hidden] {
    display: none;
}

/* Gratis-Versuche verbraucht: KI-Credits oder eigenes KI-Tool */
.bb-ai-exhausted {
    padding: .75rem .85rem;
    border: 1px solid var(--bb-ai-accent, var(--bs-primary, #0d6efd));
    border-radius: .5rem;
    background: var(--bb-ai-box-bg, rgba(13, 110, 253, .04));
    font-size: .9rem;
    line-height: 1.45;
}

.bb-ai-exhausted p {
    margin: 0 0 .6rem;
}

.bb-ai-exhausted-title {
    margin-bottom: .5rem;
    font-family: var(--bb-ai-heading-font-family, inherit);
    font-weight: 700;
}

.bb-ai-exhausted-buy-link {
    font-weight: 700;
}

.bb-ai-own-styles {
    margin: 0 0 6px;
}

.bb-ai-own-text {
    box-sizing: border-box;
    width: 100%;
    margin: .25rem 0 .5rem;
    font-family: inherit;
    font-size: .85rem;
    line-height: 1.4;
    background: var(--bb-ai-surface, #fff);
    resize: vertical;
}

.bb-ai-copy-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem .75rem;
    margin-bottom: .6rem;
}

.bb-ai-copy-feedback {
    font-size: .85rem;
    color: var(--bb-ai-muted, #6b7280);
}

.bb-ai-exhausted-tomorrow {
    color: var(--bb-ai-muted, #6b7280);
    font-size: .85rem;
}

.bb-ai-exhausted .bb-ai-exhausted-tomorrow:last-child {
    margin-bottom: 0;
}

/* Handy: größere Tippflächen, keine automatische Vergrößerung beim Tippen (iOS ab 16 px), Knopf über die ganze Breite */
@media (max-width: 575.98px) {
    .bb-ai-prompt {
        font-size: 16px;
    }

    .bb-ai-tip-link {
        padding: 6px 0;
    }

    .bb-ai-styles-label {
        flex-basis: 100%;
    }

    .bb-ai-style {
        flex: 1 1 calc(50% - 6px);
        min-height: 40px;
    }

    .bb-ai-row {
        gap: 6px;
    }

    .bb-ai-go {
        min-height: 44px;
    }

    .bb-ai-meta {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .bb-ai-info,
    .bb-ai-footer {
        text-align: center;
    }

    .bb-ai-copy {
        width: 100%;
        min-height: 44px;
    }

    .bb-ai-own-text {
        font-size: 16px;
    }

    .bb-ai-tips {
        position: fixed;
        top: auto;
        bottom: 12px;
        left: 12px;
        right: 12px;
        max-height: 70vh;
        z-index: 1080;
    }
}

/* ---------------- Motiv-Auswahl (Bild-Datenbank) ---------------- */

.bb-ai-lib {
    font-family: var(--bb-ai-font-family, inherit);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bb-ai-lib-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.bb-ai-lib-chip {
    min-height: 32px;
    padding: 4px 12px;
    border: 1px solid var(--bb-ai-border-color, #ced4da);
    border-radius: 16px;
    background: var(--bb-ai-surface, #fff);
    color: var(--bb-ai-chip-color, #333);
    font-size: 14px;
    line-height: 1.3;
    cursor: pointer;
}

.bb-ai-lib-chip.is-active {
    border-color: var(--bb-ai-accent, var(--bs-primary, #0b539b));
    background: var(--bb-ai-accent, var(--bs-primary, #0b539b));
    color: var(--bb-ai-on-accent, #fff);
}

.bb-ai-lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    max-height: 420px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.bb-ai-lib-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 1 / 1;
    padding: 4px;
    border: 1px solid var(--bb-ai-tile-border-color, #dee2e6);
    border-radius: 6px;
    background-color: var(--bb-ai-surface, #fff);
    background-image: linear-gradient(45deg, var(--bb-ai-checker-color, #f1f3f5) 25%, transparent 25%), linear-gradient(-45deg, var(--bb-ai-checker-color, #f1f3f5) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, var(--bb-ai-checker-color, #f1f3f5) 75%), linear-gradient(-45deg, transparent 75%, var(--bb-ai-checker-color, #f1f3f5) 75%);
    background-size: 12px 12px;
    background-position: 0 0, 0 6px, 6px -6px, -6px 0;
    cursor: pointer;
}

.bb-ai-lib-tile:hover,
.bb-ai-lib-tile:focus-visible {
    border-color: var(--bb-ai-accent, var(--bs-primary, #0b539b));
    box-shadow: 0 0 0 2px var(--bb-ai-focus-ring, rgba(11, 83, 155, .25));
    outline: none;
}

.bb-ai-lib-tile img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.bb-ai-lib-status:empty {
    display: none;
}

.bb-ai-lib-status {
    color: var(--bb-ai-desc-color, #6c757d);
    font-size: 14px;
}

.bb-ai-lib-more {
    align-self: center;
}

@media (max-width: 575.98px) {
    .bb-ai-lib-search {
        font-size: 16px;
    }

    .bb-ai-lib-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        max-height: 55vh;
    }

    .bb-ai-lib-more {
        align-self: stretch;
        min-height: 44px;
    }
}
