/* BackflowFiler — общий стиль приложения.
   Токены и крупные элементы взяты из docs/demo.html:
   пользователь работает с телефона, часто в перчатках и на солнце. */

:root {
  --ink: #13324b;
  --ink-2: #2c4a63;
  --accent: #9a6414;
  --accent-dark: #7c500f;
  --brass: #e0a24a;
  --cream: #f6f3ec;
  --line: #ddd5c2;
  --text: #1c2b38;
  --muted: #6b7a87;
  --pass: #2f6e42;
  --pass-bg: #eaf4ed;
  --fail: #a3342a;
  --fail-bg: #fbecea;
  --warn: #8a5a0c;
  --warn-bg: #fdf3e2;
  --pad: 16px;
  --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--cream);
  color: var(--text);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

h1, h2, h3, .brand, button, .btn {
  font-family: 'Archivo', system-ui, sans-serif;
}

a { color: var(--ink); }

:focus-visible { outline: 3px solid var(--brass); outline-offset: 2px; }

/* ---------- Шапка ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--ink);
  color: #fff;
  padding: 12px var(--pad);
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { font-weight: 800; font-size: 18px; color: #fff; text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--brass); }
.topbar .company { font-size: 13px; color: #c9d5df; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar a.signout { color: #fff; font-size: 14px; font-weight: 600; text-decoration: none; padding: 8px 4px; white-space: nowrap; }

main { max-width: 720px; margin: 0 auto; padding: 20px var(--pad) 48px; }

.page-title { font-size: 24px; font-weight: 800; color: var(--ink); margin: 4px 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }

/* ---------- Карточки и показатели ---------- */

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 16px; color: var(--ink); margin: 0 0 12px; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-height: 104px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat .num { font-family: 'Archivo', sans-serif; font-weight: 800; font-size: 34px; line-height: 1; color: var(--ink); }
.stat .label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.bad { border-color: #e8c4bf; background: var(--fail-bg); }
.stat.bad .num { color: var(--fail); }
.stat.warn { border-color: #efd9b0; background: var(--warn-bg); }
.stat.warn .num { color: var(--warn); }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; }
.steps li {
  counter-increment: step;
  position: relative;
  padding: 10px 0 10px 44px;
  border-top: 1px solid #eee7d8;
}
.steps li:first-child { border-top: none; }
.steps li::before {
  content: counter(step);
  position: absolute; left: 0; top: 9px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--cream); border: 1.5px solid var(--line);
  font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.steps li.done::before { content: '✓'; background: var(--pass-bg); border-color: #bcd9c5; color: var(--pass); }
.steps .t { font-weight: 600; color: var(--ink); }
.steps .d { font-size: 14px; color: var(--muted); }

/* ---------- Формы ---------- */

label { display: block; font-size: 14px; font-weight: 600; color: #4a5a68; margin: 14px 0 6px; }
label:first-of-type { margin-top: 0; }
input, select {
  width: 100%;
  padding: 14px 12px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  font: inherit;
  font-size: 17px;
  background: #fff;
  color: inherit;
}
input:focus, select:focus { border-color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin-top: 14px; }
.check input { width: 22px; height: 22px; }
.field-hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  padding: 15px 20px; min-height: 52px;
  border-radius: 9px; border: none; cursor: pointer; text-decoration: none;
}
.btn-main { background: var(--accent); color: #fff; width: 100%; margin-top: 22px; }
.btn-main:hover { background: var(--accent-dark); }

.alert { border-radius: 9px; padding: 12px 14px; margin-bottom: 16px; font-size: 15px; }
.alert-error { background: var(--fail-bg); color: var(--fail); border: 1px solid #e8c4bf; }
.alert-ok { background: var(--pass-bg); color: var(--pass); border: 1px solid #bcd9c5; }

/* ---------- Экраны входа ---------- */

.auth-wrap { max-width: 440px; margin: 0 auto; padding: 32px var(--pad) 48px; }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand .brand { color: var(--ink); font-size: 26px; }
.auth-brand .brand span { color: var(--accent); }
.auth-brand p { color: var(--muted); margin: 6px 0 0; }
.auth-wrap .card { padding: 22px; }
.auth-wrap h1 { font-size: 20px; color: var(--ink); margin: 0 0 18px; }
.auth-foot { text-align: center; margin-top: 18px; font-size: 15px; }

@media (min-width: 640px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- Навигация ---------- */

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 0 var(--pad);
  scrollbar-width: none;
}
.tabs a {
  flex: 0 0 auto;
  padding: 14px 12px 12px;
  font-weight: 600;
  font-size: 15px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- Заголовок страницы с действием ---------- */

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head .page-title { margin: 0; }
.page-head .page-sub { margin: 4px 0 0; }
.crumbs { font-size: 14px; margin-bottom: 8px; color: var(--muted); }
.crumbs a { color: var(--muted); }

.btn-sm { min-height: 44px; padding: 10px 16px; font-size: 15px; width: auto; margin: 0; flex: 0 0 auto; }
.btn-add { background: var(--accent); color: #fff; }
.btn-add:hover { background: var(--accent-dark); }
.btn-ghost { background: #fff; color: var(--ink); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-danger { background: #fff; color: var(--fail); border: 1.5px solid #e8c4bf; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 22px; }
.btn-row .btn-main { margin-top: 0; flex: 1 1 200px; width: auto; }

/* ---------- Списки ---------- */

.list { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; overflow: hidden; }
.list > a, .list > .row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-top: 1px solid #eee7d8; color: inherit; text-decoration: none;
  min-height: 64px;
}
.list > :first-child { border-top: none; }
.list > a:hover { background: #fbf9f4; }
.list .main { min-width: 0; }
.list .title { font-weight: 600; color: var(--ink); }
.list .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.list .side { flex: 0 0 auto; text-align: right; font-size: 13px; color: var(--muted); }
.list-head { font-family: 'Archivo', sans-serif; font-size: 13px; font-weight: 700; text-transform: uppercase;
             letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; display: flex; justify-content: space-between; align-items: center; }
.list-head a { text-transform: none; letter-spacing: 0; font-size: 14px; }

.badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge.bad { background: var(--fail-bg); color: var(--fail); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.ok { background: var(--pass-bg); color: var(--pass); }
.badge.muted { background: #f0ede5; color: var(--muted); }
.type { font-family: 'Archivo', sans-serif; font-weight: 800; color: var(--ink); margin-right: 6px; }

.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .btn { margin-top: 14px; }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; }
.search button { width: auto; min-height: auto; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters a { padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff;
             text-decoration: none; font-weight: 600; font-size: 14px; color: var(--ink-2); }
.filters a[aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Карточка с деталями ---------- */

.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 15px; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.note-box { white-space: pre-line; background: var(--cream); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-top: 12px; }

/* ---------- Формы: ряды и секции ---------- */

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-row > div > label { margin-top: 14px; }
.form-row-3 { grid-template-columns: 2fr 1fr 1fr; }
fieldset.group { border: none; padding: 0; margin: 22px 0 0; }
fieldset.group legend { font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink); padding: 0; margin-bottom: 4px; }
textarea {
  width: 100%; min-height: 90px; padding: 12px; border: 1.5px solid var(--line); border-radius: 9px;
  font: inherit; font-size: 16px; resize: vertical;
}
.danger-zone { margin-top: 28px; padding-top: 18px; border-top: 1px solid var(--line); }

a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--ink-2); }

@media (max-width: 420px) {
  .form-row-3 { grid-template-columns: 1fr 1fr; }
  .form-row-3 > :first-child { grid-column: 1 / -1; }
}

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 14px; }

/* ---------- Экран теста (по docs/demo.html) ---------- */

fieldset.field { margin: 0 0 16px; }
fieldset.field legend { font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink); padding: 0 6px; }
.reading { display: flex; align-items: center; gap: 10px; }
.reading input { font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 24px; text-align: right; }
.unit { font-size: 14px; color: #7a8894; font-weight: 600; white-space: nowrap; }
.verdict { margin-top: 8px; font-size: 13px; font-weight: 600; min-height: 19px; }
.verdict.ok { color: var(--pass); }
.verdict.bad { color: var(--fail); }
.verdict.muted { color: #97a3ac; font-weight: 500; }

.result { border-radius: var(--radius); padding: 16px; margin-bottom: 16px; font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 18px; }
.result.pass { background: var(--pass-bg); color: var(--pass); border: 1px solid #bcd9c5; }
.result.fail { background: var(--fail-bg); color: var(--fail); border: 1px solid #e8c4bf; }
.result.idle { background: #fff; color: #7a8894; border: 1px dashed var(--line); font-weight: 600; font-size: 15px; }
#retest .result { margin: 16px 0 0; }

.alert-warn { background: var(--warn-bg); color: var(--warn); border: 1px solid #efd9b0; }
.alert-warn div + div { margin-top: 6px; }

.bar {
  position: sticky; bottom: 0; z-index: 4;
  margin: 0 calc(-1 * var(--pad));
  background: #fff; border-top: 1px solid var(--line);
  padding: 12px var(--pad); padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 10px;
}
.bar .btn-main { margin: 0; flex: 1; }
.bar .btn-ghost { flex: 0 0 auto; }

/* ---------- Результат теста ---------- */

.readings-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.readings-table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 0 0 6px; }
.readings-table td { padding: 9px 0; border-top: 1px solid #eee7d8; vertical-align: top; }
.readings-table td.num { font-family: 'Archivo', sans-serif; font-weight: 700; text-align: right; white-space: nowrap; padding-left: 12px; }
.readings-table .req { display: block; font-size: 12px; color: var(--muted); }
.readings-table .fail-mark { color: var(--fail); }

/* ---------- Поля бланка WA DOH ---------- */

.field-block { margin-top: 16px; }
.field-block:first-of-type { margin-top: 4px; }
.field-label { font-size: 14px; font-weight: 600; color: #4a5a68; margin-bottom: 6px; }
.field-label .opt { font-weight: 400; color: var(--muted); }
.reading input:disabled { background: #f3f1ec; color: #aab3ba; }
.check.flag { margin-top: 8px; font-size: 15px; }

.seg { display: flex; gap: 8px; flex-wrap: wrap; }
.seg-opt { flex: 1 1 0; min-width: 90px; margin: 0; position: relative; }
.seg-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg-opt span {
  display: flex; align-items: center; justify-content: center; min-height: 50px; padding: 8px 10px;
  border: 1.5px solid var(--line); border-radius: 9px; background: #fff;
  font-family: 'Archivo', sans-serif; font-weight: 700; font-size: 15px; color: var(--ink-2); cursor: pointer; text-align: center;
}
.seg-opt input:checked + span { background: var(--ink); border-color: var(--ink); color: #fff; }
.seg-opt input:focus-visible + span { outline: 3px solid var(--brass); outline-offset: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { margin: 0; position: relative; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span { display: inline-block; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; font-size: 14px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.chip input:checked + span { background: var(--pass-bg); border-color: #bcd9c5; color: var(--pass); }
.chip input:focus-visible + span { outline: 3px solid var(--brass); outline-offset: 2px; }

.sig-wrap { position: relative; }
#sig { display: block; width: 100%; height: 160px; border: 1.5px dashed var(--line); border-radius: 9px; background: #fff; touch-action: none; }
.sig-clear { position: absolute; top: 8px; right: 8px; min-height: 36px; padding: 6px 12px; font-size: 13px; }
.signature-img { max-width: 260px; max-height: 110px; display: block; }
