/* Postellium Cards — рабочий экран: баланс слева, переписка справа. */

body.app-page {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr);
  background: var(--canvas);
}

/* — Боковая панель — */
.side {
  background: var(--ink);
  color: #fff;
  padding: 20px 20px 18px;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 20px;
  min-height: 0;
}

.side .wordmark {
  color: #fff;
}

.side .wordmark i {
  background: #fff;
}

.side .wordmark i::after {
  border-color: var(--ink);
}

.side .wordmark span b {
  color: #8e89ad;
}

.balance {
  background: #221f3a;
  border: 1px solid #332f50;
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.balance-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.balance-row span {
  font-size: 0.88rem;
  color: #a9a4c4;
}

.balance-row b {
  font-family: var(--display);
  font-size: 1.32rem;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.balance-row b.empty {
  color: #8e89ad;
}

.balance .btn {
  background: var(--sticker);
  color: var(--ink);
}

.balance .btn:hover {
  background: #d6f232;
}

/* — Список диалогов — */
.chats {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.chats-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chats-head h2 {
  font-family: var(--sans);
  font-size: 0.87rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0;
}

.chats-head button {
  margin-inline-start: auto;
  border: 1px solid #332f50;
  background: none;
  color: #c1bdd6;
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

.chats-head button:hover {
  border-color: var(--sticker);
  color: #fff;
}

.chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: grid;
  gap: 2px;
  align-content: start;
}

.chat-list button {
  width: 100%;
  text-align: start;
  border: 0;
  background: none;
  color: #c1bdd6;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 0.89rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-list button:hover {
  background: #221f3a;
  color: #fff;
}

.chat-list button[aria-current="true"] {
  background: #2c2848;
  color: #fff;
  font-weight: 500;
}

.chat-empty {
  color: #8e89ad;
  font-size: 0.85rem;
  padding: 6px 10px;
  line-height: 1.45;
}

.side-foot {
  border-top: 1px solid #332f50;
  padding-top: 14px;
  display: grid;
  gap: 8px;
  font-size: 0.86rem;
}

.side-foot .who {
  color: #a9a4c4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.side-foot a,
.side-foot button {
  color: #c1bdd6;
  background: none;
  border: 0;
  padding: 0;
  text-align: start;
  font-size: inherit;
  cursor: pointer;
  text-decoration: none;
}

.side-foot a:hover,
.side-foot button:hover {
  color: #fff;
}

/* — Рабочая область — */
.work {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.work-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--canvas);
}

.work-head h1 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
}

.work-head .chip {
  margin-inline-start: auto;
}

.side-toggle {
  display: none;
  border: 1px solid var(--line);
  background: var(--tile);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  cursor: pointer;
}

/* — Лента сообщений — */
.stream {
  overflow-y: auto;
  padding: 24px 28px 8px;
  scroll-behavior: smooth;
}

.stream-inner {
  max-width: 760px;
  margin-inline: auto;
  display: grid;
  gap: 18px;
}

.msg {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.msg-human {
  justify-items: end;
}

.bubble {
  max-width: min(100%, 60ch);
  border-radius: 18px;
  padding: 12px 16px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.msg-human .bubble {
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}

.msg-llm .bubble {
  background: var(--tile);
  border: 1px solid var(--line-soft);
  border-bottom-left-radius: 6px;
}

.bubble p {
  margin: 0 0 10px;
  max-width: none;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  margin: 0 0 10px;
  padding-inline-start: 20px;
}

.bubble li + li {
  margin-top: 4px;
}

.bubble code {
  background: rgba(22, 21, 42, 0.08);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.92em;
}

.msg-human .bubble code {
  background: rgba(255, 255, 255, 0.18);
}

.bubble pre {
  background: var(--ink);
  color: #e9e7f4;
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 10px;
}

.bubble pre code {
  background: none;
  padding: 0;
}

.bubble a {
  color: inherit;
}

.msg-shots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(100%, 60ch);
}

.msg-shots a,
.msg-shots span {
  display: block;
  width: 104px;
  height: 104px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--canvas-deep);
}

.msg-shots img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.msg-tools {
  display: flex;
  gap: 10px;
  font-size: 0.82rem;
}

.msg-tools button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: inherit;
}

.msg-tools button:hover {
  color: var(--ink);
}

/* Ожидание ответа: три точки, одна анимация, никакой пляски */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.92rem;
}

.thinking i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.2s infinite ease-in-out;
}

.thinking i:nth-child(2) {
  animation-delay: 0.18s;
}
.thinking i:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes pulse {
  0%,
  70%,
  100% {
    opacity: 0.3;
  }
  35% {
    opacity: 1;
  }
}

/* — Бриф нового диалога — */
.brief {
  max-width: 680px;
  margin: clamp(8px, 3vh, 32px) auto 24px;
  display: grid;
  gap: 22px;
}

.brief[hidden],
.composer[hidden],
.drop-add[hidden] {
  display: none;
}

.brief-head {
  display: grid;
  gap: 10px;
}

.brief-head h2 {
  font-size: clamp(1.4rem, 3vw, 1.9rem);
}

.brief-head p {
  color: var(--ink-soft);
}

.brief-block {
  background: var(--tile);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-tile);
  padding: 18px 18px 20px;
  display: grid;
  gap: 12px;
}

.brief-label {
  display: grid;
  gap: 4px;
}

.brief-label b {
  font-weight: 600;
  font-size: 1rem;
}

.brief-label span {
  color: var(--muted);
  font-size: 0.89rem;
  line-height: 1.45;
}

.brief-text {
  resize: vertical;
  min-height: 52px;
  line-height: 1.5;
}

.style-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.style-chips button {
  border: 1px solid var(--line);
  background: var(--tile);
  border-radius: var(--r-chip);
  padding: 6px 13px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.style-chips button:hover {
  border-color: var(--ink-soft);
}

.style-chips button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.drops {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 12px;
}

.drop {
  border: 1.5px dashed var(--line);
  border-radius: 16px;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.drop.dragging {
  border-color: var(--brand);
  background: var(--brand-wash);
}

.drop.invalid {
  border-color: var(--warn);
}

.drop-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.drop-head b {
  font-size: 0.93rem;
  font-weight: 600;
}

.drop-head small {
  color: var(--muted);
  font-size: 0.82rem;
}

.drop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 8px;
}

.drop-grid:empty {
  display: none;
}

.drop-grid .shot {
  width: auto;
  height: auto;
  aspect-ratio: 1 / 1;
}

.drop-add {
  border: 0;
  background: var(--canvas);
  border-radius: 12px;
  padding: 14px 12px;
  cursor: pointer;
  display: grid;
  gap: 2px;
  justify-items: center;
  text-align: center;
  font-weight: 500;
  font-size: 0.92rem;
  color: var(--ink);
}

.drop-add:hover {
  background: var(--canvas-deep);
}

.drop-add small {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}

.brief-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.brief-foot .muted {
  font-size: 0.88rem;
}

@media (max-width: 640px) {
  .drops {
    grid-template-columns: minmax(0, 1fr);
  }
  .brief-block {
    padding: 14px;
  }
}

/* — Композер — */
.composer {
  padding: 10px 28px 20px;
}

.composer-inner {
  max-width: 760px;
  margin-inline: auto;
  background: var(--tile);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 10px 10px 10px 14px;
  display: grid;
  gap: 10px;
}

.composer-inner.dragging {
  border-color: var(--brand);
  background: var(--brand-wash);
}

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

.shots:empty {
  display: none;
}

.shot {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}

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

.shot button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 0;
  background: rgba(22, 21, 42, 0.78);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.composer-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.composer textarea {
  border: 0;
  resize: none;
  background: none;
  padding: 8px 0;
  max-height: 180px;
  line-height: 1.5;
}

.composer textarea:focus {
  outline: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--tile);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}

.icon-btn:hover {
  border-color: var(--ink-soft);
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 0;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: none;
}

.send-btn:hover {
  background: var(--brand-press);
}

.send-btn[disabled] {
  background: var(--canvas-deep);
  color: var(--muted);
  cursor: default;
}

.composer-hint {
  max-width: 760px;
  margin: 8px auto 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.composer-hint[hidden] {
  display: none;
}

/* — Модальное окно оплаты — */
dialog.sheet {
  border: 0;
  padding: 0;
  border-radius: 22px;
  width: min(760px, calc(100vw - 32px));
  background: var(--canvas);
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(22, 21, 42, 0.28);
}

dialog.sheet::backdrop {
  background: rgba(22, 21, 42, 0.45);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 22px 24px 8px;
}

.sheet-head h2 {
  font-size: 1.3rem;
}

.sheet-head p {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 6px;
}

.sheet-close {
  margin-inline-start: auto;
  border: 0;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
}

.sheet-body {
  padding: 14px 24px 24px;
  display: grid;
  gap: 14px;
}

.packs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.pack {
  text-align: start;
  background: var(--tile);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 16px;
  cursor: pointer;
  display: grid;
  gap: 8px;
  align-content: start;
  transition: border-color 0.15s ease;
}

.pack:hover {
  border-color: var(--brand);
}

.pack b {
  font-weight: 600;
}

.pack .pack-price {
  font-family: var(--display);
  font-size: 1.32rem;
  font-weight: 500;
  letter-spacing: -0.03em;
}

.pack small {
  color: var(--muted);
  font-size: 0.87rem;
  line-height: 1.45;
}

.pack[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

@media (max-width: 900px) {
  body.app-page {
    grid-template-columns: minmax(0, 1fr);
  }
  .side {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  body.side-open .side {
    transform: none;
  }
  body.side-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(22, 21, 42, 0.45);
    z-index: 50;
  }
  .side-toggle {
    display: block;
  }
  .work-head,
  .stream,
  .composer {
    padding-inline: 16px;
  }
}
