/*
 * Teravera AI Chat Widget
 * Visual design matches Teravera.Chat.System8 (_TeraVeraChat.cshtml)
 */

/* Ensure [hidden] always works regardless of site CSS resets */
.tvc [hidden] { display: none !important; }
[hidden]       { display: none !important; }

/* ── Design tokens ────────────────────────────────────────────────────────── */
.tvc {
    --tvc-bg:                  #fff;
    --tvc-hero-bg:             #fff;
    --tvc-text:                #1a1a1a;
    --tvc-text-muted:          #666;
    --tvc-text-subtle:         #999;
    --tvc-text-placeholder:    #aaa;
    --tvc-border:              #e0e0e0;
    --tvc-border-inner:        #f0f0f0;
    --tvc-chip-border:         #ddd;
    --tvc-send-bg:             #1a1a1a;
    --tvc-user-bubble-bg:      #f4f4f4;
    --tvc-assistant-bubble-bg: #f4f4f4;
    --tvc-input-bg:            #fafafa;
    --tvc-online:              #2ecc71;
    --tvc-margin-bottom:       2.5rem;
}

/* ── Widget shell ─────────────────────────────────────────────────────────── */
.tvc {
    display: flex;
    flex-direction: column;
    width: 100%;
    border-radius: 1rem;
    background: var(--tvc-bg);
    color: var(--tvc-text);
    margin-bottom: var(--tvc-margin-bottom);
    font-family: inherit;
    font-size: 0.9375rem;
    box-sizing: border-box;
}

/* ── Hero mode ────────────────────────────────────────────────────────────── */
.tvc--hero {
    height: auto;
    border: none;
    box-shadow: none;
    background: var(--tvc-hero-bg);
    border-radius: 0;
    align-items: center;
}

/* Hero page: when chat is active, center the whole widget */
.tvc--hero-page.tvc--chat-active {
    max-width: 48rem;
    margin: 0 auto;
}

/* ── Hero section ─────────────────────────────────────────────────────────── */
.tvc__hero-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 48rem;
    text-align: center;
}

.tvc__hero-heading {
    font-size: 1.5rem;
    font-weight: 400;
    margin: 0 0 2.5rem;
    color: var(--tvc-text);
    line-height: 1.3;
}

/* Hero form wraps the input + send button */
.tvc__hero-form {
    width: 100%;
    position: relative;
}

.tvc__hero-input-wrap {
    position: relative;
    width: 100%;
}

.tvc__hero-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.25rem;
    height: 1.25rem;
    color: var(--tvc-text-placeholder);
    pointer-events: none;
}

.tvc__hero-input {
    width: 100%;
    box-sizing: border-box;
    height: 3.5rem;
    padding: 0 3.25rem 0 2.75rem;
    border: 1px solid var(--tvc-border);
    border-radius: 1.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--tvc-text);
    background: var(--tvc-input-bg);
    outline: none;
    transition: border-color .15s;
}
.tvc__hero-input:focus {
    border-color: var(--tvc-text-placeholder);
    background: var(--tvc-bg);
}

/* Hero send button — dark circle, absolutely positioned inside the input wrap */
.tvc__hero-send {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: none;
    background: var(--tvc-send-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity .15s;
    padding: 0;
    flex-shrink: 0;
}
.tvc__hero-send:hover:not(:disabled) { opacity: .85; }
.tvc__hero-send:disabled { opacity: .45; cursor: default; }
.tvc__hero-send svg { width: 1.125rem; height: 1.125rem; }

/* ── Preset chips (hero) ─────────────────────────────────────────────────── */
.tvc__presets {
    width: 100%;
    box-sizing: border-box;
}

.tvc__hero-section .tvc__presets {
    padding: 0;
    margin-top: 2rem;
}

.tvc__presets-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--tvc-text-subtle);
    margin-bottom: 0.5rem;
    text-align: center;
}

.tvc__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.tvc__chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.875rem;
    border: 1px solid var(--tvc-chip-border);
    border-radius: 1.25rem;
    background: var(--tvc-bg);
    font-size: 0.8125rem;
    font-family: inherit;
    color: var(--tvc-text);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.tvc__chip:hover {
    background: var(--tvc-assistant-bubble-bg);
    border-color: var(--tvc-text-placeholder);
}

.tvc__chip-star {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    display: none;
}

/* ── Disclaimers ─────────────────────────────────────────────────────────── */
.tvc__disclaimers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
    gap: 1rem;
    width: 100%;
    margin-top: 3.5rem;
    box-sizing: border-box;
}

@media (max-width: 600px) {
    .tvc__disclaimers { grid-template-columns: 1fr; }
}

.tvc__disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    text-align: left;
    color: var(--tvc-text);
    font-size: 0.875rem;
    line-height: 1.45;
    border: 1px solid var(--tvc-border);
    border-radius: 0.625rem;
    padding: 1.125rem 1.25rem;
    background: var(--tvc-bg);
    box-sizing: border-box;
}
.tvc__disclaimer svg {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.0625rem;
    fill: var(--tvc-text);
}
.tvc__disclaimer p { margin: 0; }

/* ── Chat section ─────────────────────────────────────────────────────────── */
.tvc__chat-section {
    display: flex;
    flex-direction: column;
    width: 100%;
    flex: 1;
    min-height: 0;
}

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.tvc__toolbar {
    display: none;
    justify-content: flex-start;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 1rem 0;
}
.tvc--chat-active .tvc__toolbar {
    display: flex;
}

.tvc__toolbar-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--tvc-text);
    flex: 1;
}

/* New-chat button floats to top-right, beside the page title */
.tvc--chat-active .tvc__newchat {
    position: absolute;
    top: -6rem;
    right: 0;
    z-index: 10;
}
.tvc--chat-active {
    position: relative;
}

.tvc__newchat {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid var(--tvc-border);
    border-radius: 0.5rem;
    background: var(--tvc-bg);
    color: var(--tvc-text);
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.tvc__newchat:hover {
    background: var(--tvc-assistant-bubble-bg);
    border-color: var(--tvc-text-placeholder);
}
.tvc__newchat svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: currentColor;
}

/* ── Messages area ───────────────────────────────────────────────────────── */
.tvc__messages {
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.tvc__row               { display: flex; max-width: 100%; }
.tvc__row--user         { flex-direction: row-reverse; }
.tvc__row--assistant    { flex-direction: row; }

/* ── Bubbles ─────────────────────────────────────────────────────────────── */
.tvc__bubble {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.625rem 0.875rem;
    border-radius: 1.125rem;
    max-width: 72%;
    line-height: 1.5;
    word-break: break-word;
    text-align: left;
    box-sizing: border-box;
}

.tvc__bubble--plain { white-space: pre-wrap; }

/* User bubble — gray pill */
.tvc__bubble--user {
    background: var(--tvc-user-bubble-bg);
    color: var(--tvc-text);
}

/* Assistant bubble — no background, full width (ChatGPT style) */
.tvc__bubble--assistant {
    background: transparent;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
}

/* Markdown */
.tvc__bubble--md p            { margin: 0 0 0.75rem; }
.tvc__bubble--md p:last-of-type { margin-bottom: 0; }
.tvc__bubble--md ul,
.tvc__bubble--md ol           { margin: 0.5rem 0 1rem; padding-left: 1.25rem; }
.tvc__bubble--md li           { margin-bottom: 0.25rem; }
.tvc__bubble--md h1,
.tvc__bubble--md h2,
.tvc__bubble--md h3           { margin: 0.5rem 0; font-size: 1em; font-weight: 700; }
.tvc__bubble--md code         { background: rgba(0,0,0,.07); border-radius: 3px; padding: 1px 4px; font-family: monospace; font-size: .9em; }
.tvc__bubble--md pre          { background: rgba(0,0,0,.07); border-radius: 6px; padding: 8px 10px; overflow-x: auto; margin: 4px 0; }
.tvc__bubble--md pre code     { background: none; padding: 0; }
.tvc__bubble--md strong       { font-weight: 700; }
.tvc__bubble--md em           { font-style: italic; }
.tvc__bubble--md a            { color: inherit; text-decoration: underline; }
.tvc__bubble--md table        { border-collapse: collapse; font-size: .875em; width: 100%; margin: 0.5em 0; }
.tvc__bubble--md th,
.tvc__bubble--md td           { border: 1px solid var(--tvc-border); padding: 5px 10px; text-align: left; }
.tvc__bubble--md th           { background: var(--tvc-assistant-bubble-bg); font-weight: 600; }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.tvc__typing {
    display: flex;
    gap: 4px;
    padding: 6px 2px;
    align-items: center;
}
.tvc__typing span {
    width: 7px;
    height: 7px;
    background: var(--tvc-text-placeholder);
    border-radius: 50%;
    animation: tvc-bounce 1.2s infinite;
}
.tvc__typing span:nth-child(2) { animation-delay: .2s; }
.tvc__typing span:nth-child(3) { animation-delay: .4s; }

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

/* ── Chat input area ──────────────────────────────────────────────────────── */
.tvc__input-area {
    background: var(--tvc-bg);
}

/* Fixed input when chat is active */
.tvc--chat-active .tvc__input-area {
    position: fixed;
    bottom: 0;
    z-index: 100;
    background: var(--tvc-bg);
}

/* Chat form: relative container so send button can be absolute (mirrors hero) */
.tvc__form {
    position: relative;
    width: 100%;
}

.tvc__input {
    width: 100%;
    box-sizing: border-box;
    height: 3.5rem;
    padding: 0 3.25rem 0 1.125rem;
    border: 1px solid var(--tvc-border);
    border-radius: 1.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--tvc-text);
    background: var(--tvc-input-bg);
    outline: none;
    transition: border-color .15s;
}
.tvc__input:focus {
    border-color: var(--tvc-text-placeholder);
    background: var(--tvc-bg);
}

/* Chat send button — dark circle, absolutely positioned inside the input */
.tvc__send {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: none;
    background: var(--tvc-send-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity .15s;
    padding: 0;
    flex-shrink: 0;
}
.tvc__send:hover:not(:disabled) { opacity: .85; }
.tvc__send:disabled { opacity: .45; cursor: default; }
.tvc__send svg { width: 1.125rem; height: 1.125rem; }

/* Chat disclaimers */
.tvc__chat-disclaimers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0;
    box-sizing: border-box;
}
@media (max-width: 600px) {
    .tvc__chat-disclaimers { grid-template-columns: 1fr; }
}

/* Hide disclaimers once conversation is active */
.tvc--chat-active .tvc__chat-disclaimers { display: none; }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.tvc__footer {
    font-size: .9375rem;
    line-height: 1.5;
    text-align: left;
    padding: 20px 0;
}
.tvc__footer a {  text-decoration: underline; }

/* ── Action bar (Raw LLM Response etc.) ──────────────────────────────────── */
.tvc__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.tvc__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3125rem;
    min-width: 1.875rem;
    height: 1.875rem;
    padding: 0 0.5rem;
    border: none;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--tvc-text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.tvc__action:hover { background: var(--tvc-assistant-bubble-bg); color: var(--tvc-text); }
.tvc__action svg { width: 1.0625rem; height: 1.0625rem; fill: currentColor; }
.tvc__action.is-active { color: var(--tvc-send-bg); }
.tvc__action--copied { color: #1a7f5a; }

.tvc__action--loading { cursor: default; color: var(--tvc-text-subtle); }
.tvc__action-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(0,0,0,.15);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: tvc-spin .7s linear infinite;
    display: inline-block;
}
@keyframes tvc-spin { to { transform: rotate(360deg); } }

/* ── Expandable panel ────────────────────────────────────────────────────── */
.tvc__panel {
    margin-top: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: 0.5rem;
    background: #f1f2f5;
    font-size: 0.8125rem;
    line-height: 1.5;
}
.tvc__panel[hidden] { display: none; }

.tvc__panel-title {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.tvc__panel-title svg { width: 1.0625rem; height: 1.0625rem; fill: currentColor; flex-shrink: 0; }

.tvc__panel-note {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin: 0.5rem 0 0.625rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    background: #fff;
    color: var(--tvc-text-muted);
    font-size: 0.75rem;
    line-height: 1.45;
}
.tvc__panel-note svg { width: 1rem; height: 1rem; flex-shrink: 0; margin-top: 0.0625rem; fill: currentColor; }

.tvc__panel-body {
    color: var(--tvc-text);
    opacity: 0.85;
    white-space: pre-wrap;
    word-break: break-word;
}
.tvc__panel-body p { margin: 0 0 0.5rem; }
.tvc__panel-body p:last-child { margin-bottom: 0; }

/* ── Busy state ──────────────────────────────────────────────────────────── */
.tvc--busy .tvc__input { background: var(--tvc-assistant-bubble-bg); }

/* ── Send button spinner ─────────────────────────────────────────────────── */
.tvc__spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tvc-spin .7s linear infinite;
}
@keyframes tvc-spin {
    to { transform: rotate(360deg); }
}

/* ══════════════════════════════════════════════════════════════════════════
   Standalone portal page skin (body.tvc-standalone-page)
   Matches the Teravera open-agent-router portal: navy text, black send,
   white card, full-width vertical prompt cards.
   ══════════════════════════════════════════════════════════════════════════ */

.tvc-standalone-page .tvc {
    --tvc-send-bg:          #1a1a1a;
    --tvc-user-bubble-bg:   #dadee6;
    --tvc-text:             #0b2553;
    --tvc-border:           #c2c7d0;
    --tvc-chip-border:      #c2c7d0;
    background:             transparent;
    margin-bottom: 0;
}

/* Drop the search icon */
.tvc-standalone-page .tvc__hero-icon { display: none; }

/* Hero input — no left padding, square border */
.tvc-standalone-page .tvc__hero-input {
    padding-left: 1.125rem;
    border-radius: 0.5rem;
}

/* Hero send — squared */
.tvc-standalone-page .tvc__hero-send {
    border-radius: 0.5rem;
    width: 2.75rem;
    height: 2.75rem;
}

/* Chat input — square */
.tvc-standalone-page .tvc__input { border-radius: 0.5rem; }

/* User bubble — portal light-blue */
.tvc-standalone-page .tvc__bubble--user {
    background: #dadee6;
    color: #0b2553;
    border-radius: 0.5rem;
}
.tvc-standalone-page .tvc__bubble--assistant { color: #0b2553; }

/* Preset chips — full-width vertical cards */
.tvc-standalone-page .tvc__presets-label { text-align: left; }
.tvc-standalone-page .tvc__chips {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
}
.tvc-standalone-page .tvc__chip {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border-color: #c2c7d0;
    white-space: normal;
}
.tvc-standalone-page .tvc__chip:hover {
    border-color: #0035ad;
    background: #fff;
}
.tvc-standalone-page .tvc__chip-star {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    color: #0035ad;
    width: 14px;
    height: 14px;
}

/* Conversation layout */
.tvc-standalone-page .tvc--chat-active {
    max-width: 60rem;
    margin: 0 auto;
    background: transparent;
}
.tvc-standalone-page .tvc--chat-active .tvc__messages {
    background: #fff;
    border: 1px solid #c2c7d0;
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
}
.tvc-standalone-page .tvc__input-area,
.tvc-standalone-page .tvc--chat-active .tvc__input-area {
    position: static;
    background: transparent;
    margin-top: 1rem;
}

/* Toolbar */
.tvc-standalone-page .tvc__toolbar { justify-content: space-between; padding: 0 0.25rem 0.75rem; }
.tvc-standalone-page .tvc__toolbar-title { font-size: 1.375rem; font-weight: 700; color: #0b2553; }
.tvc-standalone-page .tvc--chat-active .tvc__newchat { position: static; }
.tvc-standalone-page .tvc__newchat { border: 1px solid #0b2553; color: #0b2553; }
.tvc-standalone-page .tvc__newchat:hover { border-color: #0b2553; background: rgba(11,37,83,.06); }

/* Disclaimer cards */
.tvc-standalone-page .tvc__disclaimer { background: #fff; border-color: #c2c7d0; color: #0b2553; }
.tvc-standalone-page .tvc__disclaimer svg { fill: #0b2553; }
