/* Chemistry chat: the same look as the other two pages. */

.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat__scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 24px; }
.chat__inner { width: min(780px, 100%); margin: 0 auto; display: flex; flex-direction: column; gap: 22px; min-height: 100%; }
.chat__messages { display: flex; flex-direction: column; gap: 26px; }

/* the first screen */
.chat-hero { position: relative; display: flex; flex-direction: column; align-items: center; gap: 16px; padding-top: 7vh; margin: auto 0; }
.chat-hero[hidden] { display: none; }
.chat-suggestions { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: 100%; margin-top: 10px; }
.chat-suggestion {
  padding: 13px 16px; border-radius: 16px; text-align: start; font-size: 14px; line-height: 1.55; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  transition: background .15s, border-color .15s, transform .15s;
}
.chat-suggestion:hover { background: var(--hover); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); transform: translateY(-1px); }

/* messages */
.msg { display: flex; gap: 12px; min-width: 0; }
.msg--user { justify-content: flex-end; }
.msg__bubble {
  max-width: min(85%, 560px); padding: 10px 14px; border-radius: 18px 18px 6px 18px;
  background: color-mix(in srgb, var(--accent) 11%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  overflow-wrap: anywhere; line-height: 1.7; font-size: 15px;
}
:root[dir="rtl"] .msg__bubble { border-radius: 18px 18px 18px 6px; }
.msg__text { white-space: pre-wrap; }
.msg__files { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg__image { display: block; max-width: 180px; max-height: 150px; border-radius: 12px; border: 1px solid var(--border); background: #fff; object-fit: contain; }
.msg__audio { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; color: var(--muted); background: var(--hover); }
.msg__audio svg, .msg__tool svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.msg--assistant { align-items: flex-start; }
.msg__avatar {
  flex: none; width: 30px; height: 30px; margin-top: 2px; border-radius: 10px; display: grid; place-items: center;
  color: var(--on-grad); background: var(--btn-grad);
}
.msg__avatar svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.msg__main { flex: 1; min-width: 0; }
.msg__who { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.msg__body { font-size: 15.5px; line-height: 1.8; min-width: 0; }
.msg__tools { display: flex; gap: 6px; margin-top: 6px; min-height: 0; }
.msg__tool {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 9px; font-size: 12.5px; color: var(--muted);
  transition: background .15s, color .15s;
}
.msg__tool:hover { background: var(--hover); color: var(--text); }
.msg__error { margin: 8px 0 0; padding: 10px 12px; border-radius: 12px; font-size: 14px; color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); border: 1px solid color-mix(in srgb, var(--bad) 30%, transparent); }
.msg__note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

.typing { display: inline-flex; gap: 5px; padding: 10px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: typing 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* the answer itself */
.md-block { min-width: 0; }
.md-block + .md-block, .md-block + .mol-grid, .mol-grid + .md-block, .mol-grid + .mol-grid { margin-top: 10px; }
.md-block > :first-child { margin-top: 0; }
.md-block > :last-child { margin-bottom: 0; }
.md-block p { margin: 0 0 .75em; }
.md-block h1, .md-block h2, .md-block h3, .md-block h4 { margin: 1.1em 0 .45em; line-height: 1.4; font-weight: 600; }
.md-block h1 { font-size: 1.3em; }
.md-block h2 { font-size: 1.18em; }
.md-block h3 { font-size: 1.07em; }
.md-block h4 { font-size: 1em; }
.md-block ul, .md-block ol { margin: 0 0 .8em; padding-inline-start: 1.5em; }
.md-block li { margin: .25em 0; }
.md-block li > p { margin: 0 0 .3em; }
.md-block strong { font-weight: 700; }
.md-block a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.md-block hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md-block blockquote { margin: 0 0 .8em; padding: 2px 14px; border-inline-start: 3px solid var(--border); color: var(--muted); }

.md-block table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0 0 .9em; font-size: .93em; }
.md-block th, .md-block td { padding: 7px 12px; border: 1px solid var(--border); text-align: start; vertical-align: top; }
.md-block th { background: var(--hover); font-weight: 600; white-space: nowrap; }
.md-block tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--hover) 55%, transparent); }

.md-block code {
  direction: ltr; unicode-bidi: isolate; padding: 1px 6px; border-radius: 6px; background: var(--hover);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em;
}
.md-block pre { direction: ltr; text-align: left; margin: 0 0 .9em; padding: 12px 14px; overflow-x: auto; border-radius: 12px; background: var(--hover); border: 1px solid var(--border); }
.md-block pre code { padding: 0; background: none; font-size: .86em; }

/* formulas always run left to right, and sit cleanly inside Persian text */
.katex { direction: ltr; unicode-bidi: isolate; font-size: 1.06em; }
.katex-display { direction: ltr; margin: .7em 0; overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.katex-display > .katex { text-align: center; }

/* structure drawings and reaction schemes */
.mol-grid { display: flex; flex-wrap: wrap; gap: 12px; margin: .5em 0 1.1em; }
.md-block > .mol-grid:first-child, .mol-grid:first-child { margin-top: 0; }
.md-block > .mol-grid:last-child, .mol-grid:last-child { margin-bottom: 0; }
.mol { margin: 0; width: 210px; max-width: 100%; padding: 8px; border-radius: 14px; background: #fff; border: 1px solid var(--border); color: #1f1d1a; text-align: center; }
.mol .mol-svg { min-height: 110px; display: grid; place-items: center; border: 0; border-radius: 0; background: none; padding: 0; }
.mol .mol-svg svg { max-width: 100%; height: auto; }
.mol figcaption { margin-top: 4px; font-size: 12.5px; color: #4a463f; overflow-wrap: anywhere; }
.mol--failed { font-size: 12px; }
.mol--failed small { display: block; color: #b04030; margin-top: 4px; }
.reaction-wrap { flex-basis: 100%; }
.reaction { direction: ltr; width: fit-content; max-width: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; border-radius: 16px; background: #fff; border: 1px solid var(--border); }
.reaction .mol { width: 150px; padding: 4px; border: 0; }
.reaction__side { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.reaction__plus { font-size: 20px; color: #6f6a62; padding: 0 2px; }
.reaction__arrow { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; color: #6f6a62; font-size: 12px; }
.reaction__arrow svg { width: 60px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.reaction__label { margin-top: 4px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* the box at the bottom */
.chat__composer { width: min(780px, 100%); margin: 0 auto; padding: 0 20px 14px; display: flex; flex-direction: column; gap: 8px; flex: none; }
.chat__composer .field-error { text-align: start; max-width: none; margin: 0; }
.chat-box { width: 100%; padding: 12px 14px 10px; }
.chat-box textarea { text-align: start; font-family: inherit; line-height: 1.7; min-height: 28px; }
:root[dir="rtl"] .chat-box textarea { text-align: right; }
.chat-box textarea::placeholder { font-family: inherit; }
.chat-box.is-drop { border-color: var(--accent); }
.chat__note { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.chat__composer .credit-cost { margin: 0; text-align: center; }

.send--stop { background: var(--text); color: var(--bg); box-shadow: none; }
.send--stop svg { width: 16px; height: 16px; fill: currentColor; stroke: none; }
.send[hidden] { display: none; }

.chat__attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attach { position: relative; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); overflow: visible; }
.attach img { display: block; width: 60px; height: 60px; object-fit: cover; border-radius: 11px; }
.attach--audio { display: inline-flex; align-items: center; gap: 6px; padding: 0 14px 0 10px; height: 36px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.attach--audio svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.attach__remove {
  position: absolute; top: -8px; inset-inline-end: -8px; width: 22px; height: 22px; border-radius: 50%; line-height: 1;
  font-size: 15px; color: var(--bg); background: var(--text); display: grid; place-items: center;
}
.chip-btn.is-recording { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, transparent); }
.chip-btn:disabled { opacity: .5; }

.chat__recording { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 8px 12px; border-radius: 14px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--bad) 45%, var(--border)); }
.chat__recording[hidden] { display: none; }
.chat__rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); animation: rec 1.1s infinite; }
@keyframes rec { 50% { opacity: .25; } }
.chat__rec-text { flex: 1; font-size: 14px; font-variant-numeric: tabular-nums; }

@media (max-width: 700px) {
  .chat__scroll { padding-inline: 14px; }
  .chat__composer { padding-inline: 14px; padding-bottom: 10px; }
  .chat-hero { padding-top: 3vh; }
  .chat-suggestions { grid-template-columns: minmax(0, 1fr); }
  .msg__bubble { max-width: 92%; }
  .msg__avatar { width: 26px; height: 26px; border-radius: 9px; }
  .msg { gap: 9px; }
  .msg__body { font-size: 15px; }
  .mol { width: calc(50% - 6px); }
  .reaction .mol { width: 110px; }
}

@media (prefers-reduced-motion: reduce) { .typing i, .chat__rec-dot { animation: none; } }

/* print: just the conversation */
@media print {
  .chat__composer, .msg__tools { display: none !important; }
}

/* The page of a shared chat, and the Share dialog */
.share-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.share-head[hidden], .share-missing[hidden], .share-cta[hidden] { display: none; }
.share-head__title { font-size: 22px; font-weight: 600; line-height: 1.5; overflow-wrap: anywhere; }
.share-head__note { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.share-missing { margin: 40px 0; padding: 18px; text-align: center; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); }
.share-cta { display: flex; justify-content: center; padding: 18px 0 8px; }


/* The PDF of a chat: the same look as the screen (theme, colours, bubbles, formulas, drawings), laid out for paper. */
.report--chat .report__title { font-size: 20px; font-weight: 600; line-height: 1.5; margin: 4px 0 18px; }
@media print {
  .report--chat { min-height: 0; padding: 12mm; font-size: 13px; }
  .report--chat, .report--chat * { animation: none !important; transition: none !important; }
  .report--chat .chat__messages { display: flex; flex-direction: column; gap: 20px; }
  .report--chat .msg__bubble, .report--chat .msg__who, .report--chat .mol, .report--chat .reaction, .report--chat .reaction-wrap,
  .report--chat .katex-display, .report--chat pre, .report--chat tr, .report--chat .md-block li { break-inside: avoid; }
  .report--chat .md-block h1, .report--chat .md-block h2, .report--chat .md-block h3, .report--chat .md-block h4, .report--chat .msg__who { break-after: avoid; }
  .report--chat .md-block p { orphans: 3; widows: 3; }
  .report--chat .md-block table { display: table; width: auto; max-width: 100%; overflow: visible; }
  .report--chat .md-block pre { white-space: pre-wrap; overflow: visible; }
  .report--chat .katex-display { overflow: visible; }
  .report--chat .msg__image { max-height: 160px; }
}

/* Narrow screens: the chat has two more buttons in the top bar (PDF, Share), so the bar gets tighter. */
@media (max-width: 520px) {
  .topbar { padding-inline: 8px; gap: 4px; }
  .topbar__end { gap: 2px; min-width: 0; }
  .topbar .credit-chip [data-i18n="credits.unit"] { display: none; }
  .topbar #langSelect { max-width: 86px; padding-inline: 8px; }
}

/* The shared page of predicted spectra or a structure analysis: read only, so what needs an account or credits is hidden */
#chatView[hidden], #resultView[hidden] { display: none; }
#resultView .share-head { padding-top: 22px; }
.is-shared [data-act="pdf"], .is-shared [data-dl], .is-shared [data-cand-dl], .is-shared [data-retry], .is-shared .credit-warn { display: none; }
.is-shared .elu-results .dl-row { display: none; }
