/* ── Chat Widget: Floating Bubble + Panel ─────────────────────────── */

/* Bubble button */
#chatWidgetRoot .cw-bubble {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1040;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #0d6efd;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chatWidgetRoot .cw-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

#chatWidgetRoot .cw-bubble:focus-visible {
    outline: 3px solid #86b7fe;
    outline-offset: 2px;
}

/* Panel */
#chatWidgetRoot .cw-panel {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1050;
    width: 380px;
    max-height: 60vh;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    background: #fff;
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    opacity: 1;
    transform: translateY(0);
}

#chatWidgetRoot .cw-panel-hidden {
    display: none !important;
}

/* Panel header */
#chatWidgetRoot .cw-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #0d6efd;
    color: #fff;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-panel-title {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 8px;
}

#chatWidgetRoot .cw-plan-badge {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.35);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    margin-right: 8px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chatWidgetRoot .cw-panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-close-btn {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    border-radius: 4px;
}

#chatWidgetRoot .cw-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

#chatWidgetRoot .cw-close-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 1px;
}

/* Context strip: suggestions + disclaimer */
#chatWidgetRoot .cw-context {
    padding: 8px 12px;
    border-bottom: 1px solid #dee2e6;
    background: #f8f9fa;
}

#chatWidgetRoot .cw-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

#chatWidgetRoot .cw-suggestion-btn {
    border: 1px solid #ced4da;
    background: #fff;
    color: #333;
    font-size: 0.78rem;
    padding: 4px 8px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#chatWidgetRoot .cw-suggestion-btn:hover {
    background: #e9f1ff;
    border-color: #86b7fe;
}

#chatWidgetRoot .cw-disclaimer {
    margin-top: 6px;
    font-size: 0.75rem;
    color: #666;
}

#chatWidgetRoot .cw-disclaimer summary {
    cursor: pointer;
    color: #0d6efd;
}

#chatWidgetRoot .cw-disclaimer div {
    margin-top: 4px;
}

/* Messages area */
#chatWidgetRoot .cw-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 120px;
}

#chatWidgetRoot .cw-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
    font-size: 0.9rem;
}

/* Messages */
#chatWidgetRoot .chat-message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 10px;
    word-wrap: break-word;
    font-size: 0.9rem;
    line-height: 1.4;
}

#chatWidgetRoot .chat-message-user {
    align-self: flex-end;
    background: #0d6efd;
    color: #fff;
}

#chatWidgetRoot .chat-message-assistant {
    align-self: flex-start;
    background: #f1f1f1;
    color: #333;
}

#chatWidgetRoot .chat-message-label {
    font-size: 0.7rem;
    font-weight: 600;
    margin-bottom: 2px;
    opacity: 0.75;
}

#chatWidgetRoot .chat-message-body {
    font-size: 0.875rem;
}

/* Policy notice */
#chatWidgetRoot .cw-policy-notice {
    border: 1px solid #f1c40f;
    background: #fff9db;
    color: #5c4b00;
    border-radius: 8px;
    padding: 8px 10px;
    margin-bottom: 6px;
}

#chatWidgetRoot .cw-policy-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

#chatWidgetRoot .cw-policy-body {
    font-size: 0.85rem;
}

#chatWidgetRoot .cw-inline-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

/* Citations */
#chatWidgetRoot .cw-sources {
    margin-top: 6px;
    font-size: 0.75rem;
    color: #555;
    border-top: 1px solid #ddd;
    padding-top: 6px;
}

#chatWidgetRoot .cw-sources summary {
    cursor: pointer;
    color: #0d6efd;
}

#chatWidgetRoot .cw-source {
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

#chatWidgetRoot .cw-source:last-child {
    border-bottom: none;
}

#chatWidgetRoot .cw-source-title {
    font-weight: 600;
    font-size: 0.78rem;
}

#chatWidgetRoot .cw-source-excerpt {
    font-size: 0.75rem;
    color: #444;
}

/* Typing indicator */
@keyframes cw-typing-dot {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

#chatWidgetRoot .cw-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
}

#chatWidgetRoot .cw-typing span {
    display: inline-block;
    font-size: 1.2rem;
    line-height: 1;
    animation: cw-typing-dot 1.4s infinite;
}

#chatWidgetRoot .cw-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

#chatWidgetRoot .cw-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Status bar (errors / rate-limit) */
#chatWidgetRoot .cw-status {
    padding: 6px 14px;
    font-size: 0.8rem;
    color: #842029;
    background: #f8d7da;
    border-top: 1px solid #f5c2c7;
    flex-shrink: 0;
}

/* Input row */
#chatWidgetRoot .cw-input-row {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid #dee2e6;
    flex-shrink: 0;
    background: #fff;
}

#chatWidgetRoot .cw-input-row input {
    flex: 1;
    min-width: 0;
}

/* Remember button in input row */
#chatWidgetRoot .cw-remember-btn {
    padding: 2px 6px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* ── Remember form overlay ───────────────────────────────────────── */

#chatWidgetRoot .cw-remember-overlay {
    padding: 10px 12px;
    border-top: 1px solid #dee2e6;
    background: #f8f9fa;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-remember-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.85rem;
}

#chatWidgetRoot .cw-remember-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#chatWidgetRoot .cw-remember-error {
    font-size: 0.8rem;
    color: #842029;
}

/* ── Memories list overlay ───────────────────────────────────────── */

#chatWidgetRoot .cw-memories-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: 120px;
}

#chatWidgetRoot .cw-memories-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #dee2e6;
    font-weight: 600;
    font-size: 0.85rem;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-memories-items {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 12px;
}

#chatWidgetRoot .cw-memory-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
    gap: 8px;
}

#chatWidgetRoot .cw-memory-item:last-child {
    border-bottom: none;
}

#chatWidgetRoot .cw-memory-info {
    flex: 1;
    min-width: 0;
}

#chatWidgetRoot .cw-memory-key {
    font-weight: 600;
    font-size: 0.8rem;
    color: #555;
}

#chatWidgetRoot .cw-memory-value {
    font-size: 0.85rem;
    word-wrap: break-word;
}

#chatWidgetRoot .cw-memory-delete {
    flex-shrink: 0;
    padding: 2px 6px;
    font-size: 0.75rem;
}

#chatWidgetRoot .cw-memories-empty {
    padding: 20px 12px;
    text-align: center;
    color: #888;
    font-size: 0.85rem;
}

/* ── Disclaimer footer ────────────────────────────────────────────── */

#chatWidgetRoot .cw-disclaimer-footer {
    padding: 6px 12px;
    font-size: 0.7rem;
    color: #888;
    text-align: center;
    border-top: 1px solid #dee2e6;
    flex-shrink: 0;
    background: #f8f9fa;
}

/* ── Memory banner ───────────────────────────────────────────────── */

#chatWidgetRoot .cw-memory-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: #e8f0fe;
    border-bottom: 1px solid #c5d9f5;
    font-size: 0.8rem;
    color: #1a56db;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-memory-banner-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-shrink: 0;
}

#chatWidgetRoot .cw-memory-banner-actions button {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.78rem;
    padding: 2px 6px;
    border-radius: 4px;
}

#chatWidgetRoot .cw-memory-banner-view {
    color: #1a56db;
    text-decoration: underline;
}

#chatWidgetRoot .cw-memory-banner-dismiss {
    color: #666;
    font-size: 1rem;
    line-height: 1;
}

/* ── Dark mode ────────────────────────────────────────────────────── */

html.dark #chatWidgetRoot .cw-panel {
    background: #1e1e1e;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

html.dark #chatWidgetRoot .cw-context {
    background: #1a1a1a;
    border-bottom: 1px solid #333;
}

html.dark #chatWidgetRoot .cw-suggestion-btn {
    background: #2a2a2a;
    border-color: #3a3a3a;
    color: #ddd;
}

html.dark #chatWidgetRoot .cw-suggestion-btn:hover {
    background: #223a5e;
    border-color: #2f5fa8;
}

html.dark #chatWidgetRoot .cw-disclaimer {
    color: #aaa;
}

html.dark #chatWidgetRoot .cw-policy-notice {
    background: #2d2a17;
    border-color: #8c6d1f;
    color: #f1d38a;
}

html.dark #chatWidgetRoot .cw-policy-label {
    color: #f1d38a;
}

html.dark #chatWidgetRoot .cw-messages {
    background: #1e1e1e;
}

html.dark #chatWidgetRoot .cw-empty-state {
    color: #aaa;
}

html.dark #chatWidgetRoot .chat-message-assistant {
    background: #2d2d2d;
    color: #e0e0e0;
}

html.dark #chatWidgetRoot .cw-sources {
    border-top: 1px solid #3a3a3a;
    color: #bbb;
}

html.dark #chatWidgetRoot .cw-source {
    border-bottom: 1px solid #333;
}

html.dark #chatWidgetRoot .cw-status {
    background: #3b1d20;
    color: #f5c2c7;
    border-top-color: #5c2b30;
}

html.dark #chatWidgetRoot .cw-input-row {
    background: #1e1e1e;
    border-top-color: #444;
}

html.dark #chatWidgetRoot .cw-input-row input {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #555;
}

html.dark #chatWidgetRoot .cw-bubble {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

html.dark #chatWidgetRoot .cw-remember-overlay {
    background: #2d2d2d;
    border-top-color: #444;
}

html.dark #chatWidgetRoot .cw-memories-header {
    border-bottom-color: #444;
}

html.dark #chatWidgetRoot .cw-memory-item {
    border-bottom-color: #444;
}

html.dark #chatWidgetRoot .cw-memory-key {
    color: #aaa;
}

html.dark #chatWidgetRoot .cw-memories-empty {
    color: #aaa;
}

html.dark #chatWidgetRoot .cw-disclaimer-footer {
    background: #1a1a1a;
    border-top-color: #333;
    color: #777;
}

html.dark #chatWidgetRoot .cw-memory-banner {
    background: #1a2744;
    border-bottom-color: #2a3d5c;
    color: #7db3ff;
}

html.dark #chatWidgetRoot .cw-memory-banner-view {
    color: #7db3ff;
}

html.dark #chatWidgetRoot .cw-memory-banner-dismiss {
    color: #aaa;
}

html.dark #chatWidgetRoot .cw-memory-value {
    color: #e5e7eb;
}

html.dark #chatWidgetRoot .cw-source-excerpt {
    color: #9ca3af;
}

html.dark #chatWidgetRoot .cw-source-title {
    color: #60a5fa;
}

/* ── Mobile responsive ────────────────────────────────────────────── */

@media (max-width: 480px) {
    #chatWidgetRoot .cw-panel {
        width: calc(100vw - 1rem);
        max-height: calc(100vh - 5rem);
        bottom: 0.5rem;
        right: 0.5rem;
        border-radius: 12px;
    }

    #chatWidgetRoot .cw-bubble {
        bottom: 1rem;
        right: 1rem;
    }
}
