/* PR Data Observatory: the "Ask the observatory" chat (chat.js). Loads after twin.css and economy.css. */
:root { --chat-w: 390px; }

.chat-btn { white-space: nowrap; }
.chat-btn[aria-expanded="true"] { background: var(--tint-blue-bg); border-color: var(--tint-blue-bg); color: var(--tint-blue-fg); }

.chat { position: fixed; top: var(--topbar-height); right: 0; bottom: 0; width: var(--chat-w); z-index: 960; background: #fff; border-left: 1px solid var(--color-border); box-shadow: -4px 0 12px rgba(42,46,46,.08); display: flex; flex-direction: column; }
.chat[hidden] { display: none; }
body.chat-open #map { right: var(--chat-w); }
body.chat-open .econ-bench { right: var(--chat-w); }
body.chat-open .hover-info, body.chat-open .econ-hover { display: none !important; }

.ch-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--color-border); }
.ch-head h2 { margin: 0; font-size: 15px; color: var(--color-primary-dark); }
.ch-head > .ms-icon { color: var(--color-primary); font-size: 20px; }
.ch-head .tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; border-radius: 10px; padding: 2px 8px; background: var(--tint-green-bg); color: #2E3808; }
.ch-sp { flex: 1; }
.ch-head .btn.small { padding: 4px 10px; font-size: 11.5px; }
.ch-head .icon-btn.small { width: 30px; height: 30px; border-color: transparent; }
.ch-head .icon-btn .ms-icon { font-size: 18px; }

.ch-log { flex: 1; min-height: 0; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ch-msg { display: flex; }
.ch-msg.user { justify-content: flex-end; }
.ch-b { max-width: 94%; border-radius: 14px; padding: 9px 12px; font-size: 13px; line-height: 1.5; background: var(--color-bg); overflow-wrap: anywhere; }
.ch-msg.user .ch-b { background: var(--color-primary-strong); color: #fff; border-bottom-right-radius: 4px; }
.ch-msg.bot .ch-b { border-bottom-left-radius: 4px; width: 100%; max-width: 100%; }
.ch-b p { margin: 0 0 6px; }
.ch-b p:last-child { margin-bottom: 0; }
.ch-b small { color: var(--color-text-muted); }
.ch-note { font-size: 11.5px; color: var(--color-text-muted); }
.ch-wait { color: var(--color-text-muted); font-style: italic; }
.ch-ul, .ch-ol, .ch-src { margin: 4px 0 6px; padding-left: 18px; }
.ch-ul li, .ch-ol li, .ch-src li { margin: 3px 0; }
.ch-src { list-style: none; padding-left: 0; font-size: 12px; }
.ch-src a { word-break: break-word; }
.ch-det { margin: 4px 0; border-top: 1px solid var(--color-border); }
.ch-det summary { cursor: pointer; padding: 6px 0; font-weight: 700; font-size: 12.5px; }
.ch-tw { overflow-x: auto; margin: 4px 0 8px; }
table.ch-t { width: 100%; border-collapse: collapse; font-size: 12px; background: #fff; border-radius: 6px; }
table.ch-t th, table.ch-t td { padding: 4px 8px; border-bottom: 1px solid var(--color-border-light); text-align: left; vertical-align: top; }
table.ch-t thead th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); border-bottom: 1px solid var(--color-border); }
table.ch-t th[scope=row] { font-weight: 500; min-width: 140px; }
table.ch-t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ch-acts, .ch-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ch-acts .btn.small { padding: 5px 11px; font-size: 11.5px; text-decoration: none; }
.ch-chips .chip { text-align: left; }
.ch-start { padding: 0 12px 8px; margin: 0; }
.ch-start:empty { display: none; }

.ch-in { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--color-border); }
.ch-in textarea { flex: 1; resize: none; border: 1px solid var(--color-border); border-radius: 18px; padding: 8px 14px; font: inherit; line-height: 1.4; max-height: 120px; background: var(--color-bg); }
.ch-in textarea:focus { outline: 2px solid var(--color-primary-dark); outline-offset: 1px; background: #fff; }
.ch-in .icon-btn { flex: none; background: var(--color-primary-strong); color: #fff; border-color: var(--color-primary-strong); }
.ch-in .icon-btn:hover { background: var(--color-primary-dark); color: #fff; }
.ch-foot { font-size: 10.5px; color: var(--color-text-muted); padding: 0 14px 10px; line-height: 1.4; }

@media (max-width: 860px) {
  .chat { top: auto; left: 0; width: 100%; height: 56vh; z-index: 1160; border-left: 0; border-top: 1px solid var(--color-border); box-shadow: 0 -4px 12px rgba(42,46,46,.14); }
  body.chat-open #map { right: 0; bottom: 56vh; }
  body.chat-open .econ-bench { display: none; }
  .chat-btn { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: 50%; }
  .chat-btn .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* a page without a map (askpage.js): the chat's short messages, at its foot */
.ch-toast { position: fixed; right: 16px; bottom: 16px; z-index: 1200; max-width: min(360px, calc(100vw - 32px)); background: var(--color-primary-dark); color: #fff; border-radius: 8px; padding: 8px 12px; font-size: 13px; box-shadow: 0 4px 12px rgba(42,46,46,.2); opacity: 0; pointer-events: none; transition: opacity .2s; }
.ch-toast.show { opacity: 1; }
/* a page without a map (askpage.js adds .ask-page): the chat above the page's own maps (Leaflet's buttons are at 1000) and, on a desktop, below the Knowledge Area tabs, which stay in view */
.ask-page .chat { z-index: 1100; }
@media (min-width: 861px) { .ask-page .toc ~ .chat { top: calc(var(--topbar-height) + 40px); } }
