/* ─── Prompt Builder — mobile-first, animated ──────────────
 *
 * Layout philosophy:
 *   - Stack vertically on mobile. Two columns on desktop (preview | editor).
 *   - The "prompt preview" is the centerpiece. Variables appear as inline
 *     pill-shaped chips that pulse when empty and animate to a filled state.
 *   - Tapping a chip slides up an editor panel (mobile) or focuses the side
 *     editor (desktop). Auto-advance to the next chip when an option is picked.
 *   - All interactive targets are >=44px on mobile.
 */

/* ── Base container ── */
.pb {
    --pb-bg:        #ffffff;
    --pb-border:    #e5e7eb;
    --pb-text:      #111827;
    --pb-muted:     #6b7280;
    --pb-brand:     #6366f1;
    --pb-brand-50:  #eef2ff;
    --pb-brand-100: #e0e7ff;
    --pb-brand-700: #4338ca;
    --pb-success:   #10b981;
    --pb-success-50:#ecfdf5;
    --pb-radius:    14px;
    --pb-radius-sm: 10px;

    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--pb-bg);
    border-radius: var(--pb-radius);
}

/* ── Intro line + progress dots ── */
.pb__intro {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.pb__intro-title {
    font-size: 13px;
    color: var(--pb-muted);
    font-weight: 500;
}
.pb-progress {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.pb-progress__dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #e5e7eb;
    transition: background 200ms ease, transform 200ms ease;
}
.pb-progress__dot--on {
    background: var(--pb-success);
    transform: scale(1.15);
}

/* ── Prompt preview block ── */
.pb__preview-wrap {
    position: relative;
}
.pb__preview {
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
    border: 1px solid var(--pb-border);
    border-radius: var(--pb-radius);
    padding: 16px;
    font-size: 15px;
    line-height: 1.85;
    color: var(--pb-text);
    word-break: break-word;
}

/* Right side of intro (prefill button + progress dots) */
.pb__intro-right {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

/* ── Prefill helper (Try with example) ── */
.pb-prefill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 11px 6px 9px;
    min-height: 32px;
    background: var(--pb-brand-50);
    border: 1px solid var(--pb-brand-100);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--pb-brand-700);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    box-shadow: 0 1px 2px rgba(99, 102, 241, .06);
    transition:
        background 180ms ease,
        color 180ms ease,
        transform 120ms ease,
        box-shadow 180ms ease,
        opacity 220ms ease;
    animation: pb-prefill-glow 2.6s ease-in-out 1.4s infinite;
}
.pb-prefill[hidden] {
    display: none;
}
.pb-prefill:hover {
    background: var(--pb-brand);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, .35);
    animation-play-state: paused;
}
.pb-prefill:active { transform: translateY(0); }
.pb-prefill svg {
    color: currentColor;
    flex-shrink: 0;
}
@keyframes pb-prefill-glow {
    0%, 100% { box-shadow: 0 1px 2px rgba(99, 102, 241, .06); }
    50%      { box-shadow: 0 1px 2px rgba(99, 102, 241, .06), 0 0 0 5px rgba(99, 102, 241, .14); }
}

.pb-text {
    color: #374151;
}

/* ── Chips (the inline variable buttons) ── */
.pb-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 2px 1px;
    padding: 4px 12px 4px 8px;
    min-height: 32px;
    border: 0;
    border-radius: 999px;
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition:
        background 220ms ease,
        color 220ms ease,
        transform 180ms cubic-bezier(.2, .8, .2, 1.2),
        box-shadow 220ms ease;
}
.pb-chip:focus-visible {
    outline: 2px solid var(--pb-brand);
    outline-offset: 2px;
}

.pb-chip__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}
.pb-chip__label {
    white-space: nowrap;
}

/* Empty state — pulsing brand color with bracket */
.pb-chip--empty {
    background: var(--pb-brand-50);
    color: var(--pb-brand-700);
    box-shadow: 0 0 0 1px var(--pb-brand-100), 0 1px 2px rgba(99, 102, 241, .08);
    animation: pb-pulse 2.4s ease-in-out infinite;
}
.pb-chip--empty .pb-chip__num {
    background: var(--pb-brand);
    color: #fff;
}
.pb-chip--empty .pb-chip__label::before { content: '['; opacity: .55; margin-right: 2px; }
.pb-chip--empty .pb-chip__label::after  { content: ']'; opacity: .55; margin-left: 2px; }

.pb-chip--empty:hover,
.pb-chip--empty:active {
    transform: translateY(-1px) scale(1.04);
    box-shadow: 0 0 0 2px var(--pb-brand-100), 0 4px 10px rgba(99, 102, 241, .18);
    animation-play-state: paused;
}

/* Filled state — solid green pill */
.pb-chip--filled {
    background: var(--pb-success);
    color: #fff;
    box-shadow: 0 1px 2px rgba(16, 185, 129, .25), 0 0 0 1px rgba(16, 185, 129, .35);
}
.pb-chip--filled .pb-chip__num {
    background: rgba(255, 255, 255, .25);
    color: #fff;
}
.pb-chip--filled:hover,
.pb-chip--filled:active {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 4px 12px rgba(16, 185, 129, .35);
}

/* "Just-filled" pop animation */
.pb-chip--just-filled {
    animation: pb-pop 600ms cubic-bezier(.2, .8, .2, 1.2);
}

@keyframes pb-pulse {
    0%, 100% { box-shadow: 0 0 0 1px var(--pb-brand-100), 0 1px 2px rgba(99, 102, 241, .08); }
    50%      { box-shadow: 0 0 0 4px var(--pb-brand-100), 0 1px 2px rgba(99, 102, 241, .18); }
}

@keyframes pb-pop {
    0%   { transform: scale(.85); }
    45%  { transform: scale(1.15); }
    100% { transform: scale(1); }
}

/* ── Editor panel (slides up on mobile, side panel on desktop) ── */
.pb-editor {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    background: #fff;
    border-top: 1px solid var(--pb-border);
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    box-shadow: 0 -10px 32px rgba(15, 23, 42, .14);
    padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
    transform: translateY(110%);
    transition: transform 240ms cubic-bezier(.2, .8, .2, 1);
    max-height: 78vh;
    display: flex;
    flex-direction: column;
}
.pb-editor[hidden] { display: none; }
.pb-editor--open {
    transform: translateY(0);
}

/* Drag handle */
.pb-editor::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 999px;
    margin: -2px auto 12px;
}

.pb-editor__head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.pb-editor__back {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #f3f4f6;
    border: 0;
    border-radius: 999px;
    color: #4b5563;
    cursor: pointer;
}
.pb-editor__back:hover { background: #e5e7eb; }
.pb-editor__step {
    font-size: 11px;
    font-weight: 600;
    color: var(--pb-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
}
.pb-editor__label {
    font-size: 17px;
    font-weight: 700;
    color: var(--pb-text);
    margin-top: 2px;
}

.pb-editor__body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 8px;
    min-height: 80px;
}

.pb-editor__nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px solid #f3f4f6;
}
.pb-editor__prev,
.pb-editor__next {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    min-height: 44px;
    border: 0;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    background: #f3f4f6;
    color: #4b5563;
    transition: background 180ms ease, color 180ms ease, opacity 180ms ease;
}
.pb-editor__prev:disabled {
    opacity: .4;
    cursor: not-allowed;
}
.pb-editor__next {
    background: var(--pb-brand);
    color: #fff;
    margin-left: auto;
}
.pb-editor__next:hover { background: var(--pb-brand-700); }

/* ── Field types inside editor body ── */
.pb-options {
    display: grid;
    gap: 8px;
}
.pb-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    min-height: 56px;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    color: var(--pb-text);
    font-size: 15px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: border-color 180ms ease, background 180ms ease, transform 120ms ease;
}
.pb-option:hover {
    border-color: var(--pb-brand);
    background: var(--pb-brand-50);
}
.pb-option:active { transform: scale(.98); }
.pb-option__check {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #d1d5db;
    border-radius: 999px;
    color: transparent;
    transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}
.pb-option--selected {
    border-color: var(--pb-success);
    background: var(--pb-success-50);
    color: var(--pb-text);
}
.pb-option--selected .pb-option__check {
    border-color: var(--pb-success);
    background: var(--pb-success);
    color: #fff;
}

.pb-input {
    width: 100%;
    padding: 14px 16px;
    min-height: 52px;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 14px;
    font-size: 16px;        /* 16px to prevent iOS zoom on focus */
    font-family: inherit;
    color: var(--pb-text);
    transition: border-color 180ms ease, box-shadow 180ms ease;
}
.pb-input:focus {
    outline: 0;
    border-color: var(--pb-brand);
    box-shadow: 0 0 0 4px var(--pb-brand-100);
}
.pb-input__hint {
    margin-top: 8px;
    font-size: 12px;
    color: var(--pb-muted);
}

/* ── Bottom action bar (Send / Copy) ── */
.pb-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}
.pb-actions__copy,
.pb-actions__send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 180ms ease, color 180ms ease, transform 120ms ease, box-shadow 180ms ease, opacity 180ms ease;
}
.pb-actions__copy {
    background: #f3f4f6;
    color: #4b5563;
    flex-shrink: 0;
}
.pb-actions__copy:hover:not(:disabled) { background: #e5e7eb; }
.pb-actions__copy--ok {
    background: var(--pb-success-50);
    color: var(--pb-success);
}
.pb-actions__copy:disabled,
.pb-actions__send:disabled {
    opacity: .45;
    cursor: not-allowed;
}
.pb-actions__send {
    flex: 1;
    background: #d1d5db;
    color: #fff;
}
.pb-actions__send--ready {
    background: var(--pb-brand);
    color: #fff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, .35);
}
.pb-actions__send--ready:hover { background: var(--pb-brand-700); }
.pb-actions__send--pulse {
    animation: pb-send-pulse 1.2s ease-in-out;
}
@keyframes pb-send-pulse {
    0%, 100% { transform: scale(1);    box-shadow: 0 4px 14px rgba(99, 102, 241, .35); }
    25%      { transform: scale(1.05); box-shadow: 0 6px 22px rgba(99, 102, 241, .55); }
    50%      { transform: scale(.98);  box-shadow: 0 2px 10px rgba(99, 102, 241, .35); }
    75%      { transform: scale(1.04); box-shadow: 0 6px 22px rgba(99, 102, 241, .55); }
}

/* ── Response box ── */
.pb-response {
    margin-top: 8px;
    border: 1px solid var(--pb-border);
    border-radius: var(--pb-radius);
    overflow: hidden;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 220ms ease, transform 220ms ease;
}
.pb-response[hidden] { display: none; }
.pb-response--open {
    opacity: 1;
    transform: translateY(0);
}
.pb-response__head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #f9fafb;
    border-bottom: 1px solid var(--pb-border);
    font-size: 12px;
    font-weight: 600;
    color: var(--pb-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.pb-response__dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #10a37f;  /* ChatGPT green */
}
.pb-response__body {
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.6;
    color: var(--pb-text);
    white-space: pre-wrap;
    min-height: 60px;
}
.pb-response__loading {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--pb-muted);
    font-size: 14px;
}
.pb-response__spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: var(--pb-brand);
    border-radius: 999px;
    display: inline-block;
    animation: pb-spin .9s linear infinite;
}
@keyframes pb-spin { to { transform: rotate(360deg); } }

/* Continue footer — appears after streaming finishes */
.pb-response__foot {
    display: flex;
    justify-content: flex-end;
    padding: 12px 14px;
    border-top: 1px solid var(--pb-border);
    background: #fafbfc;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 260ms ease, transform 260ms ease;
}
.pb-response__foot[hidden] { display: none; }
.pb-response__foot--in {
    opacity: 1;
    transform: translateY(0);
}
.pb-response__continue {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    min-height: 44px;
    background: var(--pb-brand);
    color: #fff;
    border: 0;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99, 102, 241, .35);
    transition: background 180ms ease, transform 120ms ease, opacity 180ms ease;
    animation: pb-send-pulse 1.4s ease-in-out 200ms 1;  /* one gentle pulse to draw the eye */
}
.pb-response__continue:hover { background: var(--pb-brand-700); }
.pb-response__continue:disabled {
    opacity: .55;
    cursor: not-allowed;
    animation: none;
}

/* ── Desktop layout: side editor instead of bottom sheet ── */
@media (min-width: 768px) {
    .pb__intro-title {
        font-size: 14px;
    }
    .pb__preview {
        font-size: 16px;
        padding: 20px 22px;
    }
    .pb-chip {
        font-size: 15px;
        padding: 5px 14px 5px 9px;
        min-height: 34px;
    }

    .pb-editor {
        position: absolute;
        left: auto;
        right: 0;
        top: 0;
        bottom: auto;
        width: 380px;
        max-height: none;
        border-radius: var(--pb-radius);
        border: 1px solid var(--pb-border);
        box-shadow: 0 12px 32px rgba(15, 23, 42, .12);
        transform: translateX(20px);
        opacity: 0;
        padding: 18px 20px;
    }
    .pb-editor::before { display: none; }
    .pb-editor--open {
        transform: translateX(0);
        opacity: 1;
    }

    /* When editor is open on desktop, give the preview some breathing room.
       Keeps things simple — we don't shift the preview, the editor floats. */
    .pb__preview-wrap {
        position: relative;
    }

    .pb-actions__send {
        min-height: 52px;
        font-size: 15px;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .pb-chip--empty { animation: none; }
    .pb-chip--just-filled { animation: none; }
    .pb-actions__send--pulse { animation: none; }
    .pb-prefill { animation: none; }
    .pb-response__continue { animation: none; }
    .pb-editor { transition: none; }
    .pb-response { transition: none; }
    .pb-response__foot { transition: none; }
}
