:root {
  --bg: #f6f7fb;
  --bg-2: #ffffff;
  --bg-3: #eef0f7;
  --ink: #1a1b2e;
  --muted: #6b7080;
  --line: #e4e6f0;
  --accent: #7c3aed;
  --accent-2: #d946ef;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Syne", system-ui, sans-serif;
  --sidebar-w: 260px;
}

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

html {
  height: 100%;
  overflow: hidden;
}

html, body { height: 100%; }

body.chat-body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg);
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: inherit; text-decoration: none; }

.chat-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.chat-app.is-settings-open {
  grid-template-columns: 1fr;
}

.chat-app.is-settings-open .chat-sidebar {
  display: none;
}

.chat-sidebar {
  display: flex;
  flex-direction: column;
  min-width: var(--sidebar-w);
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg-2);
}

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

.chat-sidebar__brand {
  display: flex;
  align-items: center;
  padding: 16px 16px 8px;
}

.chat-logo__img {
  display: block;
  height: 28px;
  width: auto;
}

.chat-sidebar__top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 12px;
}

.chat-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.22);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.chat-new-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(124, 58, 237, 0.28);
}

.chat-icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
}

.chat-icon-btn:hover { background: var(--bg-3); color: var(--ink); }

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
}

.chat-list__empty {
  margin: 24px 12px;
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
  color: var(--muted);
}

.chat-list__empty[hidden] {
  display: none !important;
}

.chat-list__item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.85rem;
  text-align: left;
  color: var(--muted);
  border-radius: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-list__item:hover { background: var(--bg-3); color: var(--ink); }
.chat-list__item.is-active { background: var(--bg-3); color: var(--ink); }

.chat-list__row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
}

.chat-list__row:hover,
.chat-list__row.is-active,
.chat-list__row.is-menu-open {
  background: var(--bg-3);
}

.chat-list__row.is-active .chat-list__item,
.chat-list__row:hover .chat-list__item,
.chat-list__row.is-menu-open .chat-list__item {
  color: var(--ink);
}

.chat-list__row .chat-list__item {
  flex: 1;
  min-width: 0;
  background: transparent;
}

.chat-list__row .chat-list__item:hover {
  background: transparent;
}

.chat-list__menu-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-list__menu-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-right: 4px;
  color: var(--muted);
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.chat-list__row:hover .chat-list__menu-btn,
.chat-list__row.is-menu-open .chat-list__menu-btn,
.chat-list__menu-btn:focus-visible {
  opacity: 1;
}

.chat-list__menu-btn:hover,
.chat-list__menu-btn[aria-expanded="true"] {
  background: var(--bg);
  color: var(--ink);
}

.chat-list__dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 50;
  min-width: 168px;
  padding: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 44px rgba(26, 27, 46, 0.18);
}

.chat-list__dropdown[hidden] {
  display: none !important;
}

.chat-list__dropdown-item {
  display: block;
  width: 100%;
  padding: 9px 12px;
  font-size: 0.85rem;
  text-align: left;
  color: var(--ink);
  border-radius: 7px;
  transition: background 0.15s;
}

.chat-list__dropdown-item:hover {
  background: var(--bg-3);
}

.chat-list__dropdown-item--danger {
  color: #f87171;
}

.chat-list__dropdown-item--danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.chat-list__rename {
  flex: 1;
  min-width: 0;
  margin: 4px 0 4px 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--accent-2);
  border-radius: 8px;
}

.chat-list__rename:focus {
  outline: none;
}

@media (hover: none) {
  .chat-list__menu-btn {
    opacity: 1;
  }
}

/* Chat persona modes */
.mode-modal[hidden] {
  display: none !important;
}

.mode-modal {
  position: fixed;
  inset: 0;
  z-index: 250;
  display: grid;
  place-items: center;
  padding: 20px;
}

.mode-modal__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  cursor: default;
}

.mode-modal__panel {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(90vh, 720px);
  overflow-y: auto;
  padding: 24px 22px 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
}

.mode-modal__title {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 800;
}

.mode-modal__hint {
  margin: 0 0 18px;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 14px 14px 12px;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.mode-card:hover,
.mode-card:focus-visible {
  border-color: var(--mode-color, var(--accent-2));
  background: var(--bg-3);
  outline: none;
  transform: translateY(-1px);
}

.mode-card__label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.mode-card__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mode-color, var(--muted));
  flex-shrink: 0;
}

.mode-card__desc {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.chat-list__item-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
  width: 100%;
}

.chat-list__title {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-mode-badge {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--mode-color, var(--muted));
  background: color-mix(in srgb, var(--mode-color, #9b9b9b) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--mode-color, #9b9b9b) 35%, transparent);
  border-radius: 999px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 560px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-header__left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.chat-header__right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.chat-support-btn {
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}

.chat-support-btn:hover {
  background: var(--bg-3);
  border-color: #3f3f3f;
}

.chat-sidebar__profile {
  flex-shrink: 0;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.profile-row {
  position: relative;
}

.profile-row__main {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 14px;
  text-align: left;
  transition: background 0.15s;
}

.profile-row__main:hover,
.profile-row.is-open .profile-row__main {
  background: var(--bg-3);
}

.profile-row__avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 50%;
}

.profile-row__text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.profile-row__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

.profile-row__topup {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
  color: var(--muted);
  transition: color 0.15s;
}

.profile-row__main:hover .profile-row__topup {
  color: var(--accent);
}

.profile-row__chevron {
  flex-shrink: 0;
  color: var(--muted);
}

.profile-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 12px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.22);
  transition: transform 0.15s, box-shadow 0.15s;
}

.profile-login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(124, 58, 237, 0.28);
}

.profile-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 120;
  padding: 6px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 16px 44px rgba(26, 27, 46, 0.18);
}

.profile-dropdown[hidden] {
  display: none !important;
}

.profile-dropdown__item {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font-size: 0.9rem;
  text-align: left;
  color: var(--ink);
  border-radius: 8px;
  transition: background 0.15s;
  text-decoration: none;
}

.profile-dropdown__item:hover {
  background: var(--bg-3);
}

.profile-dropdown__item--danger {
  color: #f87171;
}

.profile-dropdown__item--danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.chat-view[hidden],
.chat-settings[hidden] {
  display: none !important;
}

.chat-settings {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 40px;
}

.chat-settings__inner {
  max-width: 560px;
  margin: 0 auto;
}

.chat-settings__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  padding: 6px 10px 6px 4px;
  font-size: 0.88rem;
  color: var(--muted);
  border-radius: 8px;
  text-decoration: none;
}

.chat-settings__back:hover {
  color: var(--ink);
  background: var(--bg-3);
}

.chat-settings__title {
  margin: 0 0 24px;
  font-family: var(--display);
  font-size: 1.6rem;
  font-weight: 800;
}

.settings-card {
  margin-bottom: 16px;
  padding: 18px 20px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.settings-card__title {
  margin: 0 0 14px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-list {
  margin: 0;
}

.settings-list__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.settings-list__row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-list__row dt {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.settings-list__row dd {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

.settings-limits {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.settings-limit {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
}

.settings-limit strong {
  color: var(--ink);
  font-weight: 600;
}

.settings-limit--pro span {
  color: var(--accent-2);
}

.settings-upgrade {
  display: inline-flex;
  justify-content: center;
  margin-top: 16px;
  text-decoration: none;
}

.settings-upgrade[hidden] {
  display: none !important;
}

.settings-note {
  margin: 14px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.45;
}

.chat-usage-wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.chat-usage {
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.chat-usage.is-exhausted {
  color: #f0a8a8;
  border-color: rgba(240, 168, 168, 0.35);
}

.chat-usage.is-pro {
  color: var(--accent-2);
  border-color: rgba(139, 92, 246, 0.35);
}

.chat-usage--tokens {
  font-variant-numeric: tabular-nums;
}

.chat-auth-btn {
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  background: #fff;
  color: #111;
  border-radius: 999px;
}

.chat-auth-btn:hover { opacity: 0.9; }

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 24px 20px 16px;
}

.chat-messages:not(:has(.msg)) {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.chat-empty {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px;
  text-align: center;
}

.chat-empty h1 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 800;
}

.chat-empty p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.msg {
  max-width: 720px;
  margin: 0 auto 20px;
  line-height: 1.55;
}

.msg--user {
  padding: 14px 16px;
  background: var(--bg-3);
  border-radius: 12px;
  border: 1px solid var(--line);
}

.msg--assistant {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  color: var(--ink);
}

.msg__body {
  white-space: pre-wrap;
  word-break: break-word;
}

.msg__body--preview {
  position: relative;
}

.msg__preview-text {
  white-space: pre-wrap;
}

.msg__preview-hidden {
  display: inline;
  filter: blur(4px);
  opacity: 0.42;
  user-select: none;
  pointer-events: none;
}

.msg--assistant .msg__preview-cta {
  margin-top: 12px;
  color: #34d399;
  font-weight: 600;
}

.msg--assistant .msg__preview-cta-link {
  color: #6ee7b7;
  text-decoration: underline;
  cursor: pointer;
}

.msg--assistant .msg__preview-cta-link:hover,
.msg--assistant .msg__preview-cta-link:focus-visible {
  color: #a7f3d0;
  outline: none;
}

.msg-copy {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  color: var(--muted);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.msg-copy:hover,
.msg-copy:focus-visible {
  color: var(--ink);
  background: var(--bg-2);
  border-color: #3f3f3f;
  outline: none;
}

.msg-copy.is-copied {
  color: var(--accent-2);
  border-color: rgba(139, 92, 246, 0.45);
}

.msg-copy__tip {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  pointer-events: none;
  z-index: 2;
}

.msg-copy:hover .msg-copy__tip,
.msg-copy:focus-visible .msg-copy__tip,
.msg-copy.is-copied .msg-copy__tip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.msg__attach {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 4px 8px;
  font-size: 0.78rem;
  color: var(--accent-2);
  background: rgba(124, 58, 237, 0.15);
  border-radius: 6px;
}

.msg--thinking {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: var(--accent-2);
  border-radius: 50%;
  animation: dot 1.2s ease-in-out infinite;
}

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

@keyframes dot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.85); }
  40% { opacity: 1; transform: scale(1); }
}

.chat-composer-wrap {
  flex-shrink: 0;
  padding: 12px 20px max(20px, env(safe-area-inset-bottom));
}

.chat-pin {
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg-2);
  border: 1px solid var(--accent, #7c6cff);
  border-radius: 10px;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent, #7c6cff) 30%, transparent);
}

.chat-pin:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-pin__thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  border: 1px solid var(--line);
}

.chat-composer-wrap.is-dragover .chat-composer {
  border-color: var(--accent, #7c6cff);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #7c6cff) 25%, transparent);
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(26, 27, 46, 0.08);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 12px 34px rgba(124, 58, 237, 0.14);
}

.chat-composer textarea {
  flex: 1;
  min-height: 64px;
  max-height: 200px;
  resize: none;
  border: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.5;
  padding: 10px 4px;
}

.chat-composer textarea:focus { outline: none; }

.chat-type {
  display: inline-flex;
  flex-shrink: 0;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.chat-type__btn {
  padding: 5px 8px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  white-space: nowrap;
}

.chat-type__btn.is-active {
  color: var(--ink);
  background: rgba(139, 92, 246, 0.18);
}

.msg__image {
  display: block;
  max-width: min(100%, 420px);
  border-radius: 12px;
  margin-top: 4px;
  border: 1px solid var(--line);
}

.msg-image {
  position: relative;
  display: inline-block;
  max-width: min(100%, 420px);
}

.msg-image .msg__image {
  margin-top: 0;
  width: 100%;
  cursor: zoom-in;
}

.msg-image__actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg-image:hover .msg-image__actions,
.msg-image:focus-within .msg-image__actions {
  opacity: 1;
}

@media (hover: none) {
  .msg-image__actions {
    opacity: 1;
  }
}

.msg-image__btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--ink);
  background: rgba(13, 13, 13, 0.82);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(6px);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.msg-image__btn:hover,
.msg-image__btn:focus-visible {
  background: var(--bg-2);
  border-color: #3f3f3f;
  outline: none;
}

.image-lightbox[hidden] {
  display: none !important;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 20px;
}

.image-lightbox__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  border: none;
  cursor: zoom-out;
}

.image-lightbox__dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: min(96vw, 1100px);
  max-height: 94vh;
}

.image-lightbox__close {
  position: absolute;
  top: -44px;
  right: 0;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  transition: background 0.15s;
}

.image-lightbox__close:hover {
  background: rgba(255, 255, 255, 0.18);
}

.image-lightbox__img {
  display: block;
  max-width: 100%;
  max-height: calc(94vh - 56px);
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  object-fit: contain;
}

.image-lightbox__bar {
  display: flex;
  justify-content: center;
}

.image-lightbox__download {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  transition: background 0.15s;
}

.image-lightbox__download:hover {
  background: rgba(255, 255, 255, 0.18);
}

.chat-send-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.28);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.chat-send-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(124, 58, 237, 0.34);
}

.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Modals */
.auth-switch[hidden] {
  display: none;
}

.modal--locked .modal__close {
  display: none;
}

.modal--locked .modal__backdrop {
  cursor: default;
}

.modal[hidden] { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.modal__panel {
  position: relative;
  width: min(420px, 100%);
  padding: 28px 24px 24px;
  background: #fff;
  color: #111;
  border: 2px solid #0a0a0f;
  box-shadow: 8px 8px 0 #4c1d95;
}

.modal__panel--sm { width: min(380px, 100%); }

.modal__panel h2 {
  margin: 0 0 16px;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 800;
}

.modal__close {
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 1.5rem;
  line-height: 1;
  color: #666;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
  border: 2px solid #e8e4f0;
}

.auth-tabs__item {
  flex: 1;
  padding: 10px 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
  background: #fafafa;
  border-right: 2px solid #e8e4f0;
}

.auth-tabs__item:last-child { border-right: none; }
.auth-tabs__item.is-active { background: linear-gradient(128deg, #4c1d95, #7c3aed); color: #fff; }
.auth-tabs__item:disabled { opacity: 0.55; cursor: not-allowed; }

.auth-soon {
  margin: 0 0 16px;
  font-size: 0.75rem;
  color: #888;
}

.auth-subtitle {
  margin: 0 0 18px;
  font-size: 0.9rem;
  line-height: 1.4;
  color: #6b6b80;
}

.auth-sso__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  margin-bottom: 4px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.auth-sso__btn--yandex {
  color: #fff;
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
}

.auth-sso__btn--yandex:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}

.auth-sso__btn--vk {
  color: #fff;
  background: linear-gradient(128deg, #0a6eff, #2f7bff);
  border: 1px solid rgba(17, 107, 245, 0.6);
}

.auth-sso__btn--vk:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(47, 123, 255, 0.28);
}

.auth-sso__icon {
  display: block;
  width: auto;
  height: 22px;
}

.auth-sso__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 14px 0 16px;
  font-size: 0.75rem;
  color: #999;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #e8e4f0;
}

.auth-divider span {
  flex-shrink: 0;
}

.auth-form label {
  display: block;
  margin-bottom: 14px;
}

.auth-form label span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #555;
}

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  border: 2px solid #e8e4f0;
  border-radius: 0;
}

.auth-form input:focus {
  outline: 2px solid #7c3aed;
  outline-offset: -2px;
}

.auth-error {
  margin: 0 0 12px;
  font-size: 0.85rem;
  color: #b91c1c;
}

.auth-switch {
  margin: 16px 0 0;
  text-align: center;
  font-size: 0.85rem;
}

.auth-switch button {
  color: #5b21b6;
  text-decoration: underline;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 2px solid transparent;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(128deg, #4c1d95, #7c3aed);
  color: #fff;
  border-color: #4c1d95;
}

.btn-outline {
  background: #fff;
  color: #111;
  border-color: #0a0a0f;
}

.btn-block { width: 100%; }

.paywall-features {
  margin: 0 0 20px;
  padding-left: 18px;
  color: #444;
  font-size: 0.9rem;
}

.paywall-features li { margin-bottom: 6px; }

.paywall-topup-balance {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: var(--accent-2);
}

.paywall-error {
  margin: 0 0 12px;
  font-size: 0.88rem;
  color: #f0a8a8;
}

.profile-plan { margin: 0 0 20px; color: #666; font-size: 0.9rem; }

@media (max-width: 768px) {
  .chat-app {
    grid-template-columns: 92px 1fr;
  }

  :root {
    --sidebar-w: 92px;
  }

  .chat-sidebar__brand {
    justify-content: center;
    padding: 12px 8px 6px;
  }

  .chat-logo__img {
    height: 22px;
  }

  .chat-new-btn {
    padding: 10px;
    font-size: 0;
    gap: 0;
  }

  .chat-list__empty {
    font-size: 0.7rem;
    margin: 16px 6px;
  }

  .profile-row__text,
  .profile-row__chevron {
    display: none;
  }

  .profile-row__main {
    justify-content: center;
    padding: 6px;
  }

  .profile-dropdown {
    left: -8px;
    right: auto;
    min-width: 180px;
  }

  .chat-type__btn {
    padding: 4px 6px;
    font-size: 0.62rem;
  }

  .chat-composer-wrap {
    padding: 10px 12px max(16px, env(safe-area-inset-bottom));
  }

  .chat-composer {
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
  }

  .chat-composer textarea {
    min-width: 0;
    width: 100%;
    min-height: 52px;
    font-size: 1rem;
  }

  .chat-header {
    padding: 10px 12px;
    gap: 8px;
  }

  .chat-header__left {
    min-width: 0;
  }

  .chat-header__right {
    gap: 6px;
    min-width: 0;
  }

  .chat-usage {
    font-size: 0.72rem;
    padding: 4px 8px;
  }
}

/* ==== Image chat messages (PixGPT) ==== */
.msg {
  display: flex;
  margin: 14px 0;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  padding: 0 16px;
}
.msg--user {
  justify-content: flex-end;
}
.msg__bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 12px 16px;
  border-radius: 18px 18px 4px 18px;
  max-width: 80%;
  line-height: 1.45;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.22);
  white-space: pre-wrap;
  word-break: break-word;
}
.msg--assistant {
  justify-content: flex-start;
}
.msg__image {
  position: relative;
  width: 320px;
  max-width: 78%;
  aspect-ratio: 1 / 1;
  border-radius: 20px;
  overflow: hidden;
  background: var(--bg-3);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgba(26, 27, 46, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg__image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}
.msg__image--loading {
  flex-direction: column;
  gap: 12px;
  color: var(--muted);
}
.msg__spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(124, 58, 237, 0.2);
  border-top-color: var(--accent);
  animation: pixspin 0.8s linear infinite;
}
@keyframes pixspin {
  to { transform: rotate(360deg); }
}
.msg__loading-text {
  font-size: 0.85rem;
}
.msg__error {
  background: #fff0f2;
  color: #c02b4a;
  border: 1px solid #ffd4dc;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.9rem;
}
.msg__image--teaser {
  color: #fff;
}
.msg__teaser-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Frost strong enough to hide detail, light enough to keep silhouettes. */
  filter: blur(12px) saturate(1.05);
  transform: scale(1.1);
}
.msg__teaser-blur {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 30%, #ffd27d, transparent 45%),
    radial-gradient(circle at 70% 40%, #ff7eb3, transparent 45%),
    radial-gradient(circle at 50% 75%, #7c5cff, transparent 50%),
    linear-gradient(135deg, #8b5cf6, #d946ef);
  /* Light frost only — server already blurs; keep the subject recognizable. */
  filter: blur(6px) saturate(1.05);
  transform: scale(1.08);
}
.msg__teaser-overlay {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: rgba(20, 12, 40, 0.18);
  width: 100%;
  height: 100%;
  justify-content: center;
}
.msg__teaser-overlay p {
  margin: 0;
  font-weight: 600;
  line-height: 1.4;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
}
.msg__teaser-btn {
  margin-top: 4px;
  border: none;
  cursor: pointer;
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent);
  background: #fff;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}
.msg__teaser-btn:hover {
  transform: translateY(-1px);
}
.chat-usage {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 6px 12px;
  background: var(--bg-3);
  border-radius: 999px;
}
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-lightbox[hidden] { display: none; }
.image-lightbox__backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(15, 12, 30, 0.72);
  backdrop-filter: blur(4px);
}
.image-lightbox__dialog {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 88vh;
}
.image-lightbox__img {
  max-width: 90vw;
  max-height: 88vh;
  border-radius: 16px;
  display: block;
}
.image-lightbox__close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* ==== Image editing: attach button + attachment chip ==== */
.chat-attach-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  color: var(--muted);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.chat-attach-btn:hover {
  background: var(--bg-3);
  color: var(--accent);
}

.chat-pin__caption {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-pin__mode {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent, #7c6cff);
}

.chat-pin__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.chat-pin__remove {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--muted);
  border-radius: 50%;
  transition: background 0.15s, color 0.15s;
}

.chat-pin__remove:hover {
  background: var(--bg-3);
  color: #c02b4a;
}

/* Изображение-источник, помеченное как «редактируется». */
.msg--editing .msg__image {
  outline: 2px solid var(--accent, #7c6cff);
  outline-offset: 2px;
  border-radius: 14px;
}

.msg--editing .msg__image-wrap {
  position: relative;
}

.msg--editing .msg__image-wrap::before {
  content: 'редактируется';
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 2;
  padding: 3px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #fff;
  background: var(--accent, #7c6cff);
  border-radius: 999px;
  pointer-events: none;
}

/* ==== Assistant image action toolbar (edit / remove bg) ==== */
.msg__image-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.msg__img-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg__img-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.msg__img-action:hover {
  background: var(--bg-3);
  border-color: var(--accent-2);
  color: var(--accent);
}

.msg__img-action svg {
  flex-shrink: 0;
}

.msg__edit-hint {
  max-width: 720px;
  margin: -4px auto 8px;
  padding: 0 16px;
  font-size: 0.8rem;
  color: var(--accent);
}

