/*
  chat-widget.css — The Numerology API visitor chat widget
  Self-contained styles — no framework dependency
  Hosted on Cloudflare Pages alongside website/*.html
*/

/* ── CSS custom properties (inherit from site or fallback) ── */
:root {
    --cw-accent:     #0ea5e9; /* Teal */
    --cw-accent-2:   #f97316; /* Orange */
    --cw-accent-fg:  #ffffff;
    --cw-bg:         #ffffff;
    --cw-bg-panel:   #f8fafc;
    --cw-border:     rgba(0,0,0,0.10);
    --cw-text:       #060b16;
    --cw-text-muted: #64748b;
    --cw-mine-bg:    linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    --cw-mine-fg:    #ffffff;
    --cw-shadow:     0 20px 60px rgba(14,165,233,0.18), 0 8px 24px rgba(0,0,0,0.12);
    --cw-radius:     20px;
    --cw-fab-size:   58px;
}

/* Dark mode overrides */
[data-theme="dark"] {
    --cw-accent:     #38bdf8; /* Dark Teal */
    --cw-accent-2:   #fb923c; /* Dark Orange */
    --cw-bg:         #060b16;
    --cw-bg-panel:   #1e293b;
    --cw-border:     rgba(255,255,255,0.08);
    --cw-text:       #f1f5f9;
    --cw-text-muted: #94a3b8;
}

/* ── Floating action button ── */
#cwFab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99990;
    width: var(--cw-fab-size);
    height: var(--cw-fab-size);
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    color: var(--cw-accent-fg);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.3s ease,
                opacity 0.2s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}
#cwFab:hover {
    transform: scale(1.12);
    box-shadow: 0 12px 36px rgba(14,165,233,0.52), 0 4px 12px rgba(0,0,0,0.18);
}
#cwFab:active { transform: scale(0.96); }
#cwFab.open .cw-fab-open  { display: none; }
#cwFab.open .cw-fab-close { display: flex; }
#cwFab .cw-fab-close { display: none; align-items: center; justify-content: center; }

/* Unread badge on FAB */
#cwFabBadge {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 18px; height: 18px;
    border-radius: 9px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid var(--cw-bg);
    animation: cwPulse 2s cubic-bezier(0.4,0,0.6,1) infinite;
}
#cwFabBadge.visible { display: flex; }

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

/* ── Chat panel ── */
#cwPanel {
    position: fixed;
    bottom: calc(var(--cw-fab-size) + 44px);
    right: 28px;
    z-index: 99989;
    width: 360px;
    max-width: calc(100vw - 40px);
    max-height: 540px;
    display: flex;
    flex-direction: column;
    border-radius: var(--cw-radius);
    background: var(--cw-bg);
    border: 1px solid var(--cw-border);
    box-shadow: var(--cw-shadow);
    overflow: hidden;
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.35s cubic-bezier(0.34,1.56,0.64,1),
                opacity 0.25s ease;
}
#cwPanel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ── Panel header ── */
.cw-header {
    padding: 16px 18px;
    background: linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.cw-header-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: rgba(255,255,255,0.22);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.cw-header-info { flex: 1; min-width: 0; }
.cw-header-title {
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cw-header-sub {
    font-size: 0.7rem;
    opacity: 0.78;
    margin-top: 1px;
}
.cw-header-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.65rem;
    opacity: 0.85;
    margin-top: 3px;
}
.cw-header-status-dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: #bbf7d0;
    animation: cwPulse 2s cubic-bezier(0.4,0,0.6,1) infinite;
}

/* ── Identity form (shown before first message) ── */
#cwIdentityForm {
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
}
#cwIdentityForm h3 {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--cw-text);
    margin: 0;
}
#cwIdentityForm p {
    font-size: 0.775rem;
    color: var(--cw-text-muted);
    margin: -4px 0 0;
    line-height: 1.5;
}
.cw-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.cw-field label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--cw-text-muted);
}
.cw-field input {
    padding: 9px 12px;
    border: 1px solid var(--cw-border);
    border-radius: 10px;
    background: var(--cw-bg-panel);
    color: var(--cw-text);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    width: 100%;
    box-sizing: border-box;
}
.cw-field input:focus {
    border-color: var(--cw-accent);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.14);
}
.cw-start-btn {
    padding: 11px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    color: white;
    font-size: 0.875rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    letter-spacing: -0.01em;
    margin-top: 4px;
}
.cw-start-btn:hover { transform: scale(1.02); box-shadow: 0 6px 18px rgba(14,165,233,0.30); }
.cw-start-btn:active { transform: scale(0.98); }

/* ── Messages area ── */
#cwMessages {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}
#cwMessages::-webkit-scrollbar { width: 3px; }
#cwMessages::-webkit-scrollbar-thumb {
    background: rgba(100,116,139,0.25);
    border-radius: 3px;
}

/* ── Messages ── */
.cw-msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: cwMsgIn 0.28s cubic-bezier(0.34,1.56,0.64,1) both;
}
.cw-msg-row.mine { flex-direction: row-reverse; }
@keyframes cwMsgIn {
    from { opacity: 0; transform: translateY(10px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
.cw-msg-avatar {
    width: 26px; height: 26px; border-radius: 50%;
    background: linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: white; font-weight: 700; flex-shrink: 0;
}
.cw-msg-row.mine .cw-msg-avatar { background: linear-gradient(135deg, var(--cw-accent-2), var(--cw-accent)); }

.cw-msg-bubble {
    max-width: 78%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-break: break-word;
}
.cw-msg-row.mine .cw-msg-bubble {
    background: var(--cw-mine-bg);
    color: var(--cw-mine-fg);
    border-bottom-right-radius: 3px;
}
.cw-msg-row.theirs .cw-msg-bubble {
    background: var(--cw-bg-panel);
    color: var(--cw-text);
    border-bottom-left-radius: 3px;
    border: 1px solid var(--cw-border);
}
.cw-msg-time {
    font-size: 9px;
    opacity: 0.5;
    margin-top: 2px;
    display: block;
    text-align: right;
}
.cw-msg-row.theirs .cw-msg-time { text-align: left; }

/* ── Typing indicator ── */
#cwTyping {
    display: none;
}
.cw-typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 9px 12px;
    background: var(--cw-bg-panel);
    border: 1px solid var(--cw-border);
    border-radius: 14px;
    border-bottom-left-radius: 3px;
    width: fit-content;
}
.cw-typing-dots span {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--cw-text-muted);
    animation: cwTyping 1.4s ease-in-out infinite;
}
.cw-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.cw-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cwTyping {
    0%,80%,100% { transform: translateY(0); opacity: 0.5; }
    40%          { transform: translateY(-5px); opacity: 1; }
}

/* ── Session closed notice ── */
#cwClosedNotice {
    display: none;
    padding: 10px 16px;
    font-size: 0.75rem;
    color: var(--cw-text-muted);
    text-align: center;
    background: var(--cw-bg-panel);
    border-top: 1px solid var(--cw-border);
}

/* ── Composer ── */
.cw-composer {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--cw-border);
    background: var(--cw-bg);
    align-items: flex-end;
    flex-shrink: 0;
}
#cwInput {
    flex: 1;
    resize: none;
    border: 1px solid var(--cw-border);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 0.825rem;
    line-height: 1.5;
    background: var(--cw-bg-panel);
    color: var(--cw-text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    max-height: 100px;
    min-height: 38px;
    font-family: inherit;
}
#cwInput:focus {
    border-color: var(--cw-accent);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.13);
}
#cwSendBtn {
    width: 38px; height: 38px; border-radius: 10px;
    background: linear-gradient(135deg, var(--cw-accent), var(--cw-accent-2));
    color: white; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}
#cwSendBtn:hover { transform: scale(1.08); box-shadow: 0 4px 14px rgba(14,165,233,0.35); }
#cwSendBtn:active { transform: scale(0.94); }
#cwSendBtn:disabled { background: var(--cw-border); cursor: not-allowed; transform: none; box-shadow: none; }

/* ── Powered by bar ── */
.cw-powered {
    text-align: center;
    font-size: 9px;
    padding: 5px 12px 6px;
    color: var(--cw-text-muted);
    opacity: 0.55;
    flex-shrink: 0;
}
.cw-powered a { color: inherit; text-decoration: none; }
.cw-powered a:hover { opacity: 1; text-decoration: underline; }

/* ── Responsive tweaks ── */
@media (max-width: 420px) {
    #cwPanel { right: 12px; left: 12px; width: auto; }
    #cwFab   { right: 16px; bottom: 20px; }
}

/* ── Rich inline formatting ── */
.rich-inline-code {
    font-family: monospace;
    background: rgba(100, 116, 139, 0.12);
    color: #ef4444;
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 0.85em;
    border: 1px solid var(--cw-border);
}
.cw-msg-bubble .rich-inline-code {
    color: inherit;
}
.rich-link {
    color: var(--cw-accent);
    text-decoration: underline;
    font-weight: 600;
    transition: opacity 0.2s;
}
.rich-link:hover { opacity: 0.8; }

/* ── Attachments ── */
.cw-attachment-btn {
    width: 38px; height: 38px; border-radius: 10px;
    border: 1px solid var(--cw-border);
    background: transparent;
    color: var(--cw-text-muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    transition: all 0.2s;
    outline: none;
    flex-shrink: 0;
}
.cw-attachment-btn:hover {
    border-color: var(--cw-accent);
    color: var(--cw-accent);
    background: rgba(14, 165, 233, 0.06);
}

.cw-upload-progress-card {
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--cw-border);
    background: var(--cw-bg-panel);
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 220px;
    font-size: 0.7rem;
    align-self: flex-end;
}

.cw-progress-bar-container {
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: var(--cw-bg);
    overflow: hidden;
    border: 1px solid var(--cw-border);
}

.cw-progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(95deg, var(--cw-accent), var(--cw-accent-2));
    border-radius: 3px;
    transition: width 0.1s linear;
}

.cw-attachment-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    border: 1px solid var(--cw-border);
    background: var(--cw-bg-panel);
    max-width: 240px;
    font-size: 0.725rem;
    cursor: pointer;
    transition: all 0.2s;
}
.cw-attachment-card:hover {
    border-color: var(--cw-text-muted);
    transform: translateY(-1px);
}

.cw-attachment-icon {
    width: 28px; height: 28px; border-radius: 8px;
    background: rgba(14, 165, 233, 0.12);
    color: var(--cw-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

.cw-attachment-info {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; gap: 1px;
}
.cw-attachment-name {
    font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--cw-text);
}
.cw-attachment-size {
    font-size: 8px; color: var(--cw-text-muted);
}

.cw-attachment-download {
    color: var(--cw-text-muted);
    font-size: 11px;
    padding: 3px;
    transition: color 0.2s;
}
.cw-attachment-download:hover { color: var(--cw-accent); }

.cw-attachment-image-preview {
    max-width: 220px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--cw-border);
    margin-top: 4px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    cursor: pointer;
    transition: transform 0.2s;
}
.cw-attachment-image-preview:hover {
    transform: scale(1.01);
}
.cw-attachment-image-preview img {
    width: 100%;
    height: auto;
    display: block;
}
