/* Цвета берутся из темы Telegram, если она есть; иначе — светлая палитра макета. */
:root {
  color-scheme: light;
  --surface: var(--tg-theme-bg-color, #fff);
  --background: var(--tg-theme-secondary-bg-color, #f3f5f8);
  --text: var(--tg-theme-text-color, #172434);
  --hint: var(--tg-theme-hint-color, #66758b);
  --accent: var(--tg-theme-button-color, #347ce8);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --soft: #edf3fd;
  --soft-text: #2867b8;
  --line: #8295ac40;
  --danger: #bb4141;
  --ok: #287845;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 0; }
body { background: var(--background); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
main { max-width: 480px; min-height: 100dvh; margin: 0 auto; padding: 20px 16px 130px; overflow-wrap: anywhere; }

header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
header strong { font-size: 22px; }
h1 { font-size: 25px; line-height: 1.2; margin: 20px 0 8px; }
h2 { font-size: 20px; line-height: 1.3; margin: 0 0 8px; }
h3 { font-size: 16px; margin: 20px 0 6px; }
p { margin: 6px 0 14px; }
.muted { color: var(--hint); }
.small { font-size: 12px; }
.center { text-align: center; }
.error { color: var(--danger); }
.success { color: var(--ok); }
.hidden { display: none !important; }
.tag { font-size: 11px; background: #eef2f7; border-radius: 6px; padding: 4px 8px; }

/* Вкладки */
nav { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; background: var(--surface); padding: 4px; border-radius: 14px; }
nav button { background: transparent; color: var(--hint); padding: 10px 4px; }
nav button.active { background: #eaf1ff; color: #2569d5; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; line-height: 18px; }

/* Кнопки */
button { min-width: 0; min-height: 44px; border: 0; border-radius: 12px; padding: 11px 14px; font: 600 14px/1.3 system-ui, sans-serif; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); }
button.secondary { background: var(--soft); color: var(--soft-text); }
button.danger { background: #fdeeee; color: var(--danger); }
button.link { background: none; min-height: 0; padding: 0; color: var(--soft-text); text-decoration: underline; font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
.wide { width: 100%; margin-top: 10px; }

/* Формы */
section { background: var(--surface); border-radius: 16px; padding: 16px; margin: 14px 0; border: 1px solid #8295ac20; }
label { display: block; font-size: 13px; font-weight: 600; margin: 16px 0 7px; }
section > label:first-child, #channelBox.hidden + label { margin-top: 0; }
input, select, textarea { display: block; width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 16px/1.4 system-ui, sans-serif; background: var(--surface); color: var(--text); }
textarea { min-height: 100px; resize: vertical; }
input[type=date], input[type=time], input[type=datetime-local] { height: 48px; padding: 10px 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.optional { font-weight: 400; color: var(--hint); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.row > * { min-width: 0; }

.upload { margin: 0; border: 1px dashed #8295ac80; border-radius: 12px; padding: 18px; text-align: center; color: var(--soft-text); font-weight: 500; cursor: pointer; }
.upload input { display: none; }
.upload img { display: block; width: 100%; max-height: 240px; object-fit: contain; border-radius: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; font-weight: 400; }
.toggle input { width: 24px; height: 24px; flex: 0 0 24px; accent-color: var(--accent); }
.toggle small { color: var(--hint); }

.banner { background: #fff6e0; color: #7a5300; border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.banner .link { color: #7a5300; display: block; margin-top: 4px; }

#ideaList button { display: block; width: 100%; text-align: left; margin-top: 8px; font-weight: 500; }

/* Нижняя панель формы */
footer { position: fixed; z-index: 5; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 10px; padding: 12px 16px max(14px, env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid #8295ac30; }

#toast { position: fixed; z-index: 20; left: 16px; right: 16px; bottom: 96px; max-width: 448px; margin: 0 auto; padding: 12px 14px; border-radius: 12px; background: #1f2d3d; color: #fff; font-size: 14px; white-space: pre-wrap; box-shadow: 0 6px 20px #0003; }
#toast.error { background: var(--danger); }

/* Публикации */
.filters { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 12px 0 4px; background: var(--surface); padding: 4px; border-radius: 12px; }
.filters button { min-height: 38px; padding: 6px 2px; background: transparent; color: var(--hint); font-weight: 500; font-size: 13px; }
.filters span { display: block; font-size: 11px; line-height: 1; }
.filters button.active { background: #eaf1ff; color: #2569d5; }
.filters span:empty { display: none; }

.card { display: block; width: 100%; text-align: left; background: var(--surface); color: var(--text); border: 1px solid #8295ac20; border-radius: 14px; padding: 14px; margin: 10px 0; font-weight: 400; }
.card .top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--hint); }
.card .text { margin: 6px 0 0; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.status { display: inline-block; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; background: #eef2f7; color: #4a5a70; }
.status.review { background: #fff6e0; color: #7a5300; }
.status.scheduled, .status.publishing { background: #eaf1ff; color: #2569d5; }
.status.published { background: #e7f6ec; color: var(--ok); }
.status.failed, .status.uncertain, .status.missed, .status.expired { background: #fdeeee; color: var(--danger); }
.empty { text-align: center; color: var(--hint); padding: 40px 0; }

/* Диалоги */
dialog { width: calc(100% - 24px); max-width: 456px; max-height: calc(100dvh - 24px); margin: auto; padding: 18px; border: 0; border-radius: 16px; background: var(--surface); color: var(--text); overflow: auto; overflow-wrap: anywhere; }
dialog::backdrop { background: #14284180; }
dialog img { display: block; width: 100%; max-height: 300px; object-fit: contain; border-radius: 12px; margin-bottom: 12px; }
.post-text { white-space: pre-wrap; background: var(--background); border-radius: 12px; padding: 12px; }
.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.actions button { width: 100%; }
.actions .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .full { grid-column: 1 / -1; }
#people { padding-left: 22px; margin: 8px 0 0; font-size: 14px; }
.help { margin: 0; padding-left: 18px; color: var(--hint); font-size: 14px; }
.help li { margin-bottom: 6px; }
.channel-row { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; font-size: 14px; }

@media (max-width: 360px) {
  main { padding-left: 12px; padding-right: 12px; }
  section { padding: 12px; }
  footer { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 23px; }
}

/* Панель форматирования */
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 16px 0 7px; }
.label-row label { margin: 0; }
section > .label-row:first-child { margin-top: 0; }
.label-row .link { font-size: 13px; white-space: nowrap; }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.tool { min-height: 34px; min-width: 38px; padding: 4px 8px; background: var(--soft); color: var(--soft-text); font-size: 15px; }
.tool-b { font-weight: 800; }
.tool-i { font-style: italic; }
.tool-u { text-decoration: underline; }
.tool-s { text-decoration: line-through; }
.tool-wide { font-size: 13px; }
.upload { margin-top: 12px; }

details.section { background: var(--surface); border-radius: 16px; padding: 14px 16px; margin: 14px 0; border: 1px solid #8295ac20; }
details.section summary { font-weight: 600; cursor: pointer; }
details.section textarea { margin-top: 10px; }
#channelBox { margin-top: 14px; }
#tab-create > section:first-child.hidden + * { margin-top: 14px; }

/* Как Telegram показывает форматирование */
.post-text tg-spoiler { background: #8295ac55; color: transparent; border-radius: 4px; transition: color .2s; }
.post-text tg-spoiler:hover, .post-text tg-spoiler:active { color: inherit; }
.post-text blockquote { margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--accent); background: #8295ac14; border-radius: 4px; }
.post-text code, .post-text pre { font-family: ui-monospace, monospace; background: #8295ac1f; border-radius: 4px; padding: 0 4px; }
.post-text a { color: var(--soft-text); }
#winnersList { padding-left: 22px; margin: 4px 0 8px; font-weight: 600; }

/* Визуальный редактор */
.editor { min-height: 100px; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 16px/1.45 system-ui, sans-serif; background: var(--surface); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.editor.tall { min-height: 180px; }
.editor:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.editor:empty::before { content: attr(data-placeholder); color: var(--hint); pointer-events: none; }
.editor tg-spoiler, .post-text tg-spoiler { background: #8295ac55; border-radius: 4px; }
.editor tg-spoiler { color: inherit; }
.editor blockquote { margin: 6px 0; padding: 4px 10px; border-left: 3px solid var(--accent); background: #8295ac14; border-radius: 4px; }
.editor a { color: var(--soft-text); }

/* Панель форматирования над клавиатурой */
.format-menu { position: fixed; z-index: 30; left: 0; right: 0; display: flex; gap: 2px; padding: 6px 8px; overflow-x: auto; background: var(--surface); border-top: 1px solid #8295ac40; box-shadow: 0 -4px 14px #0000000f; }
.fmt { flex: 1 1 auto; min-height: 42px; min-width: 0; padding: 6px 4px; border-radius: 9px; background: var(--soft); color: var(--soft-text); font-size: 15px; white-space: nowrap; }
.fmt:active { background: #d8e6fb; }
.fmt-b { font-weight: 800; }
.fmt-i { font-style: italic; }
.fmt-u { text-decoration: underline; }
.fmt-s { text-decoration: line-through; }
.fmt-link { flex: 1; min-width: 0; min-height: 40px; padding: 6px 10px; font-size: 16px; }
footer.editing { display: none; }

/* Занятые даты */
.busy-box { margin-top: 12px; }
.busy-box summary { color: var(--soft-text); cursor: pointer; }
.busy { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; max-height: 180px; overflow-y: auto; }
.busy li { padding: 5px 0; border-bottom: 1px solid #8295ac20; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.busy li b { font-weight: 600; margin-right: 4px; }
input.clash { border-color: var(--danger); background: #fdeeee; }
