/* Reuse the signed-in shell's theme tokens and the line icons used on Home. */
body.workspace-flow-active :is([data-app-view="chat"], #iuai-ai-conversation-panel-v21) {
  --room-tone: var(--shell-accent);
  --room-action: #405fae;
  --room-contour: 82% -56%;
  --room-symbol: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 6.5h16a3 3 0 0 1 3 3v10a3 3 0 0 1-3 3h-9l-6 4v-4H6a3 3 0 0 1-3-3v-10a3 3 0 0 1 3-3Z'/%3E%3Cpath d='M8 12h12M8 16.5h7'/%3E%3C/svg%3E");
}
body.workspace-flow-active :is([data-app-view="research"], [data-app-view="result"], [data-app-view="progress"], #iuai-research-conversation-panel-v1) {
  --room-tone: var(--shell-violet);
  --room-action: #6950a8;
  --room-contour: 109% -8%;
  --room-symbol: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32' fill='none' stroke='black' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='13.5' cy='13.5' r='9.5'/%3E%3Cpath d='m21 21 6 6M8.5 16l3.5-4 3 2 3.5-5'/%3E%3C/svg%3E");
}

body.workspace-flow-active #workspace section.app-view.active:is([data-app-view="chat"], [data-app-view="research"]) {
  --room-line: color-mix(in srgb, var(--flow-line) 78%, transparent);
  --room-tint: color-mix(in srgb, var(--room-tone) 10%, var(--card));
  --room-edge: color-mix(in srgb, var(--room-tone) 34%, var(--line));
  min-width: 0;

  :is(.chat-page-head, .page-head) {
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--room-line);
  }
  :is(.chat-page-head, .page-head) .page-kicker { display: none; }
  :is(.chat-page-head, .page-head) h1 {
    margin: 0;
    font-size: clamp(21px, 1.6vw, 26px);
    line-height: 1.35;
    font-weight: 650;
    letter-spacing: -.025em;
    overflow-wrap: anywhere;
  }
  :is(.chat-page-head, .page-head) .btn {
    min-height: 36px;
    padding: 7px 12px;
    border: 1px solid var(--room-line);
    border-radius: 9px;
    background: var(--shell-fill);
    color: var(--ink);
    box-shadow: none;
    font-size: 13px;
    font-weight: 500;
  }
  :is(.chat-page-head, .page-head) .btn:hover { background: var(--room-tint); border-color: var(--room-edge); }

  /* The welcome banner only exists visually in an empty, personal conversation. */
  :is(#chat-empty, #research-welcome-v1) {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    min-width: 0;
    min-height: 0 !important;
    gap: 6px 16px;
    grid-template-columns: auto minmax(0, 1fr);
    align-content: center;
    align-items: center;
    justify-items: start;
    padding: clamp(18px, 2.1vw, 30px) !important;
    margin: 0 !important;
    border: 1px solid var(--room-edge);
    border-radius: 16px;
    background: linear-gradient(112deg, var(--room-tint), var(--card) 76%);
    color: var(--ink);
    text-align: start;
  }
  .chat-workspace-shell:not(.has-messages, .iuai-collab-active-v5910) #chat-empty:not([hidden]),
  #research-welcome-v1:not([hidden]) { display: grid; }
  :is(#chat-empty, #research-welcome-v1)::after {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0 0 0 auto;
    width: min(72%, 440px);
    pointer-events: none;
    color: var(--room-tone);
    background: repeating-radial-gradient(ellipse 200px 126px at var(--room-contour), transparent 0 14px, currentColor 15px 16px, transparent 17px 27px);
    mask-image: linear-gradient(248deg, #000, transparent 55%);
    opacity: .26;
  }
  :is(#chat-empty, #research-welcome-v1) :is(.chat-empty-mark, .research-welcome-spark-v1) {
    display: grid;
    grid-area: 1 / 1 / 3 / 2;
    place-items: center;
    width: 48px;
    height: 48px;
    margin: 0;
    font-size: 0;
    border: 1px solid var(--room-edge);
    border-radius: 14px;
    background: color-mix(in srgb, var(--room-tone) 16%, var(--card));
    color: var(--room-tone);
    box-shadow: none;
  }
  :is(.chat-empty-mark, .research-welcome-spark-v1)::before {
    content: "";
    width: 28px;
    height: 28px;
    background: currentColor;
    mask: var(--room-symbol) center/contain no-repeat;
  }
  :is(#chat-empty, #research-welcome-v1) h2 {
    grid-column: 2;
    margin: 0;
    color: var(--ink);
    font-size: clamp(22px, 2vw, 30px);
    font-weight: 650;
    line-height: 1.3;
    letter-spacing: -.03em;
    overflow-wrap: anywhere;
  }
  :is(#chat-empty, #research-welcome-v1) p {
    grid-column: 2;
    margin: 0;
    max-width: 78ch;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.65;
  }
  :is(#chat-composer, #research-composer-v1) {
    min-width: 0;
    border: 1px solid var(--room-edge) !important;
    border-radius: 16px !important;
    background: var(--card) !important;
    box-shadow: none !important;
  }
  :is(#chat-composer, #research-composer-v1):focus-within {
    border-color: var(--room-tone) !important;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--room-tone) 17%, transparent) !important;
  }
  :is(#chat-question, #research-question)::placeholder { color: var(--muted); opacity: 1; }
  :is(#chat-send, #research-start) {
    border: 1px solid color-mix(in srgb, var(--room-action) 66%, white) !important;
    border-radius: 11px !important;
    background: var(--room-action) !important;
    color: white !important;
    box-shadow: none !important;
  }
  :is(#chat-send, #research-start):hover:not(:disabled) { filter: brightness(1.12); }
  :is(#chat-send, #research-start):disabled { opacity: .55; }
  :is(.chat-toolbar, .research-composer-tools-v1) {
    gap: 6px !important;
    align-items: center;
    flex-wrap: wrap;
    border-color: var(--room-line);
  }
  :is(.chat-toolbar, .research-composer-tools-v1) > button:not([hidden]) {
    min-height: 34px;
    padding: 6px 10px;
    background: var(--shell-fill);
    color: var(--ink);
    border: 1px solid var(--room-line);
    border-radius: 9px;
    font: inherit;
    font-size: 12px;
    line-height: 1.4;
  }
  :is(.chat-toolbar, .research-composer-tools-v1) > button:is(:hover, .active) {
    color: var(--room-tone);
    border-color: var(--room-edge);
    background: var(--room-tint);
  }
  :is(#chat-starters-v1, #research-examples-v3) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  :is(#chat-starters-v1, #research-examples-v3) > button {
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: 68px;
    gap: 4px;
    justify-content: center;
    padding: 12px 44px 12px 15px;
    border: 1px solid var(--room-line);
    border-radius: 13px;
    background: var(--card);
    text-align: start;
    color: var(--ink);
  }
  :is(#chat-starters-v1, #research-examples-v3) > button span { font-size: 14px; font-weight: 600; line-height: 1.45; }
  :is(#chat-starters-v1, #research-examples-v3) > button small { color: var(--muted); font-size: 12px; line-height: 1.5; }
  :is(#chat-starters-v1, #research-examples-v3) > button i {
    position: absolute;
    inset: 50% 12px auto auto;
    transform: translateY(-50%);
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 1px solid var(--room-line);
    border-radius: 50%;
    color: var(--room-tone);
    font: normal 14px/1 system-ui, sans-serif;
  }
  :is(#chat-starters-v1, #research-examples-v3) > button:hover { background: var(--room-tint); border-color: var(--room-edge); }
  :is(.assistant-message.user .assistant-bubble, .intake-turn-v6.user, .research-conv-msg-v1.user .research-conv-bubble-v1) {
    background: var(--room-tint) !important;
    color: var(--ink) !important;
    border: 1px solid var(--room-edge) !important;
    box-shadow: none;
  }
  :is(.assistant-avatar, .research-conv-avatar-v1) {
    background: var(--room-tint) !important;
    color: var(--room-tone) !important;
    border: 1px solid var(--room-edge);
    border-radius: 10px;
  }
  :is(.rich-text, .research-turn-content-r148) { min-width: 0; overflow-wrap: anywhere; }
  .rich-text :is(img, video) { max-width: 100%; height: auto; }
  :is(.rich-text pre, .report-table-wrap) { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
  :is(button, summary, a):focus-visible { outline: 2px solid var(--room-tone) !important; outline-offset: 2px; }
}

body.workspace-flow-active #workspace section.app-view[data-app-view="chat"].active {
  .chat-page-head { padding-bottom: 12px !important; }
  .chat-workspace-shell:not(.has-messages, .iuai-collab-active-v5910) #chat-thread { padding-top: 14px !important; }
  .chat-workspace-shell:not(.has-messages, .iuai-collab-active-v5910) #chat-messages:empty { display: none; }
}
body.workspace-flow-active #workspace section.app-view[data-app-view="research"].active {
  .research-form { min-width: 0; }
  #research-answer-goal-v1, #research-advanced-v6 {
    border: 1px solid var(--room-line);
    border-radius: 12px;
    background: var(--card);
  }
  #research-conv-mode-v1 {
    color: var(--room-tone);
    background: var(--room-tint);
    border: 1px solid var(--room-edge);
  }
  :is(.research-progress-card-v1, .research-brief-card-v2, .research-result-card-v1) {
    min-width: 0;
    border: 1px solid var(--room-edge);
    border-radius: 14px;
    background: var(--card);
    box-shadow: none;
  }
  .research-progress-track-v1 i { background: var(--room-action); }
  .research-result-conclusion-v1 { line-height: 1.8; }
  :is(.rc-config, .rc-academic, .rc-protocol, .rc-method-note) { min-width: 0; background: var(--shell-fill); color: var(--ink); border-color: var(--room-line); }
  :is(.rc-config, .research-form) select { min-width: 0; max-width: 100%; }
  #research-welcome-v1:not([hidden]) ~ #research-stream-v1:has(#research-intake-thread-v6:empty):has(#research-runtime-v1:empty):not(:has(#research-clarify-box:not([hidden]))) {
    min-height: 0; margin: 0; padding: 0;
  }
}

body.workspace-flow-active #workspace section.app-view[data-app-view="result"].active {
  .result-page-head { gap: 12px; align-items: center; flex-wrap: wrap; }
  .result-page-head .page-kicker, .result-hero .result-eyebrow { display: none; }
  .result-head-actions, .result-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
  :is(.result-head-actions, .result-tabs) button {
    max-width: 100%; min-height: 36px;
    border: 1px solid var(--shell-edge); border-radius: 9px;
    color: var(--ink); background: var(--shell-fill);
  }
  .result-tabs button.active {
    color: var(--room-tone);
    background: color-mix(in srgb, var(--room-tone) 12%, var(--card));
    border-color: color-mix(in srgb, var(--room-tone) 38%, var(--line));
  }
  :is(.result-main-col, .result-detail, .report-body, .result-title-row > div) { min-width: 0; }
  .result-hero {
    border-radius: 16px;
    border: 1px solid color-mix(in srgb, var(--room-tone) 32%, var(--line));
    background: linear-gradient(115deg, color-mix(in srgb, var(--room-tone) 9%, var(--card)), var(--card));
    color: var(--ink);
  }
  .rich-text { overflow-wrap: anywhere; line-height: 1.8; }
  .rich-text :is(img, video), canvas { max-width: 100%; }
  :is(.report-table-wrap, pre) { max-width: 100%; overflow-x: auto; }
  :is(button, a, summary):focus-visible { outline: 2px solid var(--room-tone); outline-offset: 2px; }
}
body.workspace-flow-active #workspace section.app-view[data-app-view="progress"].active {
  .progress-head { gap: 12px; align-items: flex-start; }
  .progress-head > div:first-child { min-width: 0; overflow-wrap: anywhere; }
  .progress-head .page-kicker { display: none; }
  .progress-percent { color: var(--room-tone); font-variant-numeric: tabular-nums; }
  .progress-track > i { background: var(--room-action); }
}

/* The history panels live under body, outside the workspace's theme variables. */
body.workspace-flow-active :is(#iuai-ai-conversation-panel-v21, #iuai-research-conversation-panel-v1) {
  --rail-edge: color-mix(in srgb, var(--flow-line) 80%, transparent);
  background: var(--flow-side);
  color: var(--flow-text);
  border-color: var(--rail-edge);
  box-shadow: none;
  :is(.iuai-ai-panel-head-v21, .iuai-research-panel-head-v1) { min-height: 60px; gap: 8px; padding: 10px 12px; border-color: var(--rail-edge); }
  :is(.iuai-ai-panel-mark-v21, .iuai-research-panel-mark-v1) {
    display: grid;
    place-items: center;
    flex: none;
    width: 29px; height: 29px;
    border-radius: 9px;
    color: var(--room-tone);
    background: color-mix(in srgb, var(--room-tone) 12%, var(--flow-side));
    border: 1px solid color-mix(in srgb, var(--room-tone) 27%, var(--flow-line));
    font-size: 0;
  }
  :is(.iuai-ai-panel-mark-v21, .iuai-research-panel-mark-v1)::before { content: ""; width: 19px; height: 19px; background: currentColor; mask: var(--room-symbol) center/contain no-repeat; }
  :is(.iuai-ai-panel-new-v21, .iuai-research-panel-new-v1) {
    min-height: 32px; padding: 5px 9px;
    border: 1px solid var(--rail-edge); border-radius: 9px;
    background: var(--shell-fill); color: var(--flow-text);
    font-size: 12px; font-weight: 550;
  }
  :is(.iuai-ai-panel-search-v21, .iuai-research-panel-search-v1) {
    height: 37px; border: 1px solid var(--rail-edge); background: var(--shell-fill); border-radius: 10px;
    color: var(--flow-muted);
  }
  :is(.iuai-ai-panel-search-v21, .iuai-research-panel-search-v1):focus-within { border-color: var(--room-tone); }
  input { color: var(--flow-text); }
  input::placeholder { color: var(--flow-muted); }
  :is(.iuai-ai-thread-item-v21, .iuai-research-item-v1) {
    min-width: 0;
    padding: 9px 7px;
    border-radius: 10px;
    color: var(--flow-text);
  }
  :is(.iuai-ai-thread-item-v21, .iuai-research-item-v1):is(:hover, .active) {
    border-color: color-mix(in srgb, var(--room-tone) 24%, transparent);
    background: color-mix(in srgb, var(--room-tone) 10%, var(--flow-side));
    box-shadow: none;
  }
  :is(.iuai-ai-thread-copy-v21, .iuai-research-item-copy-v1) b { font-size: 13px; font-weight: 550; overflow-wrap: anywhere; }
  :is(.iuai-ai-panel-empty-v21, .iuai-research-empty-v1) { padding: 10px 8px; color: var(--flow-muted); font-size: 12px; }
  :is(.iuai-ai-thread-owner-v21, .iuai-research-item-icon-v1) {
    background: color-mix(in srgb, var(--room-tone) 10%, var(--flow-side));
    border-color: var(--rail-edge); color: var(--room-tone);
  }
  :is(button, input):focus-visible { outline: 2px solid var(--room-tone); outline-offset: 2px; }
}

@media (min-width: 950px) {
  body.workspace-flow-active #workspace .app-view .iuai-mobile-records-bar-v1 { display: none !important; }
}
@media (max-width: 949px) {
  body.workspace-flow-active #workspace section.app-view.active:is([data-app-view="chat"], [data-app-view="research"]) {
    :is(.chat-page-head, .page-head) {
      display: grid !important;
      grid-template-columns: minmax(0, 1fr) auto;
      align-items: center;
      gap: 4px 8px !important;
      padding: 0 0 8px !important;
      margin-bottom: 0 !important;
    }
    :is(.chat-page-head, .page-head) > div:has(> h1) { grid-column: 1; grid-row: 1; min-width: 0; }
    :is(.chat-page-head, .page-head) h1 { font-size: 21px !important; margin: 0 !important; }
    :is(.chat-head-actions-v5941, #research-conv-head-actions-v1) {
      grid-column: 2; grid-row: 1; width: auto; min-width: 0; justify-content: flex-end; gap: 6px;
    }
    .chat-head-actions-v5941 > .btn { width: auto !important; min-height: 40px; font-size: 12px; }
    #chat-new { flex: 0 0 44px; min-width: 44px; height: 44px; }
    .iuai-mobile-records-bar-v1 {
      display: flex;
      grid-row: 2;
      grid-column: 1 / -1;
      width: 100%;
      min-width: 0;
      order: 0;
      margin: 0;
      padding: 0;
      gap: 6px;
    }
    .iuai-mobile-records-bar-v1 > button {
      display: inline-flex;
      align-items: center;
      justify-content: flex-start;
      gap: 6px;
      min-width: 0;
      min-height: 40px !important;
      padding: 4px 8px !important;
      border: 1px solid transparent;
      border-radius: 9px;
      background: transparent;
      color: var(--room-tone);
      font-size: 12px;
    }
    .iuai-mobile-records-bar-v1 svg { width: 16px; height: 16px; }
    .iuai-mobile-records-bar-v1 .iuai-chat-sync-status-v1 { color: var(--muted); font-size: 11px; }
    .iuai-chat-sync-status-v1[data-sync="error"] { color: var(--shell-warning); }
    #research-collab-open { grid-row: 2; grid-column: 2; justify-self: end; width: auto; max-width: 100%; white-space: normal; }
    .page-head .iuai-mobile-records-bar-v1 { grid-column: 1; grid-row: 2; }
    .research-form.card { padding: 0 !important; }
    :is(#chat-composer, #research-composer-v1) { border-radius: 14px !important; }
    #research-composer-v1 { padding: 10px 12px !important; }
    #research-question { font-size: 16px !important; }
    :is(.research-composer-tools-v1, .chat-toolbar) > button:not([hidden]) { min-height: 44px !important; }
    .chat-input-row { grid-template-columns: 44px minmax(0, 1fr) 44px !important; }
    #chat-mobile-tools-toggle { width: 44px; height: 44px; min-height: 44px; }
    :is(#chat-composer, #research-composer-v1) .iuai-ai-research-voice-v1 { width: 44px !important; height: 44px !important; min-width: 44px !important; }
    #chat-composer #chat-question { padding-inline-end: 54px !important; }
    :is(#chat-empty, #research-welcome-v1) {
      gap: 5px 12px;
      border-radius: 14px;
      padding: 16px !important;
    }
    :is(#chat-empty, #research-welcome-v1) :is(.chat-empty-mark, .research-welcome-spark-v1) {
      grid-area: 1 / 1;
      width: 36px; height: 36px; border-radius: 11px;
    }
    :is(.chat-empty-mark, .research-welcome-spark-v1)::before { width: 23px; height: 23px; }
    :is(#chat-empty, #research-welcome-v1) h2 { font-size: 21px; }
    :is(#chat-empty, #research-welcome-v1) p { grid-column: 1 / -1; font-size: 13px; }
    :is(#chat-starters-v1, #research-examples-v3) { gap: 8px; margin: 10px 0; }
    :is(#chat-starters-v1, #research-examples-v3) > button { padding: 11px; min-height: 62px; }
    :is(#chat-starters-v1, #research-examples-v3) > button i { display: none; }
    .research-turn-editor-r148 { min-width: 0; width: 100%; }
  }
  body.workspace-flow-active #workspace .app-view[data-app-view="research"].active.research-conversation-v1 > .page-head { margin-bottom: 12px !important; }
  body.workspace-flow-active.mobile-chat-keyboard #workspace section.app-view[data-app-view="chat"].active .chat-page-head { display: none !important; }
  body.workspace-flow-active #workspace .app-view[data-app-view="research"].active.research-conversation-v1 > .page-head > .iuai-mobile-records-bar-v1 { grid-area: 2 / 1; }
  body.workspace-flow-active #workspace section.app-view[data-app-view="result"].active {
    .result-intelligence-layout { grid-template-columns: minmax(0, 1fr); }
    .result-hero, .result-detail { padding: 16px; }
    :is(.result-head-actions, .result-tabs) button { min-height: 40px; }
  }
  body.workspace-flow-active :is(#iuai-ai-conversation-panel-v21, #iuai-research-conversation-panel-v1) {
    #iuai-mobile-records-close-v1 { flex: 0 0 44px; width: 44px; height: 44px; align-self: center; padding: 0; margin: 0; color: var(--flow-text); background: transparent; border: 1px solid var(--rail-edge); border-radius: 10px; font: 22px/1 system-ui, sans-serif; }
    :is(.iuai-ai-panel-title-v21, .iuai-research-panel-title-v1) { flex: 1; }
    :is(.iuai-ai-panel-new-v21, .iuai-research-panel-new-v1) { min-height: 44px; }
  }
}
@media (max-width: 380px) {
  body.workspace-flow-active #workspace section.app-view.active :is(#research-examples-v3, #chat-starters-v1) {
    grid-template-columns: repeat(auto-fit, minmax(min(126px, 100%), 1fr));
  }
}
