:root {
  --bg: var(--tg-theme-bg-color, #f4f6f8);
  --panel: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #18202a);
  --muted: var(--tg-theme-hint-color, #697586);
  --border: rgba(24, 32, 42, 0.1);
  --accent: var(--tg-theme-button-color, #1f72ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #c93535;
  --warning: #a66a00;
  --success: #167447;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  letter-spacing: 0;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 14px;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  margin-top: 2px;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
}

h3 {
  font-size: 14px;
  line-height: 1.3;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.segmented button {
  min-height: 38px;
  padding: 0 13px;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  white-space: nowrap;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--accent);
  color: var(--accent-text);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.queue-panel,
.review-card,
.empty-state {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.queue-panel {
  overflow: hidden;
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 700;
}

.queue-nav {
  display: flex;
  gap: 6px;
}

.queue-list {
  max-height: calc(100vh - 230px);
  overflow: auto;
}

.queue-item {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.queue-item:last-child {
  border-bottom: 0;
}

.queue-item.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.queue-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.queue-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-meta {
  color: var(--muted);
  font-size: 12px;
}

.review-card {
  padding: 18px;
}

.review-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin-bottom: 8px;
  padding: 0 9px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.muted {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.rating-badge {
  display: grid;
  width: 66px;
  height: 66px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.rating-badge span {
  font-size: 24px;
  font-weight: 800;
}

.rating-badge small {
  margin-top: -12px;
  color: var(--muted);
  font-size: 11px;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.details-grid div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.text-block {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  padding: 14px;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--bg);
}

.text-block p {
  line-height: 1.55;
  white-space: pre-wrap;
}

.reply-editor {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 12px;
}

textarea:focus {
  border-color: var(--accent);
  outline: 2px solid color-mix(in srgb, var(--accent) 24%, transparent);
}

.action-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.secondary {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.danger {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.empty-state {
  display: grid;
  gap: 8px;
  min-height: 260px;
  place-content: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state h2 {
  color: var(--text);
}

.toast {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  max-width: min(460px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #18202a;
  color: #ffffff;
  box-shadow: var(--shadow);
}

.hidden {
  display: none !important;
}

.is-busy {
  opacity: 0.65;
  pointer-events: none;
}

@media (max-width: 860px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .queue-list {
    max-height: 260px;
  }

  .details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 21px;
  }

  .toolbar,
  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1 1 0;
    padding: 0 8px;
  }

  .review-card {
    padding: 14px;
  }

  .review-head {
    display: grid;
  }

  .rating-badge {
    width: 100%;
    height: 54px;
    grid-auto-flow: column;
    justify-content: center;
    gap: 8px;
  }

  .rating-badge small {
    margin-top: 0;
  }

  .details-grid {
    grid-template-columns: 1fr;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr;
  }
}

