:root {
  --bg: #eef0ec;
  --surface: #ffffff;
  --border: #dbdfd7;
  --text: #1b211d;
  --text-dim: #667066;
  --accent: #c1440e;
  --accent-bg: #fbe6d9;
  --chip-bg: #e8ebe4;
  --shadow: 0 1px 2px rgba(20,30,20,0.05), 0 1px 10px rgba(20,30,20,0.05);
  --done-bg: #e5f1e7;
  --done-text: #2f7a4f;
  --danger: #b3261e;
  /* Просроченный срок. Отдельно от --danger: тот про удаление, а этот про
     внимание, и в тёмной теме им нужна разная яркость. */
  --late: #c62828;
  --late-bg: #fbdcdc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14180f;
    --surface: #1d2317;
    --border: #313a29;
    --text: #eef1e8;
    --text-dim: #9aa593;
    --accent: #f0955c;
    --accent-bg: #3a2416;
    --chip-bg: #262d20;
    --shadow: 0 1px 2px rgba(0,0,0,0.35), 0 1px 10px rgba(0,0,0,0.35);
    --done-bg: #1c2b1f;
    --done-text: #82cf9b;
    --danger: #ff8a80;
    --late: #ff7a70;
    --late-bg: #3a1d1b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg); }
body {
  margin: 0;
  font-family: "PT Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
}
h1, h2, h3, .brand, .roomcard-name, .typehead span:first-child {
  font-family: "Manrope", "PT Sans", sans-serif;
}
.mono, .meta, .logtime, .roomcard-progress {
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  font-variant-numeric: tabular-nums;
}
button { font-family: inherit; }
a { color: inherit; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

/* На iPhone приложение, добавленное на экран «Домой», рисуется под строкой
   состояния (часы, батарея) и под «чёлкой» — без этих отступов кнопка
   «Назад» и имя пользователя уезжают под неё. env(safe-area-inset-*) на
   всех остальных устройствах равен нулю, так что вёрстка не меняется. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px; /* запасной вариант, если env() не поддерживается */
  padding: calc(12px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           12px calc(16px + env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
/* Слева всегда заголовок, а перед ним — стрелка «назад», если есть куда.
   Заголовок сжимается многоточием: правый блок с именем и входом важнее. */
.topleft { display: flex; align-items: center; gap: 2px; min-width: 0; }
.topbar .brand {
  font-weight: 800;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  background: none;
  border: none;
  padding: 4px 2px;
  color: var(--text);
  font-family: "Manrope", "PT Sans", sans-serif;
  cursor: pointer;
  text-align: left;
}
.topbar .brand:active { opacity: 0.6; }
.topbar .brand-icon { flex: 0 0 auto; }
.topbar .brand-name {
  min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Стрелка без подписи, но с зоной нажатия во весь палец: рядом заголовок,
   промахнуться по нему было бы обидно. */
.topbar .back {
  background: none;
  border: none;
  color: var(--text);
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  width: 34px; height: 34px;
  margin-left: -8px;
  flex: 0 0 auto;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
/* На экране входа блок с именем и кнопкой «Войти» скрыт атрибутом hidden, но
   display: flex ниже его перебивал — кнопка «Войти» висела над формой входа. */
.topbar .whoami[hidden] { display: none; }
.topbar .whoami {
  font-size: 12.5px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
/* На телефоне заголовок, стрелка, подпись роли и кнопка входа вместе не
   помещаются — заголовок начинает обрезаться многоточием. Он важнее: ради него
   всё и затевалось, а что человек не вошёл, видно по кнопке «Войти». Слово
   «Наблюдатель» остаётся на планшетах и ноутбуках, где место есть. */
@media (max-width: 430px) {
  .topbar .whoami > span { display: none; }
}
/* Кнопка входа для наблюдателя — заметнее, чем «Выйти». */
.topbar .whoami button.enter {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* Колокольчик появляется, только пока уведомления не разрешены. */
.topbar .whoami button.bell {
  background: var(--accent-bg);
  border-color: var(--accent);
  font-size: 14px;
  padding: 3px 7px;
  line-height: 1.2;
}
.topbar .whoami button {
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
}

main {
  flex: 1;
  padding: 14px 16px 40px; /* запасной вариант, если env() не поддерживается */
  padding: 14px calc(16px + env(safe-area-inset-right))
           calc(40px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

/* ---------- Login ---------- */
/* На экране входа верхней панели нет, поэтому отступ от «чёлки» — здесь. */
.login-wrap {
  max-width: 380px;
  margin: 10vh auto 0;      /* запасные варианты, если env() не поддерживается */
  padding: 0 16px;
  margin: calc(10vh + env(safe-area-inset-top)) auto 0;
  padding: 0 calc(16px + env(safe-area-inset-right)) 0 calc(16px + env(safe-area-inset-left));
}
.login-wrap h1 { font-size: 22px; margin: 0 0 4px; }
.login-wrap p.sub { color: var(--text-dim); font-size: 14px; margin: 0 0 22px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field select, .field input, .field textarea {
  width: 100%;
  padding: 12px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  box-sizing: border-box;
}
.field textarea { resize: vertical; }
.field select:focus, .field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field .hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.btn-primary {
  width: 100%;
  padding: 13px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15.5px;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.55; }
.error-box {
  background: var(--accent-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13.5px;
  margin-bottom: 14px;
}

/* ---------- Room list ---------- */
.overall { margin-bottom: 16px; }
.overall .label { font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.overallbar { height: 7px; border-radius: 5px; background: var(--chip-bg); overflow: hidden; }
.overallbar > div { height: 100%; background: var(--done-text); transition: width .2s ease; }

/* ---------- Recent activity feed ---------- */
/* Лента целиком кликабельна — открывает полный журнал. */
.recentfeed { margin-bottom: 18px; cursor: pointer; border-radius: 12px; }
.recentfeed:active { opacity: 0.75; }
.recentfeed-title {
  font-size: 12.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--text-dim); margin: 0 0 8px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
}
.recentfeed-more { text-transform: none; letter-spacing: 0; color: var(--accent); font-weight: 700; white-space: nowrap; }
.recentrows { display: flex; flex-direction: column; gap: 7px; }
.recentrow {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  box-shadow: var(--shadow);
}
.recentrow.is-check { border-left-color: var(--done-text); }
.recentrow.is-uncheck { border-left-color: var(--accent); }
.recenticon {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  margin-top: 1px;
}
.is-check .recenticon { background: var(--done-bg); color: var(--done-text); }
.is-uncheck .recenticon { background: var(--accent-bg); color: var(--accent); }
.is-edit .recenticon { background: var(--chip-bg); color: var(--text-dim); }
.is-edit { border-left-color: var(--text-dim); }
.is-create .recenticon { background: var(--accent-bg); color: var(--accent); font-weight: 800; }
.is-create { border-left-color: var(--accent); }
.is-delete .recenticon { background: var(--accent-bg); color: var(--danger); font-weight: 800; }
.is-delete { border-left-color: var(--danger); }
.recentbody { flex: 1; min-width: 0; }
.recenttext { font-size: 13.5px; line-height: 1.35; }
.recenttime { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* Плитки раскладываются под конкретный экран: число колонок и высоту строки
   считает layoutTiles() в app.js, исходя из того, сколько места реально
   осталось ниже ленты изменений. Здесь только значения по умолчанию — на
   случай, если расчёт ещё не отработал.
   minmax(0, 1fr) вместо 1fr: иначе длинное название («Малая гардеробная»)
   растягивает свою колонку и строка едет. */
.roomlist {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  grid-auto-rows: var(--tile-h, auto);
  gap: var(--tile-gap, 8px);
}
.roomcard {
  /* iOS красит текст любой <button> системным синим, если цвет не задан явно.
     Без этой строки названия помещений выглядят ссылками. */
  color: var(--text);
  display: flex;
  flex-direction: column;
  /* Содержимое по центру плитки: высота подгоняется под экран, и при
     небольшом числе плиток они получаются высокими — прижатые к краям
     название и счётчик смотрелись бы растянутыми. */
  justify-content: center;
  gap: 5px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.roomcard.done { border-color: var(--done-text); }
.roomcard-name {
  font-weight: 700;
  /* Размер подбирает fitTileNames() в app.js: один общий кегль на всю сетку,
     самый крупный из тех, при которых самое длинное название ещё помещается
     в строку. Переносы и расстановку дефисов убрали — названия в одну строку
     выглядят опрятнее. */
  font-size: var(--tile-font, 12px);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  /* Если название не влезает даже на нижней границе кегля — обрезаем
     многоточием, а не ломаем строку. */
  text-overflow: ellipsis;
}
.roomcard-foot { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.roomcard-progress { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }
.roomcard.done .roomcard-progress { color: var(--done-text); }
.roomcard-chevron { color: var(--text-dim); font-size: 15px; line-height: 1; }

/* Переключатель стоит прямо над сеткой, которой управляет, поэтому отступ
   снизу небольшой: он должен читаться заодно с ней, а не отдельным блоком. */
.navtabs { display: flex; gap: 6px; margin: 2px 0 8px; }
.navtabs button {
  flex: 1;
  padding: 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 700;
  font-size: 13.5px;
  cursor: pointer;
}
.navtabs button.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

/* Плашка типа работ — тот же формат, что у помещений, но с цветной полосой
   слева, теми же цветами, что и заголовки типов внутри помещения. */
.typecard { border-left: 4px solid var(--tc, var(--accent)); }
.typecard .roomcard-name { color: var(--tc, var(--text)); }

/* В разрезе по типам заголовок группы — это помещение, по нему можно
   провалиться в само помещение. */
.typehead.clickable { cursor: pointer; }
.typehead.clickable:active { opacity: 0.6; }
.typehead.clickable span:first-child::after { content: ' ›'; font-weight: 800; }

.recent-empty {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 13.5px;
  color: var(--text-dim);
  box-shadow: var(--shadow);
}

/* ---------- Room detail ---------- */
.roomhead { margin-bottom: 14px; }
/* Счётчик выполненного и тумблер «Все / Открытые» — в одну строку. */
.headrow {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 2px;
}
.donefilter { display: flex; gap: 0; flex: 0 0 auto; }
.donefilter button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 11px;
  cursor: pointer;
}
.donefilter button:first-child { border-radius: 8px 0 0 8px; }
.donefilter button:last-child { border-radius: 0 8px 8px 0; border-left: none; }
.donefilter button.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}
.donefilter button.active + button { border-left-color: var(--accent); }
.roomhead-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.roomhead h2 { margin: 0 0 4px; font-size: 21px; }
.roomhead .meta { font-size: 12.5px; color: var(--text-dim); }
.btn-add {
  flex: 0 0 auto;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
}

.typegrid { display: flex; flex-direction: column; gap: 14px; }
.typecol {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px 14px;
  box-shadow: var(--shadow);
}
.typehead {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  font-size: 14px;
  color: var(--tc, var(--accent));
  border-bottom: 2px solid var(--tc, var(--accent));
  padding-bottom: 6px;
  margin-bottom: 8px;
}
.typehead .count { font-weight: 400; font-size: 11px; color: var(--text-dim); }

ul.items { list-style: none; margin: 0; padding: 0; }
li.item { border-radius: 8px; }
li.item + li.item { margin-top: 2px; }
.itemrow { display: flex; align-items: flex-start; gap: 10px; padding: 9px 4px; cursor: pointer; }
.itemrow:active { background: var(--chip-bg); }
.itembody { flex: 1; min-width: 0; }

/* ---------- Перетаскивание пунктов ---------- */
li.item {
  /* Разрешаем обычную вертикальную прокрутку списка пальцем, но убираем
     всплывающее меню iOS при долгом нажатии — оно мешает «взять» пункт. */
  touch-action: pan-y;
  -webkit-touch-callout: none;
  transition: transform 140ms ease, background 140ms ease, box-shadow 140ms ease;
}
/* Палец лёг на пункт — он слегка «вдавливается», видно, что удержание идёт. */
li.item.press-hold { background: var(--chip-bg); transform: scale(0.985); }
/* Пункт взят: приподнят, с тенью, следует за пальцем. */
li.item.dragging {
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(20, 30, 20, 0.22);
  /* outline, а не border: рамка не занимает места и пункт не дёргается */
  outline: 1px solid var(--tc, var(--accent));
  position: relative;
  z-index: 5;
  transition: none;
  cursor: grabbing;
}
li.item.dragging .itemrow { cursor: grabbing; }
/* Список, внутри которого идёт перестановка, подсвечен — сразу понятно,
   что пункт двигается только в пределах своего типа работ. */
ul.items.reordering {
  background: var(--chip-bg);
  border-radius: 10px;
  outline: 1px dashed var(--tc, var(--border));
  outline-offset: 2px;
}
/* Отпустили — короткая вспышка подтверждает, что место принято. */
@keyframes just-moved-flash {
  from { background: var(--accent-bg); }
  to { background: transparent; }
}
li.item.just-moved { animation: just-moved-flash 900ms ease-out; }
body.is-dragging { -webkit-user-select: none; user-select: none; }

/* Листание вкладок пальцем. Соседняя сетка на время жеста лежит за краем
   экрана, поэтому страницу нужно придержать от горизонтальной прокрутки. */
html.swiping, html.swiping body {
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}
.roomlist[data-swipe-ghost] { margin: 0; }

/* Квадратик отметки — самостоятельная кнопка: тап по нему сразу ставит или
   снимает галочку, не открывая карточку пункта. */
.box[role="checkbox"] { cursor: pointer; }
.box[role="checkbox"]:active { transform: scale(0.9); }
.box {
  flex: 0 0 auto;
  width: 22px; height: 22px;
  border: 2px solid var(--text-dim);
  border-radius: 6px;
  margin-top: 1px;
  position: relative;
  background: transparent;
}
.box.checked { background: var(--done-text); border-color: var(--done-text); }
.box.checked::after {
  content: ""; position: absolute; left: 6px; top: 2px;
  width: 6px; height: 11px;
  border: solid #fff; border-width: 0 2.5px 2.5px 0;
  transform: rotate(40deg);
}
.box.locked { opacity: 0.45; }
.box.checked.locked { opacity: 0.65; }
/* Текст задачи крупнее всего остального в списке: его читают в работе, часто
   на ходу и не с самого удобного расстояния. Подписи вокруг — исполнитель,
   срок, отметка о выполнении — остаются мелкими: это справка, а не то, что
   читают. */
.itext { font-size: 18px; line-height: 1.35; padding-top: 1px; }
/* За ноутбуком расстояние до экрана больше, а строка длиннее — там 18 px уже
   перебор. Условие то же, что у шторки правки: широкий экран и мышь. Планшет
   под него не попадает и остаётся с телефонным кеглем — его и держат в руках
   похоже. */
@media (min-width: 700px) and (pointer: fine) {
  .itext { font-size: 16px; }
}
.itext.done { color: var(--text-dim); text-decoration: line-through; }
/* Важная работа — жирным, чтобы отличалась от мелочи с одного взгляда. */
.itext.important { font-weight: 700; }

/* Флажок в шторках правки и создания пункта. */
.check-field { display: flex; align-items: flex-start; gap: 10px; margin: 4px 0 14px; cursor: pointer; }
.check-field input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.check-field span { font-size: 14.5px; font-weight: 700; color: var(--text); }
.check-field small { display: block; font-size: 12px; font-weight: 400; color: var(--text-dim); margin-top: 2px; }
.who { display: inline-block; margin-left: 7px; font-size: 11.5px; color: var(--text-dim); background: var(--chip-bg); border-radius: 5px; padding: 2px 6px; white-space: nowrap; }
.donemeta { font-size: 11.5px; color: var(--done-text); margin-top: 2px; }
.notecount { font-size: 11.5px; color: var(--accent); margin-top: 2px; font-weight: 600; }

/* ---------- Item detail / notes ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 40;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--surface);
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  /* Снизу — запас на полоску «Домой» у iPhone без кнопки. */
  padding: 16px 16px 24px; /* запасной вариант, если env() не поддерживается */
  padding: 16px calc(16px + env(safe-area-inset-right))
           calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
}
.sheet .sheet-handle { width: 40px; height: 4px; background: var(--border); border-radius: 3px; margin: 0 auto 14px; }

/* На ноутбуке шторка во всю ширину неудобна: поле ввода слева, кнопка
   «Сохранить» — у правого края, и курсор приходится вести через весь экран.
   С мышью удобнее узкое и высокое окно по центру; на телефоне всё остаётся
   как было — там шторка снизу как раз эргономична. */
@media (min-width: 700px) and (pointer: fine) {
  .sheet-backdrop { align-items: center; justify-content: center; }
  .sheet {
    width: min(460px, 92vw);
    max-height: min(88vh, 900px);
    border-radius: 16px;
    padding: 18px 20px 20px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.28);
  }
  .sheet .sheet-handle { display: none; } /* тянуть мышью нечего */
}
.sheet h3 { margin: 0 0 4px; font-size: 17px; line-height: 1.3; }
.sheet-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sheet-title-row h3 { flex: 1; }
.sheet-title-row.editing { flex-direction: column; align-items: stretch; }
.edit-btn {
  flex: 0 0 auto;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 30px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  margin-top: -2px;
}
.edit-text-area {
  width: 100%;
  min-height: 70px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  resize: vertical;
  box-sizing: border-box;
}
.edit-btn-row { display: flex; gap: 8px; margin-top: 8px; }
.edit-btn-row .btn-primary { width: auto; flex: 1; padding: 10px; font-size: 14px; }
.edit-btn-row .sheet-close { margin: 0; flex: 0 0 auto; width: auto; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; }
.sheet .sheet-who { font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; }
.sheet .toggle-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 6px; cursor: pointer; }
.sheet .toggle-row .box { width: 24px; height: 24px; }
.sheet .toggle-row .lbl { font-weight: 700; font-size: 14.5px; }
.sheet .toggle-row.disabled { cursor: not-allowed; opacity: 0.8; }
.lock-hint { font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; }

/* Ответственный за тип работ — под названием, до счётчика. */
.leadrow { display: flex; align-items: center; gap: 6px; margin: 2px 0 8px; }
.lead-name { font-size: 13px; color: var(--text-dim); }
.lead-name b { color: var(--text); }
.sheet-hint { font-size: 13px; color: var(--text-dim); margin: 0 0 14px; line-height: 1.45; }

/* Статус пункта — главное действие карточки, поэтому это широкая кнопка, а не
   строка с квадратиком: строку бригада принимала за подпись и не нажимала. */
.status-block { margin: 4px 0 14px; }
.btn-status { font-size: 16px; padding: 14px; }
.status-done {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; color: var(--done-text); font-size: 14.5px;
  margin-bottom: 10px;
}
.status-open { font-size: 14.5px; color: var(--text-dim); font-weight: 700; }
.btn-outline {
  width: 100%; padding: 11px;
  background: none; border: 1.5px solid var(--border); border-radius: 12px;
  color: var(--text-dim); font-family: inherit; font-size: 14.5px; font-weight: 700;
  cursor: pointer;
}
.btn-outline:active { background: var(--chip-bg); }

/* Крестик закрытия в углу карточки. Кнопку «Закрыть» внизу убрали: она стояла
   вплотную к отправке заметки, и их путали. */
.sheet-x {
  flex: 0 0 auto;
  background: none; border: 0; padding: 2px 4px;
  color: var(--text-dim); font-size: 18px; line-height: 1; cursor: pointer;
}
.field-hint { font-size: 12px; color: var(--text-dim); margin-top: 5px; }

/* Срок в карточке пункта. */
.sheet-due { margin: 0 0 12px; }
.sheet-due-view { font-size: 12.5px; color: var(--text-dim); }
.sheet-due-view.late { color: var(--late); font-weight: 700; }
.sheet-due-edit { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-dim); }
.sheet-due-edit.late { color: var(--late); font-weight: 700; }
.sheet-due-edit span { flex: 0 0 auto; }
.sheet-due-edit .edit-date { flex: 1 1 auto; padding: 7px 10px; font-size: 14px; }
.edit-date {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  box-sizing: border-box;
}

/* Плановый срок в строке пункта. Просроченное — красным: это единственное
   место в списке, где цвет означает «нужно смотреть сюда». */
.due {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 7px;
  background: var(--chip-bg);
  color: var(--text-dim);
  font-size: 11.5px;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  vertical-align: 1px;
  white-space: nowrap;
}
.due.late { background: var(--late-bg); color: var(--late); font-weight: 700; }
.item.late .itext { color: var(--late); }

/* Второй уровень разбивки на экране недели: внутри типа работ — помещения
   (или наоборот). Отступ слева показывает вложенность, не съедая ширину. */
.subgroup { margin: 0 0 2px; }
.subgroup:last-child { margin-bottom: 0; }
.subhead {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 0 5px;
  font-size: 12.5px; font-weight: 700; color: var(--text-dim);
}
.subhead.clickable { cursor: pointer; }
.subhead.late { color: var(--late); }
/* Просроченная неделя снаружи — красным заголовком. */
.typehead.late { color: var(--late); }
.subhead.clickable:active { opacity: 0.6; }
.subhead .count { font-weight: 400; }
.subhead .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.subgroup .items { margin: 0; padding-left: 10px; border-left: 2px solid var(--border); }

/* Неделя, суженная до одного типа работ или помещения: заголовок называет
   сужение, а строка под ним позволяет его снять — иначе непонятно, почему
   задач так мало. */
.week-scope { font-weight: 400; color: var(--text-dim); }
.scopebar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; padding: 8px 12px;
  background: var(--chip-bg); border-radius: 10px;
  font-size: 13px; color: var(--text-dim);
}
.scopebar b { color: var(--text); }
.scope-clear {
  flex: 0 0 auto;
  background: none; border: none; padding: 2px 0;
  color: var(--accent); font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
}

/* Разбивка недели по типам работ (или помещениям): сколько всего и сколько
   закрыто. Столбики горизонтальные — вертикальные обрезали бы названия. */
.planbars { margin: 0 0 14px; }
.planbars-title {
  font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 7px;
}
.planbar {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 0; cursor: pointer;
}
.planbar:active { opacity: 0.6; }
.planbar-name {
  flex: 0 0 33%; min-width: 0;
  font-size: 13px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Обёртка задаёт длину шкалы, а ширина столбика внутри — доля от самой
   большой группы. Без обёртки проценты считались от всей строки вместе с
   названием и счётчиком, и длинные столбики уезжали за край экрана. */
.planbar-bar { flex: 1 1 auto; min-width: 0; display: block; }
/* Дорожка — весь объём работы, заливка внутри — сделанное. Цвет один,
   поэтому доля читается без легенды.
   Прозрачность задаём самому цвету, а не элементу: opacity на дорожке гасила
   бы и заливку внутри неё, и выполненное было не отличить от остатка.
   Первая строка — запасной вариант для браузеров без color-mix. */
.planbar-track {
  display: block; height: 14px; border-radius: 4px;
  position: relative;
  background: var(--chip-bg);
  background: color-mix(in srgb, var(--tc) 24%, transparent);
}
.planbar-fill {
  position: absolute; inset: 0 auto 0 0;
  border-radius: 4px; background: var(--tc);
}
.planbar-count {
  flex: 0 0 42px; text-align: right;
  font-size: 12px; color: var(--text-dim);
}

/* Переключатель разреза на экране недели — тот же вид, что и главные вкладки,
   но помельче: это не навигация верхнего уровня. */
.navtabs-sub { margin: 0 0 10px; }
.navtabs-sub button { padding: 7px 10px; font-size: 13px; }

/* График плановых сроков на главном экране. */
.schedule { margin: 10px 0 12px; }
.schedule-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-dim); margin-bottom: 6px;
}
.schedule-note { text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.schedule-bars { display: flex; gap: 6px; align-items: flex-end; }
.sbar {
  flex: 1 1 0;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 0;
  /* Столбик — кнопка: по нему открывается список задач этой недели. */
  background: none; border: 0; padding: 0; font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sbar:disabled { cursor: default; }
.sbar:not(:disabled):active .sbar-fill { opacity: 0.65; }
.sbar-track { transition: opacity 0.12s; }
h2.late { color: var(--late); }
.meta .late { color: var(--late); font-weight: 700; }
.sbar-count {
  font-size: 12px; font-weight: 700; color: var(--text);
  font-family: "IBM Plex Mono", ui-monospace, monospace; line-height: 1;
  min-height: 12px;
}
.sbar-track { width: 100%; height: 38px; display: flex; align-items: flex-end; }
.sbar-fill {
  width: 100%; border-radius: 5px 5px 2px 2px; background: var(--accent);
  position: relative; overflow: hidden;
}
/* Выполненное — зелёным снизу столбика: столбик показывает всю неделю, а
   зелёная часть — сколько от неё уже закрыто. */
.sbar-fill-done {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--done-text);
  border-radius: 0 0 2px 2px;
}
.sbar-count .sbar-done {
  color: var(--done-text); font-style: normal; font-size: 10.5px; margin-left: 2px;
}
.sbar-count .sbar-done::before { content: '✓'; margin-right: 1px; }
/* Строка про сделанное за неделю — ради неё всё и затевалось: видеть не
   только остаток, но и то, сколько уже закрыто. */
.schedule-done {
  margin-top: 7px;
  font-size: 12.5px; color: var(--done-text); font-weight: 700;
}
/* Прошлая неделя — для сравнения, но тише: главное число всё-таки текущее. */
.schedule-prev { color: var(--text-dim); font-weight: 400; }
/* «Закрытые» — зелёным, как и выполненное внутри других столбиков. */
.sbar.closed .sbar-fill { background: var(--done-text); }
.sbar.closed .sbar-count { color: var(--done-text); }
.sbar.overdue .sbar-fill { background: var(--late); }
.sbar.overdue .sbar-count { color: var(--late); }
/* Будущие недели — тем же цветом, что и текущая, но приглушённо: график
   должен читаться как одна шкала, а серый по светлому фону почти не виден. */
.sbar.next .sbar-fill { background: var(--accent); opacity: 0.42; }
.sbar.empty .sbar-fill { background: var(--border); opacity: 0.7; }
.sbar-label {
  font-size: 10.5px; color: var(--text-dim); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}

.notes-title { font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-dim); margin: 0 0 8px; }
.note { background: var(--chip-bg); border-radius: 10px; padding: 9px 11px; margin-bottom: 8px; }
.note-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11.5px; color: var(--text-dim); margin-bottom: 3px; }
.note-text { font-size: 14px; white-space: pre-wrap; }
.note-del { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 11.5px; text-decoration: underline; padding: 0; }
.note-empty { font-size: 13.5px; color: var(--text-dim); margin-bottom: 10px; }

.noteform { display: flex; gap: 8px; margin-top: 10px; }
.noteform textarea {
  flex: 1; resize: none; min-height: 44px; padding: 10px 12px;
  border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font-family: inherit; font-size: 14.5px;
}
/* Отправка заметки — второстепенное действие. Красной она перетягивала
   внимание с отметки о выполнении, ради которой карточку и открывают. */
.noteform button {
  border: 1.5px solid var(--border); background: none; color: var(--text-dim);
  border-radius: 10px; padding: 0 16px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.noteform button:enabled { color: var(--text); border-color: var(--text-dim); }
.noteform button:disabled { opacity: 0.55; cursor: default; }

.sheet-close {
  display: block; width: 100%; text-align: center; margin-top: 16px;
  background: none; border: none; color: var(--text-dim); font-size: 14px; padding: 8px; cursor: pointer;
}

/* Удаление пункта — в два касания, чтобы случайный тап ничего не снёс. */
.btn-danger {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--danger);
  background: none;
  color: var(--danger);
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
}
.btn-danger:disabled { opacity: 0.55; }
.danger-confirm {
  margin-top: 10px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 12px;
  background: var(--accent-bg);
}
.danger-text { font-size: 13.5px; color: var(--danger); margin-bottom: 10px; line-height: 1.35; }
.danger-row { display: flex; gap: 8px; align-items: center; }
.danger-row .btn-danger { margin-top: 0; flex: 1; background: var(--danger); color: #fff; border-color: var(--danger); }
.danger-row .sheet-close { margin-top: 0; width: auto; flex: 0 0 auto; padding: 12px 14px; }

/* Дата сборки внизу главных экранов. */
.buildline {
  margin-top: 22px;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  opacity: 0.75;
}

/* ---------- Log ---------- */
.logfeed { display: flex; flex-direction: column; gap: 8px; }
.logrow { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.logrow .logtime { font-size: 11px; color: var(--text-dim); float: right; }
.logrow .logtext { font-size: 14px; line-height: 1.4; }
.logrow .logtext b { font-weight: 700; }
.logrow .logroom { font-size: 11.5px; color: var(--accent); font-weight: 700; }
.empty-state { text-align: center; color: var(--text-dim); font-size: 14px; padding: 40px 20px; }

.spinner-line { text-align: center; padding: 30px; color: var(--text-dim); font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 20px;
  font-size: 13.5px; z-index: 60; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

/* ---------- Настройка объекта ---------- */
.setup-section { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-bottom: 16px; box-shadow: var(--shadow); }
.setup-section h3 { margin: 0 0 10px; font-size: 17px; }
.setup-list { display: flex; flex-direction: column; margin-bottom: 10px; }
.setup-row { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-top: 1px solid var(--border); }
.setup-row:first-child { border-top: 0; }
.setup-main { flex: 1 1 auto; min-width: 0; }
.setup-name { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.setup-meta { font-size: 12.5px; color: var(--text-dim); font-weight: 400; }
.setup-empty { font-size: 13.5px; color: var(--text-dim); padding: 6px 0; }
.edit-btn.danger { color: var(--danger); }
.setup-add { display: flex; gap: 8px; }
.setup-add input { flex: 1 1 auto; min-width: 0; padding: 9px 11px; font: inherit; font-size: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.setup-buttons { margin-bottom: 10px; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.badge { font-size: 11.5px; padding: 1px 7px; border-radius: 10px; background: var(--accent-bg); color: var(--accent); }
.badge.dim { background: var(--chip-bg); color: var(--text-dim); }
.badge.warn { background: var(--late-bg); color: var(--late); }
.import-report { font-size: 14px; margin-bottom: 10px; }
.import-sum { font-size: 15px; margin-bottom: 4px; }
.import-line { color: var(--text-dim); font-size: 13px; overflow-wrap: anywhere; }
.import-errors { margin-bottom: 10px; }
.import-errors div { margin-top: 3px; }
.import-preview { max-height: 320px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; margin-bottom: 12px; }
.import-item { padding: 6px 0; border-top: 1px solid var(--border); }
.import-item:first-child { border-top: 0; }
.btn-primary.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; margin-top: 0; }
.setup-link { margin-top: 18px; }
.setup-start .btn-primary { margin-top: 14px; }
.invite-code { font-size: 30px; font-weight: 700; letter-spacing: 3px; text-align: center; padding: 14px 0; margin: 6px 0 10px; background: var(--chip-bg); border-radius: 10px; user-select: all; }
.link-btn { display: block; margin: 14px auto 0; background: none; border: 0; color: var(--accent); font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; }
.link-btn[hidden], .field[hidden] { display: none; }
