:root {
  --bg: #f3f5f9; --card: #ffffff; --ink: #131a26; --mut: #5a6577; --line: #d6dce6;
  --blue: #1d4ed8; --blue-ink: #ffffff; --blue-soft: #e3ebff;
  --warn-bg: #fff4c2; --warn-ink: #5c4300; --warn-line: #e0b400;
  --red: #c62828; --red-soft: #fde7e7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e131b; --card: #19212d; --ink: #eef2f8; --mut: #9aa6b8; --line: #2e3a4b;
    --blue: #5b8cff; --blue-ink: #06102a; --blue-soft: #1d2b4d;
    --warn-bg: #3d3200; --warn-ink: #ffe27a; --warn-line: #8a7000;
    --red: #ff7a7a; --red-soft: #3a1818;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px; max-width: 560px; margin: 0 auto;
}
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--mut); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
main { max-width: 560px; margin: 0 auto; padding: 0 16px 32px; }
section, details.card { margin-top: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.note { color: var(--mut); font-size: 13px; margin: 8px 0 0; }
[hidden] { display: none !important; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 48px; border: 0; border-radius: 10px; background: transparent; font-weight: 600; font-size: 17px; }
.seg.small button { min-height: 36px; min-width: 48px; font-size: 14px; }
.seg button.on { background: var(--blue); color: var(--blue-ink); }

.types { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.types button {
  min-height: 72px; border: 2px solid var(--line); border-radius: 16px; background: var(--card);
  display: flex; align-items: center; gap: 10px; padding: 0 14px; font-size: 16px; font-weight: 600; text-align: left;
}
.types button b { font-size: 24px; font-weight: 400; color: var(--blue); width: 28px; text-align: center; }
.types button.on { border-color: var(--blue); background: var(--blue-soft); }

.btn {
  min-height: 52px; padding: 0 16px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); font-weight: 600; font-size: 16px;
}
.btn.primary { background: var(--blue); border-color: var(--blue); color: var(--blue-ink); }
.btn.big { width: 100%; min-height: 64px; font-size: 18px; }
.btn.danger { color: var(--red); border-color: var(--red); }
.btn.mini { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: default; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }

.field { display: block; margin-top: 10px; }
.field > span { display: block; font-size: 13px; color: var(--mut); margin-bottom: 4px; }
.inp { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; }
.inp input, .inp select { flex: 1; min-width: 0; min-height: 52px; border: 0; background: transparent; padding: 0 12px; font-size: 20px; outline: none; }
.inp select { font-size: 16px; }
.inp:focus-within { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
.inp em { font-style: normal; color: var(--mut); padding: 0 12px; }
.field.name input { font-size: 16px; }

.row { display: grid; gap: 6px; align-items: center; margin-top: 8px; }
.row.side { grid-template-columns: 22px 1fr 1.25fr 40px; }
.row.side.custom { grid-template-columns: 22px 1fr 1fr .7fr 40px; }
.row.part { grid-template-columns: 1.1fr 1fr 1fr 40px; }
.row .inp input, .row .inp select { min-height: 48px; font-size: 17px; padding: 0 8px; }
.row .inp select { font-size: 14px; padding: 0 4px; }
.row .n { color: var(--mut); font-size: 13px; text-align: center; }
.row .x { min-height: 48px; border: 1px solid var(--line); border-radius: 10px; background: transparent; color: var(--red); font-size: 18px; }
.partsign { grid-column: 1 / -1; display: flex; gap: 6px; }

.big-val { font-size: 40px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.big-lbl { color: var(--mut); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.eq { color: var(--mut); font-size: 14px; margin-top: 2px; }
.err { color: var(--blue); font-size: 14px; font-weight: 600; margin-top: 2px; }
.rows { margin-top: 10px; border-top: 1px solid var(--line); }
.rows > div { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.rows .k { color: var(--mut); }
.rows .v { text-align: right; font-weight: 600; }
.rows .v small { display: block; font-weight: 400; color: var(--mut); }
.empty { color: var(--mut); padding: 6px 0; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }
.bad { background: var(--red-soft); color: var(--red); border: 1px solid var(--red); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }

details summary { font-weight: 600; cursor: pointer; min-height: 32px; display: flex; align-items: center; }

.h-item { border-bottom: 1px solid var(--line); padding: 10px 0; }
.h-item:first-child { padding-top: 0; }
.h-top { display: flex; justify-content: space-between; gap: 8px; }
.h-name { font-weight: 600; word-break: break-word; }
.h-meta { color: var(--mut); font-size: 12px; white-space: nowrap; }
.h-res { margin-top: 2px; }
.h-btns { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--blue-soft); color: var(--blue); margin-left: 6px; vertical-align: middle; }
.foot { text-align: center; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 99px; font-size: 14px; font-weight: 600;
  max-width: 90vw; text-align: center;
}

dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--ink); width: min(520px, 94vw); max-height: 92vh; padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.ph { margin-bottom: 14px; }
.ph img { width: 100%; border-radius: 12px; display: block; background: #000; }

/* Camera (AR) screen: transparent, on top of the camera image */
#ar { position: fixed; inset: 0; background: transparent; color: #fff; z-index: 100; user-select: none; -webkit-user-select: none; }
#ar-cv { position: absolute; inset: 0; width: 100%; height: 100%; }
#ar-top { position: absolute; top: 0; left: 0; right: 0; padding: calc(12px + env(safe-area-inset-top)) 12px 0; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
#ar-step { background: rgba(10,16,28,.78); padding: 10px 14px; border-radius: 14px; font-size: 16px; font-weight: 600; text-align: center; }
#ar-warn { background: #ffd84a; color: #2b2000; padding: 8px 12px; border-radius: 12px; font-size: 14px; font-weight: 700; text-align: center; }
#ar-read { position: absolute; left: 0; right: 0; bottom: calc(176px + env(safe-area-inset-bottom)); text-align: center; font-size: 30px; font-weight: 800; text-shadow: 0 1px 6px #000, 0 0 2px #000; pointer-events: none; }
#ar-bot { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.ar-row { display: flex; gap: 8px; }
.ar-row button { flex: 1; min-height: 52px; border-radius: 14px; border: 1px solid rgba(255,255,255,.35); background: rgba(10,16,28,.78); color: #fff; font-weight: 700; font-size: 16px; }
.ar-row button.ar-main { flex: 2; min-height: 72px; font-size: 20px; background: #1d4ed8; border-color: #1d4ed8; }
.ar-row button.ar-fin { min-height: 72px; background: #fff; color: #0b1220; border-color: #fff; }
.ar-row button:disabled { opacity: .4; }
#ar-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; transition: opacity .25s; }
#ar-flash.on { opacity: .8; transition: none; }
