:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --text: var(--tg-theme-text-color, #f2f2f7);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #0a84ff);
  --button: var(--tg-theme-button-color, #0a84ff);
  --button-text: var(--tg-theme-button-text-color, #fff);
  --secondary: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --destructive: #ff453a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 12px 14px 24px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

h1, h2, h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 600;
}

.muted {
  color: var(--hint);
}

.small {
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.top {
  margin-bottom: 16px;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--secondary);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
}

.card-title {
  font-weight: 600;
  margin: 0 0 4px;
}

.panel {
  background: var(--secondary);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
}

.topic-tag-select {
  min-height: 2.75rem;
  font-size: 1rem;
  -webkit-appearance: menulist;
  appearance: menulist;
}

.topic-row {
  margin-bottom: 10px;
}

.topic-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.topic-tag-current {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--link) 18%, var(--secondary));
  font-weight: 600;
  font-size: 0.95rem;
}

.topic-tag-current.has-tag {
  color: var(--link);
}

textarea,
.threads-editor,
.topic-tag-select {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  resize: vertical;
  min-height: 200px;
}

.threads-editor {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 60vh;
  outline: none;
  line-height: 1.45;
}

.threads-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--hint);
  pointer-events: none;
}

.editor-chunk {
  display: inline;
  white-space: pre-wrap;
}

.editor-split {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0;
  padding: 4px 0;
  color: var(--hint);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

.editor-split::before,
.editor-split::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--button);
  opacity: 0.55;
}

.editor-split-mark {
  white-space: nowrap;
  color: var(--button);
}

.preview-img {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-top: 8px;
}

.image-prompt-box {
  margin: 8px 0 0;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid color-mix(in srgb, var(--hint) 45%, transparent);
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
  max-height: 10rem;
  overflow-y: auto;
  color: var(--text);
}

.image-prompt-box.is-empty {
  color: var(--hint);
  font-family: inherit;
}

.media-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--hint);
}

.media-badge.has-media {
  border-color: var(--button);
  color: var(--button);
}

.media-actions {
  margin-top: 4px;
  gap: 8px;
  flex-wrap: wrap;
}

.media-actions .small-btn {
  flex: 1 1 auto;
  min-width: 5.5rem;
}

.chunk {
  border-left: 3px solid var(--button);
  padding: 8px 10px;
  margin: 8px 0;
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.chunk-meta {
  font-size: 0.8rem;
  color: var(--hint);
  margin-bottom: 4px;
}

.chunk.over {
  border-left-color: var(--destructive);
}

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

#chunk-summary {
  margin: 0 0 8px;
}

.actions .primary {
  width: 100%;
  margin-bottom: 10px;
}

.schedule-row {
  display: flex;
  gap: 8px;
}

.schedule-row input {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 10px;
  background: var(--bg);
  color: var(--text);
}

button {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.small-btn {
  padding: 6px 10px;
  font-size: 0.85rem;
}

.link-btn {
  background: transparent;
  color: var(--link);
  padding: 0;
  margin-bottom: 10px;
}

.status.error {
  color: var(--destructive);
}

.empty {
  text-align: center;
  padding: 24px;
}

.badge {
  display: inline-block;
  min-width: 1.5rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
}

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

.chip {
  background: var(--bg);
  color: var(--text);
  border: 1px solid transparent;
  padding: 8px 12px;
  font-weight: 500;
}

.chip.active {
  border-color: var(--button);
  background: var(--button);
  color: var(--button-text);
}

.chip:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chip .soon {
  font-size: 0.75rem;
  opacity: 0.8;
  margin-left: 4px;
}

.panel-head label {
  margin: 0;
}
