/* ============================================
   SixBudzet — chat assistant widget
   ============================================ */

.chat-widget {
    position: fixed;
    right: 1.5rem;
    bottom: 1.5rem;
    z-index: 1200;
    font-family: 'Inter', sans-serif;
}

.chat-toggle {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    padding: .75rem 1.1rem;
    border: 1px solid var(--gold);
    border-radius: 999px;
    background: var(--gold);
    color: var(--black);
    font-family: inherit;
    font-size: .95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}
.chat-toggle:hover { transform: translateY(-2px); filter: brightness(1.08); }
.chat-toggle:focus-visible { outline: 2px solid var(--white); outline-offset: 3px; }
.chat-toggle-icon { width: 1.15rem; height: 1.15rem; }

.chat-widget.is-open .chat-toggle {
    background: var(--graphite);
    color: var(--gold);
    border-color: var(--border);
    padding: .75rem;
    box-shadow: none;
}
.chat-widget.is-open .chat-toggle-label { display: none; }

.chat-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + .85rem);
    display: flex;
    flex-direction: column;
    width: min(680px, calc(100vw - 2rem));
    height: min(820px, calc(100vh - 6.5rem));
    background: var(--graphite);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .6);
    overflow: hidden;
    animation: chat-pop .16s ease-out;
}
.chat-panel[hidden] { display: none; }

@keyframes chat-pop {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Header ---------- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .8rem 1rem;
    background: var(--black);
    border-bottom: 1px solid var(--border);
}
.chat-heading { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.chat-heading strong { display: block; font-size: .98rem; color: var(--white); }
.chat-context {
    display: block;
    font-size: .75rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-dot {
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    background: var(--gold);
    box-shadow: 0 0 0 4px rgba(247, 189, 44, .14);
    flex: none;
}
.chat-header-actions { display: flex; align-items: center; gap: .35rem; }

.chat-year {
    width: auto;
    max-width: 5.4rem;
    padding: .3rem .35rem;
    font-size: .8rem;
    border-radius: 6px;
    background: var(--graphite);
    border-color: var(--graphite-light);
    color: var(--white);
}
.chat-year[hidden] { display: none; }

.chat-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 7px;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: color .15s, background .15s, border-color .15s;
}
.chat-icon-btn svg { width: 1.05rem; height: 1.05rem; }
.chat-icon-btn:hover {
    color: var(--gold);
    background: var(--graphite-light);
    border-color: var(--border);
}
.chat-icon-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ---------- Messages ---------- */
.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    scrollbar-width: thin;
    scrollbar-color: var(--graphite-light) transparent;
}
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--graphite-light);
    border-radius: 8px;
}

.chat-message { display: flex; width: 100%; }
.chat-message.user { justify-content: flex-end; }

.chat-bubble {
    max-width: 88%;
    padding: .65rem .85rem;
    border-radius: 12px;
    font-size: .9rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.chat-message.assistant .chat-bubble {
    background: var(--black);
    border: 1px solid rgba(255, 255, 255, .07);
    color: var(--white);
    border-bottom-left-radius: 4px;
}
.chat-message.user .chat-bubble {
    background: var(--gold);
    color: var(--black);
    border-bottom-right-radius: 4px;
    font-weight: 500;
}
.chat-message.error .chat-bubble {
    background: rgba(224, 82, 82, .12);
    border: 1px solid rgba(224, 82, 82, .45);
    color: #ffb3b3;
}

.chat-bubble p { margin: 0 0 .55rem; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble h4 {
    margin: .4rem 0 .45rem;
    font-size: .95rem;
    color: var(--gold);
}
.chat-bubble ul,
.chat-bubble ol { margin: .2rem 0 .55rem; padding-left: 1.15rem; }
.chat-bubble li { margin: .15rem 0; }
.chat-bubble strong { color: var(--white); }
.chat-message.user .chat-bubble strong { color: var(--black); }
.chat-bubble code {
    background: rgba(255, 255, 255, .1);
    padding: .08rem .3rem;
    border-radius: 4px;
    font-size: .84em;
}
.chat-message.user .chat-bubble code { background: rgba(0, 0, 0, .12); }
.chat-bubble pre {
    margin: .4rem 0;
    padding: .6rem;
    background: rgba(0, 0, 0, .45);
    border-radius: 6px;
    overflow-x: auto;
}
.chat-bubble pre code { background: none; padding: 0; }
.chat-bubble blockquote {
    margin: .4rem 0;
    padding: .2rem 0 .2rem .7rem;
    border-left: 3px solid var(--gold);
    color: var(--text-dim);
}
.chat-bubble hr {
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, .12);
    margin: .6rem 0;
}

.chat-table-wrap { overflow-x: auto; margin: .45rem 0; }
.chat-bubble table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.chat-bubble th,
.chat-bubble td {
    padding: .3rem .45rem;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
    text-align: left;
    white-space: nowrap;
}
.chat-bubble th { color: var(--gold); background: rgba(0, 0, 0, .3); font-weight: 600; }
.chat-bubble td.numeric,
.chat-bubble th.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.chat-typing { display: inline-flex; gap: .22rem; padding: .15rem 0; }
.chat-typing span {
    width: .36rem;
    height: .36rem;
    border-radius: 50%;
    background: var(--text-dim);
    animation: chat-blink 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .18s; }
.chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes chat-blink {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- Suggestions ---------- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    padding: 0 1rem .65rem;
}
.chat-suggestions:empty { display: none; }
.chat-chip {
    padding: .34rem .6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-family: inherit;
    font-size: .75rem;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
}
.chat-chip:hover { color: var(--gold); border-color: var(--gold); background: rgba(247, 189, 44, .08); }
.chat-chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

/* ---------- Composer ---------- */
.chat-form {
    display: flex;
    align-items: flex-end;
    gap: .45rem;
    padding: .7rem .8rem .4rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
    background: var(--black);
}
.chat-input {
    flex: 1 1 auto;
    resize: none;
    max-height: 7.5rem;
    padding: .55rem .7rem;
    border-radius: 9px;
    border: 1px solid var(--graphite-light);
    background: var(--graphite);
    color: var(--white);
    font-size: .9rem;
    line-height: 1.4;
}
.chat-input::placeholder { color: #8f97a3; }
.chat-input:focus { outline: none; border-color: var(--gold); }
.chat-input:disabled { opacity: .55; }

.chat-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 2.4rem;
    height: 2.4rem;
    padding: 0;
    border: 1px solid var(--gold);
    border-radius: 9px;
    background: var(--gold);
    color: var(--black);
    cursor: pointer;
    transition: filter .15s, opacity .15s;
}
.chat-send:hover:not(:disabled) { filter: brightness(1.1); }
.chat-send:disabled { opacity: .4; cursor: not-allowed; }
.chat-send:focus-visible { outline: 2px solid var(--white); outline-offset: 2px; }
.chat-send svg { width: 1.15rem; height: 1.15rem; }
.chat-stop-icon { display: none; width: .8rem; height: .8rem; border-radius: 2px; background: var(--black); }

.chat-widget.is-streaming .chat-send-icon { display: none; }
.chat-widget.is-streaming .chat-stop-icon { display: block; }

.chat-disclaimer {
    margin: 0;
    padding: 0 .9rem .6rem;
    background: var(--black);
    color: #8f97a3;
    font-size: .68rem;
    text-align: center;
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
    .chat-widget { right: .9rem; bottom: .9rem; }
    .chat-panel {
        position: fixed;
        inset: auto .5rem .5rem .5rem;
        width: auto;
        height: min(calc(100vh - 5.25rem - env(safe-area-inset-bottom, 0px)), 760px);
        bottom: calc(3.6rem + env(safe-area-inset-bottom, 0px));
    }
    .chat-bubble { max-width: 92%; }
}
