:root {
  --bg: #f4f5f7; --card: #fff; --text: #1a1d21; --muted: #6b7280; --line: #e3e5e9;
  --accent: #2563eb; --accent-text: #fff; --pos: #15803d; --neg: #b91c1c;
  --vip: #b45309; --vip-bg: #fef3c7; --badge-bg: #eef0f3; --bar: #cfd8ea;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121417; --card: #1c1f24; --text: #e7e9ee; --muted: #9aa3b2; --line: #2b2f36;
    --accent: #3b82f6; --pos: #4ade80; --neg: #f87171;
    --vip: #fbbf24; --vip-bg: #3a2e12; --badge-bg: #2a2e35; --bar: #334155;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
}
body.has-bottom { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
a { color: inherit; text-decoration: none; }
main { padding: 0 12px 24px; max-width: 720px; margin: 0 auto; }

.top {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top)); max-width: 720px; margin: 0 auto;
}
.top h1 { font-size: 20px; margin: 0; flex: 1; }
.back { font-size: 32px; line-height: 1; padding: 0 10px 4px 2px; color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); font: inherit; padding: 6px; }

.card { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.stack > * + * { margin-top: 12px; }
.big { font-size: 28px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.r { text-align: right; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.error { color: var(--neg); margin: 0; }
.flash { max-width: 720px; margin: 0 auto 8px; padding: 0 12px; }
.flash div { background: var(--pos); color: #fff; padding: 10px 14px; border-radius: 10px; }

.badge { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--badge-bg); color: var(--muted); }
.badge.vip { background: var(--vip-bg); color: var(--vip); font-weight: 600; }
.badges { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.label { font-weight: 500; color: var(--accent); font-size: 15px; }

input, textarea, button { font: inherit; color: inherit; }
input[type=search], input[type=password], input[type=text], input:not([type]), textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
textarea { resize: vertical; min-height: 180px; line-height: 1.45; }
.btn {
  display: inline-block; padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); text-align: center; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.big-btn { display: block; width: 100%; font-size: 18px; padding: 16px; }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent); max-width: 720px; margin: 0 auto;
}

.toolbar { margin-bottom: 10px; }
.segment { display: flex; background: var(--badge-bg); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.segment a, .segment label {
  flex: 1; text-align: center; padding: 9px 4px; border-radius: 10px; font-size: 14px; color: var(--muted); cursor: pointer;
}
.segment .on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segment input { position: absolute; opacity: 0; width: 0; height: 0; }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; padding: 12px 14px; }
.row-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.num { font-weight: 700; font-size: 17px; }
.row-bottom { display: flex; gap: 6px; font-size: 14px; margin-top: 3px; flex-wrap: wrap; }
.row-bottom .last { margin-left: auto; color: var(--muted); }
.row-action {
  display: flex; align-items: center; justify-content: center; width: 56px; font-size: 28px;
  color: var(--accent); border-left: 1px solid var(--line);
}
.row-action:active { background: var(--badge-bg); }

.tbl { width: 100%; border-collapse: collapse; }
.tbl th { font-size: 12px; color: var(--muted); font-weight: 500; text-align: left; padding: 0 0 6px; }
.tbl td { padding: 8px 0; border-top: 1px solid var(--line); vertical-align: top; }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { margin-bottom: 10px; }
.bar-head { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 3px; }
.bar { height: 6px; background: var(--badge-bg); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }

.plain { list-style: none; margin: 0; padding: 0; }
.plain > li + li { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }
.pos-row, .kv { display: flex; justify-content: space-between; gap: 10px; }
.kv { padding: 4px 0; }

.label-edit { margin-top: 10px; }
.label-edit summary { color: var(--accent); cursor: pointer; }
.inline { display: flex; gap: 8px; margin-top: 8px; }
.inline input { flex: 1; }

.feed-head { display: flex; justify-content: space-between; font-size: 14px; }
.feed .text { margin: 4px 0 0; white-space: pre-wrap; }
.feed .deal { margin: 6px 0 0; font-size: 14px; }

/* Этап 3: разбор, шаги, CRM-текст */
.badge.warn { background: var(--vip-bg); color: var(--vip); }
.status { margin: 8px 0; padding: 8px 10px; border-radius: 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.status.wait { background: var(--badge-bg); color: var(--muted); }
.status.fail { background: var(--vip-bg); color: var(--vip); }
.spin { width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.inline-form { display: inline; }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn.ghost { background: transparent; }
.fields { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 14px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; }
.steps { list-style: none; margin: 10px 0 0; padding: 0; }
.steps .step { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--line); }
.steps .step:first-child { border-top: 0; }
#steps .steps .step:first-child { border-top: 0; }
.step-body { flex: 1; min-width: 0; }
.step-title { font-weight: 500; }
.step-actions { display: flex; flex-direction: column; gap: 6px; }
.step.busy { opacity: .5; pointer-events: none; }
.step.done .step-title, .step.dismissed .step-title { color: var(--muted); font-weight: 400; }
.step.dismissed .step-title { text-decoration: line-through; }
.crm { margin-top: 10px; background: var(--badge-bg); border-radius: 10px; padding: 8px 10px; }
.crm-head { display: flex; justify-content: space-between; align-items: center; }
.crm pre { white-space: pre-wrap; margin: 6px 0 0; font: 14px/1.4 inherit; font-family: inherit; }
.act-actions { margin-top: 8px; font-size: 13px; display: flex; gap: 14px; }
.act-actions a, .act-actions .link { color: var(--accent); padding: 0; }
.notice { background: var(--vip-bg); color: var(--vip); padding: 8px 12px; border-radius: 10px; margin-bottom: 10px; font-size: 14px; }
.sides { padding-left: 12px; }
.sides .kv { padding: 1px 0; }

/* Этап 5: материалы */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label, .stack > label { display: block; font-size: 13px; color: var(--muted); }
.grid2 input, .grid2 select, .stack > label input { display: block; width: 100%; margin-top: 3px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font-size: 15px; }
.chk { display: inline-flex; align-items: center; gap: 4px; margin-right: 10px; font-size: 14px; color: var(--text); }
.vipc { color: var(--vip); }
.matref { color: var(--accent); }
.notice a { color: inherit; text-decoration: underline; }
code { background: var(--badge-bg); padding: 1px 5px; border-radius: 5px; }
