*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
a { color: var(--c-link); text-decoration: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.logo { display: block; color: var(--c-text); }
.logo-lg { width: 168px; height: 50px; }
.logo-sm { width: 74px; height: 22px; }

/* ---- splash ---- */
.splash {
  position: fixed; inset: 0; z-index: 20;
  background: var(--c-bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  transition: opacity .25s ease;
}
.splash.gone { opacity: 0; pointer-events: none; }
.splash-bar { width: 56px; height: 4px; border-radius: 999px; background: var(--c-accent); }
.splash-text { font-size: 15px; color: var(--c-muted); text-align: center; line-height: 1.5; }

/* ---- shell ---- */
.app {
  display: flex; flex-direction: column;
  height: var(--tg-viewport-stable-height, 100vh);
  height: var(--tg-viewport-stable-height, 100dvh);
  min-height: 0;
  padding-top: var(--tg-content-safe-area-inset-top, 0px);
}
.top {
  flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 12px;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--c-accent); color: var(--c-on-accent);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-weight: 700; font-size: 14px;
}
.avatar:empty { visibility: hidden; }
.view {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 4px 16px 20px;
  display: flex; flex-direction: column; gap: 16px;
  outline: none;
}
.tabs {
  flex-shrink: 0; display: flex;
  border-top: 1px solid var(--c-line); background: var(--c-bar);
  padding: 6px 4px calc(10px + var(--tg-safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1; min-width: 0; border: 0; background: transparent; min-height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--c-muted); font-size: 11px; font-weight: 600;
}
.tab[aria-current="page"] { color: var(--c-link); }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- type ---- */
.h1 { font-family: var(--font-head); font-weight: 700; font-size: 24px; line-height: 1.2; margin: 0; padding: 4px 4px 0; overflow-wrap: anywhere; }
.h2 { font-family: var(--font-head); font-weight: 700; font-size: 18px; margin: 0; padding: 4px 4px 0; }
.h3 { font-family: var(--font-head); font-weight: 700; font-size: 20px; margin: 0; overflow-wrap: anywhere; }
.lead { font-size: 14px; color: var(--c-muted); padding: 0 4px 4px; margin: 0; }
.muted { color: var(--c-muted); }
.small { font-size: 13px; }
.eyebrow { font-weight: 600; font-size: 13px; color: var(--c-muted); padding: 0 4px; text-transform: uppercase; letter-spacing: .04em; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }

/* ---- cards ---- */
.card { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 22px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card-sm { border-radius: 18px; padding: 16px; gap: 10px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chip { font-size: 12px; color: var(--c-muted); background: var(--c-chip); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.chip-warn { background: var(--c-warn-bg); color: var(--c-warn-fg); }
.bar { height: 8px; border-radius: 999px; background: var(--c-chip); overflow: hidden; }
.bar > i { display: block; height: 8px; border-radius: 999px; background: var(--c-accent); }
.tile-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

/* ---- buttons ---- */
.btn {
  border: 0; border-radius: 14px; padding: 13px 16px; min-height: 48px;
  background: var(--c-accent); color: var(--c-on-accent); font-weight: 600; font-size: 15px; text-align: left;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%;
}
.btn:active { filter: brightness(.92); }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-ghost { background: var(--c-chip); color: var(--c-text); border: 1px solid var(--c-line); }
.btn-danger { background: transparent; border: 1px solid var(--c-line); color: var(--c-danger); text-align: center; justify-content: center; }
.btn-center { justify-content: center; text-align: center; }
.tile {
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 18px; padding: 16px; min-height: 104px;
  text-align: left; color: var(--c-text); display: flex; flex-direction: column; justify-content: space-between; gap: 10px;
}
.tile svg { width: 26px; height: 26px; fill: none; stroke: var(--c-link); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tile span { font-weight: 600; font-size: 15px; }

/* ---- lists ---- */
.step {
  background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 18px; padding: 16px; min-height: 76px;
  text-align: left; color: var(--c-text); display: flex; align-items: center; gap: 14px; width: 100%;
}
.badge {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 12px; background: var(--c-chip); color: var(--c-text);
  display: flex; align-items: center; justify-content: center; font-family: var(--font-head); font-weight: 700;
}
.badge.done { background: var(--c-done-bg); color: var(--c-done-fg); }
.badge.now { background: var(--c-accent); color: var(--c-on-accent); }
.step-body { flex: 1; min-width: 0; }
.step-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.step-status { font-size: 12px; color: var(--c-link); white-space: nowrap; }
.step-status.done { color: var(--c-done-fg); }
.tip { background: var(--c-tip); border-radius: 18px; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.tip b { font-weight: 600; font-size: 15px; }
.tip p { margin: 0; font-size: 14px; color: var(--c-muted); line-height: 1.45; }
.list { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 18px; display: flex; flex-direction: column; overflow: hidden; }
.item {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%;
  padding: 15px 16px; min-height: 48px; background: transparent; border: 0; border-bottom: 1px solid var(--c-line);
  color: var(--c-text); text-align: left;
}
.item:last-child { border-bottom: 0; }
.item b { font-weight: 600; display: block; }
.item small { font-size: 13px; color: var(--c-muted); display: block; overflow-wrap: anywhere; }
.item .chev { color: var(--c-muted); flex-shrink: 0; }
.item.off b { color: var(--c-muted); }
.dashed { border: 1px dashed var(--c-line); border-radius: 14px; padding: 13px 16px; color: var(--c-muted); font-size: 14px; }
.beta { font-size: 11px; font-weight: 600; color: var(--c-link); border: 1px solid var(--c-link); border-radius: 999px; padding: 2px 8px; }

/* ---- profile ---- */
.who { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0 4px; text-align: center; }
.avatar-lg { width: 76px; height: 76px; font-size: 26px; }
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.seg button { border: 1px solid var(--c-line); border-radius: 12px; padding: 10px 4px; min-height: 44px; background: var(--c-surface); color: var(--c-text); font-weight: 600; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--c-accent); border-color: var(--c-accent); color: var(--c-on-accent); }

/* ---- admin ---- */
.kpi { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: 18px; padding: 16px; min-width: 0; }
.kpi .v { font-family: var(--font-head); font-weight: 700; font-size: 22px; margin-top: 6px; overflow-wrap: anywhere; }
.kpi .s { font-size: 12px; color: var(--c-muted); margin-top: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--c-muted); min-width: 0; }
.field input, .field select, .field textarea {
  border: 1px solid var(--c-line); border-radius: 12px; padding: 12px; min-height: 44px; width: 100%;
  font-size: 16px; background: var(--c-bg); color: var(--c-text);
}
.field textarea { min-height: 96px; font-size: 13px; resize: vertical; word-break: break-all; }
.field .err { color: var(--c-danger); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.batch .name { font-weight: 600; overflow-wrap: anywhere; }

/* ---- states ---- */
.state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px 12px; }
.state h2 { font-family: var(--font-head); font-size: 20px; margin: 0; }
.state p { margin: 0; color: var(--c-muted); font-size: 14px; max-width: 30ch; }
.state .btn { max-width: 260px; justify-content: center; text-align: center; }
.state svg { width: 44px; height: 44px; fill: none; stroke: var(--c-link); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.banner { background: var(--c-warn-bg); color: var(--c-warn-fg); border-radius: 14px; padding: 12px 14px; font-size: 14px; }
.sk { border-radius: 14px; background: linear-gradient(90deg, var(--c-chip), var(--c-line), var(--c-chip)); background-size: 200% 100%; animation: sk 1.3s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--tg-safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px);
  max-width: calc(100vw - 32px); background: var(--c-text); color: var(--c-bg); border-radius: 12px; padding: 10px 14px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  .app { max-width: 560px; margin: 0 auto; }
  .tabs { border-radius: 0; }
}
@media (max-width: 340px) {
  .tab { font-size: 10px; letter-spacing: -0.01em; }
  .tabs { padding-left: 0; padding-right: 0; }
  .h1 { font-size: 21px; }
  .tile { min-height: 92px; padding: 12px; }
  .view { padding-left: 12px; padding-right: 12px; }
  .card { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .sk { animation: none; }
  .splash, .toast { transition: none; }
}
