/* ============================================================
   PROMPT HELPER UI
   Docked footer bar integrated beneath #h3PromptEditor inside
   #prompt-div by /scripts/ai/prompt-helper.js. Follows the
   PixForge generator-workspace.css design language: crisp 0/2px
   geometry, --bg-elevated / --bg-input surfaces, --border lines,
   and --brand-cyan accents.
   ============================================================ */

:where(.pf-prompt-helper-toolbar, .pf-prompt-helper-toolbar *) {
    box-sizing: border-box;
}

/* Visually fuse #prompt with the docked helper footer directly beneath it. */
#prompt-div:has(.pf-prompt-helper-toolbar) #h3PromptEditor {
    margin-bottom: 0 !important;
}

#prompt-div:has(.pf-prompt-helper-toolbar) #prompt {
    margin-bottom: 0 !important;
    border-bottom-left-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.pf-prompt-helper-toolbar {
    --pf-ph-text: var(--text-primary, var(--text-colour, currentColor));
    --pf-ph-muted: var(--text-secondary, color-mix(in srgb, currentColor 65%, transparent));
    --pf-ph-line: var(--border, var(--border-colour, color-mix(in srgb, currentColor 22%, transparent)));
    --pf-ph-surface: var(--bg-elevated, color-mix(in srgb, currentColor 6%, transparent));
    --pf-ph-input: var(--bg-input, var(--bg-surface, color-mix(in srgb, currentColor 10%, transparent)));
    --pf-ph-accent: var(--brand-cyan, var(--light-highlight-colour, #4d9cff));
    --pf-ph-accent-soft: rgba(var(--brand-cyan-rgb, 77, 156, 255), 0.12);
    --pf-ph-accent-hover: rgba(var(--brand-cyan-rgb, 77, 156, 255), 0.22);

    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    margin-top: -1px;
    padding: 7px 10px;
    border: 1px solid var(--pf-ph-line);
    border-left: 2px solid var(--pf-ph-accent);
    border-radius: 0 0 2px 2px;
    background: var(--pf-ph-surface);
    color: var(--pf-ph-text);
    font: inherit;
    font-size: 0.82rem;
    line-height: 1.3;
    color-scheme: light dark;
}

.pf-prompt-helper-toolbar[hidden],
.pf-prompt-helper-toolbar [hidden] {
    display: none !important;
}

/* Segmented mode switcher matching .pf-mode-switcher in generator-workspace.css. */
.pf-prompt-helper-modes {
    display: inline-flex;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 0;
    border: 1px solid var(--pf-ph-line);
    border-radius: 2px;
    background: var(--pf-ph-input);
    overflow: hidden;
}

.pf-prompt-helper-mode {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 5px 11px;
    border-right: 1px solid var(--pf-ph-line);
    color: var(--pf-ph-muted);
    font-size: 0.8rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background-color var(--transition-fast, 120ms) ease,
                color var(--transition-fast, 120ms) ease,
                box-shadow var(--transition-fast, 120ms) ease;
}

.pf-prompt-helper-mode:last-child {
    border-right: 0;
}

.pf-prompt-helper-mode:hover {
    color: var(--pf-ph-text);
    background: color-mix(in srgb, var(--pf-ph-text) 5%, transparent);
}

/* Keep native radio inputs keyboard- and screen-reader-accessible without showing raw radio dots. */
.pf-prompt-helper-mode input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    opacity: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    pointer-events: none;
}

.pf-prompt-helper-mode:has(input:checked) {
    color: var(--pf-ph-accent);
    background: var(--pf-ph-accent-soft);
    box-shadow: inset 0 -2px 0 var(--pf-ph-accent);
}

.pf-prompt-helper-mode:has(input:focus-visible) {
    outline: 2px solid var(--pf-ph-accent);
    outline-offset: -2px;
}

/* Optional targeted edit instructions input inside the same bar as AI Help. */
input.pf-prompt-helper-instructions {
    flex: 1 1 200px;
    min-width: 150px;
    min-height: 28px;
    margin: 0;
    padding: 4px 9px;
    border: 1px solid var(--pf-ph-line);
    border-radius: 2px;
    background: var(--pf-ph-input);
    color: var(--pf-ph-text);
    font: inherit;
    font-size: 0.8rem;
    line-height: 1.2;
    transition: border-color var(--transition-fast, 120ms) ease,
                box-shadow var(--transition-fast, 120ms) ease;
}

input.pf-prompt-helper-instructions::placeholder {
    color: var(--pf-ph-muted);
    opacity: 0.85;
}

input.pf-prompt-helper-instructions:focus {
    outline: none;
    border-color: var(--pf-ph-accent);
    box-shadow: 0 0 0 1px var(--pf-ph-accent);
}

input.pf-prompt-helper-instructions:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Primary action button ("AI Help"), aligned cleanly to the right edge of the bar. */
button.pf-prompt-helper-run {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: none;
    min-height: 28px;
    margin: 0;
    padding: 4px 13px;
    border: 1px solid var(--pf-ph-accent);
    border-radius: 2px;
    background: var(--pf-ph-accent-soft);
    color: var(--pf-ph-accent);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background-color var(--transition-fast, 120ms) ease,
                color var(--transition-fast, 120ms) ease,
                border-color var(--transition-fast, 120ms) ease,
                opacity var(--transition-fast, 120ms) ease;
}

button.pf-prompt-helper-run::before {
    content: "✦";
    font-size: 0.85em;
    line-height: 1;
}

button.pf-prompt-helper-run:hover:not(:disabled) {
    background: var(--pf-ph-accent);
    color: #0b1118;
}

button.pf-prompt-helper-run:active:not(:disabled) {
    filter: brightness(0.94);
}

button.pf-prompt-helper-run:focus-visible {
    outline: 2px solid var(--pf-ph-accent);
    outline-offset: 2px;
}

/* Reference image picker button & attached thumbnail chips. */
button.pf-prompt-helper-add-ref {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    min-height: 28px;
    margin: 0;
    padding: 4px 10px;
    border: 1px solid var(--pf-ph-line);
    border-radius: 2px;
    background: var(--pf-ph-input);
    color: var(--pf-ph-muted);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color var(--transition-fast, 120ms) ease,
                color var(--transition-fast, 120ms) ease,
                background-color var(--transition-fast, 120ms) ease;
}

button.pf-prompt-helper-add-ref:hover:not(:disabled) {
    border-color: var(--pf-ph-accent);
    color: var(--pf-ph-text);
    background: var(--pf-ph-accent-soft);
}

button.pf-prompt-helper-add-ref:focus-visible {
    outline: 2px solid var(--pf-ph-accent);
    outline-offset: 2px;
}

button.pf-prompt-helper-add-ref:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.pf-prompt-helper-toolbar.pf-prompt-helper-dragover {
    border-color: var(--pf-ph-accent);
    background: var(--pf-ph-accent-soft);
}

.pf-prompt-helper-refs {
    display: flex;
    flex: 1 1 100%;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding-top: 6px;
    border-top: 1px solid color-mix(in srgb, var(--pf-ph-line) 75%, transparent);
}

.pf-prompt-helper-ref-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 6px 2px 2px;
    border: 1px solid var(--pf-ph-line);
    border-radius: 2px;
    background: var(--pf-ph-input);
    color: var(--pf-ph-text);
    font-size: 0.76rem;
    font-weight: 600;
}

.pf-prompt-helper-ref-thumb {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 1px;
    display: block;
}

.pf-prompt-helper-ref-label {
    line-height: 1;
}

button.pf-prompt-helper-ref-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 2px;
    background: transparent;
    color: var(--pf-ph-muted);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1;
    cursor: pointer;
}

button.pf-prompt-helper-ref-remove:hover {
    color: var(--pf-ph-text);
    background: color-mix(in srgb, var(--pf-ph-text) 12%, transparent);
}

/* Busy state: replace sparkle with a crisp inline spinner. */
.pf-prompt-helper-toolbar.pf-prompt-helper-busy button.pf-prompt-helper-run {
    cursor: progress;
    opacity: 0.8;
    background: var(--pf-ph-accent-soft);
    color: var(--pf-ph-accent);
}

.pf-prompt-helper-toolbar.pf-prompt-helper-busy button.pf-prompt-helper-run::before {
    content: "";
    width: 11px;
    height: 11px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: pf-prompt-helper-spin 700ms linear infinite;
}

@keyframes pf-prompt-helper-spin {
    to { transform: rotate(360deg); }
}

button.pf-prompt-helper-run:disabled,
.pf-prompt-helper-busy .pf-prompt-helper-mode {
    cursor: not-allowed;
}

/* Integrated progress strip inside the footer bar. */
.pf-prompt-helper-progress {
    display: flex;
    flex: 1 1 100%;
    flex-direction: column;
    min-width: 0;
    margin-top: 2px;
}

.pf-prompt-helper-progress-track {
    position: relative;
    width: 100%;
    height: 3px;
    border-radius: 1px;
    background: var(--pf-ph-input);
    overflow: hidden;
}

.pf-prompt-helper-progress-bar {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background-color: var(--pf-ph-accent);
    background-image: linear-gradient(
        90deg,
        color-mix(in srgb, #ffffff 30%, var(--pf-ph-accent)) 25%,
        transparent 25%,
        transparent 50%,
        color-mix(in srgb, #ffffff 30%, var(--pf-ph-accent)) 50%,
        color-mix(in srgb, #ffffff 30%, var(--pf-ph-accent)) 75%,
        transparent 75%
    );
    background-size: 16px 16px;
    transition: width 240ms linear;
}

.pf-prompt-helper-toolbar.pf-prompt-helper-busy .pf-prompt-helper-progress-bar {
    animation: pf-prompt-helper-shimmer 850ms linear infinite;
}

@keyframes pf-prompt-helper-shimmer {
    from { background-position: 0 0; }
    to { background-position: 16px 0; }
}

.pf-prompt-helper-progress-label {
    flex: 1 1 auto;
    min-width: 0;
    color: var(--pf-ph-text);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
}

.pf-prompt-helper-progress-meta {
    flex: 0 1 auto;
    min-width: 0;
    margin-left: auto;
    color: var(--pf-ph-muted);
    font-size: 0.74rem;
    font-weight: 500;
    line-height: 1.3;
}

.pf-prompt-helper-toolbar.pf-prompt-helper-done .pf-prompt-helper-progress-bar {
    background-image: none;
    animation: none;
}

/* Status & optional usage line sit cleanly on a subtle bottom strip when visible. */
.pf-prompt-helper-status,
.pf-prompt-helper-usage {
    flex: 1 1 100%;
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.pf-prompt-helper-status {
    padding-top: 6px;
    border-top: 1px solid color-mix(in srgb, var(--pf-ph-line) 75%, transparent);
    color: var(--pf-ph-text);
    font-size: 0.78rem;
    font-weight: 600;
}

.pf-prompt-helper-usage {
    color: var(--pf-ph-muted);
    font-size: 0.75rem;
    font-weight: 500;
}

@media (prefers-reduced-motion: reduce) {
    .pf-prompt-helper-progress-bar,
    .pf-prompt-helper-toolbar.pf-prompt-helper-busy .pf-prompt-helper-progress-bar,
    .pf-prompt-helper-toolbar.pf-prompt-helper-busy button.pf-prompt-helper-run::before {
        transition: none;
        animation: none;
    }
}

@media (max-width: 560px) {
    .pf-prompt-helper-toolbar {
        gap: 6px 8px;
        padding: 6px 8px;
    }

    .pf-prompt-helper-modes {
        flex: 1 1 100%;
    }

    .pf-prompt-helper-mode {
        flex: 1 1 50%;
        padding: 6px 8px;
    }

    button.pf-prompt-helper-run {
        width: 100%;
        margin-left: 0;
        min-height: 32px;
    }

    input.pf-prompt-helper-instructions {
        flex: 1 1 100%;
        min-width: 0;
        min-height: 32px;
    }

    .pf-prompt-helper-progress-meta {
        flex: 1 1 100%;
        margin-left: 0;
    }
}
