/* ================================================================
   Assistant Panel — floating FAB → popup window with unified chat + voice
   ================================================================ */

/* Container — positions popup window */
.assist {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: var(--z-modal);
    transition: bottom 0.2s ease;
}

/* Lift above the sticky player when it's active */
body.player-active .assist {
    bottom: calc(var(--player-h) + var(--space-6));
}

/* FAB removed — chat trigger is now in bottom tab bar */
.assist__fab { display: none; }

/* Popup window */
.assist__window {
    display: none;
    position: absolute;
    bottom: 0;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: var(--white);
    border: 0.5px solid color-mix(in srgb, var(--cloud) 50%, transparent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-modal);
    overflow: hidden;
    flex-direction: column;
}

.assist--open .assist__window {
    display: flex;
    animation: assist-window-in 0.2s ease-out;
}

@keyframes assist-window-in {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Desktop expanded — near-fullscreen, minimal chrome */
.assist--expanded .assist__window {
    position: fixed;
    top: calc(var(--nav-h) + 16px);
    bottom: 16px;
    right: 16px;
    left: 16px;
    width: auto;
    max-width: 800px;
    max-height: none;
    margin: 0 auto;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
}

.assist--expanded .assist__messages {
    max-height: none;
    flex: 1;
}

@media (max-width: 480px) {
    .assist {
        bottom: 16px;
        right: 16px;
    }
    .assist__window {
        position: fixed;
        bottom: 16px;
        right: 16px;
        left: 16px;
        width: auto;
        max-height: 70vh;
    }
    /* Expanded = fullscreen below the fixed nav (+ announce bar if present) */
    .assist--expanded .assist__window {
        top: var(--nav-h);
        bottom: 0;
        left: 0;
        right: 0;
        max-height: none;
        border-radius: 0;
        border: none;
        border-top: 1px solid var(--cloud);
        box-shadow: none;
    }
    body.has-announce .assist--expanded .assist__window {
        top: calc(var(--nav-h) + var(--announce-h));
    }
    /* Player-active offset only in non-expanded */
    body.player-active .assist:not(.assist--expanded) {
        bottom: calc(var(--player-h, 64px) + 16px);
    }
    /* Expanded ignores player offset — it's fullscreen */
    body.player-active .assist--expanded .assist__window {
        bottom: 0;
    }
    /* Messages fill available space in expanded */
    .assist--expanded .assist__messages {
        max-height: none;
        flex: 1;
    }
    /* Fullscreen overrides — must be inside @media to beat the mobile rules above */
    .assist--fullscreen {
        position: static;
        bottom: auto;
        right: auto;
    }
    .assist--fullscreen .assist__window {
        position: static;
        width: 100%;
        max-height: none;
        height: calc(100dvh - var(--nav-h) - var(--tab-bar-h));
        border-radius: 0;
        border: none;
        box-shadow: none;
    }
}

/* Title bar */
.assist__titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 0.5px solid color-mix(in srgb, var(--cloud) 50%, transparent);
    background: var(--pearl);
    flex-shrink: 0;
}

.assist__title {
    font-family: var(--font-display);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--navy);
}

.assist__titlebar-actions {
    display: flex;
    gap: 4px;
}

.assist__titlebar-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--warm-gray);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--duration-fast) var(--ease-smooth),
                color var(--duration-fast) var(--ease-smooth);
}

.assist__titlebar-btn:hover {
    background: var(--cloud);
    color: var(--charcoal);
}

/* Voice indicator — in titlebar */
.assist__voice-indicator {
    font-size: 11px;
    color: var(--warm-gray);
    margin-left: auto;
    margin-right: 8px;
    white-space: nowrap;
}

.assist__voice-indicator--active {
    color: var(--sage);
    font-weight: var(--font-weight-medium);
}

/* Panes */
.assist__pane {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Mic button — inline voice toggle in input row */
.assist__mic {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: 0.5px solid var(--cloud);
    background: transparent;
    color: var(--warm-gray);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: border-color var(--duration-fast),
                background var(--duration-fast),
                color var(--duration-fast);
}

.assist__mic:hover:not(:disabled) {
    border-color: var(--navy-light);
    color: var(--navy);
}

.assist__mic:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.assist__mic--connecting {
    border-color: var(--gold);
    color: var(--gold);
    animation: assist-mic-pulse 1.5s ease-in-out infinite;
}

@keyframes assist-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(212, 175, 55, 0); }
}

.assist__mic--active {
    border-color: var(--sage);
    background: var(--sage);
    color: var(--white);
}

.assist__mic--active:hover:not(:disabled) {
    background: var(--coral);
    border-color: var(--coral);
    color: var(--white);
}

/* Messages area (Chat pane) */
.assist__messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 14px;
    min-height: 160px;
    max-height: 300px;
}

.assist--expanded .assist__messages {
    max-height: 480px;
}

.assist__messages::-webkit-scrollbar {
    width: 4px;
}

.assist__messages::-webkit-scrollbar-thumb {
    background: var(--cloud);
    border-radius: 2px;
}

/* Message bubbles — reuse existing .nb-chat-msg classes */
.nb-chat-msg {
    max-width: 88%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: 1.45;
    word-break: break-word;
}

.nb-chat-msg--user {
    align-self: flex-end;
    background: var(--navy);
    color: var(--white);
    border-bottom-right-radius: var(--radius-sm);
}

.nb-chat-msg--system {
    align-self: flex-start;
    background: var(--pearl);
    border: none;
    color: var(--slate);
    border-bottom-left-radius: var(--radius-sm);
}

.nb-chat-msg--system a {
    color: var(--navy-light);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
}

.nb-chat-msg--system a:hover {
    text-decoration: underline;
}

.nb-chat-msg--error {
    align-self: flex-start;
    background: var(--coral-light);
    border: none;
    color: var(--coral);
    border-bottom-left-radius: var(--radius-sm);
}

/* Thinking indicator — replaces bouncing dots */
.nb-chat-thinking {
    align-self: flex-start;
    padding: 8px 12px;
    font-size: var(--text-sm);
    color: var(--warm-gray);
    font-style: italic;
}

.nb-chat-thinking::after {
    content: '';
    animation: nb-think-dots 1.5s steps(4, end) infinite;
}

@keyframes nb-think-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

/* Streaming cursor on message being typed */
.nb-chat-msg--streaming::after {
    content: '▊';
    color: var(--navy-light);
    animation: nb-cursor-blink 0.6s step-end infinite;
    margin-left: 1px;
}

@keyframes nb-cursor-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Quick action chips */
.assist__chips {
    display: flex;
    gap: 4px;
    padding: 0 14px 8px;
    overflow-x: auto;
}

.assist__chips::-webkit-scrollbar { display: none; }

.assist__chip {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 0.5px solid var(--cloud);
    background: transparent;
    color: var(--warm-gray);
    font-size: 11px;
    font-family: var(--font-body);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color var(--duration-fast), color var(--duration-fast);
}

.assist__chip:hover {
    border-color: var(--navy-light);
    color: var(--slate);
}

/* Input row */
.assist__input-row {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 8px 14px;
    border-top: 0.5px solid color-mix(in srgb, var(--cloud) 50%, transparent);
    flex-shrink: 0;
}

.assist__field {
    flex: 1;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 0.5px solid var(--cloud);
    background: var(--white);
    color: var(--charcoal);
    font-size: var(--text-sm);
    font-family: var(--font-body);
    outline: none;
    transition: border-color var(--duration-fast);
}

.assist__field::placeholder {
    color: var(--silver);
}

.assist__field:focus {
    border-color: var(--navy-light);
}

.assist__send {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--navy);
    color: var(--white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity var(--duration-fast);
}

.assist__send:hover { opacity: 0.85; }
.assist__send:disabled { opacity: 0.4; cursor: not-allowed; }


/* ── Notebook search & card delete (unchanged) ── */

.nb-search { margin-bottom: 12px; }
.nb-search form { display: flex; gap: 8px; }

.nb-search__input {
    flex: 1;
    padding: 8px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--cloud);
    background: var(--white);
    color: var(--charcoal);
    font-size: var(--text-sm);
    outline: none;
    transition: border-color var(--duration-fast);
}

.nb-search__input::placeholder { color: var(--silver); }
.nb-search__input:focus { border-color: var(--navy-light); }

.nb-card__delete {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--silver);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--duration-fast), color var(--duration-fast), background var(--duration-fast);
}

.nb-card:hover .nb-card__delete { opacity: 1; }

.nb-card__delete:hover {
    color: var(--coral);
    background: var(--coral-light);
}

/* ── Chat tab loading placeholder ── */

.chat-tab-loading {
    text-align: center;
    padding: 2rem;
    color: var(--warm-gray);
}

/* ================================================================
   Fullscreen chat mode — mobile Chat tab embeds assist in page flow
   ================================================================ */

.assist--fullscreen {
    position: static;
    bottom: auto;
    right: auto;
    z-index: auto;
}

.assist--fullscreen .assist__fab {
    display: none;
}

.assist--fullscreen .assist__window {
    display: flex;
    position: static;
    width: 100%;
    max-height: none;
    height: calc(100dvh - var(--nav-h) - var(--tab-bar-h));
    border-radius: 0;
    border: none;
    box-shadow: none;
    animation: none;
}

.assist--fullscreen .assist__messages {
    max-height: none;
    flex: 1;
}

/* Hide expand button in fullscreen — already full */
.assist--fullscreen .assist__titlebar-btn[aria-label="Expand"] {
    display: none;
}

/* ── Artifact file browser ── */
.nb-artifacts {
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 8px;
}

.nb-artifacts__toggle {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: var(--text-muted, #8e9bae);
    font-size: 0.75rem;
    padding: 4px 10px;
    cursor: pointer;
    transition: background 0.15s;
}

.nb-artifacts__toggle:hover {
    background: rgba(255, 255, 255, 0.06);
}

.nb-artifacts__list {
    list-style: none;
    padding: 0;
    margin: 6px 0 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nb-artifact {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary, #c4cad4);
}

.nb-artifact__badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

.nb-artifact__badge--screenplay { background: var(--badge-screenplay-bg); color: var(--badge-screenplay-fg); }
.nb-artifact__badge--script     { background: var(--badge-script-bg);     color: var(--badge-script-fg); }
.nb-artifact__badge--segment    { background: var(--badge-segment-bg);    color: var(--badge-segment-fg); }
.nb-artifact__badge--audio      { background: var(--badge-audio-bg);      color: var(--badge-audio-fg); }
.nb-artifact__badge--video      { background: var(--badge-video-bg);      color: var(--badge-video-fg); }
.nb-artifact__badge--image      { background: var(--badge-image-bg);      color: var(--badge-image-fg); }

.nb-artifact__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.nb-artifact__meta {
    color: var(--text-muted, #8e9bae);
    font-size: 0.65rem;
    flex-shrink: 0;
}

.nb-artifacts__status {
    font-size: 0.7rem;
    color: var(--text-muted, #8e9bae);
    margin-top: 4px;
    font-style: italic;
}

/* ── Mobile: hide FAB (Chat tab in top nav instead) ── */
@media (max-width: 480px) {
    .assist:not(.assist--fullscreen) .assist__fab {
        display: none;
    }
}