/* ============================================================
   Kash AI – Chat Widget  v3
   Modern gradient-header layout, matches any WP theme.
   Every rule scoped to #kash-root.
============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ─── Tokens ─────────────────────────────────────────────────── */
#kash-root {
    --kp:      #4A6FD4;           /* brand blue */
    --kp2:     rgb(74, 111, 212, .08);           /* lighter blue */
    --kt:      rgb(74, 111, 212, 1);           /* accent blue */
    --kgrad:   linear-gradient(135deg, #4A6FD4 0%, rgb(74, 111, 212, 1) 100%);
    --kgh:     linear-gradient(135deg, #1E3A8A 0%, #4A6FD4 100%); /* header navy gradient */
    --kw:      #FFFFFF;
    --kg1:     #F8FAFC;           /* slate 50 */
    --kg2:     #F1F5F9;           /* slate 100 */
    --kg3:     #E2E8F0;           /* slate 200 */
    --kg4:     #64748B;           /* slate 500 */
    --ktxt:    #1e202a;           /* slate 900 (matches login button) */
    --krad:    12px;              /* cleaner radius */
    --krads:   8px;
    --kfont:   'Inter', 'Segoe UI', system-ui, sans-serif;
    --kshadow: 0 10px 40px rgba(15,23,42,0.15), 0 4px 12px rgba(0,0,0,0.08);

    font-family: var(--kfont);
    position:   fixed;
    bottom:     24px;
    right:      24px;
    z-index:    999999;
    display:    flex;
    flex-direction: column;
    align-items: flex-end;
    gap:        10px;
}

/* ─── FAB BUTTON ─────────────────────────────────────────────── */
#kash-fab {
    width:            50px;
    height:           50px;
    border-radius:    50%;
    background:       var(--kgrad);
    border:           none;
    cursor:           pointer;
    display:          flex;
    align-items:      center;
    justify-content:  center;
    position:         relative;
    flex-shrink:      0;
    box-shadow:       0 6px 24px rgba(91,79,232,0.55);
    transition:       transform .25s cubic-bezier(.34,1.56,.64,1),
                      box-shadow .2s ease;
    outline:          none;
    -webkit-tap-highlight-color: transparent;
}
#kash-fab svg{
    width: 24px;
    height: 24px;
}

#kash-fab:hover          { transform: scale(1.1);  box-shadow: 0 8px 30px rgba(91,79,232,.7); }
#kash-fab:active         { transform: scale(0.93); }
#kash-fab[aria-expanded="true"] { box-shadow: 0 4px 16px rgba(91,79,232,.4); }

/* Pulse ring */
#kash-fab::after {
    content:       '';
    position:      absolute;
    inset:         0;
    border-radius: 50%;
    background:    var(--kgrad);
    opacity:       0;
    animation:     kpulse 3s ease-out 2s infinite;
    pointer-events: none;
}
@keyframes kpulse {
    0%   { transform: scale(1);   opacity:.5; }
    70%  { transform: scale(1.75); opacity:0;  }
    100% { transform: scale(1.75); opacity:0;  }
}

/* Notification dot */
#kash-notif {
    position:      absolute;
    top:           2px;
    right:         2px;
    width:         13px;
    height:        13px;
    background:    #FF4D6D;
    border:        2.5px solid #fff;
    border-radius: 50%;
    transition:    transform .2s ease, opacity .2s ease;
}

#kash-root.kash-open #kash-notif {
    transform: scale(0);
    opacity:   0;
}

/* ─── CHAT PANEL ──────────────────────────────────────────────── */
#kash-panel {
    width:          370px;
    height:         530px;
    display: none;
    /* display:        flex; */
    flex-direction: column;
    background:     var(--kw);
    border-radius:  var(--krad);
    box-shadow:     var(--kshadow);
    overflow:       hidden;

    /* Slide-up animation */
    transform-origin: bottom right;
    transition: transform .38s cubic-bezier(.34,1.56,.64,1),
                opacity  .25s ease;
}

#kash-panel.kp-hidden {
    transform: scale(0.86) translateY(18px);
    opacity:   0;
    pointer-events: none;
}

#kash-panel.kp-open {
    transform: scale(1) translateY(0);
    opacity:   1;
    pointer-events: auto;
}

/* ─── HEADER ──────────────────────────────────────────────────── */
#kash-header {
    background:      var(--kgh);
    padding:         16px;
    display:         flex;
    align-items:     center;
    justify-content: space-between;
    flex-shrink:     0;
    /* height:          50px; */
}

/* Left side: avatar + text */
#kash-hd-left {
    display:     flex;
    align-items: center;
    gap:         8px;
    min-width:   0;   /* allow text wrap prevention */
}

#kash-avatar {
    width:            30px;
    height:           30px;
    border-radius:    50%;
    background:       #1e202a;
    border:           1px solid #1e202a;
    color:            white;
    font-size:        12px;
    font-weight:      600;
    display:          flex;
    align-items:      center;
    justify-content:  center;
    flex-shrink:      0;
    letter-spacing:   0;
}

#kash-hd-text {
    min-width: 0;
}

#kash-hd-name {
    color:       white;
    font-size:   16px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

#kash-hd-name span {
    opacity: 0.75;
    font-weight: 500;
}

#kash-hd-status {
    display:     flex;
    align-items: center;
    gap:         4px;
    /* color:       rgba(255,255,255,0.65); */
    color: #94a3b8;
    font-size:   10px;
    margin-top:  1px;
    white-space: nowrap;
    line-height: 1.2;
    margin-top: 4px;
}

#kash-online-dot {
    width:         6px;
    height:        6px;
    border-radius: 50%;
    background:    #2ECC71;
    box-shadow:    0 0 5px #2ECC71;
    display:       inline-block;
    flex-shrink:   0;
    animation:     kblink 2.5s ease-in-out infinite;
}

@keyframes kblink {
    0%, 100% { opacity: 1; }
    50%       { opacity: .3; }
}

/* Right side: quota + buttons */
#kash-hd-right {
    display:     flex;
    align-items: center;
    gap:         3px;
    flex-shrink: 0;
}

#kash-quota-pill {
    display:       flex;
    align-items:   center;
    gap:           3px;
    color:         rgba(255,255,255,0.85);
    font-size:     12px;
    font-weight:   500;
    background:    rgba(255,255,255,0.15);
    border:        1px solid rgba(255,255,255,0.25);
    border-radius: 100px;
    padding:       4px 12px;
    line-height: 1.5;
    white-space:   nowrap;
}

.kash-hbtn {
    width:           26px;
    height:          26px;
    border-radius:   100px;
    background:      none;
    border:          none;
    color:           rgba(255,255,255,0.6);
    cursor:          pointer;
    display:         flex;
    align-items:     center;
    justify-content: center;
    transition:      background .15s, color .15s;
    outline:         none;
}

.kash-hbtn:hover {
    background: rgba(255,255,255,0.15);
    color:      white;
}

/* ─── MESSAGE FEED ────────────────────────────────────────────── */
#kash-feed {
    flex:           1;
    overflow-y:     auto;
    padding:        16px;
    display:        flex;
    flex-direction: column;
    gap:            8px;
    background:     var(--kw);
    scroll-behavior: smooth;
}

#kash-feed::-webkit-scrollbar        { width: 4px; }
#kash-feed::-webkit-scrollbar-thumb  { background: var(--kg3); border-radius: 4px; }
#kash-feed::-webkit-scrollbar-track  { background: transparent; }

/* ─── MESSAGE ROWS ────────────────────────────────────────────── */
.km {
    display:     flex;
    align-items: flex-end;
    gap:         8px;
    animation:   kfadein .28s ease;
}

@keyframes kfadein {
    from { opacity:0; transform: translateY(8px); }
    to   { opacity:1; transform: translateY(0);   }
}

.km-user { flex-direction: row-reverse; }

/* Avatar inside feed messages */
.km-av {
    width:           30px;
    height:          30px;
    border-radius:   50%;
    font-size:       12px;
    font-weight:     600;
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    letter-spacing:  0;
    background:      #1e202a;
    color:           white;
    border: 1px solid #1E202A;
}

.km-user .km-av {
    background: var(--kg2);
    color:      var(--kg4);
    border-color: var(--kg2);
}

/* Bubble */
.km-bbl {
    max-width:     77%;
    padding:       10px 13px;
    font-size:     0.84rem;
    line-height:   1.5;
    word-break:    break-word;
    border-radius: 5px 5px 5px 2px;
    background:    #FFF;
    border:        1px solid #1E202A;
    color:         var(--ktxt);
}

.km-user .km-bbl {
    background:    var(--kgrad);
    border:        none;
    border-radius: 5px 5px 3px 5px;
    color:         white;
}

/* Welcome bubble */
.km-welcome .km-bbl {
    background:   #FFF;
    border-color: #1E202A;
}

/* ── Rich text inside bot bubbles ─────────────────────────────── */
.km-bbl p             { margin: 0 0 8px; font-size: 14px; }
.km-bbl p:last-child  { margin-bottom: 0; }

.km-bbl strong        { font-weight: 600; color: var(--ktxt); }
.km-bbl em            { font-style: italic; color: #5a5d7c; }
.km-user .km-bbl em   { color: rgba(255,255,255,.9); }
.km-bbl br            { display: block; content: ''; margin-top: 3px; }

/* Key-Value labels generated for pairs like "Amount: $136B" */
.km-bbl strong.klabel { 
    color: var(--ktxt); 
    font-weight: 700; 
    margin-right: 2px;
}
.km-user .km-bbl strong.klabel { color: white; }

/* Numbered & bullet lists */
.km-bbl ol,
.km-bbl ul {
    margin:     6px 0 6px 4px;
    padding-left: 18px;
}
.km-bbl li {
    margin-bottom: 6px;
    padding-left:  2px;
    line-height:   1.55;
}
.km-bbl li:last-child { margin-bottom: 0; }

/* Deal item separator */
.km-bbl hr {
    border:     none;
    border-top: 1px solid var(--kg2);
    margin:     8px 0;
}

/* Inline code / pill values */
.km-bbl code {
    background:    var(--kg2);
    border-radius: 4px;
    padding:       1px 5px;
    font-size:     0.8em;
    font-family:   'Courier New', monospace;
}

.kh  { color: var(--kp); font-weight: 600; }
.km-bbl a  { color: var(--kp); text-decoration: underline; }
.km-user .km-bbl a { color: rgba(255,255,255,.85); }

/* Streaming content div — no extra padding needed */
.km-stream-content { width: 100%; }

/* Blinking cursor on the active streaming bubble */
.km-stream-content.km-streaming::after {
    content:    '▋';
    display:    inline;
    color:      var(--kp);
    animation:  kcursor .8s step-end infinite;
    font-size:  0.75em;
    margin-left: 1px;
    vertical-align: middle;
}

@keyframes kcursor {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* Meta info line (intent badge etc.) */
.km-meta {
    display:       flex;
    align-items:   center;
    gap:           5px;
    flex-wrap:     wrap;
    margin-bottom: 7px;
    font-size:     0.67rem;
}

.km-badge {
    background:   rgba(29,78,216,0.08); /* brand blue alpha */
    color:        var(--kp);
    border:       1px solid rgba(29,78,216,0.15);
    border-radius: 100px;
    padding:      2px 8px;
    font-weight:  600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.km-badge-dev {
    background:  rgba(255,100,55,0.1);
    color:       #E74C3C;
    border-color: rgba(231,76,60,0.2);
}

.km-cnt { color: var(--kg4); }
.km-ms  { color: var(--kg3); margin-left: auto; }

/* ─── CHIPS ROW (inside feed) ────────────────────────────────── */
.km-chips-row {
    display:   flex;
    flex-wrap: wrap;
    gap:       0px;
    padding:   0;     /* override .km padding */
    align-items: flex-start;
}

.kchip {
    border: 1px solid #4A6FD4;
    color: #4A6FD4;
    background: transparent;
    font-size: 10px;
    font-weight: 500;
    padding: 5.25px 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    line-height: normal;
    text-transform: uppercase;
    margin-right: 4px;
    margin-bottom: 4px;
}

.kchip:hover {
    background:   var(--kp);
    color:        white;
}

.kchip:active { transform: scale(0.96); }

/* ─── TYPING INDICATOR ────────────────────────────────────────── */
.km-typing {
    display:     flex;
    align-items: flex-end;
    gap:         8px;
    animation:   kfadein .2s ease;
}

/* The bubble that holds dots + optional status label */
.kdots {
    display:       flex;
    align-items:   center;
    gap:           8px;
    padding:       10px 14px;
    background:    var(--kg1);
    border:        1px solid var(--kg2);
    border-radius: 14px 14px 14px 3px;
    min-width:     52px;
    max-width:     220px;
}

/* The three animated dots — always visible as a group */
.kdots-anim {
    display:     flex;
    gap:         5px;
    align-items: center;
    flex-shrink: 0;
}

.kdots-anim span {
    width:         7px;
    height:        7px;
    border-radius: 50%;
    background:    var(--kp2);
    display:       inline-block;
    animation:     kdot 1.3s ease-in-out infinite;
}

.kdots-anim span:nth-child(2) { animation-delay: .18s; }
.kdots-anim span:nth-child(3) { animation-delay: .36s; }

@keyframes kdot {
    0%,80%,100% { transform: scale(.6); opacity: .3; }
    40%          { transform: scale(1);  opacity: 1;  }
}

/* Status text that appears alongside dots */
.kash-status-text {
    font-size:    0.75rem;
    font-weight:  500;
    color:        var(--kg4);
    white-space:  nowrap;
    overflow:     hidden;
    text-overflow: ellipsis;
    max-width:    150px;
    animation:    kfadein .2s ease;
}

/* ─── INPUT BAR ───────────────────────────────────────────────── */
#kash-input-bar {
    display:       flex;
    align-items:   flex-end;
    gap:           8px;
    padding:       16px;
    background:    var(--kw);
    border-top:    1.5px solid var(--kg2);
    flex-shrink:   0;
    position: relative;
}

#kash-input {
    flex:          1;
    border:        1.5px solid var(--kg3);
    border-radius: var(--krads);
    padding:       9px 13px;
    font-family:   var(--kfont);
    font-size:     0.855rem;
    color:         var(--ktxt);
    background:    var(--kg1);
    resize:        none;
    outline:       none;
    line-height:   1.5;
    max-height:    110px;
    overflow-y:    auto;
    transition:    border-color .18s, box-shadow .18s, background .18s;
    padding-right: 50px !important;
}

#kash-input::placeholder { color: var(--kg4); }

#kash-input:focus {
    border-color: var(--kp);
    background:   white;
    box-shadow:   0 0 0 3px rgba(91,79,232,0.10);
}

#kash-send {
    width:           30px;
    height:          30px;
    border-radius:   50%;
    border:          1px solid #1E202A;
    background:      #1e202a;
    cursor:          pointer;
    display:         flex;
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    color:           white;
    transition: .3s ease-in-out,
                opacity .3s ease-in-out;
    outline:         none;
    position: absolute;
    right: 32px;
    bottom: 32px;
}
#kash-send svg {
    width: 12px;
    height: 12px;
    transform: rotate(-90deg);
    transition: all 0.3s ease-in-out;
}
#kash-send:hover:not(:disabled) { background: #FFF; color: #1e202a; }

#kash-send:active:not(:disabled) { transform: scale(0.92); }

#kash-send:disabled {
    opacity:   .35;
    cursor:    not-allowed;
    transform: none;
    box-shadow: none;
}


#kash-stop {
    width:           30px;
    height:          30px;
    border-radius:   50%;
    border:          1px solid #1E202A;
    background:      #1e202a;
    cursor:          pointer;
    display:         none; /* hidden by default */
    align-items:     center;
    justify-content: center;
    flex-shrink:     0;
    color:           white;
    transition: .3s ease-in-out,
                opacity .3s ease-in-out;
    outline:         none;
    position: absolute;
    right: 32px;
    bottom: 32px;
}

#kash-stop svg {
    width: 14px;
    height: 14px;
}

#kash-stop:hover { background: #E74C3C; border-color: #E74C3C; color: white; }

#kash-stop:active { transform: scale(0.92); }

/* ─── ERROR TOAST ─────────────────────────────────────────────── */
#kash-err {
    position:     absolute;
    bottom:       74px;
    left:         20px;
    right:        20px;
    background:   #ea580c;
    color:        white;
    font-size:    0.78rem;
    font-weight:  500;
    padding:      9px 13px;
    border-radius: var(--krads);
    display:      none;
    box-shadow:   0 4px 14px rgba(0,0,0,.2);
    animation:    kfadein .2s ease;
    z-index:      10;
}

/* ─── LOGIN NOTICE ────────────────────────────────────────────── */
.kash-login-notice {
    font-family: var(--kfont);
    padding:     20px;
    text-align:  center;
    color:       #888;
    font-size:   .88rem;
}
.kash-login-notice a { color: var(--kp); }

/* ─── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 420px) {
    #kash-root { bottom:16px; right:16px; }
    #kash-panel { width: calc(100vw - 32px); height: 72vh; max-height: 540px; }
}
