:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111417);
  --muted: var(--tg-theme-hint-color, #77828c);
  --card: var(--tg-theme-secondary-bg-color, #f2f4f7);
  --accent: var(--tg-theme-button-color, #2f7fe0);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--muted) 30%, transparent);
  --radius: 12px;
}

* { box-sizing: border-box; }

/* Атрибут hidden выставляет display:none браузерным стилем, но ЛЮБОЕ
   авторское правило display его перебивает. Без этой строки .modal с
   display:flex висит поверх всей панели и съедает все клики. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 0 0 24px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 6px; flex: 1; }

.tab {
  flex: 1;
  padding: 8px 6px;
  border: 0;
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font-size: 14px;
  cursor: pointer;
}
.tab.is-active { background: var(--accent); color: var(--accent-fg); }

.badge { font-size: 12px; color: var(--muted); white-space: nowrap; }

.screen { display: none; padding: 12px; }
.screen.is-active { display: block; }

.locked { padding: 48px 24px; text-align: center; color: var(--muted); }
.locked h2 { margin: 0 0 8px; font-size: 18px; color: var(--fg); }
.locked p { margin: 0; font-size: 14px; }

.section-title {
  margin: 20px 0 8px;
  font-size: 14px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 0; }

/* ── календарь ───────────────────────────────────────────────────────── */

.month-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 600;
}

.ghost {
  border: 0;
  background: var(--card);
  color: var(--fg);
  border-radius: 8px;
  width: 34px;
  height: 30px;
  font-size: 18px;
  cursor: pointer;
}

.weekday-row, .calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.weekday-row { margin-bottom: 4px; font-size: 11px; color: var(--muted); text-align: center; }

.day {
  min-height: 62px;
  padding: 3px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid transparent;
  font-size: 10px;
  overflow: hidden;
}
.day.other { opacity: .35; }
.day.today { border-color: var(--accent); }
.day.drop-hot { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--card)); }
.day-num { color: var(--muted); font-size: 10px; margin-bottom: 2px; }

.slot-chip {
  display: block;
  width: 100%;
  margin-bottom: 2px;
  padding: 2px 4px;
  border: 0;
  border-left: 3px solid var(--chip, var(--muted));
  border-radius: 4px;
  background: var(--bg);
  color: var(--fg);
  font-size: 10px;
  text-align: left;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.slot-chip.forecast { opacity: .55; border-left-style: dashed; }
.slot-chip.empty { color: var(--muted); }
.slot-chip.pinned { font-weight: 700; }

.legend { display: flex; gap: 12px; margin: 10px 0; font-size: 11px; color: var(--muted); }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; background: var(--muted); }
.legend .dot.confirmed { background: var(--accent); }
.legend .dot.forecast { opacity: .4; background: var(--accent); }
.legend .dot.pinned { background: #e0902f; }

.drawer { border-top: 1px solid var(--line); padding-top: 10px; }
.drawer-title { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--card);
  border-left: 4px solid var(--chip, var(--muted));
  font-size: 12px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  touch-action: none;
  cursor: grab;
}

/* ── очереди ─────────────────────────────────────────────────────────── */

.urgent-strip { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.urgent-strip:empty { display: none; }

.cat-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.cat-tab {
  flex: 0 0 auto;
  padding: 6px 10px;
  border: 0;
  border-radius: 999px;
  background: var(--card);
  color: var(--fg);
  font-size: 13px;
  cursor: pointer;
}
.cat-tab.is-active { background: var(--accent); color: var(--accent-fg); }
.cat-tab .count { opacity: .7; margin-left: 4px; }

.list { display: flex; flex-direction: column; gap: 8px; }

.row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--card);
  border-left: 4px solid var(--chip, var(--accent));
  touch-action: pan-y;
}
.row.dragging { opacity: .4; }
.row .grip { color: var(--muted); cursor: grab; font-size: 16px; line-height: 1; padding-top: 2px; }
.row .body { flex: 1; min-width: 0; }
.row .title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .meta { margin-top: 3px; font-size: 11px; color: var(--muted); }

.pill {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 10px;
  margin-right: 4px;
}
.pill.urgent { background: #e04b3a; color: #fff; }
.pill.pinned { background: #e0902f; color: #fff; }

.empty-note { color: var(--muted); font-size: 13px; padding: 18px 4px; text-align: center; }

/* ── слоты ───────────────────────────────────────────────────────────── */

.slot-form { display: flex; gap: 6px; margin-top: 12px; }
.slot-form select, .slot-form input {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.slot-form button, .modal button.primary {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
.hint { color: var(--muted); font-size: 12px; }

.field { display: block; margin-bottom: 8px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field input {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
#chats-form button {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}

/* ── карточка поста ──────────────────────────────────────────────────── */

/* Показывается только с классом is-open. Скрытие атрибутом hidden ненадёжно:
   любое авторское правило display перебивает браузерное [hidden]{display:none},
   и модалка молча висит поверх панели, перехватывая все клики. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .45);
}
.modal.is-open { display: flex; }
.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow: auto;
  padding: 16px;
  border-radius: 16px 16px 0 0;
  background: var(--bg);
}
.modal h2 { margin: 0 0 4px; font-size: 16px; }
.modal .preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--card);
  border-radius: 10px;
  padding: 10px;
  margin: 10px 0;
  font-size: 14px;
  max-height: 40vh;
  overflow: auto;
}
.modal img.thumb { width: 100%; border-radius: 10px; margin-bottom: 10px; }
.modal .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.modal .actions button {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  cursor: pointer;
}
.modal .actions button.danger { color: #e04b3a; }
.modal select, .modal .actions input { padding: 7px; border-radius: 8px; background: var(--bg); color: var(--fg); border: 1px solid var(--line); }
.modal .hint { margin: 10px 0 2px; }

/* Пока тащим пост, выделять текст интерфейса нельзя — иначе под курсором
   подсвечивается всё подряд и перенос выглядит сломанным. */
body.dragging,
body.dragging * {
  user-select: none;
  -webkit-user-select: none;
  cursor: grabbing;
}

.drag-ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  opacity: .9;
  transform: translate(-50%, -50%);
}

.fatal {
  position: fixed;
  left: 8px;
  right: 8px;
  top: 8px;
  z-index: 100;
  padding: 8px 10px;
  border-radius: 8px;
  background: #b3261e;
  color: #fff;
  font-size: 12px;
  word-break: break-word;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 60;
  max-width: 90vw;
  padding: 9px 14px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .82);
  color: #fff;
  font-size: 13px;
}
