/* ══════════════════════════════════════════════════════════════
   Chat — layout, estructura y animaciones.
   Sin hex / rgba aquí: todos los colores vienen de las variables
   declaradas en assets/brands/<brand>/css/skin.css.
   ══════════════════════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

/* WebKit counts an off-canvas panel as scrollable width even when it is
   translated out of sight, so an iPhone gets a page that slides sideways while
   a desktop browser shows nothing wrong. Clipping at the root is what stops
   it; the sidebar below is also taken out of the layout when it is closed. */
html {
    overflow-x: hidden;
}

body {
    font-family: var(--font-family);
    /* dvh follows the browser chrome as it hides and shows. 100vh on iOS is
       the height with the chrome gone, so the input ends up under it. */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-font-smoothing: antialiased;
    color: var(--text);
}

/* ── Layout ── */
.app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--sidebar-border);
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: 1px solid var(--sidebar-divider-on-dark);
    border-radius: var(--radius-sm);
    color: var(--sidebar-text-strong);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
.new-chat-btn:hover { background: var(--sidebar-hover); }
.new-chat-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-conversations {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.sidebar-section-title {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 8px 6px;
}

.conv-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--sidebar-text);
    font-family: inherit;
    font-size: 0.84rem;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-hover); color: var(--sidebar-text-strong); }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-footer a {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}
.sidebar-footer a:hover { color: var(--sidebar-text); }

/* Account block above the site link. Two lines of small text and a name that
   can be an email, so it truncates rather than pushing the sidebar wider. */
.sidebar-account {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--sidebar-divider-on-dark);
}

.sidebar-account-name {
    color: var(--sidebar-text-strong);
    font-size: 0.82rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Main chat area ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    min-width: 0;
}

/* ── Top bar ── */
.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--chat-bg);
    flex-shrink: 0;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text);
    padding: 4px;
}
.menu-toggle svg { width: 22px; height: 22px; }

.topbar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--text);
}
.topbar-logo svg { width: 28px; height: 31px; color: var(--cube-color); }
.topbar-logo .wordmark {
    font-weight: 800;
    font-size: 1.1rem;
    letter-spacing: -0.03em;
}
.topbar-logo .wordmark em {
    font-style: normal;
    color: var(--cube-color);
}

.topbar-badge {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--cube-color);
    background: var(--accent-soft);
    padding: 3px 8px;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

/* ── Messages area ── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.messages-inner {
    max-width: 768px;
    margin: 0 auto;
    padding: 24px 20px 100px;
}

/* ── Welcome screen ── */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px 40px;
}

.welcome-logo {
    color: var(--cube-color);
}
.welcome-logo svg {
    width: 56px;
    height: 62px;
    margin-bottom: 20px;
}

.welcome h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.welcome p {
    color: var(--text-muted);
    font-size: 0.95rem;
    max-width: 460px;
    line-height: 1.5;
    margin-bottom: 36px;
}

/* Once the conversation has started the greeting has been read; what is worth
   keeping is the four questions a visitor is allowed to ask. */
.welcome--suggestions-only {
    justify-content: flex-start;
    padding-top: 16px;
    min-height: 0;
}

.welcome--suggestions-only .welcome-logo,
.welcome--suggestions-only h1,
.welcome--suggestions-only p {
    display: none;
}

.suggestions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 600px;
}

.suggestion-btn {
    padding: 14px 16px;
    background: var(--chat-input-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.84rem;
    color: var(--text);
    text-align: left;
    cursor: pointer;
    transition: all 0.15s;
    line-height: 1.45;
}
.suggestion-btn:hover {
    background: var(--chat-bg);
    border-color: var(--suggestion-hover-border);
    box-shadow: var(--suggestion-hover-shadow);
}

.suggestion-icon {
    display: inline-block;
    margin-right: 6px;
    opacity: 0.5;
}

/* ── Message bubbles ── */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    animation: fadeIn 0.25s ease;
}

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

.message.user { justify-content: flex-end; }

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 700;
}

.message.assistant .message-avatar {
    background: var(--assistant-avatar-bg);
    color: var(--assistant-avatar-color);
}

.message.user .message-avatar {
    background: var(--accent);
    color: var(--user-text);
    order: 2;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

.message.assistant .message-bubble {
    background: var(--assistant-bubble);
    color: var(--assistant-text);
    border-bottom-left-radius: 4px;
    /* The assistant's side is rendered markdown, which brings its own blocks.
       pre-wrap on top of that counts every newline twice: once as the space
       marked already turned into an element, once as literal whitespace. The
       user's side stays pre-wrap — that one really is plain text. */
    white-space: normal;
}

/* The global reset zeroes padding on everything, and a list marker is drawn
   outside its own box: with no indent the bullets land on the bubble's padding
   and reach the edge. The paragraphs never moved because they have no marker. */
.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol {
    padding-inline-start: 1.35em;
    margin: 0.5em 0;
}

.message.assistant .message-bubble li + li {
    margin-top: 0.25em;
}

.message.assistant .message-bubble p {
    margin: 0.5em 0;
}

.message.assistant .message-bubble > :first-child {
    margin-top: 0;
}

.message.assistant .message-bubble > :last-child {
    margin-bottom: 0;
}

.message.user .message-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-bottom-right-radius: 4px;
}

/* Always there, faint. A button that appears on hover is a button half the
   people never find, and on a phone there is no hover to appear on. */
/* Taking a whole search away: offered under the answer that said there is more. */
.message-export-row {
    display: flex;
    justify-content: flex-start;
    padding: 0 0 8px 52px;
}

.message-export {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--assistant-text);
    border-radius: 10px;
    background: transparent;
    color: var(--assistant-text);
    font-size: 0.9rem;
    cursor: pointer;
    opacity: 0.75;
}

.message-export:hover {
    opacity: 1;
}

.message-export[disabled] {
    cursor: progress;
    opacity: 0.4;
}

.message-copy {
    align-self: flex-end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    margin-left: 6px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--assistant-text);
    opacity: 0.5;
    cursor: pointer;
    transition: opacity 0.15s ease, background 0.15s ease;
}

/* A finger is not a mouse pointer: 44px is the size a target has to be before
   people stop missing it. */
@media (pointer: coarse) {
    .message-copy {
        width: 44px;
        height: 44px;
    }
}

.message-copy:hover,
.message-copy:focus-visible {
    opacity: 1;
    background: var(--assistant-bubble);
}

.message-copy.is-copied {
    opacity: 1;
    color: var(--accent);
}

/* ── Typing indicator ── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}
.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.85); }
    30% { opacity: 1; transform: scale(1); }
}

/* ── Input area ── */
.input-area {
    position: sticky;
    bottom: 0;
    background: linear-gradient(transparent, var(--chat-bg) 20%);
    padding: 12px 20px 20px;
}

.input-wrapper {
    max-width: 768px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--chat-input-bg);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 10px 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
    border-color: var(--chat-input-focus-border);
    box-shadow: 0 0 0 3px var(--chat-input-focus-ring);
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text);
    resize: none;
    min-height: 24px;
    max-height: 150px;
    line-height: 1.5;
}
.input-wrapper textarea::placeholder { color: var(--text-muted); }

/* iOS zooms the whole page in when a field it is about to focus has text
   under 16px, and never zooms back out. That is the sideways-sliding page:
   not an element too wide, the viewport made too narrow. 16px is the number,
   and it is the browser's rule rather than a preference. */
@media (pointer: coarse) {
    .input-wrapper textarea {
        font-size: 16px;
    }
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--user-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}
.send-btn:hover { background: var(--accent-light); }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn svg { width: 18px; height: 18px; }

.input-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 8px;
    max-width: 768px;
    margin-left: auto;
    margin-right: auto;
}

/* ── Sidebar overlay (mobile) ── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--sidebar-overlay);
    z-index: 49;
}
.sidebar-overlay.active { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform 0.3s ease, visibility 0.3s ease;
    }
    .sidebar.open {
        transform: translateX(0);
        visibility: visible;
    }

    .menu-toggle { display: block; }

    /* Once the conversation has started the greeting has been read; what is worth
   keeping is the four questions a visitor is allowed to ask. */
.welcome--suggestions-only {
    justify-content: flex-start;
    padding-top: 16px;
    min-height: 0;
}

.welcome--suggestions-only .welcome-logo,
.welcome--suggestions-only h1,
.welcome--suggestions-only p {
    display: none;
}

.suggestions { grid-template-columns: 1fr; }

    .message-bubble { max-width: 88%; }

    .welcome h1 { font-size: 1.3rem; }
}
