:root {
  --bg: #EDF1F6;
  --card: #FFFFFF;
  --ink: #1B2A41;
  --ink-soft: #5B6B80;
  --line: #DCE3EC;
  --navy: #1F3864;
  --blue: #2E75B6;
  --input-bg: #FFF2CC;
  --input-line: #BF9000;
  --calc-bg: #F4F6F9;
  --calc-line: #BFBFBF;
  --ok-bg: #E2EFDA;
  --ok-line: #A9D08E;
  --bad-bg: #FBE3D6;
  --bad-line: #D98C5F;
  --warn-bg: #FFF2CC;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
}

.top {
  background: linear-gradient(135deg, #1F3864 0%, #2E5A96 60%, #2E75B6 100%);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
}
.top-in { max-width: 620px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 12px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.25);
  display: flex; align-items: center; justify-content: center;
  font-size: 25px; font-weight: 600; font-style: italic;
}
.brand h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: 0.2px; }
.brand p { margin: 2px 0 0; font-size: 12.5px; color: #C9D8EC; }

main { max-width: 620px; margin: 0 auto; padding: 14px 12px 8px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin: 0 0 12px;
  box-shadow: 0 1px 2px rgba(23, 43, 77, 0.06), 0 1px 8px rgba(23, 43, 77, 0.04);
}

h2 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2 .num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
}

.field { margin: 0 0 12px; }
.field:last-child { margin-bottom: 0; }
.lbl { display: block; font-size: 12.5px; color: var(--ink-soft); margin-bottom: 6px; }

.seg {
  display: flex;
  background: var(--calc-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  padding: 9px 4px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg button.on {
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(31, 56, 100, 0.35);
}

.grid-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.inp-cell {
  flex: 1 1 44%;
  min-width: 130px;
  display: block;
}
.inp-cell.wide { flex: 1 1 100%; }
.inp-cell > span {
  display: block;
  font-size: 12.5px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.inp-cell input {
  width: 100%;
  font: inherit;
  font-size: 19px;
  font-weight: 600;
  color: var(--navy);
  background: var(--input-bg);
  border: 1.5px solid var(--input-line);
  border-radius: 10px;
  padding: 10px 12px;
  -webkit-appearance: none;
  appearance: none;
  font-variant-numeric: tabular-nums;
}
.inp-cell input::placeholder { color: #B08A2E; opacity: 0.55; font-weight: 400; }
.inp-cell input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 117, 182, 0.18);
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.4;
}

.switch {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--calc-bg);
  color: var(--ink-soft);
  font: inherit;
  font-size: 11.5px;
  padding: 4px 10px;
  border-radius: 20px;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
}
.switch.on { background: var(--ok-bg); border-color: var(--ok-line); color: #2F5B1F; }

.card.result {
  border: 1.5px solid var(--ok-line);
  background: var(--ok-bg);
}
.card.result.bad { border-color: var(--bad-line); background: var(--bad-bg); }
.card.result.empty { border-color: var(--line); background: var(--calc-bg); }

.res-head {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #2F5B1F;
  font-weight: 600;
  margin-bottom: 4px;
}
.card.result.bad .res-head { color: #8A3B12; }
.card.result.empty .res-head { color: var(--ink-soft); }

.res-value {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-variant-numeric: tabular-nums;
}
.res-value > span:first-child {
  font-size: 42px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #1E4620;
}
.card.result.bad .res-value > span:first-child { color: #8A3B12; }
.card.result.empty .res-value > span:first-child { color: var(--ink-soft); font-size: 30px; }
.unit { font-size: 15px; color: var(--ink-soft); font-weight: 500; }

.res-sub { margin-top: 4px; font-size: 13px; color: #3F5B2E; }
.card.result.bad .res-sub { color: #8A3B12; }
.card.result.empty .res-sub { color: var(--ink-soft); }

.res-flags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.flag {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 20px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(47, 91, 31, 0.25);
  color: #2F4B22;
}
.flag.warn { background: #FFF2CC; border-color: var(--input-line); color: #6B4E00; }
.flag.bad { background: #F8CBAD; border-color: #C55A11; color: #7B2E00; }

.actions { display: flex; gap: 10px; margin: 0 0 12px; }
.btn {
  flex: 1 1 0;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 10px;
  border-radius: 11px;
  border: 1.5px solid var(--navy);
  background: var(--navy);
  color: #fff;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--navy); }

.acc { padding: 0; overflow: hidden; }
.acc > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after {
  content: "›";
  font-size: 20px;
  color: var(--blue);
  transform: rotate(90deg);
  transition: transform 0.15s;
  line-height: 1;
}
.acc[open] > summary::after { transform: rotate(-90deg); }
.acc-body, #steps { padding: 0 14px 14px; }

.f {
  margin: 8px 0;
  font-size: 14.5px;
  font-family: Cambria, Georgia, "Times New Roman", serif;
  background: var(--calc-bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 34px 8px 10px;
  text-align: center;
  position: relative;
}
.fnum {
  position: absolute;
  right: 9px;
  bottom: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
}
.note { margin: 8px 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; }
.steps-list, .memo { margin: 8px 0; padding-left: 20px; font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; }
.steps-list li, .memo li { margin: 0 0 6px; }

.disclaimer { font-size: 11.5px; color: #8794A6; margin: 4px 4px 16px; line-height: 1.4; }
.foot {
  text-align: center;
  font-size: 11.5px;
  color: #8794A6;
  padding: 0 12px calc(16px + env(safe-area-inset-bottom));
}

/* пошаговый разбор */
.det-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  margin: 12px 0 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.det-title:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13px; border-bottom: 1px dotted #E3E8EF; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-soft); }
.kv .v { font-weight: 600; color: var(--navy); font-variant-numeric: tabular-nums; text-align: right; }
.kv .v.calc { background: var(--calc-bg); border: 1px solid var(--calc-line); border-radius: 6px; padding: 1px 7px; }
.err { color: #8A3B12; font-size: 13px; }

@media (max-width: 360px) {
  .res-value > span:first-child { font-size: 36px; }
  .seg button { font-size: 12px; }
}

/* ---------- журнал измерений (PRO) ---------- */
.journal h2 { justify-content: space-between; }
.pro {
  background: var(--input-bg);
  border: 1px solid var(--input-line);
  color: #6B4E00;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.6px;
}
.lock-text { font-size: 13px; color: var(--ink-soft); margin: 0 0 10px; line-height: 1.4; }
.lock-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.lock-actions .btn { flex: 1 1 140px; text-align: center; text-decoration: none; padding: 11px 10px; }
.j-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.j-actions .btn { flex: 1 1 0; }
.j-list { list-style: none; margin: 0; padding: 0; }
.j-item { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px dotted #E3E8EF; }
.j-main { flex: 1 1 auto; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.j-rho { font-size: 17px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.j-unit { font-size: 12px; color: var(--ink-soft); }
.j-meta { flex: 1 1 100%; font-size: 11.5px; color: var(--ink-soft); }
.j-del { border: 0; background: transparent; color: #8794a6; font-size: 20px; line-height: 1; padding: 0 4px; cursor: pointer; }
.j-clear { margin-top: 10px; border: 0; background: transparent; color: #8794a6; font: inherit; font-size: 12px; text-decoration: underline; cursor: pointer; padding: 0; }

/* ---------- модальное окно активации ---------- */
.modal { position: fixed; inset: 0; background: rgba(23, 43, 77, 0.45); display: flex; align-items: center; justify-content: center; padding: 18px; z-index: 60; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(15, 30, 60, 0.35); }
.modal-box h3 { margin: 0 0 6px; font-size: 17px; color: var(--navy); }
.modal-box input {
  width: 100%; font: inherit; font-size: 20px; font-weight: 600; letter-spacing: 2px; text-align: center;
  color: var(--navy); background: var(--input-bg); border: 1.5px solid var(--input-line);
  border-radius: 10px; padding: 11px 12px; margin: 10px 0 4px; text-transform: uppercase;
}
.modal-actions { display: flex; gap: 8px; margin-top: 10px; }
.modal-actions .btn { flex: 1 1 0; }
.modal-err { color: #8A3B12; font-size: 12.5px; margin: 6px 0 0; }
.j-toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--navy); color: #fff; font-size: 13px; padding: 10px 16px; border-radius: 22px;
  box-shadow: 0 8px 24px rgba(23, 43, 77, 0.3); z-index: 70; white-space: nowrap;
}
.j-toast[hidden] { display: none; }


/* ---------- установка PWA ---------- */
.install-hint {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 12px;
}
.install-hint[hidden] { display: none; }
.ih-text { flex: 1 1 auto; min-width: 0; }
.ih-text b { display: block; font-size: 13.5px; color: var(--navy); margin-bottom: 2px; }
.ih-text span { display: block; font-size: 12px; color: var(--ink-soft); line-height: 1.35; }
.ih-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.ih-btn {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  color: #fff;
  background: var(--navy);
  border: 1px solid var(--navy);
  border-radius: 9px;
  padding: 8px 11px;
  cursor: pointer;
}
.ih-btn[hidden] { display: none; }
.ih-link {
  font-size: 12.5px;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
}
.ih-close {
  border: 0;
  background: transparent;
  color: #8794a6;
  font-size: 20px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
}
.update-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--navy);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 6px 24px rgba(23, 43, 77, 0.28);
  z-index: 50;
}
.update-bar[hidden] { display: none; }
.update-bar button {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
}

@media (max-width: 380px) {
  .install-hint { flex-wrap: wrap; }
  .ih-actions { width: 100%; justify-content: flex-end; }
}
