:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- Шапка ---------- */
#topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}
.brand { font-weight: 700; cursor: pointer; white-space: nowrap; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; }
#nav a {
  text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 600;
  padding: 7px 12px; border-radius: 8px;
}
#nav a.active, #nav a:hover { background: #eff6ff; color: var(--primary); }
#nav a.logout { color: var(--red); }

/* ---------- Общее ---------- */
#app { max-width: 1000px; margin: 0 auto; padding: 16px; padding-bottom: 90px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
h1 { font-size: 22px; margin: 6px 0 14px; }
h2 { font-size: 17px; margin-bottom: 10px; }
.muted { color: var(--muted); font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 15px;
  border: none; border-radius: 10px; padding: 11px 18px; cursor: pointer;
  background: var(--primary); color: #fff; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button.secondary { background: #eff6ff; color: var(--primary); }
button.danger { background: #fef2f2; color: var(--red); }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; width: 100%; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }

.error-msg { color: var(--red); font-size: 14px; margin-top: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase;
     letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.planned { background: #eff6ff; color: var(--primary); }
.badge.completed { background: #f0fdf4; color: var(--green); }
.badge.cancelled { background: #f8fafc; color: var(--muted); }
.badge.overdue { background: #fef2f2; color: var(--red); }
.badge.draft { background: #f5f3ff; color: #7c3aed; }

.pct { font-weight: 700; }
.pct.good { color: var(--green); }
.pct.mid { color: var(--amber); }
.pct.bad { color: var(--red); }

/* ---------- Логин ---------- */
.login-wrap { max-width: 380px; margin: 8vh auto 0; }
.login-logo { text-align: center; font-size: 40px; margin-bottom: 8px; }
.login-title { text-align: center; margin-bottom: 20px; }
.demo-users { margin-top: 14px; }
.demo-users span { display: inline-block; margin: 3px 4px 0 0; padding: 5px 10px;
  background: #eff6ff; color: var(--primary); border-radius: 8px; font-size: 13px; cursor: pointer; }

/* ---------- Календарь ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .month { font-weight: 700; font-size: 17px; text-transform: capitalize; }
.cal-head button { padding: 6px 14px; background: #eff6ff; color: var(--primary); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day {
  min-height: 52px; border-radius: 10px; padding: 5px 6px; font-size: 13px;
  background: #f8fafc; cursor: pointer; position: relative; border: 2px solid transparent;
}
.cal-day:hover { background: #eff6ff; }
.cal-day.other { opacity: .35; }
.cal-day.today { border-color: var(--primary); }
.cal-day.selected { background: #dbeafe; }
.cal-day .dots { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.planned { background: var(--primary); }
.dot.completed { background: var(--green); }
.dot.cancelled { background: #cbd5e1; }
.dot.overdue { background: var(--red); }
.dot.draft { background: #7c3aed; }
.cal-day.wknd { background: #e9edf3; }
.cal-day.wknd.selected { background: #dbeafe; }
.cal-sel { display: flex; gap: 6px; }
.cal-sel select { width: auto; padding: 6px 8px; font-size: 14px; }

.visit-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px;
  cursor: pointer; background: #fff;
}
.visit-item:hover { border-color: var(--primary); }
.visit-item .who { font-weight: 600; }
.visit-item.warn { background: #fffbeb; border-color: #fde68a; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 640px; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--primary); }

.kpi .val .t-done { color: var(--green); }
.kpi .val .t-over { color: var(--red); }

/* ---------- Модалка ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); border-radius: 18px 18px 0 0; padding: 20px;
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
}
@media (min-width: 640px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; }
}

/* ---------- Чек-лист ---------- */
.fill-block { margin-bottom: 14px; }
.fill-block .block-title { font-weight: 700; margin-bottom: 8px; }
.fill-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.fill-item:last-child { border-bottom: none; }
.fill-item .q { margin-bottom: 9px; font-size: 15px; }
.score-btns { display: flex; gap: 6px; }
.score-btns.scale5 { gap: 4px; }
.score-btns.scale5 button { padding: 10px 0; font-size: 14px; }
.score-btns button {
  flex: 1; padding: 10px 0; background: #f1f5f9; color: var(--text); font-size: 15px;
}
.score-btns button.sel0 { background: var(--red); color: #fff; }
.score-btns button.sel1 { background: var(--amber); color: #fff; }
.score-btns button.sel2 { background: var(--green); color: #fff; }
.score-btns button.selna { background: #475569; color: #fff; }
.comment-toggle { background: none; color: var(--primary); padding: 6px 0 0; font-size: 13px; }
.comment-toggle:hover { background: none; text-decoration: underline; }
.fill-item textarea { margin-top: 8px; min-height: 56px; }

/* Кнопки — обычным блоком в конце чек-листа: видны, только когда лист домотан до конца */
.fill-footer {
  margin-top: 16px; background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 16px;
}
.fill-footer-inner { max-width: 1000px; margin: 0 auto; display: flex; gap: 12px; align-items: center; }
.progress-text { font-size: 14px; color: var(--muted); white-space: nowrap; }
.fill-footer button { flex: 1; }

/* ---------- Дашборд ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .val { font-size: 26px; font-weight: 800; }
.kpi .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.bar-row .bar-label { width: 42%; min-width: 130px; font-size: 13px; }
.bar-row .bar-track { flex: 1; height: 18px; background: #f1f5f9; border-radius: 9px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 9px; background: var(--primary); }
.bar-row .bar-fill.good { background: var(--green); }
.bar-row .bar-fill.mid { background: var(--amber); }
.bar-row .bar-fill.bad { background: var(--red); }
.bar-row .bar-val { width: 48px; text-align: right; font-size: 13px; font-weight: 700; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select { width: auto; flex: 1; min-width: 140px; }

/* ---------- Детали визита ---------- */
.detail-score { font-size: 34px; font-weight: 800; }
.answer-line { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; font-size: 14px; }
.answer-line .a-score { min-width: 34px; text-align: center; border-radius: 8px; font-weight: 700; padding: 2px 0; }
.a-score.s0 { background: #fef2f2; color: var(--red); }
.a-score.s1 { background: #fffbeb; color: var(--amber); }
.a-score.s2 { background: #f0fdf4; color: var(--green); }
.a-score.sna { background: #f1f5f9; color: var(--muted); }
.answer-line .a-comment { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Факт/План и задачи ---------- */
.metric-inputs { display: flex; gap: 8px; }
.metric-inputs input { flex: 1; min-width: 0; }
.metric-inputs select { flex: 0 0 auto; width: auto; }
.a-score.sm { background: #eff6ff; color: var(--primary); min-width: 76px; font-size: 12px; padding: 3px 6px; white-space: nowrap; }

.task-row { display: flex; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.task-row:last-child { border-bottom: none; }
.task-row input[type="checkbox"] { width: 19px; height: 19px; flex: none; accent-color: var(--green); }
.task-row .task-text { flex: 1; }
.task-row.done .task-text { text-decoration: line-through; color: var(--muted); }
.task-deadline { font-size: 12px; font-weight: 700; color: var(--amber); white-space: nowrap; }
.task-row.done .task-deadline { color: var(--muted); }

.task-edit-row { display: flex; gap: 6px; margin-bottom: 8px; }
.task-edit-row input[type="date"] { max-width: 150px; }
.task-edit-row button { padding: 8px 12px; }

.tpl-item-row select { max-width: 120px; padding: 8px 6px; }

/* ---------- Редактор шаблона ---------- */
.tpl-block { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.tpl-item-row { display: flex; gap: 6px; margin-top: 6px; }
.tpl-item-row button { padding: 8px 12px; }

@media (max-width: 640px) {
  #app { padding: 12px; padding-bottom: 100px; }
  th, td { padding: 8px 6px; font-size: 13px; }
}

/* ---------- Допуск к продукту (п.8) ---------- */
.adm-row { display: flex; align-items: center; gap: 8px; margin-top: 9px;
  font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; }
.adm-row input[type="checkbox"] { width: 19px; height: 19px; flex: none; accent-color: var(--green); }
.adm-badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.adm-badge.ok { background: #f0fdf4; color: var(--green); }
.adm-badge.no { background: #fef2f2; color: var(--red); }

/* ---------- Зоны развития и курсы (п.9) ---------- */
.zone-block { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
.course-chip { display: inline-flex; align-items: center; gap: 6px; margin: 3px 6px 3px 0;
  padding: 5px 10px; background: #eff6ff; color: var(--primary); border-radius: 999px; font-size: 13px; }
.course-chip button { background: none; color: var(--red); padding: 0 2px; font-size: 13px; }
.course-line { padding: 7px 0; border-bottom: 1px solid var(--border); }
.course-line:last-child { border-bottom: none; }
.course-line a { color: var(--primary); font-weight: 600; text-decoration: none; }
.course-line a:hover { text-decoration: underline; }

/* Пасхалка: белый кролик из Матрицы */
.rabbit { position: absolute; top: 14px; right: 16px; font-size: 20px; cursor: default;
  opacity: .55; transition: opacity .3s; display: flex; align-items: center; gap: 6px; }
.rabbit:hover { opacity: 1; }
.rabbit-txt { font-size: 11px; color: var(--muted); font-style: italic;
  opacity: 0; transition: opacity .4s; white-space: nowrap; }
.rabbit:hover .rabbit-txt { opacity: 1; }

/* ---------- Вкладка «Качество» ---------- */
.q-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.q-row:last-child { border-bottom: none; }
.q-row a { color: var(--primary); font-weight: 600; text-decoration: none; }
.q-flag { display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 999px;
  background: #fef2f2; color: var(--red); font-size: 12px; font-weight: 700; }
.q-count { display: inline-block; min-width: 22px; text-align: center; padding: 1px 7px;
  border-radius: 999px; background: #eff6ff; color: var(--primary); font-size: 13px; }

/* ---------- Экран успешной регистрации: анимация 🎉 и конфетти ---------- */
.party-pop { display: inline-block;
  animation: party-pop .6s cubic-bezier(.2, 1.4, .4, 1) both,
             party-wiggle 1.8s ease-in-out .9s infinite; }
@keyframes party-pop {
  0%   { transform: scale(0) rotate(-45deg); }
  70%  { transform: scale(1.3) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes party-wiggle {
  0%, 100% { transform: rotate(0) scale(1); }
  25%      { transform: rotate(-8deg) scale(1.08); }
  75%      { transform: rotate(8deg) scale(1.08); }
}
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 999; overflow: hidden; }
.confetti i { position: absolute; display: block; border-radius: 2px; opacity: 0;
  animation: confetti-fly ease-out forwards; }
@keyframes confetti-fly {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  25%  { transform: translate(calc(var(--dx) * .5), var(--peak)) rotate(calc(var(--rot) * .3)); opacity: 1; }
  100% { transform: translate(var(--dx), 70vh) rotate(var(--rot)); opacity: 0; }
}

/* ---------- Отзыв НС: оценка звёздами ---------- */
.star-row { display: flex; gap: 6px; margin-top: 4px; }
.star-row button { flex: 1; padding: 8px 0; font-size: 24px; line-height: 1;
  background: #f1f5f9; color: #94a3b8; }
.star-row button.on { background: #fffbeb; color: var(--amber); }
.star-line { margin-top: 6px; font-size: 17px; color: var(--amber); letter-spacing: 2px; }
.star-avg { font-size: 17px; color: var(--amber); font-weight: 700; }

/* ---------- Прогресс-бары регистрации и покрытия ---------- */
.bar-row .bar-val.wide { width: auto; min-width: 110px; white-space: nowrap; }
.prog-split { margin: 12px 0 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
