/* Global Chat launcher — header button + agent modal overlay. */

/* Header button (sits in the persistent app header alongside ⌘K / bell). */
.header-chat-btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
    border: 1px solid var(--apple-blue); border-radius: 8px;
    background: var(--apple-blue); color: #fff; font-size: 12px; font-weight: 600;
    cursor: pointer; font-family: inherit; white-space: nowrap;
}
.header-chat-btn:hover { filter: brightness(1.06); }
.header-chat-btn svg { display: block; }

/* Modal overlay */
.agent-modal-overlay {
    position: fixed; inset: 0; z-index: 10001;
    display: none; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .5); backdrop-filter: blur(4px); padding: 24px;
}
body.agent-modal-open { overflow: hidden; }

.agent-modal {
    display: flex; flex-direction: column;
    width: min(720px, 100%); height: min(80vh, 760px); max-height: 100%;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .4); overflow: hidden;
}
.agent-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.agent-modal-title { font-weight: 700; font-size: 15px; color: var(--text); }
.agent-modal-close {
    width: 32px; height: 32px; border: none; background: transparent; color: var(--text-secondary);
    font-size: 22px; line-height: 1; cursor: pointer; border-radius: 8px;
}
.agent-modal-close:hover { background: var(--bg-input); color: var(--text); }
.agent-modal-close:focus-visible,
.header-chat-btn:focus-visible { outline: 2px solid var(--apple-blue); outline-offset: 2px; }
.agent-modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.agent-modal-loading { padding: 32px; text-align: center; color: var(--text-secondary); }
.agent-modal-loading[data-error="1"] { color: var(--danger, #ff453a); }

/* The agent plugin fills the modal body; its own header is redundant here. */
#agentModal .ag-header { display: none; }
#agentModal .ag-main { padding: 0; flex: 1; min-height: 0; display: flex; flex-direction: column; }
#agentModal .ag-chat-card { height: 100%; min-height: 0; border: none; border-radius: 0; box-shadow: none; }

/* Mobile / narrow split-screen: full-screen sheet. */
@media (max-width: 640px) {
    .agent-modal-overlay { padding: 0; }
    .agent-modal { width: 100%; height: 100%; max-height: 100%; border: none; border-radius: 0; }
    /* Use the dynamic viewport so the on-screen keyboard doesn't bury the composer. */
    .header-chat-btn span { display: none; } /* icon-only when space is tight */
    .header-chat-btn { padding: 6px 8px; }
    /* Safe-area insets so the head clears the notch and the composer clears the home indicator. */
    #agentModal .agent-modal-head { padding-top: calc(12px + env(safe-area-inset-top)); }
    #agentModal .ag-input-row { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    #agentModal .ag-disclaimer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    /* 16px composer kills iOS Safari focus-zoom; cap the textarea to the viewport. */
    #agentModal .ag-input, #agentModal .ag-context { font-size: 16px; }
    #agentModal .ag-input { max-height: 30dvh; }
    /* 44px touch targets (min-height/width preserves desktop visuals). */
    #agentModal .agent-modal-close { width: 44px; height: 44px; }
    #agentModal .ag-send-btn { width: 44px; height: 44px; }
    #agentModal .ag-btn,
    #agentModal .ag-sess-btn,
    #agentModal .ag-select,
    #agentModal .ag-msg-copy,
    #agentModal .ag-msg-retry,
    #agentModal .ag-starter { min-height: 44px; }
    /* Let the session bar wrap so long titles aren't squeezed. */
    #agentModal .ag-session-bar { flex-wrap: wrap; }
    #agentModal .ag-select { flex-basis: 100%; order: -1; }
}
@supports (height: 100dvh) {
    @media (max-width: 640px) { .agent-modal { height: 100dvh; } }
}
