:root {
  --bg: var(--tg-theme-bg-color, #eef3f7);
  --panel: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17212b);
  --muted: var(--tg-theme-hint-color, #6f7f8f);
  --link: var(--tg-theme-link-color, #2aabee);
  --bubble: var(--tg-theme-secondary-bg-color, #ffffff);
  --border: rgba(23, 33, 43, 0.12);
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
  --soft-link: rgba(42, 171, 238, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.topics-panel,
.chat-panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.topics-panel {
  border-right: 1px solid var(--border);
  z-index: 2;
}

.topbar,
.chat-header {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.topbar {
  justify-content: space-between;
  min-height: 74px;
  border-bottom: 0;
  background: linear-gradient(135deg, #1687d9, #20b486);
  color: #fff;
  box-shadow: 0 8px 20px rgba(22, 135, 217, 0.24);
}

.chat-header {
  justify-content: flex-start;
  gap: 8px;
  border-bottom: 0;
  background: #eef7fb;
  box-shadow: 0 4px 14px rgba(23, 33, 43, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-size: 19px;
  line-height: 1.25;
  font-weight: 700;
}

.topbar p,
.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.topbar p {
  color: rgba(255, 255, 255, 0.78);
}

.chat-title-wrap {
  position: relative;
  min-width: 0;
  flex: 1;
  padding-left: 12px;
}

.chat-title-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: 3px;
  border-radius: 999px;
  background: #20b486;
}

.chat-title-wrap h2 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #0f4f6f;
}

.chat-title-wrap p {
  color: #3b7a90;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--soft-link);
  color: var(--link);
  font-size: 13px;
  font-weight: 750;
}

.topbar .status-pill {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.topics-list {
  height: calc(100dvh - 74px);
  overflow: auto;
}

.notice {
  margin: 12px;
  padding: 12px;
  border: 1px solid rgba(239, 68, 68, 0.28);
  border-radius: 8px;
  background: #fff1f1;
  color: #991b1b;
  font-size: 14px;
  line-height: 1.35;
}

.notice.hidden {
  display: none;
}

.topic-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 72px;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.topic-item.active,
.topic-item:hover {
  background: rgba(42, 171, 238, 0.09);
}

.topic-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #25a4e8, #20c084);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  text-transform: uppercase;
}

.topic-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.topic-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.topic-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.topic-count {
  display: inline-grid;
  place-items: center;
  min-width: 30px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(111, 127, 143, 0.12);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
}

.back-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--link);
  font-size: 32px;
  line-height: 28px;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 16px 34px;
  background: var(--bg);
}

.message {
  width: min(620px, calc(100vw - 420px));
  margin: 0 auto 24px;
  padding: 8px;
  border-radius: 14px 14px 14px 6px;
  background: #f4f8fb;
  box-shadow: var(--shadow);
  animation: message-in 160ms ease both;
}

.date-separator {
  display: table;
  margin: 2px auto 16px;
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(92, 112, 128, 0.28);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
  padding: 0 4px 2px;
  color: var(--muted);
  font-size: 12px;
}

.message-meta .meta-sender {
  flex: 1;
  flex-basis: 120px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.message-meta time {
  white-space: nowrap;
}

.batch-status {
  flex: 0 0 auto;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: #526070;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.2;
}

.batch-status[data-status="approved"] {
  background: #e7f4ff;
  color: #1769aa;
}

.batch-status[data-status="completed"] {
  background: #e7f8ef;
  color: #147a55;
}

.batch-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 1 auto;
  min-width: 0;
}

.media-grid {
  display: grid;
  gap: 8px;
  overflow: hidden;
  border-radius: 10px 10px 8px 8px;
  background: transparent;
}

.photo-caption-block {
  padding: 0;
  border-radius: 10px;
}

.media-grid.one {
  grid-template-columns: 1fr;
}

.media-grid.two {
  grid-template-columns: repeat(2, 1fr);
}

.media-grid.three {
  grid-template-columns: 1.2fr 1fr;
  grid-template-rows: repeat(2, minmax(110px, 1fr));
}

.media-grid.three .photo-tile:first-child {
  grid-row: span 2;
}

.media-grid.many {
  grid-template-columns: repeat(2, 1fr);
}

.photo-tile {
  position: relative;
  display: block;
  min-height: 160px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  background: #d7dee6;
  cursor: zoom-in;
}

.media-grid.one .photo-tile {
  max-height: 640px;
  aspect-ratio: auto;
}

.photo-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease, filter 180ms ease;
}

.photo-tile:hover img {
  transform: scale(1.025);
  filter: saturate(1.05);
}

.photo-tile.broken {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.photo-tile.broken img {
  display: none;
}

.photo-tile.broken::after {
  content: attr(data-error);
}

.media-grid.one .photo-tile img {
  height: auto;
  max-height: 640px;
  object-fit: contain;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.86);
}

.lightbox.hidden {
  display: none;
}

.lightbox img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.35);
}

.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 32px;
  line-height: 1;
}

body.lightbox-open {
  overflow: hidden;
}

.more-count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
}

.caption {
  margin: 0;
  padding: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.45;
}

.caption-footer {
  padding: 12px 2px 0;
}

.caption-footer .caption {
  min-width: 0;
}

.caption-spacer {
  display: none;
  min-width: 0;
}

.batch-action-button {
  flex: 0 0 auto;
  padding: 0;
  min-height: auto;
  border: 0;
  background: transparent;
  color: var(--link);
  font-size: 12px;
  font-weight: 700;
}

.batch-action-button:disabled {
  opacity: 0.65;
}

.batch-action-button.sent {
  color: #20b486;
}

.batch-action-button.failed {
  color: #ef4444;
}

.batch-action-button.loading {
  animation: button-pulse 900ms ease-in-out infinite;
}

.batch-action-button.approve {
  color: #1769aa;
}

.batch-action-button.complete {
  color: #147a55;
}

@keyframes button-pulse {
  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(0.94);
  }
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 100%;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}

.loader {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  min-height: 100%;
}

.loader span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--link);
  animation: pulse 900ms ease-in-out infinite;
}

.loader span:nth-child(2) {
  animation-delay: 120ms;
}

.loader span:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-5px);
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .topics-panel,
  .chat-panel {
    position: absolute;
    inset: 0;
    height: 100dvh;
  }

  .chat-panel {
    z-index: 1;
    transform: translateX(100%);
    transition: transform 180ms ease;
  }

  .chat-panel.open {
    z-index: 5;
    transform: translateX(0);
  }

  .message {
    width: min(100%, 560px);
    margin-bottom: 22px;
  }

  .messages {
    padding: 16px 12px 24px;
  }

  .photo-tile {
    min-height: 126px;
  }

  .media-grid {
    gap: 7px;
  }

  .photo-caption-block {
    padding: 7px;
  }
}
