/* Conversation layout owns only the inside of the shared shell. Load after
   native-v6: earlier mobile rules assigned incompatible grid rows and spacing. */
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-toolbar {
  flex: 0 0 auto;
  align-items: center;
  min-width: 0;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc4-toolbar-actions {
  flex: none;
  flex-wrap: nowrap;
  align-items: center;
  min-width: 0;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row {
  min-width: 0;
}
/* Message margins own the rhythm; do not add the legacy transcript gap too. */
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-transcript {
  gap: 0;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row button {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row textarea {
  /* Override the legacy index input-size !important without capping large text. */
  font-size: max(16px, 1rem) !important;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-message__bubble,
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-ai-message__content,
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-empty { font-size: max(16px, 1rem); }
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-message__meta,
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-ai-message__who { font-size: max(14px, .875rem); }
/* Secondary tools keep their full touch area without competing with Send. */
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced :is(.pwc4-mobile-back, .pwc4-toolbar-actions > button, .pwc-team-refresh, #pwc-team-photo, .pwc-talk-button) {
  color: var(--pwc4-muted, #596579);
  border-color: transparent;
  border-radius: 12px;
  background: transparent;
  box-shadow: none;
}
body.pw-authenticated #app-root .pwc-page.pwc4-enhanced :is(.pwc4-mobile-back, .pwc4-toolbar-actions > button, .pwc-team-refresh, #pwc-team-photo, .pwc-talk-button):hover:not(:disabled) {
  color: var(--pwc4-text, #172033);
  background: var(--pwc4-pane-muted, #f1f3f7);
}
/* Metadata and message options share one row, so each message does not spend
   another full touch-target row advertising a destructive correction. */
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 44px;
  grid-template-areas: ". meta actions" "avatar bubble bubble";
  column-gap: 8px;
  row-gap: 3px;
  padding-left: 0;
}
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message--mine {
  grid-template-columns: minmax(0, 1fr) 44px;
  grid-template-areas: "meta actions" "bubble bubble";
}
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc4-team-avatar {
  position: static;
  grid-area: avatar;
  align-self: start;
  margin: 0;
  width: 32px;
  height: 32px;
}
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message__meta {
  align-self: center;
  margin: 0;
  min-width: 0;
}
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message--mine .pwc-message__meta { justify-content: flex-end; }
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message__bubble { max-width: 100%; }
body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-message--mine .pwc-message__bubble { justify-self: end; }
/* Corrections are secondary message tools, never repeated primary actions. */
body.pw-authenticated #app-root .pwc-team .pwc-message__actions {
  position: relative;
  grid-area: actions;
  display: block;
  align-self: start;
  width: 44px;
  margin: 0;
  text-align: right;
}
body.pw-authenticated #app-root .pwc-team .pwc-message__actions > summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--pwc4-subtle, #526274);
  background: transparent;
  cursor: pointer;
  list-style: none;
}
body.pw-authenticated #app-root .pwc-team .pwc-message__actions > summary::-webkit-details-marker { display: none; }
body.pw-authenticated #app-root .pwc-team .pwc-message__actions > summary svg { width: 20px; height: 20px; }
body.pw-authenticated #app-root .pwc-team .pwc-message__actions > summary:hover { background: var(--pwc4-pane-muted, #edf0f4); }
body.pw-authenticated #app-root .pwc-team .pwc-message__actions > summary:focus-visible { outline: 2px solid var(--pwc4-focus, #2767a0); outline-offset: 2px; }
body.pw-authenticated #app-root .pwc-team .pwc-message__actions[open] { z-index: 2; }
body.pw-authenticated #app-root .pwc-team .pwc-message__actions .pwc-message__remove {
  position: absolute;
  top: 100%;
  right: 0;
  min-height: 44px;
  padding: 8px 12px;
  color: var(--pwc4-text, #172b40);
  background: var(--pwc4-pane, #fff);
  border: 1px solid var(--pwc4-line, #d5dbe3);
  border-radius: 12px;
  white-space: nowrap;
}

@media (max-width: 767px) {
  /* The shell measures both safe areas once. The transcript is the only
     vertical scroll owner; composers stay inside the visible keyboard area. */
  body.pw-authenticated[data-pw-route="/chat"],
  body.pw-authenticated[data-pw-route="/ai"] { overflow: hidden; }
  body.pw-authenticated[data-pw-route="/chat"] #app-root,
  body.pw-authenticated[data-pw-route="/ai"] #app-root {
    position: fixed;
    top: var(--pw-viewport-top, 0px);
    right: 0;
    bottom: auto;
    left: 0;
    width: auto;
    height: 100vh;
    height: var(--pw-viewport-height, 100vh);
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: var(--pw-shell-top-height, 63px) 0 var(--pw-shell-bottom-height, 72px);
    /* Legacy index main gutters use !important. Conversations are edge to edge. */
    padding-right: var(--pw-safe-right, 0px) !important;
    padding-left: var(--pw-safe-left, 0px) !important;
    overflow: hidden;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced {
    height: 100%;
    min-height: 0;
    max-height: none;
    margin: 0;
    padding: 0;
    gap: 0;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced > .pwc4-workspace {
    height: 100%;
    min-height: 0;
    grid-row: 1;
    grid-template-rows: minmax(0, 1fr);
    overflow: hidden;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-surface {
    height: 100%;
    min-height: 0;
    border-radius: 0;
  }
  body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-toolbar {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 8px;
    padding: 6px 8px;
    min-height: 58px;
  }
  body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-team-context {
    min-width: 0;
    width: auto;
    gap: 0;
  }
  body.pw-authenticated #app-root .pwc-team.pwc4-enhanced .pwc-team-context__icon,
  body.pw-authenticated #app-root .pwc-team.pwc4-enhanced #pwc-team-context-description { display: none; }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-toolbar__copy {
    display: block;
    min-width: 0;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-toolbar__copy strong {
    display: block;
    font-size: 1rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-height: 58px;
    padding: 6px 12px;
    gap: 8px;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc4-mobile-back,
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc4-toolbar-actions > button {
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    height: 44px;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer {
    padding: 8px;
    background: var(--pwc4-pane, #fff);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
  /* A full-width field and one action row allow readable labels at large
     text sizes. Explicit placement also overrides the old Talk full row. */
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row {
    display: grid;
    /* Legacy Assistant inline stylesheet forces its old two-column geometry. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    align-items: end;
    gap: 6px 8px;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row textarea {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    min-height: 48px;
    max-height: 104px;
    margin: 0;
    padding: 10px 12px;
    line-height: 1.4;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row > button {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto !important;
    min-width: 44px;
    max-width: 100%;
    height: auto;
    min-height: 44px;
    padding: 8px 12px !important;
    gap: 6px;
    font-size: 1rem;
    line-height: 1.25;
    white-space: normal;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row > button svg { flex: 0 0 20px; width: 20px; height: 20px; }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row > button span { display: inline; word-break: normal; overflow-wrap: normal; }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__row > .pwc-button--primary {
    grid-column: 2;
    justify-self: end;
  }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-composer__help { display: none; }
  body.pw-authenticated #app-root .pwc-page.pwc4-enhanced .pwc-field-error:empty { display: none; }
  body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-suggestions {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    gap: 8px;
    height: auto;
    max-height: none;
    padding: 8px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-chip {
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    max-width: none;
    min-height: 44px;
    padding: 8px 12px;
    font-size: 1rem;
    white-space: nowrap;
  }
  body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-assistant-info[open] {
    max-height: 40%;
    overflow-y: auto;
  }
  html[data-pw-keyboard="open"] body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-suggestions,
  html[data-pw-keyboard="open"] body.pw-authenticated #app-root .pwc-assistant.pwc4-enhanced .pwc-assistant-info { display: none; }
}

body.pw-authenticated #app-root .pwc-page.pwc4-enhanced [hidden] { display: none; }
