/* ===========================================================
   Sharescart AI Analyst - Modal & Chat styles
   Scoped under .ssai- prefix to avoid collisions with the host site.
   =========================================================== */

.ssai-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: linear-gradient(135deg, #1f6feb 0%, #6f42c1 100%);
    color: #fff !important;
    font-weight: 600;
    font-size: 14px;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 6px rgba(31, 111, 235, 0.25);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.ssai-trigger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(31, 111, 235, 0.35);
}
.ssai-trigger .ssai-spark {
    font-size: 16px;
    line-height: 1;
}

/* ----- Overlay & dialog ----- */
.ssai-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 30, 0.55);
    backdrop-filter: blur(2px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    animation: ssai-fade 0.18s ease;
}
.ssai-overlay.ssai-open { display: flex; }

@keyframes ssai-fade {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.ssai-dialog {
    width: min(720px, 95vw);
    height: min(720px, 90vh);
    background: #fff;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #1f2328;
}

/* ----- Header ----- */
.ssai-header {
    padding: 14px 18px;
    background: linear-gradient(135deg, #1f6feb 0%, #6f42c1 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ssai-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
}
.ssai-title-sub {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.85;
    margin-top: 1px;
}
.ssai-actions { display: flex; gap: 8px; align-items: center; }

.ssai-balance {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s;
}
.ssai-balance.ssai-balance-low {
    background: rgba(255, 99, 99, 0.55);
    color: #fff;
}
.ssai-icon-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.ssai-icon-btn:hover { background: rgba(255, 255, 255, 0.28); }

/* ----- History panel (past conversations) ----- */
.ssai-history-panel {
    border-bottom: 1px solid #e6e8eb;
    background: #fafbfc;
    max-height: 280px;
    overflow-y: auto;
}
.ssai-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #fff;
    border-bottom: 1px solid #e6e8eb;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #57606a;
}
.ssai-history-close {
    background: #f1f3f5;
    color: #57606a;
}
.ssai-history-close:hover { background: #e1e4e8; }
.ssai-history-list { padding: 6px 8px; }
.ssai-history-row {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff;
    border: 1px solid #e6e8eb;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: background 0.12s, border-color 0.12s;
}
.ssai-history-row:hover {
    background: #f1f5fb;
    border-color: #1f6feb;
}
.ssai-history-row-active {
    border-left: 3px solid #1f6feb;
    background: #eef4ff;
}
.ssai-history-row-title {
    font-size: 13.5px;
    font-weight: 600;
    color: #1f2328;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ssai-history-row-meta {
    font-size: 11px;
    color: #8b949e;
    margin-top: 3px;
}
.ssai-history-row-meta b { color: #1f6feb; }
.ssai-history-loading,
.ssai-history-empty {
    padding: 14px;
    text-align: center;
    color: #8b949e;
    font-size: 13px;
}

/* ----- Messages area ----- */
.ssai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    background: #f7f8fa;
}
.ssai-msg {
    display: flex;
    margin-bottom: 14px;
    animation: ssai-slideup 0.18s ease;
}
@keyframes ssai-slideup {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ssai-msg-user    { justify-content: flex-end; }
.ssai-msg-bot     { justify-content: flex-start; }

.ssai-bubble {
    max-width: 82%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14.5px;
    line-height: 1.55;
    word-wrap: break-word;
}
.ssai-msg-user .ssai-bubble {
    background: #1f6feb;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ssai-msg-bot .ssai-bubble {
    background: #fff;
    color: #1f2328;
    border: 1px solid #e6e8eb;
    border-bottom-left-radius: 4px;
}

/* Markdown rendered inside bot bubbles */
.ssai-bubble h1, .ssai-bubble h2, .ssai-bubble h3 {
    margin: 8px 0 6px;
    font-size: 15px;
    font-weight: 600;
}
.ssai-bubble p          { margin: 6px 0; }
.ssai-bubble ul,
.ssai-bubble ol         { padding-left: 22px; margin: 6px 0; }
.ssai-bubble li         { margin: 2px 0; }
.ssai-bubble code {
    background: #f1f3f5;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.ssai-bubble pre {
    background: #0d1117;
    color: #e6edf3;
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12.5px;
    margin: 8px 0;
}
.ssai-bubble pre code { background: transparent; padding: 0; color: inherit; }
.ssai-bubble table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: 13.5px;
}
.ssai-bubble th, .ssai-bubble td {
    border: 1px solid #e1e4e8;
    padding: 6px 9px;
    text-align: left;
}
.ssai-bubble th { background: #f6f8fa; font-weight: 600; }
.ssai-bubble blockquote {
    border-left: 3px solid #d0d7de;
    margin: 6px 0;
    padding-left: 10px;
    color: #57606a;
}
.ssai-bubble a { color: #1f6feb; text-decoration: underline; }

/* Cost / balance meta line under bot replies (legacy, kept for fallback) */
.ssai-meta {
    font-size: 11px;
    color: #8b949e;
    margin-top: 4px;
    padding-left: 4px;
}

/* ----- Entity badge ("About Asian Paints Ltd") ----- */
.ssai-entity-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    padding: 4px 10px;
    background: linear-gradient(135deg, #eef4ff 0%, #f5f0ff 100%);
    border: 1px solid #d4e3fb;
    border-radius: 999px;
    font-size: 12px;
    color: #1f2328;
    line-height: 1.3;
}
.ssai-entity-badge b { color: #1f6feb; font-weight: 600; }
.ssai-entity-icon { font-size: 13px; }

/* ----- Fallback notice (when primary provider failed and a fallback answered) ----- */
.ssai-fallback-note {
    margin-top: 6px;
    padding: 5px 9px;
    background: #fff8e1;
    border: 1px solid #f7d774;
    border-radius: 6px;
    font-size: 11.5px;
    color: #6a4c00;
    line-height: 1.4;
}
.ssai-fallback-note b { color: #1f2328; }
.ssai-fallback-icon {
    color: #b07900;
    font-weight: 700;
    margin-right: 2px;
}

/* ----- Sources strip (RAG citations) ----- */
.ssai-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding: 0 2px;
}
.ssai-sources-label {
    font-size: 11px;
    font-weight: 600;
    color: #57606a;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.ssai-source-tag {
    font-size: 11.5px;
    background: #f1f5fb;
    border: 1px solid #d4e3fb;
    color: #1f6feb;
    padding: 2px 8px;
    border-radius: 999px;
    cursor: help;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ----- Billing card (cost + tokens + balance) ----- */
.ssai-billing-card {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    padding: 0 2px;
    flex-wrap: wrap;
}
.ssai-pill {
    flex: 1 1 0;
    min-width: 90px;
    background: #f1f5fb;
    border: 1px solid #e1e8f2;
    border-radius: 8px;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}
.ssai-pill-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #6e7681;
}
.ssai-pill-value {
    font-size: 14px;
    font-weight: 700;
    color: #1f2328;
    margin-top: 1px;
}
.ssai-pill-sub {
    font-size: 10.5px;
    color: #8b949e;
    margin-top: 1px;
}
.ssai-pill-cost {
    background: #eef4ff;
    border-color: #d4e3fb;
}
.ssai-pill-cost .ssai-pill-value { color: #1f6feb; }
.ssai-pill-tokens {
    background: #f5f0ff;
    border-color: #e6dafc;
}
.ssai-pill-tokens .ssai-pill-value { color: #6f42c1; }
.ssai-pill-balance {
    background: #eafbef;
    border-color: #cdf0d8;
}
.ssai-pill-balance .ssai-pill-value { color: #1a7f37; }
.ssai-pill-balance-low {
    background: #fff1f0 !important;
    border-color: #ffcbcc !important;
}
.ssai-pill-balance-low .ssai-pill-value { color: #cf222e !important; }

@media (max-width: 600px) {
    .ssai-pill { min-width: 0; padding: 5px 8px; }
    .ssai-pill-value { font-size: 13px; }
}

/* Insufficient-balance warning bubble */
.ssai-bubble-warn {
    background: #fff8e1 !important;
    border-color: #f7d774 !important;
    color: #6a4c00 !important;
}
.ssai-bubble-warn strong { color: #b07900; }

/* Typing indicator */
.ssai-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.ssai-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: #9aa4ad;
    animation: ssai-bounce 1.2s infinite;
}
.ssai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ssai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ssai-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* Suggestion chips on first open */
.ssai-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}
.ssai-chip {
    padding: 6px 12px;
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.12s;
    color: #1f2328;
}
.ssai-chip:hover {
    background: #f1f3f5;
    border-color: #1f6feb;
    color: #1f6feb;
}

/* Welcome card */
.ssai-welcome {
    background: #fff;
    border: 1px solid #e6e8eb;
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 14px;
}
.ssai-welcome h4 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.ssai-welcome p  { margin: 0; font-size: 13.5px; color: #57606a; line-height: 1.5; }

/* ----- Input area ----- */
.ssai-inputbar {
    border-top: 1px solid #e6e8eb;
    background: #fff;
    padding: 10px 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ssai-input {
    flex: 1;
    border: 1px solid #d0d7de;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 40px;
    background: #f7f8fa;
    transition: border-color 0.15s, background 0.15s;
}
.ssai-input:focus {
    border-color: #1f6feb;
    background: #fff;
}
.ssai-send {
    background: #1f6feb;
    color: #fff;
    border: none;
    padding: 0 16px;
    height: 40px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.ssai-send:hover    { background: #1858c2; }
.ssai-send:disabled { background: #b6c2cf; cursor: not-allowed; }

.ssai-footer-note {
    text-align: center;
    font-size: 11px;
    color: #8b949e;
    padding: 6px 12px 10px;
    background: #fff;
}

/* Mobile */
@media (max-width: 600px) {
    .ssai-dialog { width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
    .ssai-bubble { max-width: 90%; }
}
