/* Shared controls remain mounted when folded, preserving selected model and images. */
body.aichat-page .main-content {
  box-sizing: border-box;
  height: 100dvh;
  min-height: 0;
  padding-top: 104px !important;
  padding-bottom: 12px !important;
}
body.aichat-page .main-content .aichat-shell {
  height: 100%;
  min-height: 0;
  align-items: stretch;
}
body.aichat-page .main-content .aichat-main {
  grid-template-rows: minmax(0, 1fr) auto auto;
  overflow: hidden;
}
body.aichat-page .site-footer {
  display: none;
}
@media (max-width: 900px) {
  body.aichat-page .main-content {
    padding-inline: 12px !important;
    height: calc(100dvh - var(--mobile-nav-space));
    padding-top: calc(128px + env(safe-area-inset-top, 0px)) !important;
    padding-bottom: 8px !important;
  }
}

/* A single input surface: draft, selected attachments, then the action row. */
body.aichat-page .main-content .aichat-composer {
  grid-template-columns: 40px minmax(0, 1fr) 40px 40px;
  column-gap: 4px;
  row-gap: 0;
  align-items: center;
  margin: 4px 16px 8px;
  padding: 4px !important;
  border: 1px solid var(--ui-line-strong) !important;
  border-radius: 26px !important;
  background: var(--ui-input) !important;
  transition: border-color 160ms ease;
}
body.aichat-page .main-content .aichat-composer:focus-within {
  border-color: var(--ui-accent) !important;
}
body.aichat-page .main-content .aichat-composer::before {
  content: none;
}
body.aichat-page .main-content .aichat-composer textarea {
  grid-column: 2;
  grid-row: 4;
  height: 40px;
  min-height: 40px;
  max-height: min(180px, 24dvh);
  padding: 8px 2px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--ui-text) !important;
  box-shadow: none !important;
  outline: none !important;
  font-size: 16px;
  line-height: 1.5;
}
body.aichat-page .main-content .aichat-composer textarea::placeholder {
  color: var(--ui-muted) !important;
}
.aichat-attachments,
.aichat-attachments .max-file-tools,
.aichat-attachments .max-images {
  display: contents;
}
.aichat-attachments button[data-file-add],
.aichat-attachments button[data-image-add] {
  display: none;
}
.aichat-attachments button:focus-visible,
body.aichat-page .main-content .aichat-send:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}
.aichat-attachments button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.aichat-attachments [data-file-status],
.aichat-attachments [data-image-status] {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 4px 8px;
  color: var(--ui-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
.aichat-attachments [data-file-status] {
  grid-row: 5;
}
.aichat-attachments [data-image-status] {
  grid-row: 6;
}
.aichat-attachments small:empty,
.aichat-attachments .max-file-tools ul[hidden],
.aichat-attachments .max-image-previews:empty {
  display: none;
}
.aichat-attachments .max-file-tools ul {
  grid-column: 1 / -1;
  grid-row: 2;
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.max-file-chip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  gap: 2px 6px;
  padding: 6px 8px;
  min-width: 0;
  max-width: 240px;
  flex: 0 0 200px;
  border: 1px solid var(--ui-line);
  border-radius: 10px;
  background: var(--ui-surface);
}
.max-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}
.max-file-chip small {
  min-width: 0;
  grid-row: 2;
  font-size: 11px;
  overflow-wrap: anywhere;
  color: var(--ui-muted);
}
.max-file-chip button {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  height: 32px;
  border: 0;
  border-radius: 6px;
  padding: 0;
  color: var(--ui-muted);
  background: transparent;
  cursor: pointer;
  font-size: 20px;
}
.max-file-chip button:hover {
  background: var(--ui-surface-soft);
}
.max-file-chip[data-state='error'] {
  border-color: #c66754;
}
.aichat-attachments .max-image-previews {
  grid-column: 1 / -1;
  grid-row: 3;
  margin-bottom: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 2px;
}
.aichat-attachments .max-image-previews img {
  width: 56px;
  height: 56px;
}
body.aichat-page .main-content .aichat-send {
  grid-column: 4;
  grid-row: 4;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50% !important;
  box-shadow: none !important;
}
body.aichat-page .main-content .aichat-send > span:first-child {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
body.aichat-page .main-content .aichat-send-arrow {
  font-size: 22px;
}
body.aichat-page .main-content .aichat-meta-row {
  min-height: 0;
  padding: 0 24px 8px;
  background: transparent;
}
body.aichat-page .main-content .aichat-shortcut {
  font-size: 11px;
}
body.aichat-page .main-content .aichat-shortcut kbd {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
}
@media (max-width: 900px) {
  body.aichat-page .main-content .aichat-composer {
    margin: 2px 10px 8px;
  }
  body.aichat-page .main-content .aichat-meta-row {
    padding: 0 18px;
  }
  body.aichat-page .main-content .aichat-meta-row:not(:has(.aichat-status:not(:empty))) {
    display: none;
  }
}

/* History opens from the conversation header; it consumes no separate row. */
@media (max-width: 900px) {
  body.aichat-page .main-content .aichat-shell {
    grid-template-rows: minmax(0, 1fr);
    gap: 0;
  }
  body.aichat-page .main-content .aichat-main {
    grid-row: 1;
  }
  body.aichat-page .main-content .aichat-main-header {
    min-height: 56px;
    padding: 8px 12px;
    gap: 8px;
  }
  body.aichat-page .main-content .aichat-main-avatar {
    width: 32px;
    height: 32px;
  }
  body.aichat-page .main-content .aichat-main-identity {
    grid-template-columns: 32px minmax(0, 1fr);
  }
  body.aichat-page .main-content .aichat-dialog-toggle {
    min-height: 40px;
    height: 40px;
    margin-left: auto;
    padding: 0 8px;
    gap: 5px;
    border: 0 !important;
    background: transparent !important;
    color: var(--ui-muted) !important;
    font-size: 12px;
  }
  body.aichat-page .main-content .aichat-dialog-toggle span {
    color: inherit !important;
  }
  body.aichat-page .main-content .aichat-dialog-toggle img {
    filter: none;
    opacity: 0.7;
  }
  body.aichat-page .main-content .aichat-presence {
    display: none;
  }
}

/* The conversation is the page, not another card inside it. */
body.aichat-page .main-content .aichat-main {
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  background: transparent !important;
}
body.aichat-page .main-content .aichat-main-header {
  border: 0 !important;
  background: transparent !important;
}
body.aichat-page .main-content .aichat-thread {
  background: transparent !important;
}

@media (max-width: 900px) {
  body.aichat-page.max-input-active {
    overflow: hidden;
  }
  body.aichat-page.max-input-active .topbar,
  body.aichat-page.max-input-active .mobile-nav,
  body.aichat-page.max-input-active .main-content .aichat-meta-row {
    display: none !important;
  }
  body.aichat-page.max-input-active .main-content {
    position: fixed;
    inset: var(--max-visible-top, 0px) 0 auto;
    z-index: 100;
    width: 100%;
    height: var(--max-visible-height, 100dvh);
    margin: 0 !important;
    padding: 0 8px 4px !important;
  }
  body.aichat-page.max-input-active .main-content .aichat-main {
    grid-template-rows: minmax(0, 1fr) auto;
  }
  body.aichat-page.max-input-active .main-content .aichat-composer {
    margin: 2px 0 0;
  }
  body.aichat-page.max-input-active .main-content::before,
  body.aichat-page.max-input-active .main-content::after {
    display: none !important;
  }
}

/* One compact row in every viewport; attachments occupy the rows above it. */
#max-create-mode {
  grid-row: 5;
  grid-column: 2 / -1;
  justify-self: start;
  width: auto;
  max-width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  color: var(--ui-text);
  font: inherit;
  font-size: 0.8rem;
}
.max-artifact-action {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.max-artifact-action button,
.max-artifact-stop {
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--ui-line-strong);
  border-radius: 8px;
  background: var(--ui-surface);
  color: var(--ui-text);
  cursor: pointer;
}
.max-artifact-source,
.max-artifact-stop {
  grid-column: 2;
  min-width: 0;
}
.max-artifact-source pre {
  max-height: 280px;
  overflow: auto;
  font-size: 0.8rem;
}
.max-artifact-source summary {
  cursor: pointer;
  padding-block: 8px;
}
body.aichat-page .main-content .aichat-composer {
  position: relative;
  overflow: visible;
}
.max-composer-menu {
  grid-row: 4;
  color: var(--ui-text);
}
.max-composer-add {
  grid-column: 1;
}
.max-composer-tools {
  grid-column: 3;
}
.max-composer-menu > summary {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  list-style: none;
  cursor: pointer;
}
.max-composer-menu > summary::-webkit-details-marker {
  display: none;
}
.max-composer-menu > summary:hover,
.max-composer-menu[open] > summary {
  background: var(--ui-surface-soft);
}
.max-composer-menu > summary:focus-visible {
  outline: 2px solid var(--ui-accent);
}
.max-composer-popover {
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 8px);
  left: 0;
  width: min(340px, 100%);
  box-sizing: border-box;
  padding: 8px;
  max-height: min(320px, 55dvh);
  overflow: auto;
  border: 1px solid var(--ui-line);
  border-radius: 16px;
  background: var(--ui-surface);
  box-shadow: 0 8px 28px #0002;
}
.max-composer-tools .max-composer-popover {
  left: auto;
  right: 0;
}
.max-composer-popover .aichat-options {
  padding: 8px;
  border: 0;
  background: transparent;
}
.max-composer-popover .max-model-picker {
  padding: 0;
}
.max-composer-popover select {
  max-width: 100%;
  font-size: 16px;
}
.max-composer-add .max-composer-popover {
  width: min(250px, calc(100vw - 40px));
}
.max-creation-choices {
  border-bottom: 1px solid var(--ui-line);
  padding-bottom: 6px;
  margin-bottom: 6px;
}
.max-creation-choices button::before {
  content: '';
  width: 16px;
  flex: 0 0 16px;
}
.max-creation-choices button[aria-pressed='true']::before {
  content: '✓';
}
.max-creation-choices button[aria-pressed='true'] {
  color: var(--ui-accent) !important;
  background: var(--ui-surface-soft) !important;
}
#max-create-mode[hidden] {
  display: none !important;
}
.max-composer-add .max-composer-popover button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.max-composer-add .max-composer-popover button:hover {
  background: var(--ui-surface-soft);
}
.max-composer-add .max-composer-popover button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.max-attachment-choices {
  display: flex;
  gap: 4px;
}
.max-composer-add .max-attachment-choices button {
  flex: 1;
  width: auto;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
  padding: 8px 4px;
  font-size: 13px;
}
@media (max-width: 900px) {
  body.aichat-page .main-content .aichat-composer {
    grid-template-columns: 36px minmax(0, 1fr) 36px 40px;
    margin-inline: 0;
  }
  .max-composer-menu > summary {
    width: 36px;
  }
}

/* History lives in the mobile top bar, with no duplicate conversation title row. */
@media (max-width: 900px) {
  body.aichat-page .main-content::before {
    font-size: 0 !important;
  }
  body.aichat-page .topbar > .aichat-dialog-toggle {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    left: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    z-index: 131;
  }
  body.aichat-page .topbar > .aichat-dialog-toggle span {
    display: none;
  }
  body.aichat-page.max-input-active .topbar > .aichat-dialog-toggle {
    display: none !important;
  }
}
body.aichat-page .topbar > .aichat-dialog-toggle img {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}

body.aichat-page .main-content::before {
  font-size: 0 !important;
}

body.aichat-page .topbar > .aichat-dialog-toggle {
  background: transparent !important;
  border: 0 !important;
}
body.aichat-page .topbar > .aichat-dialog-toggle img {
  filter: brightness(0) invert(1);
}
body.aichat-page.theme-light .topbar > .aichat-dialog-toggle img {
  filter: none;
}
