/* Artifacts of the tessairact|code chat (EPIC 4ae6c318bdf5, item 3): the channel header's button,
   the panel (desktop column, tablet and chat-panel overlay, phone sheet), its list and detail, the
   per-kind rendering (artifact_render.js) and the chips under answers (artifact_chips.js). Tokens
   come from chat.css; the runner frames themselves are styled in artifact_frame.css. */

:root {
  --artifacts: clamp(320px, 30vw, 560px);
}

/* The channel header's button with the channel's count. */

.chat-artifacts-button {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.chat-artifacts-count {
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--cyan-soft);
  color: var(--cyan);
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 18px;
  text-align: center;
}

.chat-artifacts-count:empty {
  display: none;
}

.chat-artifacts-button[aria-expanded="true"] {
  background: var(--cyan-soft);
  color: var(--cyan);
}

/* Phone: a "stack of pages" mark instead of the word; the count stays. */
html[data-chat-layout="phone"] .chat-artifacts-button {
  position: relative;
  width: 44px;
  height: 44px;
  min-height: 44px;
  justify-content: center;
  padding: 0;
  border-radius: 12px;
  font-size: 0;
}

html[data-chat-layout="phone"] .chat-artifacts-button::before,
html[data-chat-layout="phone"] .chat-artifacts-button::after {
  position: absolute;
  width: 14px;
  height: 17px;
  border: 2px solid currentColor;
  border-radius: 3px;
  content: "";
}

html[data-chat-layout="phone"] .chat-artifacts-button::before {
  top: 10px;
  left: 12px;
}

html[data-chat-layout="phone"] .chat-artifacts-button::after {
  top: 14px;
  left: 16px;
  background: var(--panel-solid);
}

html[data-chat-layout="phone"] .chat-artifacts-count {
  position: absolute;
  top: 4px;
  right: 2px;
  z-index: 1;
  min-width: 16px;
  padding: 0 4px;
  font-size: 10px;
  line-height: 16px;
}

/* The panel: a column on desktop, an overlay on tablets and in the chat panel of the map pages. */

.chat-artifacts:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel-solid);
}

html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"] {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--artifacts);
}

html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"][data-thread="open"] {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--thread) var(--artifacts);
}

@media (max-width: 1439px) {
  html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"][data-thread="open"] {
    grid-template-columns: var(--sidebar) minmax(0, 1fr) 320px clamp(300px, 26vw, 400px);
  }
}

html[data-chat-layout="tablet"] .chat-artifacts[data-mode="overlay"] {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  width: min(560px, 90%);
  box-shadow: -18px 0 40px rgba(20, 33, 38, 0.16);
}

html:not([data-chat-layout]) .chat-artifacts[data-mode="overlay"] {
  position: fixed;
  inset: 0;
  z-index: 30;
  border-left: 0;
}

.chat-artifacts-head {
  gap: 8px;
}

.chat-artifacts-title {
  margin: 0;
  font-size: 15px;
}

.chat-artifacts-title:focus {
  outline: none;
}

.chat-artifacts-scroll {
  min-height: 0;
  padding: 10px 14px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-artifacts-status {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.chat-artifacts-status:empty {
  display: none;
}

/* The phone sheet holds the same content. */
.chat-artifacts.chat-artifacts-sheet {
  display: block;
  border-left: 0;
}

.chat-artifacts-sheet .chat-artifacts-scroll {
  padding: 0 2px 12px;
  overflow: visible;
}

/* The list */

.chat-artifacts-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chat-artifacts-row {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.chat-artifacts-row:hover,
.chat-artifacts-row:focus-visible {
  background: var(--cyan-soft);
}

.chat-artifacts-row-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-artifacts-row-title {
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-artifacts-row-meta {
  color: var(--muted);
  font-size: 12px;
}

.chat-artifacts-empty,
.chat-artifacts-more,
.chat-artifact-more,
.chat-artifact-empty {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

/* The kind mark (lists, the detail and the chips). */

.chat-artifact-mark {
  display: inline-grid;
  flex: none;
  min-width: 30px;
  height: 24px;
  place-items: center;
  padding: 0 4px;
  border-radius: 6px;
  background: var(--cyan-soft);
  color: var(--cyan);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
}

.chat-artifact-mark[data-kind="python"] {
  background: rgba(36, 95, 190, 0.12);
  color: var(--blue);
}

.chat-artifact-mark[data-kind="html"] {
  background: rgba(140, 87, 0, 0.13);
  color: var(--amber);
}

.chat-artifact-mark[data-kind="mermaid"] {
  background: rgba(111, 66, 165, 0.12);
  color: var(--purple);
}

.chat-artifact-mark[data-kind="table"] {
  background: rgba(53, 111, 29, 0.12);
  color: var(--lime);
}

/* One artifact */

.chat-artifact-back {
  margin: 0 0 6px -8px;
}

.chat-artifact-title {
  margin: 2px 0 4px;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.chat-artifact-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 8px;
  color: var(--muted-bright);
  font-size: 13px;
}

.chat-artifact-version-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 0 6px;
}

.chat-artifact-version-label {
  color: var(--muted);
  font-size: 13px;
}

.chat-artifact-versions {
  min-width: 0;
  max-width: 100%;
  min-height: 34px;
}

.chat-artifact-note {
  margin: 0 0 6px;
  padding: 6px 10px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted-bright);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.chat-artifact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0 0 10px;
}

.chat-artifact-message {
  margin-right: 4px;
  color: var(--blue);
  font-size: 13px;
}

.chat-artifact-fresh:not([hidden]) {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(140, 87, 0, 0.12);
  font-size: 13px;
  font-weight: 600;
}

.chat-artifact-body {
  min-width: 0;
}

/* The panel names the artifact above the frame already. */
.chat-artifact-body .artifact-frame-title {
  display: none;
}

/* With the thread and the panel open the conversation is narrow: its name keeps room and the
   header's buttons move to a second line instead of pushing the name out. */
.chat-shell[data-artifacts="open"] .chat-main .chat-header {
  flex-wrap: wrap;
}

.chat-shell[data-artifacts="open"] .chat-main .chat-header-main {
  flex: 1 1 160px;
  min-width: 160px;
}

.chat-shell[data-artifacts="open"] .chat-main .chat-header-actions {
  /* Shrinkable, or the buttons never wrap and run into the panel (a wide panel leaves ~400 px). */
  flex: 0 1 auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.chat-artifact-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.chat-artifact-frame-tools {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

/* An HTML app has a fixed height (~70 % of the panel); "Expand" gives it nearly the whole screen. */
.chat-artifact-body[data-kind="html"] .artifact-frame-runner {
  height: min(70vh, 760px) !important;
}

.chat-artifact-body[data-kind="html"][data-expanded="true"] .artifact-frame-runner {
  height: calc(100dvh - 120px) !important;
}

/* Code, documents and tables */

.chat-artifact-code {
  margin: 0;
  max-height: none;
  font-size: 12.5px;
  line-height: 1.45;
}

.chat-artifact-code code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

.chat-artifact-markdown {
  font-size: 14px;
  line-height: 1.5;
}

.chat-artifact-markdown > * + * {
  margin-top: 8px;
}

.chat-artifact-markdown p.chat-rich-p {
  margin: 0;
}

.chat-artifact-markdown pre.chat-codeblock code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  white-space: pre;
}

.chat-artifact-heading {
  margin: 14px 0 4px;
  line-height: 1.3;
  white-space: normal;
}

h3.chat-artifact-heading {
  font-size: 18px;
}

h4.chat-artifact-heading {
  font-size: 16px;
}

h5.chat-artifact-heading,
h6.chat-artifact-heading {
  font-size: 14px;
}

.chat-artifact-rule {
  border: 0;
  border-top: 1px solid var(--line);
}

.chat-artifact-table-wrap {
  max-height: min(70vh, 900px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chat-artifact-table {
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

/* Cells break only between words (a number or a name stays whole); a wide table scrolls sideways. */
.chat-artifact-table th,
.chat-artifact-table td {
  max-width: 360px;
  padding: 5px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: pre-wrap;
  overflow-wrap: normal;
  word-break: normal;
}

.chat-artifact-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-raised);
  font-weight: 700;
}

.chat-artifact-table tbody tr:nth-child(even) td {
  background: rgba(31, 47, 52, 0.03);
}

/* Chips under an answer of the Codex agent */

.chat-artifact-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.chat-artifact-chip {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  max-width: 100%;
  min-height: 34px;
  padding: 4px 10px 4px 5px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.chat-artifact-chip:hover,
.chat-artifact-chip:focus-visible {
  border-color: var(--cyan);
}

.chat-artifact-chip .chat-artifact-mark {
  height: 22px;
}

.chat-artifact-chip-title {
  overflow: hidden;
  min-width: 0;
  max-width: 280px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-artifact-chip-version {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

html[data-chat-layout="phone"] .chat-artifact-chip {
  min-height: 44px;
}

/* Wider (artifact_size.js, EPIC 711e363e4582): the desktop column at about 60 % of the window. The
   conversation keeps at least 380 px, so on smaller screens and with the thread open the column
   grows less; it never gets narrower than its normal width. */

.chat-artifacts-wide {
  margin-left: auto;
}

.chat-artifacts-wide[aria-pressed="true"] {
  background: var(--cyan-soft);
  color: var(--cyan);
}

html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"][data-artifacts-wide="on"] {
  grid-template-columns:
    var(--sidebar) minmax(0, 1fr)
    max(var(--artifacts), min(60vw, calc(100vw - var(--sidebar) - 380px)));
}

html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"][data-artifacts-wide="on"][data-thread="open"] {
  grid-template-columns:
    var(--sidebar) minmax(0, 1fr) var(--thread)
    max(var(--artifacts), min(60vw, calc(100vw - var(--sidebar) - var(--thread) - 380px)));
}

@media (max-width: 1439px) {
  html[data-chat-layout="desktop"] .chat-shell[data-artifacts="open"][data-artifacts-wide="on"][data-thread="open"] {
    grid-template-columns:
      var(--sidebar) minmax(0, 1fr) 320px
      max(clamp(300px, 26vw, 400px), min(60vw, calc(100vw - var(--sidebar) - 700px)));
  }
}

/* Full screen (artifact_size.js): the stage of the open artifact (a title bar, the new-version note
   and the body) covers the viewport. The panel rises above the page's bars meanwhile: the tablet
   overlay and the chat panel's overlay otherwise stack below them. In the phone sheet the stage is
   inside the sheet's dialog, which is above everything already. */

/* More specific than the overlay rules above (tablet: z-index 6, chat panel: 30). */
:root .chat-artifacts[data-mode][data-fullscreen="on"] {
  z-index: 50;
}

.chat-artifact-stage {
  min-width: 0;
}

.chat-artifact-stage-head {
  display: none;
}

.chat-artifact-stage[data-fullscreen="on"] {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  background: var(--panel-solid);
  overscroll-behavior: contain;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-stage-head {
  display: flex;
  flex: none;
  gap: 10px;
  align-items: center;
  min-height: 54px;
  padding: 8px 12px 8px 18px;
  border-bottom: 1px solid var(--line);
}

.chat-artifact-stage-title {
  display: flex;
  flex: 1 1 auto;
  gap: 8px;
  align-items: center;
  min-width: 0;
  font-size: 15px;
  font-weight: 650;
}

.chat-artifact-stage-name {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-artifact-stage-version {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.chat-artifact-stage-exit {
  flex: none;
}

.chat-artifact-stage[data-fullscreen="on"] > .chat-artifact-fresh {
  flex: none;
  margin: 8px 18px 0;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 12px 18px 16px;
  overflow: auto;
  overscroll-behavior: contain;
}

/* An HTML app fills the height; its Expand has nothing left to do there. */
.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-body[data-kind="html"] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-body[data-kind="html"] .chat-artifact-frame-host {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-body[data-kind="html"] .artifact-frame {
  flex: 1 1 auto;
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-body[data-kind="html"] .artifact-frame-runner {
  height: 100% !important;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-frame-tools {
  display: none;
}

.chat-artifact-stage[data-fullscreen="on"] .chat-artifact-table-wrap {
  max-height: none;
}

/* History of the saved data (artifact_history.js, decision D5). */

.chat-artifact-history-button[aria-expanded="true"] {
  background: var(--cyan-soft);
  color: var(--cyan);
}

.chat-artifact-history {
  margin: 0 0 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
}

.chat-artifact-history-hint {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.chat-artifact-history-list {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chat-artifact-history-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  font-size: 13px;
}

.chat-artifact-history-line {
  font-variant-numeric: tabular-nums;
}

.chat-artifact-history-current {
  color: var(--muted);
  font-size: 12px;
}

.chat-artifact-history-confirm {
  margin-top: 0;
}

html[data-chat-layout="phone"] :is(.chat-artifact-actions, .chat-artifact-history-row, .chat-artifact-stage-head) .chat-button {
  min-height: 44px;
}

/* Thread hints beside "N replies" (thread_contents.js, EPIC 711e363e4582 item 4). */

.chat-thread-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
  align-items: center;
  margin-top: 5px;
}

.chat-thread-row > .chat-thread-link {
  margin-top: 0;
}

.chat-thread-hints {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  min-width: 0;
}

.chat-thread-hint {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  max-width: 220px;
  min-height: 26px;
  padding: 1px 10px 1px 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-solid);
  color: var(--muted-bright);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.chat-thread-hint:hover,
.chat-thread-hint:focus-visible {
  border-color: var(--cyan);
  color: var(--text);
}

.chat-thread-hint-files,
.chat-thread-hint-more {
  padding: 1px 10px;
  font-variant-numeric: tabular-nums;
}

.chat-thread-hint-more {
  border-style: dashed;
  color: var(--muted);
}

.chat-thread-hint .chat-artifact-mark {
  min-width: 26px;
  height: 20px;
  border-radius: 999px;
  font-size: 10px;
}

.chat-thread-hint-title {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Phone: 44 px targets (mobile_shell.css), compact text so two or three fit on a line. */
html[data-chat-layout="phone"] .chat-thread-hint {
  max-width: 46vw;
  min-height: 44px;
  padding: 1px 9px 1px 3px;
  font-size: 13px;
}

html[data-chat-layout="phone"] :is(.chat-thread-hint-files, .chat-thread-hint-more) {
  padding: 1px 10px;
}

html[data-chat-layout="phone"] .chat-thread-row {
  gap: 4px;
}
