/* ── Chat Side Panel — DataStore Research Assistant ─────────────────────── */

/* Smooth body reflow when panel is pinned */
body {
    transition: padding-right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Overlay backdrop */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(2px);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.chat-overlay--visible {
    opacity: 1;
    pointer-events: auto;
}

/* Side panel */
.chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: rgba(10, 5, 2, 0.98);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10000;
    transform: translateX(100%);
    transition:
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        width 0.25s ease;
    box-shadow: -10px 0 48px rgba(0, 0, 0, 0.55);
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    will-change: transform;
}

.chat-panel--narrow { width: 380px; }
.chat-panel--wide   { width: 620px; }
.chat-panel--max    { width: 60vw; }

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

/* Toggle button (avatar circle, fixed bottom-right) */
.chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    padding: 0;
    cursor: pointer;
    z-index: 10001;
    overflow: hidden;
    background: none;
    box-shadow:
        0 4px 18px rgba(0, 0, 0, 0.45),
        0 0 0 3px rgba(192, 90, 42, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-toggle-btn svg {
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 50%;
}

.chat-toggle-btn:hover {
    transform: scale(1.08);
    box-shadow:
        0 6px 22px rgba(0, 0, 0, 0.55),
        0 0 0 3px rgba(192, 90, 42, 0.65);
}

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

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
    flex-shrink: 0;
    background: rgba(15, 7, 3, 0.85);
}

.chat-header-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-header-avatar svg {
    width: 100%;
    height: 100%;
}

.chat-header-name {
    font-size: 14px;
    font-weight: 600;
    color: #f0ebe5;
    white-space: nowrap;
}

.chat-header-sub {
    font-size: 11px;
    color: rgba(240, 235, 229, 0.42);
    margin-top: 1px;
    white-space: nowrap;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.chat-icon-btn {
    background: none;
    border: none;
    color: rgba(240, 235, 229, 0.42);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
    line-height: 1;
}

.chat-icon-btn:hover {
    color: #f0ebe5;
    background: rgba(255, 255, 255, 0.07);
}

.chat-icon-btn--active {
    color: #E67D3A;
    background: rgba(192, 90, 42, 0.12);
}

.chat-icon-btn--active:hover {
    color: #f0ebe5;
    background: rgba(192, 90, 42, 0.22);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(192, 90, 42, 0.3);
    border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(192, 90, 42, 0.55);
}

/* Welcome card */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 28px 20px;
    text-align: center;
}

.chat-welcome-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
}

.chat-welcome-avatar svg {
    width: 100%;
    height: 100%;
}

.chat-welcome-text {
    color: rgba(240, 235, 229, 0.65);
    font-size: 14px;
    line-height: 1.65;
    margin: 0;
}

/* Individual messages */
.chat-message {
    padding: 12px 15px;
    border-radius: 10px;
    max-width: 88%;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.55;
    animation: chatFadeUp 0.22s ease;
}

@keyframes chatFadeUp {
    from { opacity: 0; transform: translateY(7px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-message--user {
    align-self: flex-end;
    background: linear-gradient(135deg, #C05A2A, #D96E38);
    color: #f0ebe5;
    border-bottom-right-radius: 3px;
}

.chat-message--assistant {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.055);
    color: #e8e3dd;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-left-radius: 3px;
    max-width: 97%;
}

.chat-message--error {
    align-self: flex-start;
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
    border: 1px solid rgba(248, 113, 113, 0.25);
    font-size: 13px;
}

/* Limit-reached CTA cards */
.chat-limit-card {
    align-self: stretch;
    background: rgba(192, 90, 42, 0.10);
    border: 1px solid rgba(192, 90, 42, 0.35);
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 100%;
}

.chat-limit-heading {
    font-size: 13px;
    font-weight: 600;
    color: #f5a87a;
    margin: 0;
}

.chat-limit-body {
    font-size: 12px;
    color: rgba(240, 235, 229, 0.65);
    margin: 0;
    line-height: 1.55;
}

.chat-limit-btn {
    display: inline-block;
    align-self: flex-start;
    margin-top: 4px;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.15s;
}

.chat-limit-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    text-decoration: none;
}

.chat-limit-btn--signup {
    background: rgba(255, 255, 255, 0.12);
    color: #f0ebe5;
    border: 1px solid rgba(255, 255, 255, 0.30);
}

.chat-limit-btn--upgrade {
    background: #c05a2a;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.10);
}

/* Typing indicator */
.chat-typing {
    padding: 14px 18px;
    display: flex;
    gap: 5px;
    align-items: center;
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-width: 80px;
    border-radius: 10px;
    border-bottom-left-radius: 3px;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: rgba(240, 235, 229, 0.5);
    animation: chatBounce 1.2s ease-in-out infinite;
}

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

@keyframes chatBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Markdown content (assistant messages) ──────────────────────────────── */

.chat-message--assistant p {
    margin: 0 0 8px;
}

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

.chat-message--assistant strong {
    color: #E67D3A;
    font-weight: 600;
}

.chat-message--assistant em {
    color: rgba(240, 235, 229, 0.85);
}

.chat-message--assistant code {
    background: rgba(0, 0, 0, 0.38);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'IBM Plex Mono', monospace;
    font-size: 12px;
    color: #E67D3A;
}

.chat-message--assistant pre {
    background: rgba(0, 0, 0, 0.38);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
}

.chat-message--assistant pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    color: #f0ebe5;
}

.chat-message--assistant h1,
.chat-message--assistant h2,
.chat-message--assistant h3,
.chat-message--assistant h4,
.chat-message--assistant h5,
.chat-message--assistant h6 {
    color: #E67D3A;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 12px 0 5px;
}

.chat-message--assistant h1:first-child,
.chat-message--assistant h2:first-child,
.chat-message--assistant h3:first-child {
    margin-top: 0;
}

.chat-message--assistant hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.11);
    margin: 10px 0;
}

.chat-message--assistant ul,
.chat-message--assistant ol {
    margin: 4px 0 8px;
    padding-left: 18px;
}

.chat-message--assistant li {
    margin-bottom: 4px;
}

.chat-message--assistant a {
    color: #E67D3A;
    text-decoration: none;
}

.chat-message--assistant a:hover {
    text-decoration: underline;
}

/* Tables */
.chat-message--assistant table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 12.5px;
    display: block;
    overflow-x: auto;
}

.chat-message--assistant th {
    background: rgba(192, 90, 42, 0.18);
    color: #E67D3A;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid rgba(192, 90, 42, 0.3);
    white-space: nowrap;
}

.chat-message--assistant td {
    padding: 7px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    color: rgba(240, 235, 229, 0.9);
    vertical-align: top;
}

.chat-message--assistant tr:last-child td {
    border-bottom: none;
}

.chat-message--assistant tbody tr:hover td {
    background: rgba(255, 255, 255, 0.04);
}

/* Input row */
.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    background: rgba(10, 5, 2, 0.85);
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #f0ebe5;
    padding: 9px 13px;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: rgba(192, 90, 42, 0.5);
    box-shadow: 0 0 0 3px rgba(192, 90, 42, 0.12);
}

.chat-input::placeholder {
    color: rgba(240, 235, 229, 0.32);
}

.chat-send-btn {
    padding: 9px 18px;
    white-space: nowrap;
    font-size: 14px;
    border-radius: 8px;
}

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

/* Responsive — full-width on small screens */
@media (max-width: 480px) {
    .chat-panel--narrow,
    .chat-panel--wide,
    .chat-panel--max {
        width: 100vw;
    }

    .chat-toggle-btn {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}
