/* ProjectQuest Pewter chat v2: additive UI refinement and in-page quick chat.
   Loaded after existing theme + Quest Board styles; preserves original React actions.
   Scope all selectors to chat surfaces to avoid changing Finance, Nutrition or Questlog. */

/* The floating button stays visible below the expanded window; tapping it again collapses. */
.pq-context-chat-launcher.pq-context-chat-expanded{
  background:var(--pq-accent,#3e8ee8)!important;
  color:#061224!important;
  box-shadow:0 8px 24px rgba(15,45,92,.32),0 0 0 4px rgba(62,142,232,.20)!important;
}
.pq-context-chat-launcher.pq-context-chat-expanded svg{color:#061224!important}
.pq-context-chat-launcher.pq-context-chat-expanded svg path:last-child{display:none}
.pq-context-chat-launcher.pq-context-chat-expanded:after{content:'−';font-size:26px;line-height:1;position:absolute;color:#061224;font-weight:650}
.pq-quick-chat-host{
  box-sizing:border-box;position:fixed;right:18px;bottom:92px;
  z-index:92;display:flex;flex-direction:column;
  width:min(440px,calc(100vw - 32px));
  height:min(640px,calc(100dvh - 120px));
  max-height:calc(100dvh - 120px);
  background:var(--pq-page-bg,#090f1b);color:var(--pq-text,#eef2f9);
  border:1px solid var(--pq-line,#344057);border-radius:22px;
  box-shadow:0 24px 85px rgba(0,0,0,.58),0 5px 25px rgba(0,0,0,.20);
  overflow:hidden;isolation:isolate;
}
.pq-quick-chat-host[hidden]{display:none!important}
.pq-quick-chat-host *{box-sizing:border-box}
.pq-quick-chat-header{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:56px;padding:7px 10px 7px 14px;background:var(--pq-surface,#151b29);border-bottom:1px solid var(--pq-line,#344057);flex:0 0 auto}
.pq-quick-chat-brand{display:flex;align-items:center;gap:8px;min-width:0}
.pq-quick-chat-brand .pq-pewter-mascot{flex:0 0 28px;max-height:33px}
.pq-quick-chat-brand span:last-child{display:flex;flex-direction:column;min-width:0}
.pq-quick-chat-brand strong{font-size:15px;line-height:1.25;color:var(--pq-text,#fff)}
.pq-quick-chat-brand small{font-size:11px;color:var(--pq-text-muted,#a7b4c9);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:140px}
.pq-quick-chat-header-actions{display:flex;align-items:center;gap:4px;flex:none}
.pq-quick-chat-header-actions button{display:grid;place-items:center;width:37px;height:37px;min-width:37px;padding:0;border:0;border-radius:11px;background:transparent;color:var(--pq-text,#fff);font:600 24px/1 system-ui,sans-serif;cursor:pointer}
.pq-quick-chat-header-actions button:hover{background:var(--pq-surface-2,#283348)}
.pq-quick-chat-header-actions button:focus-visible{outline:2px solid var(--pq-accent,#3e8ee8);outline-offset:1px}

/* Embedded chat is the SAME React ChatPage; no iframe, duplicate chat backend or second conversation store. */
.pq-quick-chat-host .pq-chat-page.pq-chat-quick-mode{
  display:flex!important;flex:1 1 auto!important;flex-direction:column!important;
  width:100%!important;max-width:100%!important;height:auto!important;
  min-height:0!important;max-height:none!important;padding:0!important;margin:0!important;overflow:hidden!important;
}
.pq-quick-chat-host .pq-chat-quick-mode>.pq-chat-mobile-head,
.pq-quick-chat-host .pq-chat-quick-mode>.pq-display,
.pq-quick-chat-host .pq-chat-quick-mode>.pq-subtitle,
.pq-quick-chat-host .pq-chat-desktop-intro,
.pq-quick-chat-host .pq-chat-desktop-toolbar{display:none!important}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-layout{
  display:flex!important;flex:1 1 auto!important;flex-direction:column!important;
  height:auto!important;max-height:none!important;min-height:0!important;
  margin:0!important;padding:0!important;border:0!important;overflow:hidden!important;
}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-panel,
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-panel-one-scroll{
  display:flex!important;flex:1 1 auto!important;flex-direction:column!important;
  height:auto!important;min-height:0!important;max-height:none!important;
  padding:0!important;margin:0!important;overflow:hidden!important;border:0!important;border-radius:0!important;background:var(--pq-page-bg,#0a101d)!important;
}
.pq-quick-chat-host .pq-chat-quick-mode .pq-messages-one-scroll{
  display:block!important;flex:1 1 auto!important;min-height:0!important;max-height:none!important;
  overflow-y:auto!important;overflow-x:hidden!important;overscroll-behavior:contain!important;
  padding:18px 14px!important;background:var(--pq-page-bg,#0a101d)!important;
}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-thread-head{display:none!important}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-empty{padding:36px 18px!important;min-height:0!important}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-empty h2{font-size:19px!important}
.pq-quick-chat-host .pq-chat-quick-mode .pq-chat-empty p{font-size:14px!important;line-height:1.5}

/* Compact context is not visible as a pasted AI instruction in the composer. */
.pq-quick-context-chip{display:flex;align-items:center;justify-content:space-between;gap:10px;margin:0 12px 8px;padding:7px 10px;border:1px solid color-mix(in srgb,var(--pq-accent,#3e8ee8) 42%,var(--pq-line,#32435d));border-radius:10px;background:color-mix(in srgb,var(--pq-accent,#3e8ee8) 10%,var(--pq-page-bg,#0b1423));color:var(--pq-text-muted,#a7c4e3);font:500 12px/1.35 system-ui,sans-serif}
.pq-quick-context-chip span{min-width:0;white-space:nowrap;text-overflow:ellipsis;overflow:hidden}
.pq-quick-context-chip button{background:transparent;border:0;color:var(--pq-text,#eee);font-size:19px;line-height:1;cursor:pointer;padding:1px 4px}

/* Reduce full-page header duplication: one header and one compact thread drawer. */
.pq-chat-page.pq-chat-full-mode>.pq-display,
.pq-chat-page.pq-chat-full-mode>.pq-subtitle,
.pq-chat-page.pq-chat-full-mode>.pq-chat-desktop-intro,
.pq-chat-page.pq-chat-full-mode>.pq-chat-desktop-toolbar{display:none!important}
.pq-chat-page .pq-chat-thread-head{display:none!important}
.pq-chat-page.pq-chat-full-mode .pq-chat-mobile-head{display:flex!important;flex:0 0 auto;align-items:center;min-height:55px;gap:8px;padding:7px 12px!important;background:var(--pq-page-bg,#0a101b)!important;border-bottom:1px solid var(--pq-line,#28374e)!important}
.pq-chat-page .pq-chat-mobile-brand{min-width:0;flex:1;gap:8px}
.pq-chat-page .pq-chat-mobile-brand strong{font-size:17px!important;font-weight:740!important;line-height:1.2}
.pq-chat-page .pq-chat-mobile-brand small{max-width:min(42vw,320px);font-size:12px!important;color:var(--pq-text-muted,#a8b7cc)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.pq-chat-page .pq-chat-mobile-head-actions button{display:grid!important;place-items:center!important;width:38px!important;height:38px!important;min-width:38px!important;padding:0!important;background:transparent!important;border:1px solid transparent!important;border-radius:12px!important;color:var(--pq-text,#e8eef8)!important;font-size:23px!important;box-shadow:none!important}
.pq-chat-page .pq-chat-mobile-head-actions button:hover{background:var(--pq-surface-2,#232e40)!important}
.pq-chat-page .pq-chat-mobile-head-actions button:focus-visible{outline:2px solid var(--pq-accent,#3e8ee8)!important}
.pq-chat-page .pq-chat-layout{gap:0!important}
.pq-chat-page .pq-chat-panel{border:0!important;box-shadow:none!important;padding:0!important;background:var(--pq-page-bg,#090e18)!important}
.pq-chat-page .pq-messages-one-scroll{padding:18px clamp(12px,3vw,32px) 16px!important;background:transparent!important;scrollbar-gutter:auto!important}

/* Calmer conversation: the user's message is a bubble; Pewter is clean text with no heavyweight card. */
.pq-chat-page .pq-messages-one-scroll .pq-msg{width:auto!important;margin:9px 0 16px!important;line-height:1.57!important;font-size:15px!important;color:var(--pq-text,#eef3fa)!important;overflow-wrap:anywhere}
.pq-chat-page .pq-messages-one-scroll .pq-msg.user{
  width:fit-content!important;max-width:min(87%,680px)!important;margin-left:auto!important;
  padding:12px 15px!important;border:1px solid var(--pq-line,#3d4b60)!important;border-right:0!important;border-radius:19px 19px 6px 19px!important;
  background:color-mix(in srgb,var(--pq-surface-2,#172338) 88%,var(--pq-accent,#3e8ee8))!important;
  box-shadow:none!important;
}
.pq-chat-page .pq-messages-one-scroll .pq-msg.assistant{
  max-width:100%!important;width:100%!important;padding:7px 2px 4px 3px!important;
  border:0!important;background:transparent!important;border-radius:0!important;box-shadow:none!important;
}
.pq-chat-page .pq-messages-one-scroll .pq-msg.assistant .pq-speaker{font-size:13px!important;font-weight:700!important;color:var(--pq-accent,#5caaff)!important}
.pq-chat-page .pq-messages-one-scroll .pq-msg.user>.pq-speaker{display:none!important}
.pq-chat-page .pq-messages-one-scroll .pq-msg.assistant .pq-msg-pewter{margin-right:8px!important}
.pq-chat-page .pq-messages-one-scroll .pq-msg p{margin:6px 0!important}
.pq-chat-page .pq-messages-one-scroll .pq-msg-tools{border:0!important;padding:0!important;margin-top:6px!important}
.pq-chat-page .pq-messages-one-scroll .pq-read-aloud{min-height:32px!important;min-width:32px!important;padding:5px!important;border:0!important}

/* Composer unified: one message field, quiet utility icons, clear send button. */
.pq-chat-page .pq-chat-panel .pq-composer,
body.pq-chat-active .pq-chat-page .pq-chat-panel .pq-composer{
  display:block!important;flex:0 0 auto!important;position:relative!important;
  margin:0!important;inset:auto!important;padding:9px 12px 10px!important;
  border-top:1px solid var(--pq-line,#334159)!important;
  background:var(--pq-page-bg,#0a101b)!important;box-shadow:none!important;backdrop-filter:none!important;
}
.pq-chat-page .pq-chat-panel .pq-composer .pq-textarea{
  width:100%!important;min-height:44px!important;max-height:116px!important;
  padding:12px 14px!important;margin:0!important;border-radius:20px!important;
  border:1px solid var(--pq-line,#36465d)!important;background:var(--pq-surface,#1a2333)!important;
  box-shadow:none!important;color:var(--pq-text,#fff)!important;font-size:15px!important;
}
.pq-chat-page .pq-composer-actions{display:flex!important;align-items:center!important;gap:7px!important;flex-wrap:nowrap!important;max-width:none!important;margin:6px 0 0!important}
.pq-chat-page .pq-composer-actions .pq-composer-tool{display:inline-flex!important;align-items:center!important;justify-content:center!important;min-width:40px!important;min-height:38px!important;padding:7px 9px!important;border-radius:12px!important;background:transparent!important;border:0!important;color:var(--pq-text-muted,#a7bad1)!important;box-shadow:none!important;font-size:13px!important}
.pq-chat-page .pq-composer-actions .pq-send-button{display:grid!important;place-items:center!important;margin-left:auto!important;min-width:41px!important;width:41px!important;height:41px!important;min-height:41px!important;padding:0!important;border-radius:50%!important;font-size:21px!important;line-height:1!important}
.pq-chat-page .pq-composer-actions .pq-send-button:disabled{opacity:.5!important}
.pq-chat-page .pq-composer-action-label{font-size:12px!important}

/* Thread history as a compact slide-out, with all original thread IDs/actions preserved. */
.pq-chat-page .pq-thread-list{background:var(--pq-surface,#111827)!important;border:1px solid var(--pq-line,#303b51)!important;padding:10px!important;box-shadow:0 24px 58px rgba(0,0,0,.40)!important}
.pq-chat-page .pq-thread-drawer-controls{display:grid!important;grid-template-columns:1fr 1fr;gap:6px!important;padding:8px 4px 12px!important}
.pq-chat-page .pq-thread-drawer-controls>.pq-btn:first-child{grid-column:1 / -1;min-height:42px!important}
.pq-chat-page .pq-thread-row{border:0!important;border-bottom:1px solid var(--pq-line,#334155)!important;margin:0!important;padding:5px 4px!important;background:transparent!important;border-radius:8px!important}
.pq-chat-page .pq-thread-row.active{background:color-mix(in srgb,var(--pq-accent,#3e8ee8) 9%,var(--pq-surface,#152033))!important}
.pq-chat-page .pq-thread-row>button{padding:8px!important;border:0!important;background:transparent!important;text-align:left!important}
.pq-chat-page .pq-thread-row strong{font-size:13px!important;line-height:1.35!important}
.pq-chat-page .pq-thread-row small{font-size:11px!important;color:var(--pq-text-muted,#9bacc1)!important}
.pq-chat-page .pq-thread-actions summary{font-size:17px!important}
.pq-chat-page .pq-chat-utility-sheet .pq-chat-action-list{gap:4px!important}

@media (min-width:901px){
  .pq-chat-page.pq-chat-full-mode{max-width:1000px!important;width:100%!important;margin:0 auto!important}
  .pq-chat-page.pq-chat-full-mode .pq-chat-layout{display:flex!important;height:min(79vh,850px)!important;min-height:470px!important;max-height:none!important;overflow:hidden!important}
  .pq-chat-page.pq-chat-full-mode .pq-chat-panel{height:100%!important;min-height:0!important;display:flex!important;flex-direction:column!important;overflow:hidden!important}
  .pq-chat-page.pq-chat-full-mode .pq-messages-one-scroll{flex:1 1 auto!important;min-height:0!important;overflow-y:auto!important}
  .pq-chat-page.pq-chat-full-mode .pq-thread-list{position:fixed!important;inset:0 auto 0 0!important;z-index:310!important;width:min(380px,88vw)!important;max-height:100dvh!important;transform:translateX(-105%)!important;transition:transform .2s ease!important}
  .pq-chat-page.pq-chat-full-mode .pq-chat-layout.threads-open .pq-thread-list{transform:translateX(0)!important}
  .pq-chat-page.pq-chat-full-mode .pq-thread-backdrop{position:fixed!important;inset:0!important;background:rgba(0,0,0,.55)!important;z-index:309!important}
}
@media (max-width:900px){
  .pq-quick-chat-host{right:12px;left:12px;width:auto;bottom:calc(158px + env(safe-area-inset-bottom,0px));height:min(590px,calc(100dvh - 215px - env(safe-area-inset-bottom,0px)));max-height:calc(100dvh - 215px - env(safe-area-inset-bottom,0px));border-radius:19px}
  .pq-context-chat-launcher{z-index:95!important}
  .pq-chat-page.pq-chat-full-mode .pq-messages-one-scroll{padding:15px 14px 12px!important}
  .pq-chat-page .pq-composer-action-label{display:none!important}
  .pq-chat-page .pq-chat-panel .pq-composer{padding:8px 10px 10px!important}
  .pq-chat-page .pq-thread-list{z-index:310!important}
}
@media (max-width:380px){
  .pq-quick-chat-host{left:8px;right:8px;bottom:calc(150px + env(safe-area-inset-bottom,0px))}
  .pq-quick-chat-header{padding-inline:8px}
  .pq-quick-chat-header-actions button{width:34px;min-width:34px}
}
@media(prefers-reduced-motion:reduce){
  .pq-quick-chat-host,.pq-quick-chat-host *{transition:none!important}
}
