/* Shared Story Assistant / Help Assistant chat chrome (sa-* SSOT).
   ONE .sa-modal size for every AI chat popup (Help + Assistant).
   Height uses dvh so soft keyboard shrinks the sheet (vh does not).
   Mobile: near-full width with a thin side peek of the page behind. */

.sa-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 9200;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.sa-modal {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.28);
    width: min(96vw, 860px);
    /* ~10% shorter than prior 88dvh / 700px */
    height: min(79dvh, 630px);
    max-height: min(79dvh, 630px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
@supports not (height: 1dvh) {
    .sa-modal { height: min(79vh, 630px); max-height: min(79vh, 630px); }
}
@media (max-width: 480px) {
    .sa-backdrop {
        align-items: flex-end;
        padding: max(18px, calc(env(safe-area-inset-top, 0px) + 10px)) 8px
                 max(8px, env(safe-area-inset-bottom, 0px)) 8px;
    }
    .sa-modal {
        width: 100%;
        /* ~10% shorter than prior ~92dvh; side padding above = page peek */
        height: min(83dvh, 100%);
        max-height: min(83dvh, 100%);
        border-radius: 16px;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.22);
    }
    @supports not (height: 1dvh) {
        .sa-modal { height: min(83vh, 100%); max-height: min(83vh, 100%); }
    }
}
.sa-header {
    display: flex;
    align-items: center;
    padding: 10px 18px 8px;
    border-bottom: 1px solid #f3f4f6;
    flex-shrink: 0;
    gap: 0;
}
.sa-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    flex: 1;
}
.sa-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sa-title-icon {
    width: 26px;
    height: 26px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.sa-title-icon svg { width: 14px; height: 14px; stroke: #fff; }
.sa-header-mid {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 140px;
    max-width: 220px;
    flex: 0 0 auto;
    margin-right: 12px;
}
.sa-progress-bar {
    height: 4px;
    background: #f3f4f6;
    border-radius: 999px;
    overflow: hidden;
}
.sa-progress-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #7c3aed, #ec4899);
    transition: width 0.3s;
}
.sa-progress-label {
    font-size: 0.68rem;
    color: #9ca3af;
    font-weight: 600;
    white-space: nowrap;
}
.sa-progress-label.paid { color: #7c3aed; }
/* Close: shared pink circle X (.inv-back-btn--close in header-profile.css) */
.sa-load-bar {
    height: 2px;
    flex-shrink: 0;
    background: #f3f4f6;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.15s;
}
.sa-load-bar.is-on { opacity: 1; }
.sa-load-bar.is-on::after {
    content: "";
    display: block;
    height: 100%;
    width: 35%;
    background: linear-gradient(90deg, #7c3aed, #ec4899);
    animation: sa-load-slide 1.05s ease-in-out infinite;
}
@keyframes sa-load-slide {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(320%); }
}
.sa-work {
    display: none;
    flex-shrink: 0;
    padding: 8px 18px 10px;
    border-bottom: 1px solid #f3f4f6;
    background: #fafafa;
}
.sa-work.is-on { display: block; }
.sa-work-bar {
    height: 4px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
}
.sa-work-fill {
    height: 100%;
    width: 0%;
    border-radius: 999px;
    background: linear-gradient(90deg, #7c3aed, #ec4899);
    transition: width 0.25s ease;
}
.sa-work-fill.is-pulse {
    width: 40% !important;
    animation: sa-load-slide 1.05s ease-in-out infinite;
}
.sa-work-label {
    margin-top: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #6b7280;
    line-height: 1.3;
}
.sa-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.sa-empty {
    color: #9ca3af;
    font-size: 0.95rem;
    text-align: center;
    margin: auto;
    padding: 20px;
}
.sa-skel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
    margin-top: auto;
    margin-bottom: auto;
}
.sa-skel-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 72%;
}
.sa-skel-row.user { align-self: flex-end; align-items: flex-end; }
.sa-skel-row.assistant { align-self: flex-start; align-items: flex-start; }
.sa-skel-line {
    height: 12px;
    border-radius: 8px;
    background: linear-gradient(90deg, #f3f4f6 0%, #ebe7f5 45%, #f3f4f6 100%);
    background-size: 200% 100%;
    animation: sa-skel-shine 1.2s ease-in-out infinite;
}
.sa-skel-line.w60 { width: 60%; }
.sa-skel-line.w80 { width: 80%; }
.sa-skel-line.w90 { width: 90%; }
.sa-skel-line.w45 { width: 45%; }
@keyframes sa-skel-shine {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}
.sa-msg {
    max-width: 82%;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sa-msg.user { align-self: flex-end; }
.sa-msg.assistant { align-self: flex-start; }
.sa-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 1rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.sa-msg.user .sa-bubble {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.sa-msg.sa-msg-seed .sa-bubble {
    background: #f3e8ff;
    color: #5b21b6;
    border-bottom-right-radius: 4px;
}
.sa-msg.assistant .sa-bubble {
    background: #f3f4f6;
    color: #111827;
    border-bottom-left-radius: 4px;
}
.sa-msg.assistant .sa-bubble.streaming::after {
    content: "▋";
    animation: sa-blink 0.7s infinite;
}
@keyframes sa-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}
.sa-use-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 7px 14px;
    background: #7c3aed;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}
.sa-use-btn:hover { background: #6d28d9; }
.sa-sketch-btn,
.sa-clear-btn,
.sa-contact-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: none;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    color: #9ca3af;
    transition: color 0.15s, border-color 0.15s;
    flex-shrink: 0;
}
.sa-sketch-btn:hover { color: #7c3aed; border-color: #7c3aed; }
.sa-clear-btn:hover { color: #ef4444; border-color: #ef4444; }
.sa-contact-btn:hover,
.sa-contact-btn.is-active { color: #7c3aed; border-color: #7c3aed; }
.sa-sketch-btn:disabled,
.sa-clear-btn:disabled,
.sa-contact-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sa-modal.drag-over {
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.35);
}
.sa-modal.drag-over .sa-messages {
    background: #fff7fb;
}
.sa-photos {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 8px;
    flex-shrink: 0;
}
.sa-photos:empty { display: none; }
.sa-thumb {
    width: 56px;
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.sa-thumb-img-wrap {
    width: 56px;
    height: 56px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
}
.sa-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sa-thumb-name {
    width: 100%;
    font-size: 0.62rem;
    font-weight: 700;
    font-family: inherit;
    color: #111827;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 2px 3px;
    box-sizing: border-box;
}
.sa-input-row {
    display: flex;
    gap: 10px;
    padding: 12px 20px 14px;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
    align-items: flex-end;
    width: 100%;
    box-sizing: border-box;
}
.sa-photos-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    min-height: 44px;
    min-width: 44px;
    padding: 0;
    border-radius: 12px;
    border: 1.5px solid #f3a6c7;
    background: #fff;
    color: #9d174d;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sa-photos-btn svg {
    width: 20px;
    height: 20px;
    display: block;
    flex-shrink: 0;
}
.sa-photos-btn:hover {
    background: #fff7fb;
    border-color: #ec4899;
}
.sa-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    outline: none;
    line-height: 1.5;
    overflow-y: auto;
}
.sa-input:focus { border-color: #7c3aed; }
.sa-send-btn {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, opacity 0.15s;
}
.sa-send-btn:hover { opacity: 0.85; }
.sa-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.sa-send-btn svg { width: 18px; height: 18px; stroke: #fff; }
.sa-send-btn.is-stop { background: #ef4444; }

/* Help contact panel (message console → email) */
.sa-contact-panel {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 14px 20px 16px;
    border-top: 1px solid #f3f4f6;
    background: #fafafa;
    flex-shrink: 0;
}
.sa-contact-panel.is-open { display: flex; }
.sa-contact-hint {
    font-size: 0.85rem;
    color: #6b7280;
    line-height: 1.45;
    margin: 0;
}
.sa-contact-status {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.4;
    margin: 0;
    display: none;
}
.sa-contact-status.is-on { display: block; }
.sa-contact-status.ok { color: #047857; }
.sa-contact-status.err { color: #b91c1c; }
.sa-contact-actions {
    display: flex;
    gap: 10px;
}
.sa-contact-actions .pmbtn,
.sa-contact-send {
    flex: 1;
    min-height: 44px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    border: none;
}
.sa-contact-send {
    background: #ec4899;
    color: #fff;
}
.sa-contact-send:disabled { opacity: 0.45; cursor: not-allowed; }
.sa-contact-cancel {
    flex: 1;
    min-height: 44px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    border: 1.5px solid #e5e7eb;
    background: #fff;
    color: #374151;
}

/* Projects header Help button — left side, labeled like profile pill */
.projects-help-btn {
    width: auto;
    min-width: 0;
    min-height: 50px;
    padding: 12px 18px;
    gap: 10px;
    border: 2px solid #f3a6c7;
    border-radius: 999px;
    background: #fff;
    color: #111827;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: inherit;
    line-height: 1.15;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.projects-help-btn:hover {
    background: #fff7fb;
    border-color: #ec4899;
    box-shadow: 0 2px 12px rgba(236, 72, 153, 0.14);
}
.projects-help-btn .sa-title-icon-inline {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.projects-help-btn .sa-title-icon-inline svg {
    width: 15px;
    height: 15px;
    stroke: #fff;
}
@media (max-width: 768px) {
    .projects-help-btn {
        padding-left: 14px;
        padding-right: 14px;
        font-size: 0.95rem;
        gap: 8px;
    }
}
