/* ============================================================
   strategy-assistant.css - floating Strategy Assistant widget

   A launcher button pinned bottom-right on every page, opening a compact panel.
   Uses only tokens from global.css - no new colours, radii or shadows.
   ============================================================ */

/* ─── Launcher ───────────────────────────────────────────────────────────────
   A bare circle read as a generic support-chat bubble and said nothing about what
   it does. This is a pill carrying its own label, so the affordance is obvious
   before the click; it collapses to a circle once opened and on small screens,
   where the label would crowd the viewport.
   ------------------------------------------------------------------------- */
.sa-launcher {
    position: fixed;
    right: 28px;
    bottom: 28px;
    z-index: 900;
    height: 60px;
    padding: 0 26px 0 20px;
    border-radius: var(--radius-pill);
    border: 1px solid rgba(255, 255, 255, 0.14);
    cursor: pointer;
    background: var(--gradient-blue);
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 650;
    letter-spacing: -0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.38), 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: transform var(--ease), box-shadow var(--ease), padding var(--ease);
}
.sa-launcher:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 40px rgba(37, 99, 235, 0.5), 0 3px 10px rgba(0, 0, 0, 0.45);
}
.sa-launcher:active { transform: translateY(-1px); }
.sa-launcher:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 3px; }

/* The compass sits on its own translucent disc so the pill has a focal point. */
.sa-launcher-icon {
    width: 34px; height: 34px;
    flex: 0 0 34px;
    border-radius: var(--radius-pill);
    background: rgba(255, 255, 255, 0.16);
    display: grid; place-items: center;
    font-size: 0.95rem;
}
.sa-launcher-label { white-space: nowrap; }

/* A slow sweep of light across the pill - present enough to draw the eye once,
   quiet enough not to nag. Stops entirely after first open. */
.sa-launcher::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.22) 50%, transparent 65%);
    background-size: 250% 100%;
    animation: sa-sheen 4.5s ease-in-out infinite;
    pointer-events: none;
}
.sa-launcher.is-seen::after { display: none; }
@keyframes sa-sheen {
    0%, 55% { background-position: 130% 0; }
    100%    { background-position: -30% 0; }
}

/* Open state: collapse to a circle holding the close icon. */
.sa-launcher.is-open {
    padding: 0;
    width: 60px;
    justify-content: center;
}
.sa-launcher.is-open .sa-launcher-label,
.sa-launcher.is-open .sa-launcher-icon { display: none; }
.sa-launcher:not(.is-open) .sa-launcher-close { display: none; }
.sa-launcher-close { font-size: 1.15rem; }

/* ─── Panel ──────────────────────────────────────────────── */
.sa-panel {
    position: fixed;
    right: 24px;
    bottom: 92px;
    z-index: 901;
    width: 380px;
    max-width: calc(100vw - 32px);
    max-height: min(560px, calc(100vh - 130px));
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transform-origin: bottom right;
    animation: sa-pop 0.22s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
.sa-panel[hidden] { display: none; }
@keyframes sa-pop {
    from { opacity: 0; transform: translateY(10px) scale(0.96); }
    to   { opacity: 1; transform: none; }
}

.sa-head {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elevated);
    flex: 0 0 auto;
}
.sa-avatar {
    width: 30px; height: 30px; flex: 0 0 30px;
    border-radius: var(--radius-pill);
    background: var(--gradient-blue);
    display: grid; place-items: center;
    color: #fff; font-size: 0.78rem;
}
.sa-head-text { flex: 1; min-width: 0; }
.sa-head-title { font-weight: 700; font-size: 0.88rem; color: var(--text-primary); }
.sa-head-sub   { font-size: 0.72rem; color: var(--text-subtle); }
.sa-head-btn {
    background: none; border: none; cursor: pointer;
    color: var(--text-subtle); font-size: 0.95rem;
    padding: 0.3rem 0.4rem; border-radius: var(--radius-xs);
    transition: color var(--ease), background var(--ease);
}
.sa-head-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.sa-progress { height: 2px; background: rgba(255,255,255,0.06); flex: 0 0 auto; }
.sa-progress-bar { height: 100%; width: 0; background: var(--gradient-blue); transition: width var(--ease); }

/* Scrollable body */
.sa-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.sa-body::-webkit-scrollbar { width: 6px; }
.sa-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-pill); }

/* ─── Messages ───────────────────────────────────────────── */
.sa-msg { display: flex; animation: sa-in 0.3s ease both; }
.sa-msg.is-user { justify-content: flex-end; }
@keyframes sa-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.sa-bubble {
    max-width: 88%;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    font-size: 0.86rem;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
}
.sa-msg.is-user .sa-bubble {
    background: var(--gradient-blue); border-color: transparent; color: #fff; font-weight: 600;
}
.sa-bubble .sa-note { display: block; margin-top: 0.35rem; font-size: 0.76rem; color: var(--text-subtle); }

.sa-typing { display: flex; gap: 4px; padding: 0.75rem 0.9rem; }
.sa-typing span { width: 5px; height: 5px; border-radius: 50%; background: var(--text-subtle); animation: sa-blink 1.3s infinite both; }
.sa-typing span:nth-child(2) { animation-delay: 0.18s; }
.sa-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes sa-blink { 0%,60%,100% { opacity: 0.25; } 30% { opacity: 1; } }

/* ─── Options ────────────────────────────────────────────── */
.sa-options { display: grid; gap: 0.45rem; }
.sa-opt {
    text-align: left; width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.84rem; font-family: inherit; cursor: pointer;
    transition: border-color var(--ease), background var(--ease);
}
.sa-opt:hover { border-color: var(--border-hover); background: var(--bg-hover); }
.sa-opt:focus-visible { outline: 2px solid var(--accent-blue); outline-offset: 1px; }
.sa-opt-label { display: block; font-weight: 600; }
.sa-opt-desc  { display: block; margin-top: 0.15rem; font-size: 0.75rem; color: var(--text-muted); }

/* ─── Result ─────────────────────────────────────────────── */
.sa-pick {
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
    background: linear-gradient(160deg, rgba(59,130,246,0.08), transparent 70%);
}
.sa-pick-tag { font-size: 0.62rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent-blue); }
.sa-pick h3 { margin: 0.25rem 0 0.1rem; font-size: 1.1rem; font-weight: 800; color: var(--text-primary); }
.sa-pick-sub { margin: 0 0 0.5rem; color: var(--text-muted); font-size: 0.78rem; }
.sa-fit { font-size: 0.72rem; color: var(--text-muted); border: 1px solid var(--border); border-radius: var(--radius-pill); padding: 0.2rem 0.6rem; display: inline-block; }
.sa-fit b { color: var(--accent-green); }

.sa-section-title {
    font-size: 0.64rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--text-subtle); margin: 0.5rem 0 0.1rem;
}
.sa-reasons { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.sa-reasons li { display: flex; gap: 0.45rem; font-size: 0.79rem; line-height: 1.5; color: var(--text-muted); }
.sa-reasons li::before { content: '—'; color: var(--accent-blue); flex: 0 0 auto; }

.sa-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sa-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; }
.sa-table th, .sa-table td { padding: 0.45rem 0.55rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.sa-table th { font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-subtle); font-weight: 700; background: var(--bg-elevated); }
.sa-table tr:last-child td { border-bottom: none; }
.sa-table td:first-child { color: var(--text-muted); }
.sa-table td.sa-val { color: var(--text-primary); font-weight: 700; font-variant-numeric: tabular-nums; }
.sa-badge { font-size: 0.58rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; padding: 0.1rem 0.3rem; border-radius: var(--radius-xs); margin-left: 0.3rem; background: rgba(16,185,129,0.14); color: var(--accent-green); }
.sa-badge.is-tuned { background: rgba(245,158,11,0.14); color: var(--accent-amber); }

.sa-alt { padding: 0.7rem 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-base); }
.sa-alt h4 { margin: 0 0 0.25rem; font-size: 0.79rem; color: var(--text-primary); }
.sa-alt p  { margin: 0; font-size: 0.76rem; color: var(--text-muted); line-height: 1.5; }

.sa-actions { display: grid; gap: 0.4rem; }
.sa-btn {
    display: block; text-align: center;
    padding: 0.55rem 0.9rem; border-radius: var(--radius-sm);
    font-size: 0.81rem; font-weight: 600; font-family: inherit;
    cursor: pointer; text-decoration: none; border: 1px solid transparent;
    transition: filter var(--ease), border-color var(--ease), color var(--ease);
}
.sa-btn-primary { background: var(--gradient-blue); color: #fff; }
.sa-btn-primary:hover { filter: brightness(1.1); }
.sa-btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.sa-btn-ghost:hover { border-color: var(--border-hover); color: var(--text-primary); }

.sa-disclaimer {
    padding: 0.6rem 0.7rem;
    border-left: 2px solid var(--accent-amber);
    background: rgba(245,158,11,0.05);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
    font-size: 0.71rem; line-height: 1.5; color: var(--text-muted);
}
.sa-disclaimer b { color: var(--text-primary); }

/* ─── Mobile: full-width sheet ───────────────────────────── */
@media (max-width: 560px) {
    /* Collapse to a circle - the label would eat too much of a phone screen. */
    .sa-launcher {
        right: 16px; bottom: 16px;
        width: 58px; height: 58px;
        padding: 0; justify-content: center;
    }
    .sa-launcher .sa-launcher-label { display: none; }
    .sa-launcher .sa-launcher-icon { background: none; width: auto; flex: none; font-size: 1.2rem; }
    .sa-panel {
        right: 8px; left: 8px; bottom: 84px;
        width: auto; max-width: none;
        max-height: calc(100vh - 116px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .sa-panel, .sa-msg { animation: none; }
    .sa-launcher { transition: none; }
}
