body {
  margin: 0;
  padding: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
}

section {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label {
  font-size: 14px;
  opacity: 0.8;
}

textarea,
input,
select {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  color: var(--tg-theme-text-color, #000);
  font-size: 15px;
}

button {
  padding: 12px;
  border: none;
  border-radius: 8px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  font-size: 15px;
  cursor: pointer;
}

#posts-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#posts-list li {
  padding: 10px;
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#add-channel-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
}

#debug-log {
  max-height: 200px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-all;
  background: #111;
  color: #0f0;
  padding: 8px;
  border-radius: 8px;
}

.mode-switch {
  display: flex;
  gap: 16px;
  font-size: 14px;
}

.article-toolbar {
  display: flex;
  gap: 8px;
}
.article-toolbar select {
  flex: 1;
}
.article-toolbar button {
  flex-shrink: 0;
  width: auto;
  padding: 10px 14px;
}

.block-card {
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.block-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  opacity: 0.7;
}

.block-card-controls button {
  width: auto;
  padding: 4px 8px;
  font-size: 12px;
  margin-left: 4px;
  background: transparent;
  color: var(--tg-theme-link-color, #2481cc);
  border: 1px solid var(--tg-theme-hint-color, #ccc);
}

.block-card textarea,
.block-card input {
  width: 100%;
  box-sizing: border-box;
}

.table-row {
  display: flex;
  gap: 4px;
  margin-bottom: 4px;
}
.table-row input {
  flex: 1;
}

#article-preview {
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 8px;
  padding: 10px;
  background: var(--tg-theme-bg-color, #fff);
}
#article-preview table {
  border-collapse: collapse;
  width: 100%;
}
#article-preview th,
#article-preview td {
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  padding: 4px 8px;
  text-align: left;
}
#article-preview blockquote {
  border-left: 3px solid var(--tg-theme-hint-color, #ccc);
  margin: 4px 0;
  padding-left: 10px;
  opacity: 0.85;
}
#article-preview details {
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
}
#article-preview summary {
  cursor: pointer;
  font-weight: 600;
}
#article-preview h1 { font-size: 24px; }
#article-preview h2 { font-size: 20px; }
#article-preview h3 { font-size: 17px; }
#article-preview h4 { font-size: 15px; }
#article-preview h5 { font-size: 14px; }
#article-preview h6 { font-size: 13px; opacity: .8; }
#article-preview img,
#article-preview video {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin: 8px 0;
}

/* Инлайн-код (моноширинный текст внутри абзаца) */
#article-preview code {
  background: rgba(127, 127, 127, 0.18);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
}

/* Блок кода - оформление в духе Stack Overflow / Habr: тёмная плашка,
   моноширинный шрифт, скролл по горизонтали вместо переноса строк. */
#article-preview pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
#article-preview pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
}

/* Спойлер в превью - имитируем "размытие" как в самом Telegram, чтобы
   визуально было понятно, что это скрытый текст. */
#article-preview tg-spoiler {
  background: rgba(127, 127, 127, 0.5);
  color: transparent;
  border-radius: 4px;
  padding: 0 2px;
}
#article-preview tg-emoji {
  outline: 1px dashed var(--tg-theme-link-color, #2481cc);
  border-radius: 4px;
  padding: 0 1px;
}

.format-toolbar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.format-toolbar button {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  color: var(--tg-theme-text-color, #000);
  border: 1px solid var(--tg-theme-hint-color, #ccc);
}
.format-hint {
  font-size: 11px;
  opacity: 0.6;
  margin: 0 0 8px;
}

#media-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.media-item {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border: 1px solid var(--tg-theme-hint-color, #ccc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  text-align: center;
}
.media-item img,
.media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.media-item.uploading {
  opacity: 0.5;
}
.media-item .remove-media {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  border: none;
}
