/* ==========================================================================
   CHAT ASSISTANT — FAB + Bottom Sheet / Side Drawer
   ========================================================================== */

/* ---------- FAB Button ---------- */
.chat-fab {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-blue);
    color: #fff;
    border: none;
    font-size: 1.35rem;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(30, 64, 175, 0.35);
    z-index: 100006;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(30, 64, 175, 0.45);
}

.chat-fab:active {
    transform: scale(0.95);
}

.chat-widget.open ~ .chat-fab {
    display: none;
}

/* ---------- Widget Container + Overlay ---------- */
.chat-widget {
    position: fixed;
    inset: 0;
    z-index: 100008;
    pointer-events: none;
    visibility: hidden;
}

.chat-widget.open {
    pointer-events: all;
    visibility: visible;
}

.chat-widget-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.chat-widget.open .chat-widget-overlay {
    opacity: 1;
}

/* ---------- Bottom Sheet (Mobile) ---------- */
.chat-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80vh;
    max-height: 90vh;
    background: var(--surface-white);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.chat-widget.open .chat-sheet {
    transform: translateY(0);
}

/* Desktop: side drawer */
@media (min-width: 769px) {
    .chat-sheet {
        right: 0;
        left: auto;
        bottom: 0;
        top: 0;
        width: 400px;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateX(100%);
        transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .chat-widget.open .chat-sheet {
        transform: translateX(0);
    }
}

/* ---------- Drag Handle (mobile only) ---------- */
.chat-drag-handle {
    display: flex;
    justify-content: center;
    padding: 0.75rem 0 0.25rem;
    flex-shrink: 0;
}

.chat-drag-handle span {
    width: 36px;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
}

@media (min-width: 769px) {
    .chat-drag-handle { display: none; }
}

/* ---------- Header ---------- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    min-height: 56px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.chat-header-left > i {
    color: var(--primary-blue);
    font-size: 1.15rem;
    flex-shrink: 0;
}

.chat-header-left h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
}

.chat-scope-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.chat-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.chat-close:hover {
    color: var(--text-main);
}

/* ---------- Messages Area ---------- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    -webkit-overflow-scrolling: touch;
}

/* ---------- Message Bubbles ---------- */
.chat-msg {
    max-width: 85%;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.55;
    word-wrap: break-word;
}

.chat-msg-user {
    align-self: flex-end;
    background: var(--primary-blue);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-assistant {
    align-self: flex-start;
    background: var(--bg-off-white);
    color: var(--text-main);
    border-bottom-left-radius: 4px;
}

.chat-msg-assistant p {
    margin: 0 0 0.5rem;
}

.chat-msg-assistant p:last-child {
    margin-bottom: 0;
}

.chat-msg-assistant strong {
    font-weight: 600;
}

.chat-msg-assistant a {
    color: var(--primary-blue);
    text-decoration: underline;
}

.chat-msg-assistant ul,
.chat-msg-assistant ol {
    margin: 0.25rem 0 0.5rem;
    padding-left: 1.25rem;
}

.chat-msg-assistant li {
    margin-bottom: 0.15rem;
}

.chat-msg-assistant code {
    background: rgba(0,0,0,0.06);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-size: 0.85em;
}

/* ---------- Welcome Message ---------- */
.chat-welcome {
    text-align: center;
    padding: 1.5rem 1rem;
}

.chat-welcome-icon {
    font-size: 2rem;
    color: var(--primary-blue);
    margin-bottom: 0.75rem;
}

.chat-welcome h4 {
    font-size: 1rem;
    margin: 0 0 0.35rem;
}

.chat-welcome p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0 0 1rem;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-suggestion {
    background: var(--bg-off-white);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.85rem;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
}

.chat-suggestion:hover {
    border-color: var(--primary-blue);
    background: var(--surface-white);
}

/* ---------- Source Citation Pills ---------- */
.chat-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.5rem;
}

.chat-source-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 500;
    text-decoration: none;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.chat-source-pill:hover {
    opacity: 0.8;
}

.chat-source-pill i {
    font-size: 0.6rem;
}

/* Source type color coding */
.chat-source-pill[data-type="statute"] {
    background: rgba(220, 38, 38, 0.1);
    color: #dc2626;
}

.chat-source-pill[data-type="regulation"] {
    background: rgba(217, 119, 6, 0.1);
    color: #d97706;
}

.chat-source-pill[data-type="va_page"] {
    background: rgba(5, 150, 105, 0.1);
    color: #059669;
}

.chat-source-pill[data-type="fact_sheet"] {
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
}

.chat-source-pill[data-type="vbc_explainer"] {
    background: rgba(30, 64, 175, 0.1);
    color: var(--primary-blue);
}

/* ---------- Verification Badge ---------- */
.chat-verification {
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    margin-top: 0.25rem;
    border-radius: 4px;
    color: var(--text-muted);
}
.chat-verification i { margin-right: 0.25rem; }
.chat-verification.verified { color: var(--success-green); }
.chat-verification.unverified { color: var(--warning-text); }

/* ---------- Loading Dots ---------- */
.chat-loading {
    align-self: flex-start;
    display: flex;
    gap: 0.3rem;
    padding: 0.75rem 1rem;
    background: var(--bg-off-white);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
}

.chat-loading span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: chatDotBounce 1.4s ease-in-out infinite;
}

.chat-loading span:nth-child(2) { animation-delay: 0.16s; }
.chat-loading span:nth-child(3) { animation-delay: 0.32s; }

@keyframes chatDotBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ---------- Refusal Message ---------- */
.chat-refusal {
    align-self: flex-start;
    background: rgba(220, 38, 38, 0.06);
    border: 1px solid rgba(220, 38, 38, 0.15);
    border-radius: var(--radius-md);
    padding: 0.75rem 0.9rem;
    font-size: 0.9rem;
    color: var(--text-main);
    max-width: 85%;
}

.chat-refusal i {
    color: var(--alert-red);
    margin-right: 0.35rem;
}

/* ---------- Input Area ---------- */
.chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-off-white);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 0.5rem 0.65rem;
    transition: border-color 0.15s;
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary-blue);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.4;
    resize: none;
    outline: none;
    color: var(--text-main);
    max-height: 100px;
    min-height: 22px;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.chat-send {
    background: var(--primary-blue);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
}

.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-send:not(:disabled):hover {
    transform: scale(1.08);
}

.chat-disclaimer {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin: 0.5rem 0 0;
}

.chat-disclaimer i {
    margin-right: 0.2rem;
}

/* ---------- Dark Mode ---------- */
[data-theme="dark"] .chat-sheet {
    background: #1e293b;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .chat-widget-overlay {
    background: rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .chat-drag-handle span {
    background: #475569;
}

[data-theme="dark"] .chat-header {
    border-bottom-color: #334155;
}

[data-theme="dark"] .chat-input-area {
    border-top-color: #334155;
}

[data-theme="dark"] .chat-msg-assistant code {
    background: rgba(255,255,255,0.08);
}

[data-theme="dark"] .chat-fab {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
    .chat-sheet {
        transition: none;
    }

    .chat-widget-overlay {
        transition: none;
    }

    .chat-fab {
        transition: none;
    }

    .chat-loading span {
        animation: none;
        opacity: 0.6;
    }
}

/* ---------- Print ---------- */
@media print {
    .chat-widget,
    .chat-fab {
        display: none !important;
    }
}
