:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --text: #1c1f2a;
  --muted: #6b7280;
  --line: #e5e7ee;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --green: #15803d;
  --green-bg: #dcfce7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --purple: #7e22ce;
  --purple-bg: #f3e8ff;
  --yellow: #a16207;
  --yellow-bg: #fef3c7;
  --normal-bg: #eef0f6;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 2px 8px rgba(20, 24, 40, .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12141c;
    --card: #1b1e29;
    --text: #e8eaf2;
    --muted: #9aa1b5;
    --line: #2a2e3d;
    --accent: #7c73f5;
    --accent-text: #0e1018;
    --green: #4ade80;
    --green-bg: #12301f;
    --red: #f87171;
    --red-bg: #3a1717;
    --purple: #c084fc;
    --purple-bg: #2b1a3d;
    --yellow: #fbbf24;
    --yellow-bg: #3a2c0c;
    --normal-bg: #262a39;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* Каркас */
.shell { max-width: 720px; margin: 0 auto; min-height: 100vh; padding: 0 16px 92px; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 14px) 0 10px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.topbar .who { color: var(--muted); font-size: 14px; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; gap: 4px;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
.nav button {
  flex: 1; max-width: 200px; background: none; border: 0; border-radius: 12px;
  padding: 10px 6px; color: var(--muted); font-weight: 600; font-size: 14px; cursor: pointer;
}
.nav button.active { background: var(--normal-bg); color: var(--accent); }

/* Элементы */
.card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 14px 16px; margin: 10px 0;
}
.card h2 { font-size: 15px; margin: 0 0 8px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); }
.row .v { text-align: right; overflow-wrap: anywhere; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; cursor: pointer;
  padding: 15px 16px; font-weight: 700; font-size: 17px;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--normal-bg); color: var(--text); font-weight: 600; font-size: 15px; padding: 12px 14px; }
.btn.danger { background: var(--red-bg); color: var(--red); font-size: 15px; padding: 12px 14px; }
.btn.inline { display: inline-block; width: auto; }
.btn:disabled { opacity: .55; cursor: default; }
.btn + .btn { margin-top: 10px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; font-size: 15px; }
input[type=text], input[type=password], input[type=search], select, textarea {
  width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
label.field { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
label.field input, label.field select { margin-top: 4px; color: var(--text); }
.error { background: var(--red-bg); color: var(--red); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.ok { background: var(--green-bg); color: var(--green); border-radius: 12px; padding: 10px 14px; margin: 10px 0; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* Вход */
.login { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 64px) 20px 40px; }
.login h1 { font-size: 24px; margin: 0 0 4px; }
.login p { margin: 0 0 18px; color: var(--muted); }

/* Список */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.item {
  display: block; width: 100%; text-align: left; border: 0; cursor: pointer;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 12px 14px; margin: 8px 0; border-left: 6px solid var(--line);
}
.item.c-green { border-left-color: var(--green); }
.item.c-red { border-left-color: var(--red); }
.item.c-purple { border-left-color: var(--purple); }
.item.c-yellow { border-left-color: #f59e0b; }
.item .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .gns { font-weight: 700; }
.item .type { font-size: 13px; color: var(--muted); }
.item .name { margin: 2px 0; overflow-wrap: anywhere; }
.item .bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 14px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; font-weight: 600; background: var(--normal-bg); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.purple { background: var(--purple-bg); color: var(--purple); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge.cancelled { background: var(--red-bg); color: var(--red); }
.days.red { color: var(--red); font-weight: 600; }
.days.purple { color: var(--purple); font-weight: 600; }

/* Карточка теста */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 6px 0 6px 18px; position: relative; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 12px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent);
}
.timeline .t { color: var(--muted); font-size: 13px; }
.stack > * + * { margin-top: 10px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px; }
.kpi .lbl { color: var(--muted); font-size: 13px; }
.kpi .val { font-size: 20px; font-weight: 700; margin-top: 2px; }
.kpi .val.pos { color: var(--green); }
.kpi .val.neg { color: var(--red); }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.users select { padding: 6px 8px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(env(safe-area-inset-bottom) + 84px);
  background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; z-index: 10;
}
