:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a1d21;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --green-border: #bbe5c8;
  --orange: #d97706;
  --orange-bg: #fff7e6;
  --orange-border: #f3d9a4;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.admin-container { max-width: 960px; }

h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.subtitle { color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

/* ---------- Статус-блок ---------- */
.status-block {
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}
.status-block.waiting { background: var(--orange-bg); border-color: var(--orange-border); }
.status-block.countdown, .status-block.started { background: var(--green-bg); border-color: var(--green-border); }
.status-block .status-title { font-weight: 600; margin: 0 0 6px; }
.status-block.waiting .status-title { color: var(--orange); }
.status-block.countdown .status-title, .status-block.started .status-title { color: var(--green); }
.status-block .status-note { margin: 0; color: var(--muted); font-size: 0.95rem; }

.status-block .status-note.counter { margin-top: 10px; font-weight: 600; color: var(--orange); }
.status-block .status-note.extra { margin-top: 8px; }

/* Пауза отсчёта — мяч снова на стороне клиента */
.status-block.paused { background: var(--orange-bg); border-color: var(--orange-border); }
.status-block.paused .status-title { color: var(--orange); }

/* ---------- Счётчик рабочих дней ---------- */
.day-counter { margin: 14px 0 10px; }
.day-value { display: flex; align-items: baseline; gap: 8px; }
.day-num { font-size: 2.4rem; font-weight: 700; line-height: 1; color: var(--green); }
.day-of { font-size: 1.3rem; font-weight: 600; color: var(--muted); }
.day-unit { font-size: 0.9rem; color: var(--muted); margin-top: 4px; }
.status-block.paused .day-num { color: var(--orange); }

.day-bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
  margin-top: 12px;
  max-width: 420px;
}
.day-bar-fill { height: 100%; border-radius: 999px; background: var(--green); transition: width 0.4s ease; }
.day-bar-fill.over { background: var(--red); }
.status-block.paused .day-bar-fill { background: var(--orange); }

/* Счётчик в админке */
.admin-counter { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.admin-counter .day-num { color: var(--text); font-size: 2rem; }
.day-unit-inline { font-size: 0.95rem; color: var(--muted); margin-left: 6px; }
.timer-state.running { color: var(--green); font-weight: 600; }
.timer-state.paused { color: var(--orange); font-weight: 600; }

/* ---------- Этапы ---------- */
.stages {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 20px;
}
.stage {
  flex: 1 0 auto;
  text-align: center;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.stage.done { color: var(--green); border-color: var(--green-border); background: var(--green-bg); }
.stage.current { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 600; }
.stage.waiting { color: var(--orange); border-color: var(--orange-border); background: var(--orange-bg); }
.stage.ready { color: var(--accent); border-color: #c7d2fe; background: #eef2ff; }
.stage-mark { font-weight: 700; }

/* Направления работ в админке */
.stage-row {
  border-top: 1px solid var(--border);
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.stage-row:first-of-type { border-top: none; }
.stage-row.completed { opacity: 0.65; }

/* Лента уведомлений */
.event-row {
  border-top: 1px solid var(--border);
  padding: 12px 0 12px 12px;
  border-left: 3px solid transparent;
}
.event-row:first-of-type { border-top: none; }
.event-row.unseen { border-left-color: var(--accent); background: #f8faff; }
.event-row.highlight { border-left-color: var(--green); background: var(--green-bg); }
.event-text { margin: 4px 0 8px; font-size: 0.92rem; color: var(--text); word-break: break-word; }
/* Спойлер «показать всё» в ленте «Что нового» */
.events-more-list > .event-row:first-of-type { border-top: 1px solid var(--border); }
.events-more { margin-top: 12px; }
.project-card h3 { display: inline; }

.status-block .status-note.in-work { font-weight: 600; color: var(--green); margin-top: 10px; }

/* ---------- Прогресс ---------- */
.progress-wrap { margin-bottom: 4px; }
.progress-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #3b82f6);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.progress-label { display: flex; justify-content: space-between; font-size: 0.9rem; color: var(--muted); margin-top: 6px; }
.progress-label .req-left { color: var(--red); font-weight: 600; }
.progress-label .req-left.ok { color: var(--green); }

/* ---------- Метки блоков ---------- */
.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.tag.required-tag { background: var(--red-bg); color: var(--red); }
.block-note { color: var(--muted); font-size: 0.9rem; margin: 0 0 16px; }

/* Блок с материалами будущего этапа — спокойный, без красных акцентов */
.card-future { background: #fbfbfc; border-style: dashed; }
.card-future h2 { color: var(--muted); font-weight: 600; }

/* Раздел «Отправленные материалы» */
.sent-card { background: #fbfbfc; }
.sent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.sent-head h2 { margin: 0; }
.sent-group {
  font-size: 0.95rem;
  color: var(--muted);
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.sent-card > div > .sent-group:first-child { margin-top: 4px; border-top: none; padding-top: 0; }

/* ---------- Пункты материалов ---------- */
.item {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.item:first-of-type { border-top: none; }
.item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.item-label-wrap { display: inline-flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.item-label { font-weight: 600; }

/* Красная подпись у пункта, который нужен уже сейчас */
.req-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--red-bg);
  color: var(--red);
  white-space: nowrap;
}
/* Необязательный пункт внутри блока направления */
.req-badge.optional { background: #f3f4f6; color: var(--muted); }
.item-hint { color: var(--muted); font-size: 0.88rem; margin: 2px 0 8px; }
.item-status { font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.item-status.done { color: var(--green); font-weight: 600; }
.item-status.pending-confirm { color: var(--accent); font-weight: 600; }

/* ---------- Загруженные файлы ---------- */
.file-list { margin: 6px 0; }

.file-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  background: #fafafa;
}
.file-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
}
.file-name { flex: 1; min-width: 120px; word-break: break-all; font-weight: 500; }

/* Превью загруженного файла: миниатюра картинки или плашка с расширением */
.file-thumb {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  object-fit: cover;
}
.file-thumb-ext {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
  background: #f1f3f8;
}

a.file-open {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  background: #eef2ff;
  color: var(--accent);
  white-space: nowrap;
}
a.file-open:hover { background: #e0e7ff; }

.comment-box { margin-top: 10px; }
.file-comment { font-size: 0.88rem; padding: 8px 10px; min-height: 40px; resize: vertical; }
/* Поле комментария с кнопкой «развернуть» в углу */
.comment-box .input-expand { position: relative; display: block; flex: none; min-width: 0; }
.comment-box .input-expand .file-comment { padding-right: 40px; }
/* Кнопка разворота у textarea — вверху, а не по центру строки */
.comment-box .expand-btn { top: 8px; transform: none; }

/* Состояние сохранения комментария видно постоянно */
.comment-status { font-size: 0.78rem; margin-top: 4px; min-height: 16px; }
.comment-status.hint { color: var(--muted); }
.comment-status.pending { color: var(--orange); }
.comment-status.saved { color: var(--green); font-weight: 600; }

.file-comment-view {
  margin-top: 8px;
  font-size: 0.88rem;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.file-comment-view .comment-label { color: var(--muted); font-weight: 600; }

.item-error { color: var(--red); font-size: 0.88rem; margin-top: 6px; }

/* Кнопка действия в пункте: отступ нужен всегда — у пункта без подсказки
   она иначе прилипает к заголовку */
.item > button {
  margin-top: 10px;
  padding: 8px 15px;
  min-height: 38px;
  font-size: 0.92rem;
}

/* ---------- Кнопки и поля ---------- */
button, .btn {
  font: inherit;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  transition: background 0.15s;
  min-height: 44px;
}
button:hover, .btn:hover { background: var(--accent-dark); }
button:disabled { opacity: 0.6; cursor: default; }

.btn-secondary { background: #eef2ff; color: var(--accent); }
.btn-secondary:hover { background: #e0e7ff; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 0.85rem; }

.btn-upload.loading { position: relative; color: transparent; }
.btn-upload.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

input[type='text'], input[type='tel'], input[type='email'], input[type='number'],
input[type='password'], textarea, select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
textarea { min-height: 90px; resize: vertical; }

.field-row { position: relative; }
.field-row textarea { min-height: 44px; resize: vertical; }
/* Кнопка «развернуть» у текстового поля — как у комментария */
.field-row .input-expand { position: relative; display: block; flex: none; min-width: 0; }
.field-row .input-expand textarea,
.field-row .input-expand input { padding-right: 40px; }
.field-row .input-expand .expand-btn { top: 8px; transform: none; }
.saved-badge {
  position: absolute;
  right: 0;
  top: -26px;
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.3s;
}
.saved-badge.show { opacity: 1; }

/* ---------- Админка ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  gap: 12px;
  flex-wrap: wrap;
}
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.project-card h3 { margin: 0 0 2px; font-size: 1.05rem; }
.project-card .type { color: var(--muted); font-size: 0.9rem; margin: 0 0 10px; }
.project-card .meta { font-size: 0.85rem; color: var(--muted); margin: 8px 0; }
.badge {
  display: inline-block;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
}
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: #eef2ff; color: var(--accent); }
.badge.gray { background: #f3f4f6; color: var(--muted); }
.badge-group { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.link-row { display: flex; gap: 8px; margin: 10px 0; }
.link-row input { font-size: 0.85rem; color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin-top: 10px; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 600;
  padding: 10px 16px;
  min-height: auto;
}
.tab:hover { background: none; color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.form-grid { display: grid; gap: 14px; }
.form-grid label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 4px; }
.inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
  background: #fafafa;
}
.row-item input[type='text'] { flex: 1 1 110px; min-width: 100px; }
.row-item select { flex: 0 1 auto; max-width: 200px; }
.row-item .btn-danger { margin-left: auto; }
.row-item .row-actions { display: flex; gap: 8px; margin-left: auto; }
.row-item .row-actions .btn-danger { margin-left: 0; }

/* ---------- Раздел направления в настройках ---------- */
/* Разделы должны читаться как отдельные карточки, иначе на белом фоне
   настройки сливаются в один длинный список. */
.stage-section {
  border: 1px solid #dfe3ea;
  border-radius: var(--radius);
  margin-bottom: 18px;
  background: #f6f8fb;
  overflow: hidden;
}
.stage-section.common { background: #f2f6ff; border-color: #ccd9f7; }

.section-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: #eaeef5;
  border-bottom: 1px solid #dfe3ea;
}
.stage-section.common .section-head { background: #e2ebff; border-bottom-color: #ccd9f7; }
.section-title { margin: 0; font-size: 1rem; font-weight: 700; color: var(--text); }

/* Заголовки карточек в админке — такие же шапки, как у разделов настройки.
   Отрицательные поля растягивают подложку на всю ширину карточки. */
.admin-container .card > h2,
.admin-container .card > .section-head {
  background: #eaeef5;
  border-bottom: 1px solid #dfe3ea;
  margin: -20px -20px 16px;
  padding: 12px 20px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.admin-container .card > h2 { font-size: 1rem; }
.admin-container .card > .section-head { justify-content: space-between; }
.section-head .input-expand { flex: 1 1 200px; }
.section-head .btn-danger { margin-left: auto; }

/* Название направления — такой же заголовок, как «Общее для проекта»,
   но его можно править прямо на месте. Рамка появляется при наведении. */
.section-head .input-expand input[type='text'] {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border-color: transparent;
  padding: 5px 8px;
}
.section-head .input-expand input[type='text']:hover {
  background: rgba(255, 255, 255, 0.7);
  border-color: #cfd6e2;
}
.section-head .input-expand input[type='text']:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
/* Кнопка «в большое окно» не должна мозолить глаза в заголовке */
.section-head .expand-btn { opacity: 0; transition: opacity 0.15s; }
.section-head:hover .expand-btn,
.section-head:focus-within .expand-btn { opacity: 1; }

/* Содержимое раздела */
.stage-section > *:not(.section-head) { margin-left: 16px; margin-right: 16px; }
.stage-section .row-item { background: #fff; }
.stage-section > .block-note,
.stage-section > .empty-note { margin-top: 12px; }
.stage-section > .add-row { margin-bottom: 14px; }
/* ---------- Сворачивание разделов ---------- */
.collapse-btn {
  background: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1;
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 6px;
  flex: 0 0 auto;
}
.collapse-btn:hover { background: rgba(15, 23, 42, 0.08); }
.collapse-toolbar { display: flex; gap: 8px; margin-bottom: 14px; }
/* Название прижато влево: иначе space-between в шапке уводит его к правому краю */
.section-head > .item-label-wrap { flex: 1 1 auto; }

/* Кнопка в углу карточки — заголовок остаётся на месте и в свёрнутом виде */
.card { position: relative; }
.collapse-btn-corner { position: absolute; top: 14px; right: 14px; z-index: 1; }
.group-title { padding-right: 34px; }
.card.collapsed .group-title > h2:last-child { margin-bottom: 0; }

/* Кликабельная шапка направления: сворачивается по клику в любом её месте.
   Отрицательные поля растягивают зону клика на паддинг карточки. */
.group-head {
  cursor: pointer;
  margin: -20px -20px 0;
  padding: 20px 20px 4px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.group-head:hover { background: rgba(15, 23, 42, 0.03); }
.card.collapsed .group-head { padding-bottom: 20px; }

/* Свёрнутая карточка — только шапка, без пустой полосы под ней */
.card.collapsed { padding-bottom: 0; }
.admin-container .card.collapsed > .section-head {
  margin-bottom: 0;
  border-bottom: none;
  border-radius: var(--radius);
}
.stage-section.collapsed .section-head { border-bottom: none; }

.kind-title {
  margin: 14px 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.add-row { margin-top: 12px; }

/* Окно переноса пункта */
.move-list { display: flex; flex-direction: column; gap: 6px; margin: 12px 0 4px; }
.move-option { justify-content: flex-start; text-align: left; width: 100%; }

/* Поле с кнопкой «открыть в большом окне» */
.input-expand { position: relative; display: flex; flex: 1 1 170px; min-width: 150px; }
.row-item .input-expand input[type='text'] { flex: 1 1 auto; min-width: 0; padding-right: 36px; }
.expand-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 6px;
  background: #eef2ff;
  color: var(--accent);
  font-size: 0.8rem;
  line-height: 1;
}
.expand-btn:hover { background: #e0e7ff; }

/* Окно для длинного текста */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  width: min(560px, 100%);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}
.modal-title { margin: 0 0 12px; font-size: 1.05rem; }
.modal-toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.modal-bold { min-width: 36px; font-weight: 800; }
.modal-textarea {
  width: 100%;
  min-height: 150px;
  resize: vertical;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.modal-hint { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.row-item .chk { display: flex; align-items: center; gap: 4px; font-size: 0.85rem; color: var(--muted); white-space: nowrap; }
.row-item input[type='checkbox'] { width: 16px; height: 16px; }
.sort-btns { display: flex; flex-direction: column; gap: 2px; }
.sort-btns button { padding: 0 8px; min-height: 20px; font-size: 0.7rem; background: #eef2ff; color: var(--accent); border-radius: 4px; }

.admin-item-value {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 6px;
}
.empty-note { color: var(--muted); font-style: italic; }

.login-box { max-width: 380px; margin: 12vh auto 0; }
.error-text { color: var(--red); font-size: 0.9rem; margin-top: 8px; }
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 50;
}
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  .container { padding: 16px 12px 48px; }
  h1 { font-size: 1.3rem; }
  .timer .unit { min-width: 60px; }
  .item-head { flex-direction: column; gap: 2px; }
  .row-item { flex-direction: column; align-items: stretch; }
  .row-item .chk { justify-content: flex-start; }
}
