:root {
  --bg: #0f1218;
  --bg-soft: #12161e;
  --surface: #171c25;
  --surface-2: #1e2430;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef2f8;
  --muted: #94a0b4;
  --accent: #5b9dff;
  --accent-soft: rgba(91, 157, 255, 0.16);
  --green: #4cd08a;
  --amber: #f2b544;
  --red: #ff6b6b;
  --radius: 18px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  --safe-bottom: max(10px, env(safe-area-inset-bottom));
}

html[data-theme='light'] {
  --bg: #f2f4f8;
  --bg-soft: #e9edf4;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --line: rgba(16, 24, 40, 0.08);
  --text: #111827;
  --muted: #667085;
  --accent: #2f7cf6;
  --accent-soft: rgba(47, 124, 246, 0.12);
  --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 50% -200px, var(--accent-soft), transparent 70%),
    var(--bg);
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  cursor: pointer;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px calc(118px + var(--safe-bottom));
}

/* ---------- top ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 2px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  background: linear-gradient(var(--bg) 70%, transparent);
  backdrop-filter: blur(12px);
}

.who {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 17px;
  color: #fff;
  background: linear-gradient(135deg, #5b9dff, #8b6bff);
  flex: 0 0 auto;
}

.who-text {
  min-width: 0;
}

.name {
  font-weight: 650;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta {
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* ---------- hero ---------- */
.hero {
  padding: 14px 2px 16px;
}

.hero-label {
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.hero-date {
  font-size: 27px;
  font-weight: 720;
  letter-spacing: -0.02em;
  margin-top: 2px;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 24px;
  font-weight: 720;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.25;
}

.stat.accent .stat-value {
  color: var(--accent);
}

.stat.danger .stat-value {
  color: var(--red);
}

.stat.ok .stat-value {
  color: var(--green);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 22px 2px 10px;
}

.section-head h2,
.card h2 {
  font-size: 16px;
  font-weight: 650;
}

.link-btn {
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 600;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- task card ---------- */
.task {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.task:active {
  transform: scale(0.99);
  border-color: rgba(91, 157, 255, 0.4);
}

.task-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 6px;
  flex: 0 0 auto;
  background: var(--accent);
}

.task-dot.done {
  background: var(--green);
}

.task-dot.overdue,
.task-dot.problem {
  background: var(--red);
}

.task-dot.new {
  background: var(--amber);
}

.task-body {
  min-width: 0;
  flex: 1;
}

.task-title {
  font-weight: 600;
  font-size: 15px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
}

.pill.green {
  color: var(--green);
  background: rgba(76, 208, 138, 0.12);
}

.pill.red {
  color: var(--red);
  background: rgba(255, 107, 107, 0.12);
}

.pill.amber {
  color: var(--amber);
  background: rgba(242, 181, 68, 0.12);
}

.pill.blue {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- checklist ---------- */
.checklist-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.ring {
  position: relative;
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.ring svg {
  width: 64px;
  height: 64px;
  transform: rotate(-90deg);
}

.ring circle {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}

.ring-bg {
  stroke: var(--surface-2);
}

.ring-fg {
  stroke: var(--accent);
  stroke-dasharray: 113;
  stroke-dashoffset: 113;
  transition: stroke-dashoffset 0.4s ease;
}

.ring span {
  position: absolute;
  font-size: 13px;
  font-weight: 700;
}

.check-item {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 14px;
  width: 100%;
  text-align: left;
}

.check-box {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 2px solid rgba(148, 160, 180, 0.5);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  transition: all 0.15s ease;
}

.check-item.done .check-box {
  background: var(--accent);
  border-color: var(--accent);
}

.check-box svg {
  width: 14px;
  height: 14px;
  opacity: 0;
  color: #fff;
}

.check-item.done .check-box svg {
  opacity: 1;
}

.check-item.done .check-title {
  color: var(--muted);
  text-decoration: line-through;
}

.check-title {
  font-size: 14.5px;
}

.check-note {
  font-size: 12px;
  color: var(--amber);
  margin-top: 2px;
}

/* ---------- segmented ---------- */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 14px;
  margin-bottom: 14px;
}

.seg {
  flex: 1;
  padding: 9px 8px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  transition: all 0.15s ease;
}

.seg.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- reports ---------- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.report-tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
}

.report-tile .value {
  font-size: 22px;
  font-weight: 720;
}

.report-tile .label {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.report-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.report-block h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 10px;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}

.bar-row .bar-label {
  width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  display: block;
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.bar-value {
  width: 62px;
  text-align: right;
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.quote {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 13.5px;
}

.quote:first-of-type {
  border-top: none;
}

.quote b {
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.empty {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: 14px;
}

.empty .big {
  font-size: 34px;
  margin-bottom: 8px;
}

/* ---------- tabbar ---------- */
.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: var(--safe-bottom);
  width: min(528px, calc(100% - 24px));
  display: flex;
  gap: 2px;
  padding: 6px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  z-index: 20;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 4px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
}

.tab svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- sheet ---------- */
.sheet-wrap {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  animation: fade 0.2s ease;
}

.sheet {
  position: relative;
  width: min(560px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 8px 18px calc(22px + var(--safe-bottom));
  animation: slide-up 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}

.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 6px auto 14px;
}

.sheet h2 {
  font-size: 19px;
  line-height: 1.3;
  margin-bottom: 6px;
}

.sheet .meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.sheet p.desc {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 10px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.task-photo {
  display: block;
  width: 100%;
  border-radius: 14px;
  margin-top: 10px;
  border: 1px solid var(--line);
}

.btn {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  font-weight: 650;
  font-size: 14.5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn.success {
  background: rgba(76, 208, 138, 0.14);
  color: var(--green);
  border-color: rgba(76, 208, 138, 0.25);
}

.btn.danger {
  background: rgba(255, 107, 107, 0.12);
  color: var(--red);
  border-color: rgba(255, 107, 107, 0.24);
}

.btn:active {
  transform: scale(0.99);
}

.timeline {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.timeline-row {
  display: flex;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  padding: 4px 0;
}

.timeline-row time {
  flex: 0 0 74px;
  font-variant-numeric: tabular-nums;
}

/* ---------- splash / toast ---------- */
.splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  background: var(--bg);
  z-index: 90;
  color: var(--muted);
  font-size: 14px;
  padding: 24px;
  text-align: center;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--surface-2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + var(--safe-bottom));
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  z-index: 80;
  animation: fade 0.18s ease;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes slide-up {
  from {
    transform: translateY(30px);
    opacity: 0.6;
  }
}

@media (prefers-color-scheme: light) {
  html:not([data-theme='dark']) {
    --bg: #f2f4f8;
    --bg-soft: #e9edf4;
    --surface: #ffffff;
    --surface-2: #f5f7fb;
    --line: rgba(16, 24, 40, 0.08);
    --text: #111827;
    --muted: #667085;
    --accent: #2f7cf6;
    --accent-soft: rgba(47, 124, 246, 0.12);
    --shadow: 0 10px 24px rgba(16, 24, 40, 0.08);
  }
}

/* ---------------------------------------------------------------------------
   Теги подразделений, кабинет управляющего, обучение.
   Отдел показывается иконкой + подписью, чтобы его было видно и без цвета.
--------------------------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  line-height: 1.3;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip.sm {
  padding: 3px 8px;
  font-size: 11px;
}

.chip.dept {
  border-color: var(--accent-soft);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip.accent {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 12px;
}

.hero-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.quick-row .btn {
  flex: 1 1 140px;
}

.task-who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* --- обучение --- */
.training-head {
  margin-bottom: 12px;
}

.training-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.training-percent {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.training-percent.sm {
  font-size: 18px;
}

.range {
  margin-top: 12px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.range span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  transition: width 0.3s ease;
}

.training-teaser {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  margin-bottom: 12px;
  cursor: pointer;
}

.training-step {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.training-step.next {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-soft) inset;
}

.training-step.done {
  opacity: 0.62;
}

.training-mark {
  flex: 0 0 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}

.training-step.done .training-mark {
  background: rgba(76, 208, 138, 0.18);
  color: var(--green);
}

.training-step.next .training-mark {
  background: var(--accent-soft);
  color: var(--accent);
}

.training-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
}

.training-title {
  font-weight: 600;
}

.training-desc {
  font-size: 13px;
  color: var(--muted);
}

.training-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

/* --- кабинет управляющего --- */
.attend {
  display: flex;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.attend-icon {
  font-size: 18px;
  line-height: 1.2;
}

.attend-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
}

.attend-title {
  font-weight: 600;
}

.attend-hint {
  font-size: 13px;
  color: var(--muted);
}

.dept-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.dept-name {
  font-weight: 600;
}

.dept-nums {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

.dept-row .bar-track {
  grid-column: 1 / -1;
  display: block;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.dept-row .bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
}

.dept-meta {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--muted);
}

.person {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.person.pick {
  text-align: left;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
}

.person-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.person-name {
  font-weight: 600;
}

.person-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.person-stat {
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.person-stat.bad {
  color: var(--red);
  background: rgba(255, 107, 107, 0.12);
}

.person-stat.warn {
  color: var(--amber);
  background: rgba(242, 181, 68, 0.12);
}

.person-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.feed {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.feed-row {
  display: flex;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}

.feed-row:last-child {
  border-bottom: none;
}

.feed-time {
  flex: 0 0 84px;
  font-size: 11px;
  color: var(--muted);
  padding-top: 2px;
}

.feed-body {
  flex: 1;
  min-width: 0;
  font-size: 13px;
}

.feed-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

/* --- inline forms (комментарии, передача, новое поручение) --- */
.inline-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.inline-form input,
.inline-form textarea,
.inline-form select {
  width: 100%;
  padding: 11px 13px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  resize: none;
}

.inline-actions {
  display: flex;
  gap: 8px;
}

.check-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
