/* Ben, the sites' AI assistant (public/js/ben.js builds it, so no page has
   markup for it). The same chat as j7creations.com's, in Atomik's colours:
   every colour here is a token from tokens.css, so both looks and both
   themes come out right by themselves. It owns the bottom-right corner. */

.ben-root {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--spacing-xs);
    /* On a phone this box is a strip the width of the screen (below), so it
       takes no taps itself: only the button and the panel do, and whatever
       is under the rest of the strip still works. */
    pointer-events: none;
}
.ben-root > * { pointer-events: auto; }

.ben-launcher {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm);
    background: linear-gradient(135deg, var(--color-gradient-start), var(--color-accent-strong));
    color: var(--on-accent);
    border: none;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--shadow-color);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ben-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--shadow-color);
}

.ben-launcher__icon { font-size: var(--text-lg); line-height: 1; }

/* [hidden] loses to any class that sets display, so it is said again here. */
.ben-panel[hidden] { display: none; }

.ben-panel {
    width: min(23rem, calc(100vw - 2rem));
    max-height: min(32rem, calc(100vh - 8rem));
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    background: var(--panel-bg-solid);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px var(--shadow-color);
    color: var(--color-text-white);
    font-family: var(--font-body);
}

.ben-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--spacing-xs);
    padding: var(--spacing-s) var(--spacing-sm);
    border-bottom: 1px solid var(--panel-border);
}

.ben-note {
    margin: 0.25rem 0 0;
    font-size: var(--text-xs);
    /* The smallest type in the chat takes the stronger grey, for contrast. */
    color: var(--color-text-gray);
}

.ben-note a { color: var(--color-accent); text-decoration: underline; }

.ben-close {
    background: none;
    border: none;
    color: var(--color-text-gray);
    font-size: var(--text-xl);
    line-height: 1;
    cursor: pointer;
    padding: 0 0.25rem;
    /* A finger-sized square to tap, the x in the middle of it. */
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ben-close:hover { color: var(--color-text-white); }

.ben-log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--spacing-sm);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.ben-msg { display: flex; flex-direction: column; max-width: 90%; }
.ben-msg--user { align-self: flex-end; align-items: flex-end; }
.ben-msg--assistant { align-self: flex-start; }
.ben-msg--wide { align-self: stretch; max-width: 100%; }

.ben-bubble {
    padding: var(--spacing-xs) var(--spacing-s);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: var(--color-input-bg);
    color: var(--color-text-gray);
}

/* An address in Ben's words (public/js/ben.js, linked). */
.ben-bubble a { color: var(--color-accent); text-decoration: underline; }

.ben-msg--user .ben-bubble {
    background: var(--wash-accent-strong);
    color: var(--color-text-white);
}

.ben-bubble--error {
    background: var(--wash-accent);
    border: 1px solid var(--color-accent);
}

.ben-sent { border: 1px solid var(--color-accent); color: var(--color-text-white); }

.ben-handoff {
    margin-top: var(--spacing-xs);
    align-self: flex-start;
    font-size: var(--text-sm);
}

/* The send form: the request form's essentials, inside the chat. */
.ben-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: var(--spacing-xs);
    padding: var(--spacing-s);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-card-bg);
}

.ben-card__title { margin: 0; font-weight: 700; color: var(--color-text-white); }
.ben-card__hint { margin: 0; font-size: var(--text-sm); color: var(--color-text-gray); }

.ben-card__label {
    margin-top: 0.25rem;
    font-size: var(--text-sm);
    color: var(--color-text-white);
}

.ben-card__optional { color: var(--color-text-gray); }
.ben-card .ben-input { width: 100%; font-family: inherit; }
.ben-card__message { resize: vertical; line-height: 1.4; }

.ben-card__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
}

.ben-card__cancel {
    background: none;
    border: none;
    padding: 0.25rem;
    color: var(--color-text-gray);
    font-size: var(--text-sm);
    text-decoration: underline;
    cursor: pointer;
}

.ben-card__status { margin: 0; font-size: var(--text-sm); color: var(--color-text-white); }
.ben-card__status:empty { display: none; }

/* Answers to tap under a question: quieter than Send, the suggested one
   marked by its border, weight and a small label, never by a fill. */
.ben-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-top: var(--spacing-xs);
}

.ben-choice {
    padding: 0.25rem var(--spacing-s);
    background: var(--color-input-bg);
    color: var(--color-text-white);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-family: inherit;
    font-size: var(--text-sm);
    line-height: 1.4;
    cursor: pointer;
}

.ben-choice:hover,
.ben-choice:focus-visible { border-color: var(--color-accent); }
.ben-choice--suggested { border-color: var(--color-accent); font-weight: 600; }
.ben-choice__tag { margin-left: 0.25rem; font-size: var(--text-xs); font-weight: 400; color: inherit; }

/* Three dots while the answer is on its way; still dots, not nothing, for
   anyone who asked for less motion. */
.ben-bubble--typing { display: flex; gap: 0.25rem; align-items: center; }

.ben-bubble--typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-muted);
    animation: ben-blink 1.2s infinite ease-in-out;
}

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

@keyframes ben-blink {
    0%, 80%, 100% { opacity: 0.3; }
    40% { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .ben-bubble--typing span { animation: none; opacity: 0.6; }
    .ben-launcher { transition: none; }
}

:root[data-motion="reduced"] .ben-bubble--typing span { animation: none; opacity: 0.6; }
:root[data-motion="reduced"] .ben-launcher { transition: none; }

.ben-form {
    display: flex;
    gap: var(--spacing-xs);
    padding: var(--spacing-xs) var(--spacing-sm) var(--spacing-sm);
}

.ben-input {
    flex: 1 1 auto;
    min-width: 0;
    padding: var(--spacing-xs) var(--spacing-s);
    background: var(--color-input-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text-white);
    font-size: var(--text-sm);
}

.ben-input:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.ben-send { flex: 0 0 auto; font-size: var(--text-sm); }

/* On a phone the panel is the screen, not a card in the corner. */
@media (max-width: 600px) {
    .ben-root { bottom: 1rem; right: 1rem; left: 1rem; align-items: stretch; }
    .ben-launcher { align-self: flex-end; }
    .ben-panel { width: 100%; max-height: calc(100vh - 6rem); }
}
