.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.btn-primary {
  border: none;
  background: #ffffff;
  color: #171922;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.028);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover:not(:disabled),
.btn-ghost:hover:not(:disabled) {
  transform: scale(0.99);
  opacity: 0.95;
}

.btn-primary:active:not(:disabled),
.btn-ghost:active:not(:disabled) {
  transform: scale(0.97);
}

/* Figma Close S (4510:52535) drawn with CSS: 24px, radius 6, white 3% fill, white 6%
   stroke, and the 8.9px X glyph export inside. One hover for every close control. */
.nf-close-button {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  color: #fff;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: background-color 140ms ease, border-color 140ms ease, transform 120ms ease;
}
.nf-close-button img {
  width: 8.9178px;
  height: 8.9178px;
  display: block;
}
@media (hover: hover) and (pointer: fine) {
  .nf-close-button:hover,
  .history-return:hover .nf-close-button {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.14);
  }
}
.nf-close-button:active,
.history-return:active .nf-close-button {
  background: rgba(255, 255, 255, 0.14);
  transform: scale(0.94);
}
.nf-close-button:focus-visible {
  outline: 1px solid var(--nf-color-accent);
  outline-offset: 2px;
}

/* UI icons are not drag sources (drag-guard.js backs this up for Firefox). Content
   images in messages, the image viewer and Assets keep the native drag. */
img:not(.message-content img):not(.message-image img):not(.image-preview-card img):not(.image-generation-detail img):not(#assets img),
svg {
  -webkit-user-drag: none;
  user-select: none;
}

/* Shared disabled look for primary actions (Figma: 40% opacity). `.is-disabled` keeps the
   control focusable and tappable so it can explain why it does nothing. */
.nf-modal__button:disabled,
.history-edit-chip:disabled,
.project-sheet-confirm:disabled,
.project-sheet-confirm.is-disabled,
.start-chat-card:disabled,
.start-chat-card.is-disabled {
  opacity: 0.4;
  cursor: default;
}
.project-sheet-confirm.is-disabled:active,
.start-chat-card.is-disabled:active {
  box-shadow: none;
  transform: none;
}

.grid {
  display: grid;
  gap: 12px;
}

input,
textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-primary);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(7, 9, 14, 0.54);
  z-index: 40;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: rgba(24, 27, 36, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-desc {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Shared visual primitives. Domain modules keep their own state and mutations. */
.app-icon-button {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: var(--nf-color-text);
  background: transparent;
  cursor: pointer;
  transition:
    background-color 140ms ease,
    transform var(--nf-press-duration, 140ms) var(--nf-press-ease, cubic-bezier(0.22, 1, 0.36, 1));
}

/* Button contract: hover tint for mouse only, open state tinted everywhere,
   press squeezes like every other button. */
.app-icon-button[aria-expanded="true"],
.app-icon-button.is-active {
  background: var(--nf-alpha-white-12);
}

.app-icon-button:active {
  transform: scale(var(--nf-press-scale, 0.96));
}

@media (hover: hover) and (pointer: fine) {
  .app-icon-button:hover {
    background: var(--nf-alpha-white-12);
  }
}

/* Internal page/header navigation. The 40px target owns no paint; the visible
   24px surface matches the Chat <-> History controls. */
.app-header-nav-control {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  color: var(--nf-color-text);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.app-header-nav-control--leading {
  margin-left: -8px;
}

.app-header-nav-control::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 10px;
  background: transparent;
  pointer-events: none;
  transition: background-color var(--nf-motion-interaction-fast) ease;
}

.app-header-nav-control:visited,
.app-header-nav-control:hover,
.app-header-nav-control:focus-visible,
.app-header-nav-control:active {
  color: var(--nf-color-text);
  background: transparent;
  outline: none;
  opacity: 1;
  transform: none;
  text-decoration: none;
}

.app-header-nav-control:focus-visible::before {
  box-shadow: 0 0 0 1px var(--nf-alpha-white-46);
}

.app-header-nav-control:active::before {
  background: var(--nf-alpha-white-12);
}

@media (hover: hover) and (pointer: fine) {
  .app-header-nav-control:hover::before {
    background: var(--nf-alpha-white-12);
  }
}

.app-header-nav-control > :is(svg, img) {
  position: relative;
  z-index: 1;
  display: block;
  pointer-events: none;
}

body.tg-native-back-active [data-app-back]:not([data-native-back-persistent]) {
  display: none !important;
}

.app-action-menu {
  --app-action-menu-width: 205px;
  --app-action-menu-row-height: 44px;
  position: fixed;
  z-index: var(--nf-layer-action-menu, 2147482900);
  left: var(--app-action-menu-left, 16px);
  top: var(--app-action-menu-top, 64px);
  width: var(--app-action-menu-width);
  max-width: calc(100vw - 32px);
  display: grid;
  grid-auto-rows: var(--app-action-menu-row-height);
  gap: 0;
  padding: 12px 8px;
  border: 0;
  border-radius: 13px;
  color: var(--nf-color-text);
  background: var(--nf-action-menu-background);
  box-shadow: 0 18px 21px rgba(0, 0, 0, .45);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(.96);
  transform-origin: top right;
  transition: opacity 120ms ease, transform 120ms cubic-bezier(.22, 1, .36, 1), visibility 0s linear 120ms;
}

.app-action-menu.is-drop-up { transform-origin: bottom right; }
.app-action-menu.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1);
  transition-delay: 0s;
}

.app-action-menu__item {
  position: relative;
  isolation: isolate;
  min-width: 0;
  height: var(--app-action-menu-row-height);
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  border: 0;
  border-radius: 9px;
  color: var(--nf-color-text);
  background: transparent;
  text-align: left;
  white-space: nowrap;
  font: var(--nf-weight-medium) 14px/20px var(--nf-font-ui);
  cursor: pointer;
}

.app-action-menu__item::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 2px 0;
  border-radius: 9px;
  background: transparent;
  pointer-events: none;
  transition: background-color 120ms ease;
}

.app-action-menu__item > * { position: relative; z-index: 1; }
.app-action-menu__item:focus-visible::before,
.app-action-menu__item:active::before { background: var(--nf-alpha-white-12); }
@media (hover: hover) and (pointer: fine) {
  .app-action-menu__item:hover::before { background: var(--nf-alpha-white-12); }
}
.app-action-menu__item--danger { color: var(--nf-action-menu-danger-text); }
.app-action-menu__icon,
.app-action-menu__icon img {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  object-fit: none;
}

/* App bottom sheets (payment success, out of credits) */
.app-bottom-sheet-modal {
  --app-sheet-motion: 0.16s;
  --app-sheet-ease: cubic-bezier(0.22, 1, 0.36, 1);
  position: fixed;
  inset: 0;
  z-index: var(--nf-layer-sheet, 2147483001);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  background: rgba(5, 6, 10, 0);
  transition: opacity var(--app-sheet-motion) var(--app-sheet-ease),
    background var(--app-sheet-motion) var(--app-sheet-ease),
    visibility 0s linear var(--app-sheet-motion);
}

.app-sheet {
  min-height: 0;
  max-height: min(78dvh, 620px);
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--nf-alpha-white-07);
  border-bottom: 0;
  color: var(--nf-color-text);
  background: var(--nf-action-menu-background);
  overflow-y: auto;
}

.app-sheet__handle {
  width: 36px;
  height: 4px;
  margin: 0 auto 14px;
  border-radius: var(--nf-radius-pill);
  background: var(--nf-alpha-white-16);
}

.app-sheet__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.app-sheet__header h3 { margin: 0; font: var(--nf-weight-bold) 18px/24px var(--nf-font-ui); }
.app-sheet__header p { margin: 4px 0 0; color: var(--nf-color-text-muted); font: 13px/18px var(--nf-font-ui); }
.app-sheet__close { width: 32px; height: 32px; border: 0; border-radius: 9px; color: var(--nf-color-text); background: var(--nf-alpha-white-07); font-size: 24px; line-height: 1; }
.app-sheet__label { display: block; margin: 18px 0 6px; color: var(--nf-color-text-muted); font: 12px/16px var(--nf-font-ui); }
.app-sheet__input { width: 100%; height: 46px; padding: 0 14px; border: 1px solid var(--nf-alpha-white-07); border-radius: var(--nf-radius-md); outline: 0; color: var(--nf-color-text); background: var(--nf-control-background); font: 14px/18px var(--nf-font-ui); }
.app-sheet__input:focus { border-color: var(--nf-color-accent); }
.app-sheet__error { margin: 8px 0 0; color: #ff8b8b; font: 12px/16px var(--nf-font-ui); }
.app-sheet__actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.app-sheet__button { height: 46px; border: 0; border-radius: var(--nf-radius-md); color: var(--nf-color-text); background: var(--nf-alpha-white-07); font: var(--nf-weight-bold) 14px/18px var(--nf-font-ui); }
.app-sheet__button.primary { color: var(--nf-color-action-text); background: var(--nf-color-action); }
.app-sheet__button.danger { background: var(--nf-danger-action-background); }
.app-sheet__button:active { box-shadow: inset 0 0 0 999px rgba(0, 0, 0, .08); }

.app-bottom-sheet-modal.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  background: rgba(5, 6, 10, 0.68);
  transition-delay: 0s;
}

.app-bottom-sheet {
  position: relative;
  width: 100%;
  max-width: 420px;
  min-height: 228px;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  overflow: hidden;
  color: var(--tg-theme-text-color, #ffffff);
  opacity: 0;
  transform: translateY(100%);
  transition: opacity var(--app-sheet-motion) var(--app-sheet-ease),
    transform var(--app-sheet-motion) var(--app-sheet-ease);
  will-change: transform, opacity;
}

.app-bottom-sheet-modal.open .app-bottom-sheet,
.app-bottom-sheet-modal.is-ready .app-bottom-sheet {
  opacity: 1;
  transform: translateY(0);
}

.payment-success-sheet {
  background:
    radial-gradient(circle at 58% 14%, rgba(56, 255, 133, 0.18), transparent 32%),
    radial-gradient(circle at 42% 72%, rgba(255, 255, 255, 0.08), transparent 24%),
    linear-gradient(135deg, #0f1725 0%, #101827 42%, #0f1a2b 100%);
}

.credits-sheet {
  background:
    radial-gradient(circle at 82% 10%, rgba(77, 69, 255, 0.18), transparent 34%),
    radial-gradient(circle at 70% 14%, rgba(53, 255, 140, 0.12), transparent 26%),
    radial-gradient(circle at 42% 74%, rgba(255, 255, 255, 0.08), transparent 24%),
    linear-gradient(135deg, #101726 0%, #11192b 44%, #0f1a2b 100%);
}

.payment-failed-sheet {
  background:
    radial-gradient(circle at 58% 14%, rgba(255, 92, 92, 0.18), transparent 32%),
    radial-gradient(circle at 42% 72%, rgba(255, 255, 255, 0.08), transparent 24%),
    linear-gradient(135deg, #1a1010 0%, #1f1218 42%, #1a1018 100%);
}

.payment-success-sheet__grabber,
.credits-sheet__grabber,
.payment-failed-sheet__grabber {
  width: 54px;
  height: 5px;
  margin: 0 auto 22px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}

.payment-success-sheet__content,
.credits-sheet__content,
.payment-failed-sheet__content {
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: start;
  gap: 14px;
}

.payment-success-sheet__icon {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #3ce886 0%, #2fd06f 100%);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(47, 208, 111, 0.28);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.credits-sheet__icon {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.92);
  color: #ffffff;
  background: transparent;
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
}

.payment-success-sheet__title,
.credits-sheet__title,
.payment-failed-sheet__title {
  margin: 2px 0 8px;
  color: #ffffff;
  font-size: 22px;
  line-height: 1.1;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.payment-success-sheet__text {
  margin: 0;
  max-width: 260px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  line-height: 1.25;
}

.credits-sheet__text {
  margin: 0;
  max-width: 294px;
  color: rgba(255, 255, 255, 0.68);
  font-size: 15px;
  line-height: 1.25;
  font-weight: 400;
}

.payment-failed-sheet__icon {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #ff6b6b 0%, #e54848 100%);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(229, 72, 72, 0.28);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}

.payment-failed-sheet__text {
  margin: 0;
  max-width: 294px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  line-height: 1.25;
}

.payment-success-sheet__actions,
.credits-sheet__actions,
.payment-failed-sheet__actions {
  margin-top: 22px;
}

.payment-success-sheet__button,
.credits-sheet__button,
.payment-failed-sheet__button {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: #f4f4f4;
  color: #111111;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.payment-success-sheet__button:active,
.credits-sheet__button:active,
.payment-failed-sheet__button:active {
  transform: scale(0.985);
}

@media (max-width: 480px) {
  .app-bottom-sheet {
    max-width: 100%;
    min-height: 220px;
    padding: 12px 16px calc(18px + env(safe-area-inset-bottom));
    border-top-left-radius: 26px;
    border-top-right-radius: 26px;
  }

  .payment-success-sheet__grabber,
  .credits-sheet__grabber {
    margin-bottom: 20px;
  }

  .payment-success-sheet__content,
  .credits-sheet__content {
    grid-template-columns: 46px 1fr;
    gap: 12px;
  }

  .payment-success-sheet__icon,
  .credits-sheet__icon {
    width: 46px;
    height: 46px;
    font-size: 22px;
  }

  .payment-success-sheet__title,
  .credits-sheet__title {
    font-size: 20px;
  }

  .payment-success-sheet__text,
  .credits-sheet__text {
    font-size: 14px;
  }

  .payment-success-sheet__button,
  .credits-sheet__button {
    min-height: 52px;
    border-radius: 15px;
  }
}

/* Brand loader (Figma 4730:56433). One loading surface for the authenticated
   bootstrap, the Telegram auth gate and the in-page login loader: the #11131a
   canvas with the slow inset glow, the 72x50 ribbon export, the 32px wordmark,
   three dots and one status line. `.app-layout-bootstrap` in pages.css shares
   the same rhythm through the selector lists below. */
.nf-brand-loader {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: #11131a;
  color: #ffffff;
  animation: nf-brand-loader-glow 5s linear infinite;
}

.nf-brand-loader__brand,
.app-layout-bootstrap__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  min-width: 0;
  text-align: center;
}

.nf-brand-loader__ribbon,
.app-layout-bootstrap__logo {
  display: block;
  width: 72px;
  height: 50px;
  object-fit: contain;
}

.nf-brand-loader__wordmark,
.app-layout-bootstrap__wordmark {
  margin: 0;
  color: #ffffff;
  font: 700 32px/1.2 Onest, var(--nf-font-ui, Inter, system-ui, -apple-system, "Segoe UI", sans-serif);
  letter-spacing: 0.7px;
}

.nf-brand-loader__dots,
.app-layout-bootstrap__dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 10px;
}

.nf-brand-loader__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.82);
  transform: scale(0.45);
  animation: nf-brand-loader-dot 1.15s ease-in-out infinite;
}

.nf-brand-loader__dots span:nth-child(2) { animation-delay: 0.18s; }
.nf-brand-loader__dots span:nth-child(3) { animation-delay: 0.36s; }

.nf-brand-loader__status {
  margin: -8px 0 0;
  min-height: 18px;
  color: rgba(255, 255, 255, 0.46);
  font: 500 13px/18px var(--nf-font-ui, Inter, system-ui, -apple-system, "Segoe UI", sans-serif);
}

.nf-brand-loader__status[hidden] {
  display: none;
}

@keyframes nf-brand-loader-dot {
  0%, 100% { transform: scale(0.45); opacity: 0.35; }
  50% { transform: scale(1); opacity: 1; }
}

/* Figma motion track for 4730:56433: two inset glows breathe over five seconds. */
@keyframes nf-brand-loader-glow {
  0% {
    box-shadow: inset 0 0 100px 0 rgba(77, 71, 255, 0.08), inset 0 0 80px 0 rgba(124, 92, 255, 0.14);
  }
  16% {
    box-shadow: inset 0 0 100px 0 rgba(77, 71, 255, 0.08), inset 0 0 89.5px 3.4px rgba(128, 88, 255, 0.19);
  }
  60% {
    box-shadow: inset 0 0 165.8px 11.3px rgba(87, 80, 255, 0.19), inset 0 0 130px 18px rgba(140, 77, 255, 0.33);
  }
  70% {
    animation-timing-function: cubic-bezier(0.45, 0, 0.65, 1);
    box-shadow: inset 0 0 170px 12px rgba(89, 82, 255, 0.22), inset 0 0 124.5px 16px rgba(136, 80, 255, 0.28);
  }
  100% {
    box-shadow: inset 0 0 100px 0 rgba(77, 71, 255, 0.08), inset 0 0 80px 0 rgba(124, 92, 255, 0.14);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nf-brand-loader,
  .app-layout-bootstrap {
    animation: none;
  }

  .nf-brand-loader__dots span {
    animation: none;
  }
}

/* Back control (all secondary pages): the 40px nav control keeps its tap zone
   and the shared 24px hover plate drawn by .app-header-nav-control::before; the
   wrapper only sizes the 17px chevron export. No box of its own: the owner asked
   for the same small plate the History control in the chat header has. */
.nf-back-button {
  position: relative;
  z-index: 1;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: #fff;
  background: transparent;
}

.nf-back-button img {
  width: 17px;
  height: 17px;
  display: block;
}
