/* SHENA Self-Hosted Chat Widget */

:root {
    --chat-primary:      #019803;
    --chat-primary-dark: #017a02;
    --chat-primary-xdark:#015401;
    --chat-primary-pale: #e6f7e6;
    --chat-bg:           #ffffff;
    --chat-thread-bg:    #f4f6f8;
    --chat-border:       #e5e7eb;
    --chat-text:         #111827;
    --chat-muted:        #9ca3af;
    --chat-bubble-r:     14px;
    --chat-font:         system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
    --chat-shadow:       0 10px 40px rgba(0,0,0,.16), 0 2px 8px rgba(0,0,0,.08);
    --chat-z:            9999;
}

/* ============================================================
   Wrapper
   ============================================================ */
#shena-chat-wrapper {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--chat-z);
    font-family: var(--chat-font);
    font-size: 14px;
    line-height: 1.5;
}

/* ============================================================
   Bubble trigger
   ============================================================ */
#shena-chat-bubble {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(1,152,3,.4), 0 2px 6px rgba(0,0,0,.15);
    transition: background .18s, transform .18s, box-shadow .18s;
    outline: none;
    position: relative;
}

#shena-chat-bubble:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(1,152,3,.45), 0 2px 8px rgba(0,0,0,.18);
}

#shena-chat-bubble:active {
    transform: scale(0.96);
}

#shena-chat-bubble:focus-visible {
    outline: 3px solid rgba(1,152,3,.4);
    outline-offset: 3px;
}

/* Pulse ring — subtle attention animation */
#shena-chat-bubble::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(1,152,3,.3);
    animation: chat-ring 3s ease-in-out infinite;
    pointer-events: none;
}

@keyframes chat-ring {
    0%, 100% { transform: scale(1); opacity: .6; }
    50%       { transform: scale(1.14); opacity: 0; }
}

/* ============================================================
   Panel
   ============================================================ */
#shena-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 360px;
    max-height: 540px;
    background: var(--chat-bg);
    border-radius: 18px;
    box-shadow: var(--chat-shadow);
    border: 1px solid rgba(0,0,0,.06);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--chat-z);
    transform-origin: bottom right;
    animation: chat-panel-in .2s cubic-bezier(.34,1.56,.64,1);
}

#shena-chat-panel[hidden] {
    display: none;
}

@keyframes chat-panel-in {
    from { opacity: 0; transform: scale(.88) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ============================================================
   Header
   ============================================================ */
#shena-chat-header {
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #fff;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative;
}

/* Subtle texture overlay */
#shena-chat-header::after {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='20' height='20' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='1' cy='1' r='1' fill='rgba(255,255,255,.04)'/%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

#shena-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
    z-index: 1;
}

/* Agent avatar placeholder */
.shena-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255,255,255,.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: .02em;
    border: 2px solid rgba(255,255,255,.35);
}

.shena-header-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#shena-chat-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -.01em;
}

#shena-chat-subtitle {
    font-size: 11.5px;
    opacity: .82;
}

#shena-chat-close {
    background: rgba(255,255,255,.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: background .15s;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

#shena-chat-close:hover {
    background: rgba(255,255,255,.28);
}

/* ============================================================
   Messages thread
   ============================================================ */
#shena-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--chat-thread-bg);
    scroll-behavior: smooth;
}

/* Scrollbar */
#shena-chat-messages::-webkit-scrollbar { width: 4px; }
#shena-chat-messages::-webkit-scrollbar-track { background: transparent; }
#shena-chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 4px; }

.shena-msg {
    display: flex;
    flex-direction: column;
}

.shena-msg--visitor { align-items: flex-end; }
.shena-msg--agent,
.shena-msg--ai      { align-items: flex-start; }
.shena-msg--system  { align-items: center; }

.shena-msg-bubble {
    max-width: 82%;
    padding: 9px 13px;
    border-radius: var(--chat-bubble-r);
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 13.5px;
    line-height: 1.55;
    position: relative;
}

/* Visitor messages — green right */
.shena-msg--visitor .shena-msg-bubble {
    background: var(--chat-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 1px 4px rgba(1,152,3,.25);
}

/* Agent messages — white card left */
.shena-msg--agent .shena-msg-bubble,
.shena-msg--ai .shena-msg-bubble {
    background: #ffffff;
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    border: 1px solid rgba(0,0,0,.05);
}

/* System messages — pill center */
.shena-msg--system .shena-msg-bubble {
    background: #fef9c3;
    color: #78350f;
    font-size: 11.5px;
    font-style: italic;
    border-radius: 20px;
    padding: 4px 16px;
    max-width: 90%;
    text-align: center;
    border: 1px solid #fde68a;
}

.shena-msg-meta {
    font-size: 10.5px;
    color: var(--chat-muted);
    margin-top: 3px;
    padding: 0 2px;
}

/* Sender label above bubble */
.shena-msg-sender {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--chat-muted);
    margin-bottom: 2px;
    padding: 0 2px;
}

/* ============================================================
   Footer
   ============================================================ */
#shena-chat-footer {
    border-top: 1px solid var(--chat-border);
    padding: 12px 13px;
    background: var(--chat-bg);
    flex-shrink: 0;
}

#shena-chat-input {
    width: 100%;
    border: 1.5px solid var(--chat-border);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-family: var(--chat-font);
    resize: none;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    color: var(--chat-text);
    background: #fafafa;
    box-sizing: border-box;
}

#shena-chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(1,152,3,.1);
    background: #fff;
}

#shena-chat-input:disabled {
    background: #f3f4f6;
    color: #9ca3af;
    cursor: not-allowed;
}

#shena-chat-input::-moz-placeholder {
    color: #c4c9d4;
}

#shena-chat-input::placeholder {
    color: #c4c9d4;
}

#shena-chat-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

#shena-chat-send {
    background: var(--chat-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    width: 38px;
    height: 38px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .1s;
    box-shadow: 0 2px 8px rgba(1,152,3,.3);
}

#shena-chat-send:hover {
    background: var(--chat-primary-dark);
    transform: scale(1.05);
}

#shena-chat-send:active {
    transform: scale(0.95);
}

#shena-chat-send:disabled {
    opacity: .45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Transcript / end actions */
#shena-chat-transcript-row {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    gap: 8px;
}

#shena-chat-end,
#shena-chat-email-transcript {
    background: none;
    border: none;
    font-size: 11px;
    color: var(--chat-muted);
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color .12s;
}

#shena-chat-end:hover,
#shena-chat-email-transcript:hover {
    color: var(--chat-text);
}

/* ============================================================
   Powered-by footer
   ============================================================ */
#shena-chat-powered {
    text-align: center;
    font-size: 10px;
    color: #c4c9d4;
    padding: 6px 0 0;
    letter-spacing: .03em;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 420px) {
    #shena-chat-wrapper {
        bottom: 0;
        right: 0;
        left: 0;
    }

    #shena-chat-bubble {
        position: fixed;
        bottom: 18px;
        right: 18px;
    }

    #shena-chat-panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 70vh;
        border-radius: 18px 18px 0 0;
        animation: chat-panel-mobile-in .22s cubic-bezier(.34,1.3,.64,1);
    }

    @keyframes chat-panel-mobile-in {
        from { transform: translateY(40px); opacity: 0; }
        to   { transform: translateY(0); opacity: 1; }
    }
}

