/* ============================================================
   SEO Advisor Popout — Styles
   Prefix: sa- (popout)  /  gseo-advisor- (toolbar entry button)
   ============================================================ */

/* ── Entry button — appears inside .gseo-tab-bar in fullscreen
   mode (the toolbar is display:none in fullscreen) and inside
   .gseo-toolbar otherwise. Both anchors are handled. ─── */

.gseo-advisor-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: var(--color-primary, #2563eb);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    margin-right: 8px;
    transition: background 120ms ease, transform 120ms ease;
}

.gseo-advisor-btn:hover {
    background: var(--color-primary-hover, #1d4ed8);
}

.gseo-advisor-btn:active {
    transform: translateY(1px);
}

.gseo-advisor-btn svg {
    flex: 0 0 auto;
}

/* When the button lives inside the tab bar, the bar's flex/stretch
   layout would otherwise stretch the button to the full tab row
   height. Center it vertically and give it a small inset so it sits
   cleanly at the right edge after the tab spacer. */
.gseo-tab-bar .gseo-advisor-btn {
    align-self: center;
    margin: 6px 8px 6px 4px;
    flex: 0 0 auto;
}

/* ── Popout container ──────────────────────────── */

.sa-popout {
    position: fixed;
    width: 360px;
    height: 480px;
    min-width: 320px;
    min-height: 360px;
    max-width: 700px;
    max-height: 820px;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
    display: flex;
    flex-direction: column;
    z-index: 9000;
    overflow: hidden;
    font-family: inherit;
    color: var(--color-text, #111827);
}

.sa-popout.hidden {
    display: none;
}

.sa-popout.sa-dragging,
.sa-popout.sa-resizing {
    user-select: none;
    transition: none;
}

/* Expanded mode: side drawer covering the right ~40% of viewport */
.sa-popout.sa-expanded {
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    width: min(40vw, 560px) !important;
    height: 100vh !important;
    max-height: none;
    border-radius: 0;
    border-right: none;
    border-top: none;
    border-bottom: none;
}

.sa-popout.sa-expanded .sa-resize-handle {
    display: none;
}

/* ── Header ──────────────────────────────────── */

.sa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--color-surface-elevated, #f9fafb);
    border-bottom: 1px solid var(--color-border, #e5e7eb);
    cursor: move;
    flex: 0 0 auto;
}

.sa-popout.sa-expanded .sa-header {
    cursor: default;
}

.sa-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text, #111827);
}

.sa-header-title svg {
    color: var(--color-primary, #2563eb);
}

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

.sa-icon-btn {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    color: var(--color-text-secondary, #6b7280);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 120ms ease, color 120ms ease;
}

.sa-icon-btn:hover {
    background: var(--color-hover, rgba(0, 0, 0, 0.05));
    color: var(--color-text, #111827);
}

/* ── Body / messages ─────────────────────────── */

.sa-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px;
    background: var(--color-surface, #fff);
    display: flex;
    flex-direction: column;
}

.sa-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1 1 auto;
}

.sa-msg {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.sa-msg-user {
    align-self: flex-end;
    background: var(--color-primary, #2563eb);
    color: #fff;
    border-bottom-right-radius: 2px;
    white-space: pre-wrap;
}

.sa-msg-assistant {
    align-self: flex-start;
    background: var(--color-surface-elevated, #f3f4f6);
    color: var(--color-text, #111827);
    border-bottom-left-radius: 2px;
}

.sa-msg-assistant p {
    margin: 0 0 8px 0;
}

.sa-msg-assistant p:last-child {
    margin-bottom: 0;
}

.sa-msg-assistant ul,
.sa-msg-assistant ol {
    margin: 6px 0 8px 18px;
    padding: 0;
}

.sa-msg-assistant li {
    margin-bottom: 4px;
}

.sa-msg-assistant strong {
    font-weight: 600;
}

.sa-msg-assistant code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sa-msg-assistant h1,
.sa-msg-assistant h2,
.sa-msg-assistant h3,
.sa-msg-assistant h4 {
    font-size: 13px;
    font-weight: 600;
    margin: 8px 0 4px 0;
}

/* Typing indicator (3 dots) */
.sa-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 14px 12px;
}

.sa-typing span {
    width: 6px;
    height: 6px;
    background: var(--color-text-secondary, #9ca3af);
    border-radius: 50%;
    animation: sa-typing-bounce 1.2s infinite ease-in-out both;
}

.sa-typing span:nth-child(1) { animation-delay: -0.32s; }
.sa-typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes sa-typing-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Starter prompts ─────────────────────────── */

.sa-starter-prompts {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.sa-starter-prompts.hidden {
    display: none;
}

.sa-starter-label {
    font-size: 12px;
    color: var(--color-text-secondary, #6b7280);
    margin-bottom: 4px;
}

.sa-starter-btn {
    text-align: left;
    background: var(--color-surface, #fff);
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--color-text, #111827);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}

.sa-starter-btn:hover {
    background: var(--color-surface-elevated, #f3f4f6);
    border-color: var(--color-primary, #2563eb);
}

/* ── Input row ───────────────────────────────── */

.sa-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-surface, #fff);
    flex: 0 0 auto;
}

.sa-input-row textarea {
    flex: 1 1 auto;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    padding: 8px 10px;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    background: var(--color-surface, #fff);
    color: var(--color-text, #111827);
}

.sa-input-row textarea:focus {
    outline: none;
    border-color: var(--color-primary, #2563eb);
}

.sa-send-btn {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    background: var(--color-primary, #2563eb);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 120ms ease, opacity 120ms ease;
}

.sa-send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover, #1d4ed8);
}

.sa-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ── Quota footer ────────────────────────────── */

.sa-quota-footer {
    flex: 0 0 auto;
    padding: 4px 12px 8px 12px;
    font-size: 11px;
    color: var(--color-text-secondary, #6b7280);
    background: var(--color-surface, #fff);
    text-align: right;
}

.sa-quota-footer:empty {
    padding: 0;
}

/* ── Resize handle (bottom-right corner) ─────── */

.sa-resize-handle {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(
        135deg,
        transparent 0%,
        transparent 50%,
        var(--color-text-secondary, #9ca3af) 50%,
        var(--color-text-secondary, #9ca3af) 60%,
        transparent 60%,
        transparent 70%,
        var(--color-text-secondary, #9ca3af) 70%,
        var(--color-text-secondary, #9ca3af) 80%,
        transparent 80%
    );
    opacity: 0.4;
}

.sa-resize-handle:hover {
    opacity: 0.8;
}
