* { margin: 0; padding: 0; box-sizing: border-box; }

/* Вне Telegram — тёмно-синяя тема; внутри Telegram цвета берутся из темы клиента */
:root {
  --bg: var(--tg-theme-bg-color, #0e1626);
  --card: var(--tg-theme-secondary-bg-color, #1b2740);
  --text: var(--tg-theme-text-color, #e6ecf7);
  --hint: var(--tg-theme-hint-color, #8494b3);
  --accent: var(--tg-theme-button-color, #3d7ff0);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  color-scheme: dark;
}

/* Оттягивание за край не должно ни перезагружать страницу, ни закрывать
   мини-апп: прокрутка останавливается на границе своего блока */
html,
body {
  overscroll-behavior: none;
}

/* Прокрутка любого блока не должна «перетекать» на страницу под ним:
   докрутил панель до конца — и следующий свайп закрывал мини-апп */
#sheet,
#topics-sheet,
#stages-sheet,
#board,
.column,
#board-tabs,
#yt-filter,
#tabs {
  /* Только по вертикали: если запереть и горизонталь, свайп вбок над колонкой
     перестаёт докручивать пайплайн — доска едет только над пустым местом */
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  /* В полноэкранном режиме Telegram рисует свои кнопки сверху — отступаем */
  padding-top: calc(
    var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)
  );
}

/* ---------- Переключатель бордов ---------- */
#board-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 12px 4px;
  overflow-x: auto;
}
#board-tabs button {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  background: transparent;
  color: var(--hint);
  cursor: pointer;
}
#board-tabs button.active {
  background: var(--card);
  color: var(--text);
}
#board-tabs .due-badge {
  font-size: 12px;
  padding: 1px 7px;
  margin-left: 2px;
  border-radius: 20px;
  background: rgba(255, 179, 0, 0.3);
  color: #ffd27a;
}

/* ---------- Подпись раздела ---------- */
#board-brand[hidden] { display: none; }
#board-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  /* Подпись — заголовок раздела, ей нужен воздух с обеих сторон,
     иначе она липнет к кнопкам под ней */
  padding: 10px 14px 14px;
}
#board-brand span {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  white-space: nowrap;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#board-brand i {
  flex: 1;
  min-width: 0; /* линия уступает место тексту, а не выдавливает его */
  height: 1px;
}
/* На узком экране девиз из четырёх слов длиннее — поджимаем разрядку */
@media (max-width: 520px) {
  #board-brand span {
    font-size: 10px;
    letter-spacing: 0.1em;
  }
  #board-brand { gap: 8px; padding: 8px 12px 12px; }
}
/* YouTube — красный канала, переходящий в тёплый */
#board-brand.brand-yt span { background-image: linear-gradient(90deg, #ff5252, #ffb057); }
#board-brand.brand-yt i {
  background: linear-gradient(90deg, rgba(255, 130, 90, 0.4), transparent);
}
/* Задачи и клиенты — спокойный сине-бирюзовый, чтобы разделы не сливались.
   Разрядка тут не идёт: у названия из одного слова она читается как логотип,
   а фразу из четырёх слов растягивает в ленту */
#board-brand.brand-core span {
  background-image: linear-gradient(90deg, #4d8dff, #43d6c4);
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 13px;
  font-weight: 600;
}
#board-brand.brand-core i {
  background: linear-gradient(90deg, rgba(77, 141, 255, 0.4), transparent);
}
/* Канал — фирменный голубой Telegram */
#board-brand.brand-tg span {
  background-image: linear-gradient(90deg, #2aabee, #6ad2ff);
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: 13px;
  font-weight: 600;
}
#board-brand.brand-tg i {
  background: linear-gradient(90deg, rgba(42, 171, 238, 0.4), transparent);
}

/* ---------- Фильтр тем YouTube ---------- */
#yt-filter[hidden] { display: none; }
#yt-filter {
  display: flex;
  gap: 6px;
  padding: 2px 12px 6px;
  overflow-x: auto;
}
.yt-topic {
  border: none;
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  white-space: nowrap;
  background: var(--card);
  color: var(--hint);
  cursor: pointer;
}
.yt-topic.active {
  background: var(--accent);
  color: var(--accent-text);
}
.yt-topic .count { opacity: 0.8; font-size: 11px; }
.yt-topic.import.no-margin { margin-left: 0; }
.yt-topic.import {
  margin-left: auto;
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15);
}
/* Открытый раздел подсвечивается — иначе непонятно, где ты находишься */
.yt-topic.import.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: none;
}

#import-overlay[hidden] { display: none; }
#import-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#import-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px;
  padding: 18px;
}
#import-sheet h3 { font-size: 16px; }
#import-file-btn {
  display: block;
  width: 100%;
  margin-bottom: 10px;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
#import-file-btn:hover { background: rgba(255, 255, 255, 0.06); }

#import-text {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
#import-go {
  flex: 1;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
#import-close {
  flex: none;
  padding-left: 18px;
  padding-right: 18px;
  background: var(--card);
  color: var(--hint);
}

#topics-overlay[hidden] { display: none; }
#topics-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#topics-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px;
  padding: 18px;
}
#topics-sheet h3 { font-size: 16px; }
#new-topic-emoji { width: 46px; text-align: center; flex: none; }
#new-topic-title { flex: 1; min-width: 0; }
#new-topic-btn {
  flex: none;
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
}
/* Палитра значков для тем */
.icon-hint {
  font-size: 12px;
  color: var(--hint);
  margin: 12px 0 8px;
  line-height: 1.35;
}
#icon-palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 6px;
  margin-bottom: 16px;
}
.icon-btn {
  border: none;
  border-radius: 9px;
  padding: 8px 0;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  background: var(--card);
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.1); }
.stage-emoji.picking {
  outline: 2px solid var(--accent);
}
#topics-close { margin-top: 4px; text-align: center; }
#stages-close { margin-top: 14px; text-align: center; }

#topics-sheet .add-row input {
  border: none;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}

#yt-fields[hidden] { display: none; }
#yt-fields { margin: 12px 0 4px; }
.date-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
#yt-remind-date,
#remind-date,
#broker-remind-date,
#docs-remind-date,
#cert-remind-date,
#recheck-date {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
  color-scheme: dark;
}
#yt-remind-clear[hidden],
#recheck-clear[hidden] { display: none; }

/* Отложенная перепроверка личной задачи */
#task-fields[hidden] { display: none; }
#task-fields { margin-top: 12px; }

/* Причина, по которой сделка не состоялась */
#lost-box[hidden] { display: none; }
#lost-box {
  margin: 4px 0 8px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(229, 115, 115, 0.08);
}
#lost-note {
  width: 100%;
  margin-top: 8px;
  border: none;
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
#lost-note::placeholder { color: var(--hint); }
#lost-box .sheet-btn { margin-top: 8px; }
/* Несостоявшийся клиент в архиве — приглушённой полосой слева */
.archive-card.lost { border-left: 3px solid rgba(229, 115, 115, 0.55); }

.titles-count {
  font-size: 11.5px;
  opacity: 0.8;
  font-weight: 400;
}
#yt-titles {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.5;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}

#yt-notes {
  width: 100%;
  min-height: 140px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}

/* ---------- Вкладки (мобильный вид) ---------- */
#tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
  overflow-x: auto;
}
#tabs button {
  flex: 1;
  white-space: nowrap;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
#tabs button.active {
  background: var(--accent);
  color: var(--accent-text);
}
#tabs .count {
  opacity: 0.7;
  font-size: 12px;
  margin-left: 3px;
}

/* ---------- Доска ---------- */
#board {
  display: grid;
  gap: 12px;
  padding: 0 12px 24px;
}

.column { display: none; }
.column.active { display: block; }

/* На телефоне шапка колонки — прозрачная обёртка, раскладка не меняется.
   Липкой она становится только на широком экране (внутри media ниже) */
.column-head { display: contents; }

.column h2 {
  font-size: 15px;
  margin: 6px 2px 10px;
  display: none;
}
.column h2 .count {
  font-size: 12px;
  color: var(--hint);
  font-weight: 500;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.add-form input {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.add-form input::placeholder { color: var(--hint); }
/* Нажали «+» с пустым полем — коротко подсвечиваем, куда писать */
.add-form input.nudge {
  animation: nudge 0.5s ease;
}
@keyframes nudge {
  0%, 100% { box-shadow: inset 0 0 0 0 transparent; transform: translateX(0); }
  15% { transform: translateX(-3px); }
  45% { transform: translateX(3px); }
  20%, 80% { box-shadow: inset 0 0 0 1.5px var(--accent, #3d7ff0); }
}
.add-form button {
  border: none;
  border-radius: 10px;
  width: 42px;
  font-size: 20px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.task {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--card);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.task.dragging { opacity: 0.4; }

/* Стрелки приоритета: только на телефоне — на широком экране есть перетаскивание */
.card-order {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: -3px -4px -3px 0;
}
.order-btn {
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 26px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--hint);
  cursor: pointer;
}
.order-btn:active { background: rgba(255, 255, 255, 0.16); }
@media (min-width: 900px) {
  .card-order { display: none; }
}
/* Куда именно встанет карточка — полоса сверху или снизу от соседа */
.task.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.task.drop-after { box-shadow: 0 3px 0 var(--accent); }
.task.docs-pending.drop-before { box-shadow: 0 -3px 0 var(--accent), inset 3px 0 0 #ffb300; }
.task.docs-pending.drop-after { box-shadow: 0 3px 0 var(--accent), inset 3px 0 0 #ffb300; }

/* Ждём документы от логистов — заметная полоса слева */
.task.docs-pending {
  box-shadow: inset 3px 0 0 #ffb300;
}

/* Напоминание сработало — карточка требует внимания */
.task.remind-due {
  background: rgba(255, 179, 0, 0.16);
  box-shadow: inset 0 0 0 1.5px rgba(255, 196, 77, 0.55);
}
.column {
  border-radius: 12px;
  outline: 2px dashed transparent;
  outline-offset: 4px;
  transition: outline-color 0.15s;
}
.column.drag-over { outline-color: var(--accent); }
.task .check {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border: 2px solid var(--hint);
  border-radius: 50%;
  background: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 18px;
  color: var(--accent-text);
}
.task.done {
  background: rgba(52, 199, 89, 0.16);
}
.task.done .check {
  background: #34c759;
  border-color: #34c759;
}
/* Обе подсветки сразу: и полоса «ждём документы», и общая тревога */
.task.remind-due.docs-pending {
  box-shadow: inset 3px 0 0 #ffb300, inset 0 0 0 1.5px rgba(255, 196, 77, 0.55);
}

.task.just-done {
  animation: done-pop 0.4s ease;
}
@keyframes done-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.04); }
  100% { transform: scale(1); }
}
.task .body { flex: 1; }
.task .text {
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}
.task .date {
  font-size: 12px;
  color: var(--hint);
  margin-top: 3px;
}
.task .chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}
.task .chip {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--hint);
}
.task .chip.cert-progress {
  background: rgba(255, 179, 0, 0.18);
  color: #ffc44d;
}
.task .chip.cert-done {
  background: rgba(52, 199, 89, 0.18);
  color: #6fbf87;
}
.task .chip.remind {
  background: rgba(255, 179, 0, 0.28);
  color: #ffd27a;
  font-weight: 600;
}
.task .chip.remind-wait {
  background: rgba(255, 255, 255, 0.06);
  color: var(--hint);
}
.task .photos {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.task .photos img {
  height: 56px;
  border-radius: 8px;
  display: block;
}

#viewer[hidden] { display: none; }
#viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
}
#viewer img {
  max-width: 95%;
  max-height: 95%;
  border-radius: 8px;
}
.task.done .text {
  text-decoration: line-through;
  color: #6fbf87;
}

.empty {
  text-align: center;
  color: var(--hint);
  font-size: 14px;
  padding: 24px 0;
}

.clear-done {
  display: block;
  margin: 4px auto 0;
  border: none;
  background: none;
  color: var(--hint);
  font-size: 13px;
  cursor: pointer;
  padding: 6px;
}

svg.yt { vertical-align: -2px; }
svg.msg-ico {
  vertical-align: -3px;
  margin-right: 1px;
}
.task .chip svg.msg-ico { vertical-align: -2px; }

/* Стрелки прокрутки пайплайна */
.scroll-arrow[hidden] { display: none; }
.scroll-arrow {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  z-index: 8;
  width: 40px;
  height: 64px;
  border: none;
  border-radius: 10px;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  opacity: 0.75;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.scroll-arrow:hover { opacity: 1; }
#scroll-left { left: 6px; }
#scroll-right { right: 6px; }

@media (max-width: 899px) {
  .scroll-arrow { display: none; }
}

/* ---------- Широкий экран: все колонки сразу ---------- */
@media (min-width: 900px) {
  /* Отступ доски сверху. Он же вычитается в .column-head — иначе прилипшая
     шапка встаёт ниже него и в просвет видно проезжающие карточки.
     Поэтому число одно на два места, а не два одинаковых числа. */
  :root { --board-pad: 12px; }
  #tabs { display: none; }
  /* Доска занимает ровно остаток окна под шапкой. Высоту считает раскладка,
     а не фиксированное число: с ним низ доски вместе с полосой прокрутки
     уезжал под край экрана, и пайплайн не докручивался вбок */
  body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }
  #board-tabs,
  #board-brand,
  #yt-filter { flex: none; }
  #board {
    padding-top: var(--board-pad);
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
  /* Число колонок задаёт JS — иначе при удалении колонки справа
     остаётся пустая ячейка во всю высоту экрана.
     Ширину самой доски не режем: если сузить её и отцентровать, то поля слева
     и справа перестают быть доской, и колесо мыши над ними ничего не крутит.
     Поэтому доска во всю ширину окна, а колонки центруем отступами */
  #board.board-tasks,
  #board.board-seo {
    grid-template-columns: repeat(var(--cols, 4), 1fr);
    padding-left: max(12px, calc((100% - var(--cols, 4) * 312px) / 2));
    padding-right: max(12px, calc((100% - var(--cols, 4) * 312px) / 2));
    align-content: start;
  }
  /* Пайплайн длинный — колонки фиксированной ширины и прокрутка вбок.
     Прокручивается вся доска целиком, обе оси сразу. Раньше каждая колонка
     была отдельным скроллером внутри доски, и трекпад отдавал ей вертикальную
     часть жеста: ведёшь вбок — доска стоит, а список карточек дёргается */
  #board.board-clients,
  #board.board-youtube {
    grid-auto-flow: column;
    grid-auto-columns: 260px;
    overflow: auto;
    align-items: start;
    padding-bottom: 12px;
  }
  /* Шапка колонки (название + строка добавления) держится наверху при
     прокрутке: иначе непонятно, на какой этап смотришь, а чтобы добавить
     карточку, приходилось крутить в самое начало */
  .column-head {
    display: block;
    position: sticky;
    /* Прилипаем ВЫШЕ верхнего отступа доски. Просто отрицательного margin
       здесь мало: прилипший элемент не поднимается выше своей границы top,
       сколько ему ни задавай отступов. */
    top: calc(-1 * var(--board-pad));
    z-index: 2;
    background: var(--bg);
    /* отступ снизу — падингом, а не маргином: иначе карточки видно в зазоре */
    padding-bottom: 10px;
    /* Сверху была та же щель, но по другой причине: доска — сама скроллер,
       и её верхний отступ прокручиваемым содержимым не закрыт. Шапка липла
       ПОД этим отступом, и в открытую полосу было видно, как под ней едут
       карточки. Вытягиваем шапку на высоту отступа вверх и возвращаем его
       своим падингом: карточки стоят на прежних местах, а полосу теперь
       закрывает фон шапки. */
    margin-top: calc(-1 * var(--board-pad));
    padding-top: var(--board-pad);
  }
  .column-head h2 {
    margin: 0 2px;
    padding: 6px 0 10px;
  }
  .column-head .add-form { margin-bottom: 0; }
  /* Видимая полоса прокрутки — подсказка, что доска едет вбок */
  #board.board-clients::-webkit-scrollbar,
  #board.board-youtube::-webkit-scrollbar {
    height: 10px;
  }
  #board.board-clients::-webkit-scrollbar-thumb,
  #board.board-youtube::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.18);
    border-radius: 5px;
  }
  #board.board-clients::-webkit-scrollbar-thumb:hover,
  #board.board-youtube::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
  }
  .column { display: block; }
  .column h2 { display: block; }
}

/* ---------- Редактор этапов ---------- */
#board-tabs .gear {
  padding: 8px 10px;
  font-size: 15px;
  background: transparent;
  opacity: 0.6;
}
#board-tabs .gear:hover { opacity: 1; }

#stages-overlay[hidden] { display: none; }
#stages-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#stages-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px;
  padding: 18px;
}
#stages-sheet h3 { font-size: 16px; }
.stages-hint {
  font-size: 12.5px;
  color: var(--hint);
  margin: 6px 0 14px;
  line-height: 1.4;
}
.stage-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 7px;
}
.stage-emoji,
.stage-title {
  border: none;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.stage-emoji {
  width: 46px;
  text-align: center;
  flex: none;
}
.stage-title { flex: 1; min-width: 0; }
.stage-title:focus { outline: 2px solid var(--accent); }
/* Колонка «Задач» — просто название, менять его нельзя */
.stage-fixed {
  flex: 1;
  min-width: 0;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 14px;
  background: var(--card);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage-count {
  flex: none;
  width: 22px;
  text-align: center;
  font-size: 12px;
  color: var(--hint);
}
.stage-btn {
  flex: none;
  width: 32px;
  height: 34px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
}
.stage-btn:disabled { opacity: 0.3; cursor: default; }
.stage-btn.danger { color: #e57373; }

/* display:flex перебивает атрибут hidden — гасим явно */
.add-row[hidden] { display: none; }
.add-row {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.add-row input {
  border: none;
  border-radius: 9px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
#new-stage-emoji { width: 46px; text-align: center; flex: none; }
#new-stage-title { flex: 1; min-width: 0; }
#new-stage-btn {
  flex: none;
  border: none;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
}
.stages-error {
  color: #e57373;
  font-size: 13px;
  margin: 12px 0 0;
}
#stages-close { margin-top: 14px; text-align: center; }

/* ---------- Статистика и архив ---------- */
#board.board-panel {
  display: block;
  padding: 4px 12px 32px;
}
.panel {
  max-width: 820px;
  margin: 0 auto;
}
.panel h3 {
  font-size: 15px;
  margin: 22px 0 10px;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
/* Два блока карточек подряд без заголовка между ними: без отступа их края
   сходятся вплотную и читаются как наложение */
.stages-grid + .tiles,
.tiles + .stages-grid,
.stages-grid + .summary,
.tiles + .summary { margin-top: 12px; }
.tile {
  background: var(--card);
  border-radius: 14px;
  padding: 16px;
}
.tile.accent {
  background: linear-gradient(140deg, rgba(61, 127, 240, 0.22), var(--card));
}
.tile-num {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.1;
}
.tile-label {
  font-size: 13px;
  margin-top: 2px;
}
.tile-sub {
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
}
.tile-sub.up { color: #6fbf87; }
.tile-sub.down { color: #e57373; }

/* Где сейчас карточки: плитки с числом вместо полос.
   Полоса показывала долю от общего и заставляла сравнивать,
   а нужен простой ответ «сколько сейчас на этапе». */
.stages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: 8px;
}
.stage-card {
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px 11px;
}
.stage-card.zero { opacity: 0.4; }
/* Цех, где что-то залежалось: видно, куда идти пинать */
.stage-card.stuck {
  box-shadow: inset 0 0 0 1px rgba(255, 179, 0, 0.45);
  opacity: 1;
}
.stage-warn {
  font-size: 11.5px;
  color: #ffd27a;
  margin-top: 3px;
}

/* ---------- Бригадир контент-фабрики ---------- */
.coach-box {
  background: linear-gradient(150deg, rgba(255, 68, 68, 0.09), rgba(90, 130, 255, 0.09));
  border-radius: 14px;
  padding: 16px 17px;
}
.coach-text {
  font-size: 15.5px;
  line-height: 1.62;
}
.coach-when,
.coach-empty,
.coach-thinking {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.55;
}
.coach-when { margin-top: 10px; }
.coach-thinking {
  /* Ответ идёт несколько секунд — показываем, что бригадир не завис */
  animation: coach-pulse 1.4s ease-in-out infinite;
}
@keyframes coach-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
.coach-error {
  font-size: 13.5px;
  color: #e57373;
  line-height: 1.55;
}
.coach-btn {
  display: block;
  width: 100%;
  margin-top: 12px;
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.coach-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.stage-name {
  font-size: 12.5px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stage-num {
  font-size: 23px;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 1px;
}
.stage-num span {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--hint);
  margin-left: 3px;
}
.stage-split {
  font-size: 11px;
  color: var(--hint);
  opacity: 0.85;
  margin-top: 3px;
}

.stats-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 12px;
  flex-wrap: wrap;
}
.stats-title { margin: 0 !important; font-size: 16px; }
.h3-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--hint);
}

/* Помесячная продуктивность канала */
.months {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--card);
  border-radius: 14px;
  padding: 14px;
}
.month { flex: 1; text-align: center; }
.month-bars {
  display: flex;
  gap: 3px;
  align-items: flex-end;
  justify-content: center;
  height: 90px;
}
.month-bars i {
  display: block;
  width: 12px;
  min-height: 3px;
  border-radius: 3px 3px 0 0;
}
.bar-ideas { background: rgba(255, 255, 255, 0.18); }
.bar-pub { background: var(--accent); }
.month-label {
  font-size: 11.5px;
  color: var(--hint);
  margin-top: 6px;
}
.month-num { font-size: 13px; font-weight: 600; }
.months-legend {
  font-size: 12px;
  color: var(--hint);
  margin: 8px 0 0;
}
.months-legend .dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 2px;
  margin-right: 3px;
}
.months-legend .dot.ideas { background: rgba(255, 255, 255, 0.18); }
.months-legend .dot.pub { background: var(--accent); }

.summary {
  background: var(--card);
  border-radius: 14px;
  padding: 6px 14px;
}
.summary div {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.summary div:last-child { border-bottom: none; }
.summary span { color: var(--hint); }

.archive-card {
  display: flex;
  align-items: center;
  flex-wrap: wrap; /* на телефоне кнопки переносятся, а не выдавливают название */
  gap: 8px;
  background: var(--card);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 8px;
}
.archive-info { flex: 1; min-width: 0; }
.archive-name {
  font-size: 14.5px;
  font-weight: 600;
}
.archive-meta {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
}
.archive-btn {
  flex: none;
  border: none;
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-text);
}
.archive-btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

/* ---------- Нижняя панель действий ---------- */
#overlay[hidden] { display: none; }
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 10;
  display: flex;
  align-items: flex-end;
}
#sheet {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 88vh;
  overflow-y: auto;
}
#sheet-text {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  /* Раньше стояла жёсткая высота с обрезкой — длинное название резалось
     посреди строки и наползало на подпись снизу. Панель и так прокручивается */
  overflow-wrap: anywhere;
}
#sheet-date {
  font-size: 12px;
  color: var(--hint);
  opacity: 0.8;
  margin: 4px 0 12px;
}
/* ---------- Поля клиента ---------- */
#sheet-fields[hidden] { display: none; }
#sheet-fields { margin: 12px 0 4px; }
.field-label {
  display: block;
  font-size: 12px;
  color: var(--hint);
  margin: 10px 0 5px;
}
/* Поле идёт сразу за рядом кнопок — без отступа они слипаются */
#yt-duration { margin-top: 7px; }

#product-input,
#yt-duration {
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.field-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.field-chip {
  border: none;
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  background: var(--card);
  color: var(--hint);
  cursor: pointer;
}
.field-chip.active {
  background: var(--accent);
  color: var(--accent-text);
}
.field-chip.danger { color: #e57373; }

/* Блок брокера */
#broker-details[hidden] { display: none; }
#broker-details {
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(61, 127, 240, 0.08);
  box-shadow: inset 0 0 0 1px rgba(61, 127, 240, 0.2);
}
.broker-waiting {
  font-size: 13px;
  color: var(--hint);
  margin: 0 0 8px;
}
.broker-waiting.overdue { color: #ffc44d; font-weight: 600; }
.broker-waiting.ok { color: #6fbf87; }
#broker-notes {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  line-height: 1.4;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.task .chip.broker-wait {
  background: rgba(61, 127, 240, 0.2);
  color: #9dc0ff;
}
.tile.warn {
  background: linear-gradient(140deg, rgba(255, 179, 0, 0.2), var(--card));
}

/* Блок документов от логистов */
#docs-details[hidden] { display: none; }
#docs-details {
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(120, 160, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(120, 160, 255, 0.18);
}
#docs-notes {
  width: 100%;
  min-height: 62px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  line-height: 1.4;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
/* Документов ещё нет — это риск для растаможки, метка должна бросаться в глаза */
.task .chip.docs-wait {
  background: rgba(255, 159, 10, 0.28);
  color: #ffc44d;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(255, 196, 77, 0.45);
}
#docs-every-chips {
  margin-top: 8px;
  align-items: center;
}
.every-label {
  font-size: 12px;
  color: var(--hint);
  margin-right: 2px;
}
.field-chip.small {
  padding: 5px 9px;
  font-size: 12px;
}

/* Блок сертификации раскрывается только когда сертификат нужен */
#cert-details[hidden] { display: none; }
#cert-details {
  margin-top: 8px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 179, 0, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 196, 77, 0.18);
}
#cert-stage {
  width: 100%;
  min-height: 68px;
  resize: vertical;
  margin-top: 8px;
  border: none;
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13.5px;
  line-height: 1.4;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}

.task .product {
  font-size: 12.5px;
  color: var(--hint);
  margin-top: 3px;
  word-break: break-word;
}

/* ---------- Заметки по клиенту ---------- */
#sheet-notes[hidden] { display: none; }
#sheet-notes { margin: 10px 0 12px; }
#notes-input {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 14px;
  line-height: 1.4;
  font-family: inherit;
  background: var(--card);
  color: var(--text);
  outline: none;
}
/* Панель длинная — кнопки закреплены снизу, до них не нужно докручивать */
#sheet-footer {
  position: sticky;
  bottom: calc(-16px - env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  margin: 14px -16px calc(-16px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: 0 -8px 16px -8px rgba(0, 0, 0, 0.5);
}
#sheet-footer button {
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 14.5px;
  font-family: inherit;
  cursor: pointer;
}
#notes-save {
  flex: 1;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
#sheet-cancel {
  flex: none;
  padding-left: 18px;
  padding-right: 18px;
  background: var(--card);
  color: var(--hint);
}

#sheet-actions[hidden] { display: none; }
#sheet-actions {
  margin: -4px 0 8px;
  padding-left: 10px;
  border-left: 2px solid rgba(255, 255, 255, 0.1);
}
#stage-toggle { display: flex; justify-content: space-between; align-items: center; }
.toggle-arrow { color: var(--hint); font-size: 12px; }

#sheet-edit[hidden] { display: none; }
#sheet-edit {
  display: flex;
  gap: 8px;
  margin: 8px 0 12px;
}
#sheet-edit input {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
  outline: 2px solid var(--accent);
}
#sheet-edit button {
  border: none;
  border-radius: 10px;
  width: 46px;
  font-size: 18px;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

/* display:block у класса перебивал атрибут hidden — кнопки протекали в чужие карточки */
.sheet-btn[hidden] { display: none; }
/* Взведённая кнопка удаления — заметно опаснее обычной */
.sheet-btn.armed {
  background: rgba(229, 115, 115, 0.22);
  color: #ff9d9d;
}
.sheet-btn {
  display: block;
  width: 100%;
  border: none;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  margin-bottom: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.sheet-btn.danger { color: #e53935; }
