:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e4e9f0;
  --chip: #f2f5f9;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --primary: #111827;
  --on-primary: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --ok: #16a34a;
  --ok-soft: #e7f6ec;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0a0f16;
  --card: #121a25;
  --text: #e9eef6;
  --muted: #8a9ab0;
  --line: #1e2a38;
  --chip: #1a2432;
  --accent: #5b93ff;
  --accent-soft: #17243d;
  --primary: #e9eef6;
  --on-primary: #0a0f16;
  --danger: #f26464;
  --danger-soft: #2a1618;
  --ok: #3ccf74;
  --ok-soft: #12261a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 500 15px/1.45 Montserrat, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
/* iPhone приближает страницу при нажатии на поле со шрифтом меньше 16px — держим 16px и запрещаем зум жестами */
input, select, textarea { font-size: 16px; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }
button { cursor: pointer; }
[hidden] { display: none !important; }

i[data-icon] { display: inline-flex; width: 20px; height: 20px; flex: none; }
i[data-icon] svg { width: 100%; height: 100%; }

/* шапка: логотип PR1ME слева сверху */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  /* в полноэкранном режиме Telegram отдаёт отступы под вырез и свои кнопки */
  padding: calc(12px + var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.logo { display: block; line-height: 0; }
.logo-mark {
  display: block; width: 84px; height: 27px;
  background: var(--text);
  -webkit-mask: url(logo.svg) left center / contain no-repeat;
  mask: url(logo.svg) left center / contain no-repeat;
}
.top-title { font-weight: 700; color: var(--muted); font-size: 14px; }
.theme { margin-left: auto; display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--chip); }
.theme button {
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  display: grid; place-items: center;
}
.theme button.on { background: var(--primary); color: var(--on-primary); }
.theme i[data-icon] { width: 16px; height: 16px; }

.view { padding: 4px 16px 104px; max-width: 560px; margin: 0 auto; }

/* карточки как в c1ick */
.card {
  background: var(--card); border-radius: 20px; padding: 18px; margin-bottom: 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.tile {
  width: 42px; height: 42px; border-radius: 12px; flex: none;
  display: grid; place-items: center; background: var(--chip); color: var(--text);
}
.card h2 { font-size: 19px; font-weight: 800; margin: 0; letter-spacing: -.01em; overflow-wrap: anywhere; min-width: 0; }
.hero h1 { font-size: 30px; line-height: 1.1; font-weight: 800; margin: 0 0 8px; letter-spacing: -.02em; overflow-wrap: anywhere; }
.hero h1 b { color: var(--accent); font-weight: 800; }
.sub { color: var(--muted); margin: 0; font-size: 14px; }
.small { font-size: 12px; color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.stat { background: var(--chip); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 20px; font-weight: 800; }
.stat span { font-size: 12px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px;
  padding: 7px 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--chip); font-weight: 600; font-size: 13px; white-space: nowrap;
}
.chip.on { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.chip i[data-icon] { width: 16px; height: 16px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px; }
.chips.scroll::-webkit-scrollbar { display: none; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 50px; padding: 12px 16px; border-radius: 14px; border: 0;
  background: var(--primary); color: var(--on-primary); font-weight: 700; font-size: 15px;
  margin-top: 12px;
}
.btn.light { background: var(--chip); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .55; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-btns .btn { margin-top: 8px; }

.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.input, select.input {
  width: 100%; min-height: 46px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--chip); outline: none;
}
.input:focus { border-color: var(--accent); }
.search { position: relative; }
.search i[data-icon] { position: absolute; left: 13px; top: 13px; color: var(--muted); }
.search .input { padding-left: 42px; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 8px; align-items: baseline; color: var(--muted); font-size: 14px; padding: 2px 0; }
.checks li::before { content: "✓"; color: var(--ok); font-weight: 800; }

/* списки */
.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 0; border: 0; border-top: 1px solid var(--line); background: transparent;
}
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .chev { color: var(--muted); }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800;
}
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.hp { height: 4px; border-radius: 4px; background: var(--chip); margin-top: 6px; overflow: hidden; }
.hp > div { height: 100%; background: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.action {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--chip); font-weight: 700; font-size: 13px; text-align: left;
}
.action.danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.action i[data-icon] { width: 18px; height: 18px; }

/* нижние вкладки */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 700; border-radius: 12px;
}
.tabs a.on { color: var(--text); background: var(--chip); }

/* шторка снизу */
.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-back { position: absolute; inset: 0; background: rgba(5, 10, 18, .45); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 22px 22px 0 0; padding: 22px 18px calc(18px + env(safe-area-inset-bottom));
  max-width: 560px; margin: 0 auto;
}
.sheet-body h3 { margin: 0 44px 4px 0; font-size: 20px; font-weight: 800; overflow-wrap: anywhere; }
.sheet-x {
  position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: var(--chip); display: grid; place-items: center;
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: 92px; z-index: 30; max-width: 528px; margin: 0 auto;
  background: var(--primary); color: var(--on-primary); padding: 12px 16px; border-radius: 14px;
  font-weight: 600; font-size: 14px; text-align: center;
}
.toast.err { background: var(--danger); color: #fff; }

.kit-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.kit-line:first-child { border-top: 0; }
.kit-line .grow { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kit-line input { width: 72px; min-height: 38px; text-align: center; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--chip); display: grid; place-items: center; flex: none; }
.icon-btn i[data-icon] { width: 16px; height: 16px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; font-weight: 600; font-size: 14px; }
.switch input { width: 46px; height: 26px; accent-color: var(--accent); }

.denied { text-align: center; padding-top: 40px; }
.denied code { background: var(--chip); padding: 2px 8px; border-radius: 8px; font-weight: 700; }

/* иконки предметов */
.thumb { position: relative; overflow: hidden; background: var(--chip); }
.thumb img { position: absolute; inset: 4px; width: calc(100% - 8px); height: calc(100% - 8px); object-fit: contain; }
.thumb:not(.noimg) i[data-icon] { visibility: hidden; }
.item .thumb { width: 52px; height: 52px; }
.kit-line .thumb { width: 38px; height: 38px; border-radius: 10px; }
.sheet-hero { display: flex; align-items: center; gap: 14px; margin-right: 44px; }
.sheet-hero .thumb { width: 72px; height: 72px; border-radius: 16px; }
.sheet-hero h3 { margin-right: 0; }
.kit-icons { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.kit-icons .thumb { width: 44px; height: 44px; border-radius: 10px; }
.list .item { content-visibility: auto; contain-intrinsic-size: auto 76px; }

/* чат */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; box-shadow: var(--shadow); }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.msg-head b { color: var(--text); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.msg-head time { margin-left: auto; flex: none; }
.msg-text { margin-top: 4px; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg.server { background: var(--accent-soft); border-color: transparent; }
.msg.server .msg-head b { color: var(--accent); }
.sys { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 8px; }
.compose {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 4;
  display: flex; gap: 8px; margin-top: 12px; padding: 10px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.compose .input { flex: 1; min-width: 0; }
.compose .btn { width: auto; margin: 0; min-height: 46px; padding: 0 16px; }
