/* ==========================================================================
   Portfolio Assistant — resume-grounded chat widget
   Reuses the site's existing design tokens (--bg-color, --neon-green, etc.
   from style.css) so it inherits the System/Terminal aesthetic exactly
   instead of introducing a second, slightly-off color system.
   ========================================================================== */

:root {
    --sys-chat-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --sys-chat-accent: var(--neon-green, #00ffaa);
}

/* Toggle button — joins the existing WhatsApp / scroll-to-top floating stack
   so it inherits their fixed positioning, sizing, and stacking behavior.

   Its layout box stays the stack's 50px circle; the visible shape is the pill
   behind it, which grows *leftwards* to reveal "Chat with resume". Widening
   the button itself would widen the centered stack and shove the WhatsApp and
   scroll-to-top buttons sideways. (The 0,2,0 selector outranks style.css's
   `.sys-chat-toggle { position: static !important }` stack rules.) */
.floating-btn-group .sys-chat-toggle {
    position: relative !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0;
    overflow: visible;
    color: var(--sys-chat-accent) !important;
    cursor: pointer;
}

.sys-chat-toggle-pill {
    position: absolute;
    top: 0;
    right: 0;
    width: 50px;
    height: 50px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    /* Text hugs the icon; as the pill widens it's uncovered from the left,
       so the words stay put and are revealed rather than sliding across. */
    justify-content: flex-end;
    overflow: hidden;
    background: #05070a;
    border: 1px solid var(--sys-chat-accent);
    border-radius: 25px;
    box-shadow: 0 0 12px rgba(0, 255, 170, 0.25), 0 4px 14px rgba(0, 0, 0, 0.3);
    transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.3s ease;
}

.sys-chat-toggle-text {
    flex-shrink: 0;
    /* Clears the icon. A margin, not pill padding: padding + border can't
       fit a 50px border-box, which stretched the "circle" to a 54px oval. */
    margin-right: 52px;
    white-space: nowrap;
    font-family: var(--sys-chat-mono);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--sys-chat-accent);
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 0.25s ease, transform 0.35s ease;
}

.sys-chat-toggle-icon {
    position: relative; /* paints above the pill */
}

.sys-chat-toggle:hover .sys-chat-toggle-pill,
.sys-chat-toggle:focus-visible .sys-chat-toggle-pill {
    box-shadow: 0 0 20px rgba(0, 255, 170, 0.45), 0 4px 14px rgba(0, 0, 0, 0.3);
}

.sys-chat-toggle.expanded .sys-chat-toggle-pill {
    /* Measured from the label in chatbot.js; 200px is a safe fallback. */
    width: var(--sys-chat-pill-w, 200px);
}

.sys-chat-toggle.expanded .sys-chat-toggle-text {
    opacity: 1;
    transform: translateX(0);
    transition-delay: 0.15s; /* let the pill open a little before the words fade in */
}

@media (prefers-reduced-motion: reduce) {
    .sys-chat-toggle-pill,
    .sys-chat-toggle-text {
        transition: none;
    }
}

/* ---- Panel ---------------------------------------------------------------- */
.sys-chat-panel {
    position: fixed;
    right: 30px;
    bottom: 96px;
    width: min(420px, calc(100vw - 40px));
    height: min(580px, calc(100vh - 140px));
    background: #05070a;
    border: 1px solid var(--sys-chat-accent);
    border-radius: 4px;
    box-shadow: 0 0 30px rgba(0, 255, 170, 0.12), 0 20px 50px rgba(0, 0, 0, 0.5);
    font-family: var(--sys-chat-mono);
    display: flex;
    flex-direction: column;
    z-index: 1000001; /* above the feedback modal (1000000), the highest layer on the site */
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.sys-chat-panel.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

@media (max-width: 480px) {
    .sys-chat-panel {
        right: 16px;
        bottom: 86px;
        width: calc(100vw - 32px);
    }
}

/* ---- Header ---------------------------------------------------------------- */
.sys-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(0, 255, 170, 0.2);
}

.sys-chat-title {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    color: var(--sys-chat-accent);
    display: flex;
    align-items: center;
    gap: 2px;
}

.sys-chat-bracket { color: rgba(0, 255, 170, 0.5); }
.sys-chat-slash { color: var(--text-secondary, #9ca3af); }

.sys-chat-cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    margin-left: 6px;
    background: var(--sys-chat-accent);
    animation: sysChatBlink 1s steps(1) infinite;
    vertical-align: middle;
}

@keyframes sysChatBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

.sys-chat-close {
    background: transparent;
    border: none;
    color: var(--text-secondary, #9ca3af);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    transition: color 0.2s ease;
}
.sys-chat-close:hover { color: var(--sys-chat-accent); }

/* ---- Status bar ---------------------------------------------------------- */
.sys-chat-status {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    font-size: 0.62rem;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #9ca3af);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sys-chat-status-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.sys-chat-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sys-chat-accent);
    box-shadow: 0 0 6px var(--sys-chat-accent);
    animation: sysChatPulse 2s ease-in-out infinite;
}

.sys-chat-dot-alt {
    background: var(--accent-blue, #3b82f6);
    box-shadow: 0 0 6px var(--accent-blue, #3b82f6);
    animation-delay: 0.6s;
}

@keyframes sysChatPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ---- Messages -------------------------------------------------------------- */
.sys-chat-messages {
    position: relative; /* offsetParent for scroll-anchoring answers in chatbot.js */
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.8rem;
    line-height: 1.55;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sys-chat-messages::-webkit-scrollbar { display: none; }

.sys-chat-msg-user {
    align-self: flex-end;
    max-width: 85%;
}

.sys-chat-bubble {
    display: inline-block;
    background: rgba(0, 255, 170, 0.08);
    border: 1px solid rgba(0, 255, 170, 0.25);
    border-radius: 4px;
    padding: 8px 12px;
    color: var(--text-primary, #f3f4f6);
}

.sys-chat-msg-ai,
.sys-chat-msg-loading,
.sys-chat-msg-error {
    align-self: flex-start;
    max-width: 92%;
    color: var(--text-primary, #f3f4f6);
}

.sys-chat-ai-tag {
    color: var(--sys-chat-accent);
    font-weight: 700;
}

.sys-chat-error-tag { color: #ff5f56; }
.sys-chat-msg-error .sys-chat-ai-text { color: #f3a5a2; }

.sys-chat-ai-text { white-space: pre-wrap; }

/* ---- Structured answers (cards) ------------------------------------------- */
.sys-chat-msg-ai { max-width: 100%; width: 100%; }

.sys-chat-msg-ai .sys-chat-ai-tag {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.sc-answer {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sc-intro {
    margin: 0;
    color: var(--text-primary, #f3f4f6);
}

.sc-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--sys-chat-accent);
}

.sc-section-title::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(0, 255, 170, 0.18);
}

.sc-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sc-item {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-left: 2px solid rgba(0, 255, 170, 0.55);
    border-radius: 4px;
    padding: 9px 11px;
}

.sc-item-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 8px;
}

.sc-item-title {
    font-weight: 700;
    color: var(--text-primary, #f3f4f6);
    line-height: 1.35;
}

.sc-tag {
    font-size: 0.6rem;
    line-height: 1.5;
    padding: 1px 6px;
    border-radius: 3px;
    color: var(--sys-chat-accent);
    background: rgba(0, 255, 170, 0.07);
    border: 1px solid rgba(0, 255, 170, 0.28);
    white-space: nowrap;
}

.sc-item-sub {
    margin-top: 3px;
    font-size: 0.72rem;
    color: var(--text-secondary, #9ca3af);
}

.sc-item-text {
    margin: 5px 0 0;
    font-size: 0.76rem;
    line-height: 1.55;
    color: #cbd5e1;
}

.sc-item-text:first-child { margin-top: 0; }

.sc-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 8px;
}

.sc-item-head + .sc-chips { margin-top: 7px; }

.sc-chip {
    font-size: 0.62rem;
    line-height: 1.5;
    padding: 1px 7px;
    border-radius: 3px;
    color: #93c5fd;
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.28);
}

.sc-link {
    color: var(--sys-chat-accent);
    text-decoration: none;
    word-break: break-all;
}

.sc-link:hover { text-decoration: underline; }

/* Contact-style label/value rows. */
.sc-section-compact .sc-items { gap: 0; }

.sc-section-compact .sc-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 11px;
    border-radius: 0;
    border-top-width: 0;
}

.sc-section-compact .sc-item:first-child {
    border-top-width: 1px;
    border-radius: 4px 4px 0 0;
}

.sc-section-compact .sc-item:last-child { border-radius: 0 0 4px 4px; }
.sc-section-compact .sc-item:only-child { border-radius: 4px; }

.sc-section-compact .sc-item-head { flex: 0 0 38%; }

.sc-section-compact .sc-item-title {
    font-weight: 400;
    font-size: 0.7rem;
    color: var(--text-secondary, #9ca3af);
}

.sc-section-compact .sc-item-text { margin: 0; }

.sc-note {
    margin: 0;
    font-size: 0.7rem;
    color: var(--text-secondary, #9ca3af);
}

.sc-suggest {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sys-chat-loading-text { color: var(--text-secondary, #9ca3af); }

/* ---- Suggested prompt pills ------------------------------------------------- */
.sys-chat-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 14px;
}

.sys-chat-pill {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(0, 255, 170, 0.25);
    color: var(--text-secondary, #9ca3af);
    font-family: var(--sys-chat-mono);
    font-size: 0.68rem;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sys-chat-pill:hover {
    color: var(--sys-chat-accent);
    border-color: var(--sys-chat-accent);
    background: rgba(0, 255, 170, 0.06);
}

/* ---- Input row -------------------------------------------------------------- */
/* style.css sets `form { flex-direction: column; gap: 1.5rem }` and pads every
   `form input` / `form button` for the contact form. This row is a <form> too,
   so every one of those properties has to be pinned back explicitly here. */
.sys-chat-input-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(0, 255, 170, 0.2);
}

.sys-chat-prompt-glyph {
    color: var(--sys-chat-accent);
    font-weight: 700;
}

.sys-chat-input {
    flex: 1;
    min-width: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 4px 0;
    outline: none;
    color: var(--text-primary, #f3f4f6);
    font-family: var(--sys-chat-mono);
    font-size: 0.8rem;
}

.sys-chat-input::placeholder { color: var(--text-secondary, #9ca3af); }

.sys-chat-send {
    background: transparent;
    border: 1px solid var(--sys-chat-accent);
    color: var(--sys-chat-accent);
    font-family: var(--sys-chat-mono);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sys-chat-send:hover:not(:disabled) {
    background: var(--sys-chat-accent);
    color: #05070a;
    box-shadow: 0 0 12px rgba(0, 255, 170, 0.4);
}

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