/* Public website assistant ("Ask MJK"): launcher + chat dialog.
   Self-contained: its own tokens, so it can be dropped into any public page.
   Markup: templates/website/components/public_assistant.html, script: js/public_assistant.js */

.pa, .pa-launch {
    --pa-bg: #0e1114;
    --pa-panel: #14181c;
    --pa-raise: #1b2026;
    --pa-line: rgba(255, 255, 255, .1);
    --pa-line-2: rgba(255, 255, 255, .18);
    --pa-text: #ece8e2;
    --pa-muted: #a6abb1;
    --pa-dim: #747a81;
    --pa-copper: #c27c2e;
    --pa-copper-hi: #eaa862;
    --pa-ink: #170f05;
    --pa-display: 'Barlow Condensed', 'Oswald', 'Arial Narrow', sans-serif;
    --pa-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --pa-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --pa-ease: cubic-bezier(.2, .7, .2, 1);
}
.pa *, .pa *::before, .pa *::after { box-sizing: border-box; }
.pa[hidden], .pa [hidden], .pa-launch[hidden] { display: none !important; }
.pa .mono { font-family: var(--pa-mono); font-size: .64rem; letter-spacing: .12em; text-transform: uppercase; }
.pa .visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------------------------------------------------------------- launcher */
.pa-launch {
    position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 70;
    display: inline-flex; align-items: center; gap: 10px; height: 54px; padding: 0 22px 0 16px;
    border: 0; border-radius: 999px; cursor: pointer;
    background: linear-gradient(180deg, #d9913f, #b87327); color: var(--pa-ink);
    font-family: var(--pa-display); font-weight: 600; font-size: 1.15rem; letter-spacing: .1em; text-transform: uppercase;
    box-shadow: 0 18px 44px -12px rgba(0, 0, 0, .8), 0 0 0 1px rgba(255, 255, 255, .12) inset, 0 0 40px -6px rgba(226, 150, 74, .5);
    transform: translateY(24px); opacity: 0; pointer-events: none;
    transition: transform .45s var(--pa-ease), opacity .3s, background .2s;
}
.pa-launch.is-shown { transform: none; opacity: 1; pointer-events: auto; }
.pa-launch:hover { background: linear-gradient(180deg, #eaa862, #c9842f); }
.pa-launch:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
.pa-launch__spark { width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; background: rgba(23, 15, 5, .16); }
.pa-launch__spark svg { width: 15px; height: 15px; }

/* ------------------------------------------------------------------ dialog */
.pa { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: clamp(12px, 3vh, 40px) 16px; font-family: var(--pa-body); color: var(--pa-text); }
.pa__backdrop { position: absolute; inset: 0; background: rgba(4, 5, 6, .72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); opacity: 0; transition: opacity .3s; }
.pa__panel {
    position: relative; width: min(880px, 100%); height: min(820px, 100%); display: flex; flex-direction: column;
    background: linear-gradient(180deg, var(--pa-panel), var(--pa-bg)); border: 1px solid var(--pa-line-2); border-radius: 10px; overflow: hidden;
    box-shadow: 0 60px 140px -30px #000, 0 0 120px -40px rgba(226, 150, 74, .45);
    transform: translateY(18px) scale(.985); opacity: 0; transition: transform .4s var(--pa-ease), opacity .3s;
}
.pa.is-open .pa__backdrop { opacity: 1; }
.pa.is-open .pa__panel { transform: none; opacity: 1; }
.pa__panel::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--pa-copper-hi), transparent); z-index: 2; }

.pa__head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 16px 16px 22px; border-bottom: 1px solid var(--pa-line); }
.pa__id { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1; }
.pa__id > div { min-width: 0; }
.pa__logo { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; background: linear-gradient(180deg, #d9913f, #b87327); color: var(--pa-ink); }
.pa__logo svg { width: 20px; height: 20px; }
.pa__id h2 { margin: 0; font-family: var(--pa-display); font-weight: 600; font-size: 1.55rem; line-height: 1; letter-spacing: .04em; text-transform: uppercase; color: #fff; }
.pa__id p { margin: 5px 0 0; font-family: var(--pa-mono); font-size: .62rem; letter-spacing: .1em; text-transform: uppercase; color: var(--pa-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pa__tools { display: flex; align-items: center; gap: 6px; flex: none; }
.pa__tool { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--pa-muted); font: 500 .82rem var(--pa-body); cursor: pointer; transition: color .2s, background .2s, border-color .2s; }
.pa__tool:hover { color: #fff; background: rgba(255, 255, 255, .06); border-color: var(--pa-line); }
.pa__tool svg { width: 18px; height: 18px; }
.pa__tool--x { width: 40px; padding: 0; justify-content: center; }
.pa__tool--x svg { width: 20px; height: 20px; }
.pa__preview { flex: none; margin: 0; padding: 9px 22px; font-size: .8rem; line-height: 1.45; color: #f3d9b8; background: rgba(194, 124, 46, .16); border-bottom: 1px solid rgba(234, 168, 98, .3); }

.pa__scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: clamp(18px, 3vw, 30px) clamp(16px, 4vw, 40px); scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, .2) transparent; }

/* intro */
.pa__hello { margin: clamp(4px, 2vh, 22px) 0 0; font-family: var(--pa-display); font-weight: 600; font-size: clamp(1.9rem, 4vw, 2.7rem); line-height: 1; text-transform: uppercase; color: #fff; }
.pa__sub { margin: 12px 0 0; max-width: 34em; color: var(--pa-muted); font-size: .98rem; line-height: 1.6; }
.pa__starters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 26px; }
.pa__starters button { display: flex; flex-direction: column; gap: 7px; align-items: flex-start; text-align: left; padding: 14px 16px; border: 1px solid var(--pa-line); border-radius: 8px; background: rgba(255, 255, 255, .03); color: #dcd9d4; font: 400 .93rem/1.45 var(--pa-body); cursor: pointer; transition: border-color .2s, background .2s, transform .3s var(--pa-ease); }
.pa__starters button:hover { border-color: rgba(234, 168, 98, .6); background: rgba(194, 124, 46, .1); transform: translateY(-2px); }
.pa__starters .mono { color: var(--pa-copper-hi); font-size: .6rem; }

/* log */
.pa__log { display: flex; flex-direction: column; gap: 22px; }
.pa-msg { max-width: 100%; animation: paIn .4s var(--pa-ease) both; }
@keyframes paIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.pa-msg--user { align-self: flex-end; max-width: min(86%, 620px); padding: 12px 16px; border-radius: 16px 16px 4px 16px; background: rgba(194, 124, 46, .2); border: 1px solid rgba(234, 168, 98, .34); color: #fff; font-size: .98rem; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.pa-msg--bot { align-self: stretch; display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 14px; }
.pa-msg__av { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; background: rgba(194, 124, 46, .18); border: 1px solid rgba(234, 168, 98, .35); color: var(--pa-copper-hi); margin-top: 1px; }
.pa-msg__av svg { width: 14px; height: 14px; }
.pa-msg__main { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; justify-items: start; }
.pa-status { display: inline-flex; align-items: center; gap: 10px; font-family: var(--pa-mono); font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--pa-copper-hi); min-height: 30px; }
.pa-status__bar { position: relative; width: 44px; height: 2px; background: rgba(234, 168, 98, .2); overflow: hidden; border-radius: 2px; }
.pa-status__bar::after { content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, var(--pa-copper-hi), transparent); animation: paFlow 1.1s linear infinite; }
@keyframes paFlow { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

.pa-body { width: 100%; font-size: .99rem; line-height: 1.68; color: #dfdcd7; overflow-wrap: anywhere; }
.pa-body > * { margin: 0; }
.pa-body > * + * { margin-top: .8em; }
.pa-body strong { color: #fff; font-weight: 600; }
.pa-body a { color: var(--pa-copper-hi); text-decoration: underline; text-underline-offset: 3px; }
.pa-body ul, .pa-body ol { padding-left: 1.25em; display: grid; gap: .38em; }
.pa-body ul { list-style: none; padding-left: 0; }
.pa-body ul > li { position: relative; padding-left: 1.25em; }
.pa-body ul > li::before { content: ''; position: absolute; left: .15em; top: .68em; width: 6px; height: 6px; background: var(--pa-copper-hi); }
.pa-body ol { list-style: decimal; }
.pa-body ol > li::marker { color: var(--pa-copper-hi); font-family: var(--pa-mono); font-size: .86em; }
.pa-body code { font-family: var(--pa-mono); font-size: .88em; background: rgba(255, 255, 255, .08); padding: .12em .38em; border-radius: 4px; color: #fff; }
.pa-body pre { background: rgba(0, 0, 0, .4); border: 1px solid var(--pa-line); border-radius: 6px; padding: 12px 14px; overflow-x: auto; }
.pa-body pre code { background: none; padding: 0; }
.pa-body h4 { font-family: var(--pa-display); font-weight: 600; font-size: 1.2rem; letter-spacing: .03em; text-transform: uppercase; color: #fff; line-height: 1.2; }
.pa-table { width: 100%; overflow-x: auto; border: 1px solid var(--pa-line); border-radius: 6px; }
.pa-table table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.pa-table th, .pa-table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--pa-line); white-space: nowrap; }
.pa-table th { font-family: var(--pa-mono); font-weight: 500; font-size: .66rem; letter-spacing: .1em; text-transform: uppercase; color: var(--pa-copper-hi); background: rgba(255, 255, 255, .03); }
.pa-table tr:last-child td { border-bottom: 0; }
.pa-cursor { display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -.18em; background: var(--pa-copper-hi); animation: paBlink 1s steps(2) infinite; }
@keyframes paBlink { 50% { opacity: 0; } }

.pa-sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.pa-sources__label { font-family: var(--pa-mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--pa-dim); margin-right: 2px; }
.pa-cite { font-family: var(--pa-mono); font-size: .68rem; letter-spacing: .04em; color: var(--pa-copper-hi); border: 1px solid rgba(234, 168, 98, .38); background: rgba(194, 124, 46, .1); padding: 4px 9px; border-radius: 4px; cursor: help; }
.pa-note { align-self: stretch; padding: 12px 16px; border: 1px solid var(--pa-line); border-left: 2px solid var(--pa-copper-hi); border-radius: 4px; background: rgba(255, 255, 255, .03); color: #dcd9d4; font-size: .93rem; line-height: 1.55; }
.pa-note--error { border-left-color: #e2705a; }
.pa-note a { color: var(--pa-copper-hi); text-decoration: underline; text-underline-offset: 3px; }

/* sent-message card */
.pa-sent { width: 100%; border: 1px solid rgba(122, 201, 142, .45); border-radius: 8px; background: rgba(122, 201, 142, .08); overflow: hidden; }
.pa-sent__head { display: flex; align-items: flex-start; gap: 14px; padding: 16px; }
.pa-sent__head svg { flex: none; width: 26px; height: 26px; color: #7ac98e; }
.pa-sent__head strong { display: block; color: #fff; font-weight: 600; }
.pa-sent__head span { display: block; margin-top: 2px; font-size: .9rem; color: var(--pa-muted); }
.pa-sent__head a { color: var(--pa-copper-hi); }
.pa-sent__copy { display: grid; gap: 8px; padding: 14px 16px 16px; border-top: 1px solid rgba(122, 201, 142, .22); background: rgba(9, 11, 13, .35); }
.pa-sent__row { display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 10px; align-items: baseline; }
.pa-sent__label { font-family: var(--pa-mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--pa-muted); }
.pa-sent__value { font-size: .92rem; color: #fff; overflow-wrap: anywhere; }
.pa-sent__body { margin-top: 4px; font-size: .95rem; line-height: 1.55; color: #e4e6e8; white-space: pre-wrap; overflow-wrap: anywhere; }

/* calculator result card (a Tools page calculator the assistant ran) */
.pa-calc { width: 100%; display: grid; gap: 10px; padding: 16px; border: 1px solid rgba(234, 168, 98, .45); border-radius: 8px; background: linear-gradient(180deg, rgba(194, 124, 46, .12), rgba(194, 124, 46, .04)); }
.pa-calc > * { margin: 0; }
.pa-calc__name { font-family: var(--pa-mono); font-size: .6rem; letter-spacing: .14em; text-transform: uppercase; color: var(--pa-copper-hi); }
.pa-calc__title { font-size: .9rem; line-height: 1.45; color: var(--pa-muted); overflow-wrap: anywhere; }
.pa-calc__answer { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.pa-calc__label { font-size: .95rem; color: #dfdcd7; }
.pa-calc__value { font-family: var(--pa-display); font-weight: 600; font-size: 2.6rem; line-height: .95; color: #fff; }
.pa-calc__value small { margin-left: 6px; font-size: .45em; color: var(--pa-copper-hi); }
.pa-calc--over .pa-calc__value { color: #f6a08e; }
.pa-calc__source { font-size: .8rem; line-height: 1.5; color: var(--pa-dim); overflow-wrap: anywhere; }
.pa-calc__rows { display: grid; border-top: 1px solid var(--pa-line); }
.pa-calc__row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--pa-line); font-size: .9rem; color: #cfccc7; }
.pa-calc__row strong { flex: none; max-width: 60%; font-family: var(--pa-mono); font-size: .86rem; font-weight: 600; color: #fff; text-align: right; }
.pa-calc__link { justify-self: start; display: inline-flex; gap: 8px; padding: 4px 0; font-family: var(--pa-display); font-weight: 600; font-size: 1.02rem; letter-spacing: .1em; text-transform: uppercase; color: var(--pa-copper-hi); border-bottom: 1px solid rgba(234, 168, 98, .4); text-decoration: none; }
.pa-calc__link:hover { border-bottom-color: var(--pa-copper-hi); }

/* composer */
.pa__form { flex: none; padding: 14px clamp(16px, 4vw, 40px) 14px; border-top: 1px solid var(--pa-line); background: rgba(9, 11, 13, .55); }
.pa__inputwrap { display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 16px; border: 1px solid var(--pa-line-2); border-radius: 8px; background: rgba(9, 11, 13, .7); transition: border-color .2s, box-shadow .2s; }
.pa__inputwrap:focus-within { border-color: rgba(234, 168, 98, .8); box-shadow: 0 0 0 4px rgba(194, 124, 46, .16); }
.pa__inputwrap textarea { flex: 1; min-width: 0; max-height: 160px; padding: 11px 0; border: 0; outline: 0; resize: none; background: transparent; color: #fff; font: 400 1rem/1.5 var(--pa-body); }
.pa__inputwrap textarea::placeholder { color: #858a90; }
.pa__send { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 6px; background: linear-gradient(180deg, #d9913f, #b87327); color: var(--pa-ink); cursor: pointer; transition: background .2s, opacity .2s; }
.pa__send:hover { background: linear-gradient(180deg, #eaa862, #c9842f); }
.pa__send[disabled] { opacity: .45; cursor: default; }
.pa__send svg { width: 20px; height: 20px; }
.pa__legal { margin: 10px 2px 0; font-size: .72rem; line-height: 1.5; color: var(--pa-dim); }
.pa__legal a { color: var(--pa-muted); text-decoration: underline; text-underline-offset: 2px; }

body.pa-lock { overflow: hidden; }

@media (max-width: 640px) {
    .pa { padding: 0; }
    .pa__panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
    .pa__head { padding: 12px 10px 12px 16px; }
    .pa__tool span { display: none; }
    .pa__id p { font-size: .58rem; letter-spacing: .02em; }   /* fits beside the two header buttons at 360px */
    .pa__tool { width: 40px; padding: 0; justify-content: center; }
    .pa__starters { grid-template-columns: minmax(0, 1fr); }
    .pa__starters button:nth-child(n+5) { display: none; }
    .pa__inputwrap textarea { font-size: 16px; }   /* no zoom on iOS focus */
    .pa__form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .pa-launch { height: 50px; padding: 0 18px 0 13px; font-size: 1.05rem; }
    .pa-msg--bot { grid-template-columns: minmax(0, 1fr); }
    .pa-msg__av { display: none; }
}
@media (max-width: 380px) {
    .pa__id p { white-space: normal; line-height: 1.35; }   /* wraps instead of being cut off */
}
@media (prefers-reduced-motion: reduce) {
    .pa *, .pa-launch { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
