/**
 * FAQ Widget Styles
 * Dark Palantir theme — matches history-sidebar.css and style.css design system.
 *
 * z-index hierarchy:
 *   history-sidebar:      900
 *   faq panel:           10500
 *   faq button:          11000
 *   municipality-modal:  10100  (faq must be above this)
 */

/* ===== FLOATING BUTTON ===== */

.faq-btn {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #2b3138;
    border: 2px solid #5ba3d1;
    box-shadow: 0 0 20px rgba(91, 163, 209, 0.6), 0 8px 24px rgba(0, 0, 0, 0.42);
    cursor: pointer;
    z-index: 11000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
    touch-action: none; /* required for pointer events on mobile */
    padding: 0;
}

.faq-btn-icon {
    width: 90px;
    height: 90px;
    object-fit: contain;
    pointer-events: none;
    display: block;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.faq-btn:hover {
    transform: scale(1.08);
    opacity: 1;
    background: rgba(125, 133, 144, 0.85);
    border-color: rgba(125, 133, 144, 0.85);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.42), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.faq-btn:hover .faq-btn-icon {
    transform: scale(1.03);
    filter: brightness(1.1);
}

.faq-btn:active {
    transform: scale(0.95);
}

.faq-btn.faq-btn--dragging {
    cursor: grabbing;
    transform: scale(1.05);
    transition: none; /* no easing while dragging */
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.faq-btn.faq-panel--open {
    opacity: 0.85;
}

/* ===== POPUP PANEL ===== */

.faq-panel {
    position: fixed;
    width: 380px;
    height: 530px;
    max-height: calc(100vh - 100px);
    background: #161b22;
    border: 1px solid #30363d;
    border-radius: 12px;
    z-index: 10500;
    display: flex;
    flex-direction: column;
    /* scale origin set by JS; starts collapsed at button corner */
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.26s cubic-bezier(0.34, 1.56, 0.64, 1),
                opacity 0.18s ease;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(255, 255, 255, 0.04);
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
}

.faq-panel.faq-panel--open {
    transform: scale(1);
    opacity: 1;
    pointer-events: auto;
}

/* ===== PANEL HEADER ===== */

.faq-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid #21262d;
    background: transparent;
    border-radius: 12px 12px 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.faq-panel-header h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #f0f6fc;
}

.faq-panel-header .faq-screen-badge {
    font-size: 11px;
    font-weight: 500;
    color: #6e7681;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 2px 7px;
    margin-left: 8px;
}

.faq-close-btn {
    background: transparent;
    border: none;
    color: #8b949e;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s ease, background 0.15s ease;
}

.faq-close-btn:hover {
    color: #f0f6fc;
    background: #30363d;
}

/* ===== MESSAGE LIST ===== */

.faq-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.faq-messages::-webkit-scrollbar {
    width: 6px;
}

.faq-messages::-webkit-scrollbar-track {
    background: transparent;
}

.faq-messages::-webkit-scrollbar-thumb {
    background: #30363d;
    border-radius: 3px;
}

.faq-messages::-webkit-scrollbar-thumb:hover {
    background: #484f58;
}

/* ===== WELCOME STATE ===== */

.faq-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 16px;
    color: #8b949e;
    gap: 12px;
    flex: 1;
}

.faq-welcome-icon {
    margin-bottom: 4px;
    color: #484f58;
    display: flex;
}

.faq-welcome h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #c9d1d9;
}

.faq-welcome p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* ===== MESSAGE BUBBLES ===== */

.faq-message {
    display: flex;
    flex-direction: column;
    max-width: 92%;
}

.faq-message--user {
    align-self: flex-end;
    align-items: flex-end;
}

.faq-message--assistant {
    align-self: flex-start;
    align-items: flex-start;
}

.faq-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.faq-message--user .faq-bubble {
    background: #1f6feb;
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.faq-message--assistant .faq-bubble {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    color: #c9d1d9;
    border-bottom-left-radius: 4px;
}

/* Markdown inside assistant bubble */
.faq-bubble p { margin: 0 0 8px; }
.faq-bubble p:last-child { margin-bottom: 0; }
.faq-bubble ul, .faq-bubble ol { margin: 4px 0 8px 18px; padding: 0; }
.faq-bubble li { margin-bottom: 3px; }
.faq-bubble strong { color: #f0f6fc; }
.faq-bubble em { color: #c9d1d9; font-style: italic; }
.faq-bubble h2, .faq-bubble h3, .faq-bubble h4 {
    margin: 10px 0 4px;
    font-weight: 600;
    color: #f0f6fc;
    line-height: 1.3;
}
.faq-bubble h2 { font-size: 14px; }
.faq-bubble h3 { font-size: 13.5px; }
.faq-bubble h4 { font-size: 13px; }
.faq-bubble code {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 12px;
}

/* ===== SOURCE CITATIONS ===== */

.faq-sources {
    margin-top: 6px;
    font-size: 11px;
    color: #6e7681;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.faq-sources-label {
    color: #6e7681;
    margin-right: 2px;
}

.faq-source-chip {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 11px;
    color: #6e7681;
    cursor: default;
    transition: border-color 0.15s, color 0.15s;
}

.faq-source-chip:hover {
    border-color: #58a6ff;
    color: #58a6ff;
}

/* ===== TYPING INDICATOR ===== */

.faq-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.faq-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #8b949e;
    animation: faq-bounce 1.2s infinite ease-in-out;
}

.faq-typing span:nth-child(2) { animation-delay: 0.2s; }
.faq-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes faq-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* ===== INPUT AREA ===== */

.faq-input-area {
    padding: 12px 16px;
    border-top: 1px solid #21262d;
    background: transparent;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}

.faq-textarea {
    flex: 1;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #e0e0e0;
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif;
    font-size: 13.5px;
    line-height: 1.5;
    padding: 8px 12px;
    resize: none;
    min-height: 38px;
    max-height: 120px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.15s ease;
}

.faq-textarea:focus {
    border-color: #388bfd;
}

.faq-textarea::placeholder {
    color: #484f58;
}

.faq-textarea:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== MIC BUTTON ===== */

.faq-mic-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #6e7681;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.faq-mic-btn:hover {
    color: #c9d1d9;
    border-color: rgba(255, 255, 255, 0.18);
}

.faq-mic-btn--listening {
    background: rgba(248, 81, 73, 0.1);
    border-color: rgba(248, 81, 73, 0.4);
    color: #f85149;
    animation: faq-mic-pulse 1.4s ease-in-out infinite;
}

@keyframes faq-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(248, 81, 73, 0.25); }
    50%       { box-shadow: 0 0 0 5px rgba(248, 81, 73, 0); }
}

.faq-send-btn {
    background: #238636;
    border: none;
    color: #ffffff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
    font-size: 16px;
}

.faq-send-btn:hover:not(:disabled) {
    background: #2ea043;
}

.faq-send-btn:disabled {
    background: rgba(255, 255, 255, 0.05);
    color: #484f58;
    cursor: not-allowed;
}

/* ===== ERROR STATE ===== */

.faq-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    color: #f85149;
    align-self: flex-start;
    max-width: 92%;
}

/* ===== MOBILE ===== */

@media (max-width: 480px) {
    .faq-panel {
        width: calc(100vw - 16px);
    }
}
