/* Global Floating Analyst Widget */
#gsAnalystWidget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2147483647; /* Pushed to max to ensure it clears everything */
    font-family: var(--font-sans, system-ui, sans-serif);
}

/* Hide the floating launcher everywhere — accessed via nav on desktop, bottom bar on mobile */
.gsw-launcher { display: none !important; }

/* Blurred Background Overlay */
.gsw-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1; 
    display: none;
}

#gsAnalystWidget.active.is-fullscreen .gsw-overlay { display: block; }
@media (max-width: 480px) {
    #gsAnalystWidget.active .gsw-overlay { display: block; }
}

/* The Launcher Button */
.gsw-launcher {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #111;
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    position: relative;
    z-index: 2;
}
.gsw-launcher:hover { transform: scale(1.05); }
.gsw-launcher svg { width: 24px; height: 24px; fill: currentColor; }

/* The Chat Window */
.gsw-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 500px;
    height: 700px;
    max-height: calc(100vh - 100px);
    background: var(--color-elevate, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,1);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.2s ease-in-out;
    z-index: 2;
}
#gsAnalystWidget.active .gsw-window { display: flex; }
#gsAnalystWidget.active .gsw-launcher { display: none; }

/* Fullscreen Modifier */
.gsw-window.gsw-fullscreen {
    position: fixed;
    top: 50px !important;
    left: 0;
    bottom: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 50px) !important;
    max-height: calc(100vh - 50px) !important;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.3);
}

.gsw-header {
    background: #111;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.gsw-title { font-family: var(--font-mono, monospace); font-size: 11px; font-weight: 700; letter-spacing: 0.1em; }

.gsw-header-actions { display: flex; align-items: center; gap: 14px; }
.gsw-clear { background: none; border: none; color: #fff; font-size: 9px; font-family: var(--font-mono, monospace); font-weight: 700; cursor: pointer; opacity: 0.6; letter-spacing: 0.08em; text-transform: uppercase; padding: 0; }
.gsw-clear:hover { opacity: 1; text-decoration: underline; }
.gsw-icon-btn { background: none; border: none; color: #fff; cursor: pointer; opacity: 0.7; padding: 0; display: flex; align-items: center; justify-content: center; }
.gsw-icon-btn:hover { opacity: 1; }
.gsw-close { font-size: 20px; line-height: 1; }

.gsw-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--color-background, #fafafa);
    scrollbar-width: thin;
}
.gsw-window.gsw-fullscreen .gsw-body { padding: 24px 10%; }

.gsw-msg { padding: 12px 14px; border-radius: 6px; font-size: 13px; line-height: 1.6; max-width: 90%; word-wrap: break-word; }
.gsw-msg--user { background: #e5e7eb; color: #111; align-self: flex-end; border-bottom-right-radius: 2px; }
.gsw-msg--bot { background: #fff; border: 1px solid var(--color-border, #e5e7eb); border-left: 3px solid #dc2626; color: #111; align-self: flex-start; border-bottom-left-radius: 2px; }
.gsw-msg strong { font-weight: 700; color: #000; } 
.gsw-msg-loading { opacity: 0.6; font-style: italic; }
.gsw-cite { display:inline-flex; align-items:center; justify-content:center; min-width:16px; height:16px; padding:0 4px; margin:0 1px; border-radius:8px; background:#111; color:#fff !important; font:700 10px/1 ui-monospace,Menlo,Consolas,monospace; text-decoration:none !important; vertical-align:2px; }
.gsw-cite:hover { background:#b91c1c; }

.gsw-footer {
    padding: 12px;
    border-top: 1px solid var(--color-border, #e5e7eb);
    background: #fff;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}
.gsw-window.gsw-fullscreen .gsw-footer { padding: 16px 10%; }

.gsw-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 4px;
    font-size: 13px;
    outline: none;
}
.gsw-input:focus { border-color: #111; }
.gsw-send {
    padding: 0 16px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
}
.gsw-send:hover { background: #b91c1c; }

/* Save to Notes button */
.gsw-save-note-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
    padding: 3px 8px;
    background: transparent;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 3px;
    font-family: var(--font-mono, monospace);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .06em;
    color: var(--color-text-muted, #6b7280);
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
.gsw-save-note-btn:hover { color: #111; border-color: #aaa; background: #f5f5f5; }
.gsw-save-note-btn.saved { color: #16a34a; border-color: rgba(22,163,74,.4); background: rgba(22,163,74,.07); cursor: default; }
.gsw-save-note-btn svg { width: 9px; height: 9px; flex-shrink: 0; }

/* Context Banner */
.gsw-context-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(22, 163, 74, 0.06);
    border-bottom: 1px solid rgba(22, 163, 74, 0.15);
    color: #16a34a;
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1.5;
    flex-shrink: 0;
}

/* Paywall Styles */
.gsw-paywall {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}
.gsw-paywall-card {
    background: #fff;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 8px;
    padding: 32px 24px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.gsw-paywall-card svg { width: 42px; height: 42px; fill: #dc2626; margin-bottom: 16px; }
.gsw-paywall-title { font-family: var(--font-serif, serif); font-size: 1.2rem; font-weight: 800; margin: 0 0 12px; color: #111; }
.gsw-paywall-text { font-size: 13px; color: #666; margin: 0 0 24px; line-height: 1.5; }
.gsw-paywall-btn { display: inline-block; padding: 12px 24px; background: #111; color: #fff; text-decoration: none; border-radius: 4px; font-family: var(--font-mono, monospace); font-size: 11px; font-weight: 700; letter-spacing: 0.05em; transition: opacity 0.2s; }
.gsw-paywall-btn:hover { opacity: 0.8; color: #fff; }

@media (max-width: 480px) {
    .gsw-window { position: fixed; top: 0; bottom: 0; left: 0; right: 0; width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
    .gsw-header { flex-shrink: 0; }
    .gsw-expand { display: none; } 
    .gsw-window.gsw-fullscreen .gsw-body, .gsw-window.gsw-fullscreen .gsw-footer { padding-left: 16px; padding-right: 16px; }
    .gsw-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}
