/* Prentzas AI — premium chat shell (standalone) */

:root {
  --bg: #212121;
  --bg-sidebar: #171717;
  --bg-elevated: #2f2f2f;
  --bg-composer: #303030;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --bg-active: rgba(255, 255, 255, 0.1);
  --fg: #ececec;
  --fg-soft: #c5c5c5;
  --fg-muted: #8e8e8e;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #3fd0c9;
  --accent-fg: #071012;
  --danger: #ff8f8f;
  --user-bubble: #2f2f2f;
  --font: "DM Sans", system-ui, sans-serif;
  --font-display: "Syne", "DM Sans", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --sidebar-w: 260px;
  --header-h: 52px;
  --col-max: 48rem;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --pad: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --ease: 160ms ease;
  --ease-panel: 260ms cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-soft: 0 8px 28px rgba(0, 0, 0, 0.28);
}

*,
*::before,
*::after { box-sizing: border-box; }

html.ai-html,
body.ai-body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--fg-soft);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* —— App shell —— */
.ai-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  transition: grid-template-columns var(--ease-panel);
}

.ai-app.ai-page--vv-locked {
  height: var(--ai-vv-height, 100dvh);
  max-height: var(--ai-vv-height, 100dvh);
}

.ai-app:not(.ai-app--authed) {
  grid-template-columns: minmax(0, 1fr);
}

.ai-app.ai-app--sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.ai-app.ai-app--sidebar-collapsed .ai-sidebar {
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  border-right-width: 0;
  overflow: hidden;
}

.ai-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  position: relative;
  background: var(--bg);
}

/* —— Sidebar —— */
.ai-sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  min-width: 0;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: width var(--ease-panel), opacity var(--ease-panel), border-color var(--ease);
  z-index: 40;
}

.ai-sidebar[hidden] { display: none !important; }

.ai-sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 12px 10px;
  flex-shrink: 0;
}

.ai-sidebar__brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--fg);
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  flex: 1;
}

.ai-sidebar__brand-link img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.ai-sidebar__brand-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-soft);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--ease), color var(--ease);
}

.ai-icon-btn:hover,
.ai-icon-btn:focus-visible {
  background: var(--bg-hover);
  color: var(--fg);
  outline: none;
}

.ai-icon-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(63, 208, 201, 0.45);
}

.ai-sidebar__actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 10px 10px;
  flex-shrink: 0;
}

.ai-sidebar__primary {
  appearance: none;
  width: 100%;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font: 600 0.9rem/1.2 var(--font);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background var(--ease), border-color var(--ease);
}

.ai-sidebar__primary:hover,
.ai-sidebar__primary:focus-visible {
  background: var(--bg-hover);
  border-color: rgba(63, 208, 201, 0.35);
  outline: none;
}

.ai-sidebar__nav {
  display: flex;
  gap: 4px;
  padding: 0 10px 8px;
  flex-shrink: 0;
}

.ai-sidebar__nav-btn {
  appearance: none;
  flex: 1;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg-muted);
  font: 600 0.8rem/1.2 var(--font);
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
}

.ai-sidebar__nav-btn:hover,
.ai-sidebar__nav-btn:focus-visible {
  color: var(--fg);
  background: var(--bg-hover);
  outline: none;
}

.ai-sidebar__nav-btn.is-active {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

.ai-sidebar__empty-action {
  appearance: none;
  margin-top: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg);
  font: 600 0.85rem/1.2 var(--font);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.ai-sidebar__empty-action:hover,
.ai-sidebar__empty-action:focus-visible {
  background: var(--bg-hover);
  border-color: rgba(63, 208, 201, 0.35);
  outline: none;
}

.ai-sidebar__search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 10px 8px;
  padding: 0 10px;
  height: 36px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  flex-shrink: 0;
}

.ai-sidebar__search:focus-within {
  border-color: rgba(63, 208, 201, 0.35);
}

.ai-sidebar__search input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--fg);
  font: 400 0.85rem/1.2 var(--font);
  outline: none;
}

.ai-sidebar__search input::placeholder { color: var(--fg-muted); }

.ai-sidebar__list-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 4px 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
}

.ai-sidebar__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.ai-sidebar__section {
  padding: 14px 10px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.ai-sidebar__empty {
  padding: 16px 12px;
  color: var(--fg-muted);
  font-size: 0.88rem;
}

.ai-sidebar__item {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 8px;
  margin: 1px 0;
  position: relative;
}

.ai-sidebar__item.is-active {
  background: var(--bg-active);
}

.ai-sidebar__item:hover {
  background: var(--bg-hover);
}

.ai-sidebar__item-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-soft);
  font: 400 0.88rem/1.25 var(--font);
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-sidebar__item-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-sidebar__badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  color: #8ec8ff;
  border: 1px solid rgba(142, 200, 255, 0.35);
  border-radius: 4px;
  padding: 1px 4px;
}

.ai-sidebar__item-del {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--ease), color var(--ease), background var(--ease);
  flex-shrink: 0;
}

.ai-sidebar__item:hover .ai-sidebar__item-del,
.ai-sidebar__item:focus-within .ai-sidebar__item-del,
.ai-sidebar__item-del:focus-visible {
  opacity: 1;
}

.ai-sidebar__item-del:hover,
.ai-sidebar__item-del:focus-visible {
  color: var(--danger);
  background: rgba(255, 143, 143, 0.1);
  outline: none;
}

.ai-sidebar__foot {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-sidebar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  min-width: 0;
}

.ai-sidebar__avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(63, 208, 201, 0.18);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: 700 0.85rem/1 var(--font-display);
  flex-shrink: 0;
  overflow: hidden;
}

.ai-sidebar__avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ai-sidebar__user-meta {
  min-width: 0;
  flex: 1;
}

.ai-sidebar__user-name {
  display: block;
  color: var(--fg);
  font-weight: 600;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-sidebar__user-sub {
  display: block;
  color: var(--fg-muted);
  font-size: 0.75rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-sidebar__logout {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  font: 500 0.82rem/1 var(--font);
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  text-decoration: none;
  transition: background var(--ease), color var(--ease);
}

.ai-sidebar__logout:hover,
.ai-sidebar__logout:focus-visible {
  background: var(--bg-hover);
  color: var(--fg);
  outline: none;
}

.ai-sidebar__privacy {
  margin: 0;
  padding: 0 10px 4px;
  font-size: 0.7rem;
  color: var(--fg-muted);
  line-height: 1.35;
}

.ai-sidebar-backdrop {
  display: none;
}

/* —— Top bar —— */
.ai-topbar {
  min-height: var(--header-h);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 max(12px, var(--safe-r)) 0 max(12px, var(--safe-l));
  border-bottom: 1px solid transparent;
  flex-shrink: 0;
  background: var(--bg);
  z-index: 20;
  container-type: inline-size;
  container-name: aitopbar;
}

.ai-topbar__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px 14px;
  min-height: var(--header-h);
  width: 100%;
  transition: gap var(--ease-panel);
}

.ai-topbar__left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  justify-self: start;
}

.ai-topbar__right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  justify-self: end;
}

.ai-topbar__group {
  justify-self: center;
  max-width: min(100%, 28rem);
  min-width: 0;
}

.ai-topbar--group-stacked .ai-topbar__row {
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
}

.ai-topbar--group-stacked .ai-topbar__left {
  grid-column: 1;
  grid-row: 1;
}

.ai-topbar--group-stacked .ai-topbar__right {
  grid-column: 2;
  grid-row: 1;
}

.ai-topbar--group-stacked .ai-topbar__group {
  grid-column: 1 / -1;
  grid-row: 2;
  justify-self: stretch;
  max-width: none;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  padding-bottom: 6px;
  animation: ai-header-reflow 220ms ease;
}

@keyframes ai-header-reflow {
  from { opacity: 0.55; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-topbar__model {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--fg);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.ai-topbar__open-sidebar {
  display: none;
}

/* Desktop reopen control — must remain visible whenever the rail is collapsed */
.ai-app.ai-app--authed.ai-app--sidebar-collapsed .ai-topbar__open-sidebar {
  display: inline-flex !important;
  position: relative;
  z-index: 5;
}

.ai-topbar__cta,
.header-cta {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font: 600 0.85rem/1 var(--font);
  text-decoration: none;
  cursor: pointer;
  transition: filter var(--ease);
}

.ai-topbar__cta:hover,
.header-cta:hover {
  filter: brightness(1.05);
}

.ai-topbar__ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-soft);
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  font: 500 0.82rem/1 var(--font);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  transition: background var(--ease), color var(--ease);
}

.ai-topbar__ghost:hover {
  background: var(--bg-hover);
  color: var(--fg);
}

.header-cta__label--short { display: none; }

/* —— Workspace / shell —— */
.ai-workspace {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.ai-shell {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.ai-group-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0;
  flex-shrink: 0;
  min-width: 0;
  width: auto;
  margin: 0;
  border: 0;
}

.ai-group-bar[hidden] { display: none !important; }

.ai-group-bar__meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.ai-group-bar__icon {
  color: var(--fg-muted);
  flex-shrink: 0;
}

.ai-group-bar__title {
  color: var(--fg);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14rem;
}

.ai-group-bar__count {
  color: var(--fg-muted);
  font-size: 0.76rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.ai-group-bar__actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.ai-group-bar__btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-soft);
  border-radius: 8px;
  padding: 6px 10px;
  font: 500 0.78rem/1 var(--font);
  cursor: pointer;
}

.ai-group-bar__btn:hover { background: var(--bg-hover); color: var(--fg); }
.ai-group-bar__btn[hidden] { display: none !important; }

.ai-thread {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.ai-log {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px max(16px, var(--safe-l)) 12px max(16px, var(--safe-r));
  scroll-behavior: auto;
  scrollbar-width: thin;
  scrollbar-color: #3a3a3a transparent;
}

.ai-log__inner {
  width: min(100%, var(--col-max));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100%;
}

.ai-log.is-empty .ai-log__inner {
  justify-content: center;
}

/* Welcome / empty */
.ai-empty {
  text-align: center;
  padding: 24px 8px 8px;
  max-width: 40rem;
  margin: 0 auto;
}

.ai-empty[hidden] { display: none !important; }

.ai-empty__mark,
.ai-empty__fallback {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  margin: 0 auto 16px;
  display: block;
}

.ai-empty__fallback {
  background: rgba(63, 208, 201, 0.14);
  color: var(--accent);
  font: 700 1.4rem/56px var(--font-display);
  text-align: center;
}

.ai-empty h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(1.6rem, 3vw, 2rem);
  letter-spacing: -0.03em;
  color: var(--fg);
}

.ai-empty p {
  margin: 0 0 18px;
  color: var(--fg-muted);
  font-size: 0.95rem;
}

.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ai-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-soft);
  border-radius: 999px;
  padding: 8px 12px;
  font: 500 0.82rem/1.2 var(--font);
  cursor: pointer;
  transition: background var(--ease), border-color var(--ease), color var(--ease);
}

.ai-chip:hover,
.ai-chip:focus-visible {
  background: var(--bg-hover);
  border-color: rgba(63, 208, 201, 0.35);
  color: var(--fg);
  outline: none;
}

/* Messages */
.ai-msg {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}

.ai-msg--user {
  justify-content: flex-end;
}

.ai-msg--assistant {
  justify-content: flex-start;
}

.ai-msg__avatar,
.ai-msg__avatar-fallback {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
}

.ai-msg__avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(63, 208, 201, 0.14);
  color: var(--accent);
  font: 700 0.75rem/1 var(--font-display);
}

.ai-msg--user .ai-msg__avatar,
.ai-msg--user .ai-msg__avatar-fallback,
.ai-msg--user .ai-msg__name { display: none; }

.ai-msg--group-user .ai-msg__name--peer {
  display: block !important;
  text-align: right;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 5px;
  padding-right: 2px;
}

.ai-msg__body {
  min-width: 0;
  max-width: min(70%, 40rem);
}

.ai-msg--group-user .ai-msg__body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.ai-msg--assistant .ai-msg__body {
  max-width: min(100%, var(--col-max));
}

.ai-msg__name {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg-muted);
  margin-bottom: 4px;
}

.ai-msg__bubble {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  color: var(--fg);
  font-size: 0.98rem;
  line-height: 1.65;
}

.ai-msg--user .ai-msg__bubble {
  background: var(--user-bubble);
  border-radius: 22px;
  padding: 10px 16px;
  display: inline-block;
  max-width: 100%;
}

.ai-msg--group-user .ai-msg__bubble {
  background: var(--peer-tint, var(--user-bubble));
}

.ai-msg--assistant .ai-msg__bubble {
  background: transparent;
  padding: 0;
}

.ai-msg__bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-msg__bubble code,
.ai-md-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.ai-md-pre {
  margin: 10px 0;
  border-radius: 12px;
  background: #0f0f0f;
  border: 1px solid var(--line);
  overflow: hidden;
}

.ai-md-pre__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  font-size: 0.72rem;
  color: var(--fg-muted);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.ai-md-pre__copy {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-soft);
  font: 500 0.72rem/1 var(--font);
  cursor: pointer;
  border-radius: 6px;
  padding: 4px 8px;
}

.ai-md-pre__copy:hover { background: var(--bg-hover); color: var(--fg); }

.ai-md-pre pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--fg);
}

.ai-md-pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: inherit;
}

.ai-msg__actions {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--ease);
}

.ai-msg:hover .ai-msg__actions,
.ai-msg:focus-within .ai-msg__actions {
  opacity: 1;
}

.ai-msg__action {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-muted);
  font: 500 0.75rem/1 var(--font);
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.ai-msg__action:hover,
.ai-msg__action:focus-visible {
  background: var(--bg-hover);
  color: var(--fg);
  outline: none;
}

.ai-msg__links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
  font-size: 0.85rem;
}

.ai-msg__links a { color: var(--accent); }

.ai-followups {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ai-status {
  width: min(100%, var(--col-max));
  margin: 0 auto;
  padding: 8px 4px;
  color: var(--fg-muted);
  font-size: 0.9rem;
}

.ai-msg--system {
  justify-content: center;
  width: 100%;
}

.ai-msg--system .ai-msg__body {
  max-width: 100%;
  text-align: center;
}

.ai-msg__system {
  color: var(--fg-muted);
  font-size: 0.78rem;
  line-height: 1.4;
  padding: 2px 8px;
}

.ai-status--error { color: var(--danger); }

.ai-status--typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.ai-status--typing::before {
  content: none;
}

.ai-thinking-dots,
.ai-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
}

.ai-thinking-dots span,
.ai-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--fg-muted);
  opacity: 0.35;
  animation: ai-dot-bounce 1.1s ease-in-out infinite;
}

.ai-thinking-dots span:nth-child(2),
.ai-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.ai-thinking-dots span:nth-child(3),
.ai-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.ai-thinking-dots span {
  background: var(--accent);
}

@keyframes ai-dot-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@keyframes ai-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1); }
}

.ai-typing-line {
  width: min(100%, var(--col-max));
  margin: 0 auto;
  padding: 0 4px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg-muted);
  font-size: 0.82rem;
}

.ai-typing-line[hidden] { display: none !important; }

.ai-scroll-bottom {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  appearance: none;
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  color: var(--fg);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.ai-scroll-bottom.is-visible { display: inline-flex; }

.ai-reveal-skip {
  appearance: none;
  border: 0;
  background: none;
  color: var(--fg-muted);
  font: 500 0.8rem/1 var(--font);
  text-decoration: underline;
  cursor: pointer;
  margin-top: 6px;
  padding: 0;
}

/* —— Composer —— */
.ai-composer-dock {
  flex-shrink: 0;
  width: 100%;
  padding: 8px max(16px, var(--safe-l)) calc(12px + var(--safe-b)) max(16px, var(--safe-r));
  background: linear-gradient(180deg, rgba(33, 33, 33, 0), var(--bg) 28%);
  transition: padding var(--ease-panel);
}

.ai-shell[data-chat-state="empty"] .ai-thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.ai-shell[data-chat-state="empty"] .ai-log {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
}

.ai-shell[data-chat-state="empty"] .ai-log__inner {
  margin-top: auto;
  margin-bottom: auto;
  justify-content: center;
  flex: 0 0 auto;
}

.ai-shell[data-chat-state="empty"] .ai-composer-dock {
  padding-top: 0;
  padding-bottom: calc(16px + var(--safe-b));
  background: transparent;
  flex: 0 0 auto;
}

@media (max-height: 720px) {
  .ai-empty .ai-chips { display: none; }
  .ai-empty p { display: none; }
  .ai-empty h1 { font-size: 1.35rem; margin-bottom: 0; }
  .ai-composer__disclaimer { display: none; }
}

@media (max-height: 560px) {
  .ai-empty__mark,
  .ai-empty__fallback { display: none; }
  .ai-empty { padding-top: 8px; padding-bottom: 4px; }
}

.ai-composer {
  width: min(100%, var(--col-max));
  margin: 0 auto;
  position: relative;
}

.ai-composer__box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-composer);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 14px;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.ai-composer__box:focus-within {
  border-color: rgba(63, 208, 201, 0.35);
  box-shadow: 0 0 0 3px rgba(63, 208, 201, 0.08);
}

.ai-composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--fg);
  font-family: var(--font);
  font-weight: 400;
  font-size: 16px;
  line-height: 1.45;
  max-height: 200px;
  min-height: 24px;
  padding: 8px 0;
  field-sizing: content;
}

.ai-composer textarea::placeholder { color: var(--fg-muted); }

.ai-send {
  appearance: none;
  border: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: filter var(--ease), opacity var(--ease);
}

.ai-send:hover:not(:disabled) { filter: brightness(1.05); }
.ai-send:disabled { opacity: 0.35; cursor: not-allowed; }
.ai-send:focus-visible { outline: 2px solid rgba(63, 208, 201, 0.7); outline-offset: 2px; }

.ai-composer__hint {
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--fg-muted);
  padding: 0 4px;
}

.ai-composer__hint button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--fg-muted);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}

.ai-composer__disclaimer {
  margin: 6px 0 0;
  text-align: center;
  font-size: 0.7rem;
  color: var(--fg-muted);
}

/* Auth gates / modals */
.ai-auth-gate,
.ai-modal {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.ai-auth-gate.is-open,
.ai-modal.is-open {
  opacity: 1;
  pointer-events: auto;
}

.ai-auth-gate.is-closing,
.ai-modal.is-closing {
  opacity: 0;
  pointer-events: none;
}

.ai-auth-gate[hidden],
.ai-modal[hidden] { display: none !important; }

.ai-auth-gate__panel,
.ai-modal__panel {
  width: min(100%, 420px);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow-soft);
  transform: scale(0.97);
  opacity: 0;
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1), opacity 180ms ease;
}

.ai-auth-gate.is-open .ai-auth-gate__panel,
.ai-modal.is-open .ai-modal__panel {
  transform: scale(1);
  opacity: 1;
}

.ai-auth-gate.is-closing .ai-auth-gate__panel,
.ai-modal.is-closing .ai-modal__panel {
  transform: scale(0.97);
  opacity: 0;
}

.ai-auth-gate__panel h2,
.ai-modal__panel h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  color: var(--fg);
  font-size: 1.25rem;
}

.ai-auth-gate__panel p,
.ai-modal__hint {
  margin: 0 0 18px;
  color: var(--fg-soft);
  font-size: 0.92rem;
}

.ai-auth-gate__actions,
.ai-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-auth-gate__primary,
.ai-modal__primary {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  font: 600 0.88rem/1 var(--font);
  padding: 11px 14px;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
}

.ai-auth-gate__secondary,
.ai-modal__secondary {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-soft);
  font: 500 0.88rem/1 var(--font);
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.ai-modal__danger {
  appearance: none;
  border: 1px solid rgba(255, 143, 143, 0.35);
  background: transparent;
  color: var(--danger);
  font: 500 0.88rem/1 var(--font);
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.ai-modal__danger[hidden],
.ai-modal input[hidden] { display: none !important; }

.ai-modal input[type="text"] {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  border-radius: 10px;
  padding: 10px 12px;
  font: 400 0.92rem/1.3 var(--font);
}

.ai-member-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  max-height: 240px;
  overflow: auto;
}

.ai-member-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--fg-soft);
  font-size: 0.9rem;
}

.ai-member-list em {
  color: var(--fg-muted);
  font-style: normal;
  font-size: 0.78rem;
}

.ai-banner-error {
  margin: 8px 16px 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 143, 143, 0.1);
  border: 1px solid rgba(255, 143, 143, 0.25);
  color: var(--danger);
  font-size: 0.85rem;
  display: none;
}

.ai-banner-error.is-visible { display: block; }

/* Legacy class bridges used by PHP/JS */
.ai-nav { display: contents; }
.ai-nav__left, .ai-nav__links, .ai-layout { display: contents; }
.ai-history-toggle { /* mapped to icon btn */ }
.ai-page { /* obsolete wrapper name kept via ai-app */ }

.ai-invite-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.ai-invite-brand {
  font-family: var(--font-display);
  font-weight: 800;
  color: var(--fg);
  text-decoration: none;
  margin-bottom: 20px;
}

/* —— Responsive —— */
@media (max-width: 1024px) {
  .ai-app.ai-app--authed {
    grid-template-columns: minmax(0, 1fr);
  }

  .ai-app.ai-app--authed .ai-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(85vw, 300px);
    transform: translateX(-105%);
    opacity: 1;
    pointer-events: auto;
    transition: transform var(--ease-panel);
    box-shadow: var(--shadow-soft);
  }

  .ai-app.ai-app--authed.ai-sidebar-open .ai-sidebar {
    transform: translateX(0);
  }

  .ai-app.ai-app--authed .ai-sidebar[hidden] {
    display: flex !important;
    transform: translateX(-105%);
  }

  .ai-app.ai-app--authed.ai-sidebar-open .ai-sidebar[hidden] {
    display: flex !important;
    transform: translateX(0);
  }

  .ai-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--ease-panel);
  }

  .ai-sidebar-backdrop:not([hidden]) {
    opacity: 1;
    pointer-events: auto;
  }

  .ai-topbar__open-sidebar {
    display: inline-flex !important;
  }

  .ai-sidebar__close-mobile { display: inline-flex; }
}

@media (min-width: 1025px) {
  .ai-sidebar__close-mobile { display: none; }
  .ai-sidebar-backdrop { display: none !important; }
}

@media (max-width: 768px) {
  .ai-msg__body { max-width: 85%; }
  .ai-msg--assistant .ai-msg__body { max-width: 100%; }
  .ai-msg__actions { opacity: 1; }
  .ai-composer textarea { font-size: 16px; }
  .header-cta__label--full { display: none; }
  .header-cta__label--short { display: inline; }
  .ai-empty h1 { font-size: 1.45rem; }
}

@media (max-width: 520px) {
  .ai-composer__hint span { display: none; }
  .ai-topbar__model { font-size: 0.88rem; }
}

/* Mentions */
.ai-mention-popup {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 12;
  width: min(100%, 280px);
  max-height: 180px;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-soft);
  padding: 4px;
}

.ai-mention-popup[hidden] { display: none !important; }

.ai-mention-item {
  appearance: none;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--fg);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  font: 500 0.9rem/1.2 var(--font);
  cursor: pointer;
}

.ai-mention-item:hover,
.ai-mention-item.is-active {
  background: var(--bg-hover);
}

.ai-mention-item__hint {
  display: block;
  margin-top: 2px;
  color: var(--fg-muted);
  font: 400 0.75rem/1.2 var(--font);
}

/* Join welcome */
.ai-join-welcome {
  width: min(100%, var(--col-max));
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg-soft);
  font-size: 0.9rem;
  min-height: 28px;
  pointer-events: none;
}

.ai-join-welcome[hidden] { display: none !important; }

.ai-join-welcome__plane {
  display: inline-flex;
  color: var(--accent);
  transform: translate(0, -18px) rotate(-18deg);
  opacity: 0;
}

.ai-join-welcome.is-playing .ai-join-welcome__plane {
  animation: ai-plane-in 820ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.ai-join-welcome__text {
  opacity: 0;
  transform: translateY(4px);
}

.ai-join-welcome.is-playing .ai-join-welcome__text {
  animation: ai-fade-up 420ms ease 280ms forwards;
}

@keyframes ai-plane-in {
  0% { opacity: 0; transform: translate(36px, -28px) rotate(-28deg); }
  60% { opacity: 1; }
  100% { opacity: 1; transform: translate(0, 0) rotate(0deg); }
}

@keyframes ai-fade-up {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-keyboard-open .ai-composer-dock {
  padding-bottom: max(8px, var(--safe-b));
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .ai-thinking-dots span,
  .ai-typing-dots span { animation: none; opacity: 0.75; }
  .ai-join-welcome__plane,
  .ai-join-welcome__text {
    opacity: 1;
    transform: none;
  }
  .ai-topbar--group-stacked .ai-topbar__group { animation: none; }
  .ai-auth-gate__panel,
  .ai-modal__panel,
  .ai-auth-gate,
  .ai-modal { transition: none; transform: none; }
}
