:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #6b7785;
  --line: #e3e8ee;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}
.wrap.wide { max-width: 720px; }

.block-title {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 14px;
  letter-spacing: -.01em;
}
.block-title.small-title { font-size: 13px; font-weight: 700; color: var(--muted); }
.small { font-size: 12px; }

header.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 20px;
}

header.bar h1 {
  font-size: 20px;
  margin: 0;
  letter-spacing: -.01em;
}

.nav {
  display: flex;
  gap: 8px;
}

.nav a {
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
}

.nav a.active {
  color: var(--accent);
  background: #eef3ff;
  border-color: #dbe4ff;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin: 0 0 6px;
}

input[type="number"],
input[type="text"],
input[type="date"] {
  width: 100%;
  font-size: 18px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.row { margin-bottom: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.variants {
  display: flex;
  gap: 8px;
}
.variants button {
  flex: 1;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 700;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  cursor: pointer;
}
.variants button.on {
  border-color: var(--accent);
  background: #eef3ff;
  color: var(--accent);
}
.variants .hint { font-size: 11px; font-weight: 500; color: var(--muted); display: block; }

.variant-toggle {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; background: none; border: none; padding: 0; cursor: pointer;
  font-size: 15px; font-weight: 600; color: var(--ink); text-align: left;
}
.variant-toggle .chev { color: var(--accent); font-size: 14px; font-weight: 700; white-space: nowrap; }
.variants-wrap { margin-top: 14px; }

/* Результат */
.result .wpc {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 4px;
}
.result .big {
  font-size: 40px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.1;
  margin: 0 0 14px;
}
.result .big .zone { font-size: 30px; }

.portions {
  display: grid;
  gap: 10px;
}
.portion {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
}
.portion .lbl { font-size: 16px; color: var(--muted); }
.portion .val { font-size: 24px; font-weight: 800; }
.portion .add { font-size: 14px; font-weight: 700; color: var(--accent); margin-left: 8px; }
.portion .add.zero { color: var(--ok); }

.banner {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}
.banner.enough { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.banner.huge   { background: #ecfdf3; color: #027a48; border: 1px solid #abefc6; }
.banner.small  { background: #fef3f2; color: #b42318; border: 1px solid #fecdca; }

.note-min {
  font-size: 13px;
  color: var(--muted);
  margin-top: 12px;
  line-height: 1.45;
}

.btn {
  display: block;
  width: 100%;
  padding: 15px;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 6px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: #eef1f5; color: var(--ink); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: #b42318; }

.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.muted { color: var(--muted); }

/* Производные разбора (после разморозки/чистки) */
.derived { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.dline { display: flex; justify-content: space-between; padding: 5px 0; font-size: 15px; }
.dline span:first-child { color: var(--muted); }
.pct { font-weight: 700; padding: 1px 7px; border-radius: 7px; font-size: 13px; }
.pct.ok { background: #ecfdf3; color: #027a48; }
.pct.bad { background: #fef3f2; color: #b42318; }
.balance-err { margin-top: 8px; padding: 8px 10px; background: #fef3f2; color: #b42318; border-radius: 8px; font-size: 13px; font-weight: 600; }

/* Метрики */
.metrics, .act-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}
.act-metrics { grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); }
.metric {
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 6px;
  text-align: center;
}
.metric.bad { background: #fef3f2; border-color: #fecdca; }
.metric .m-val { font-size: 18px; font-weight: 800; }
.metric.bad .m-val { color: #b42318; }
.metric .m-lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }

.banner.warn { background: #fffaeb; color: #b54708; border: 1px solid #fedf89; }
.banner.info { background: #eff6ff; color: #1849a9; border: 1px solid #b2ddff; }
.pf-note { margin-top: 8px; }

/* Фильтры */
.filters .frow { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters .frow > div { flex: 1; min-width: 110px; }
.filters select, .filters input { font-size: 15px; padding: 10px 12px; }
.btn.small { width: auto; padding: 11px 16px; font-size: 14px; margin-top: 0; }

/* Карточка акта */
.card.act { padding: 14px 16px; }
.act-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.act-head b { font-size: 18px; }
.zone-big { font-size: 18px; }
.act-meta { font-size: 13px; color: var(--muted); }
.act-doklad { border-top: 1px solid var(--line); padding-top: 10px; font-size: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.dk-title { font-weight: 700; color: var(--muted); }
.dk { background: #eef3ff; color: var(--accent); font-weight: 700; padding: 2px 8px; border-radius: 7px; }
.copy-btn { margin-left: auto; font-size: 13px; font-weight: 600; border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 9px; cursor: pointer; }
.copy-btn:hover { background: #f4f6f8; }
.act-nos { margin-top: 8px; }
