:root {
  --bg: #F7F6F2;
  --surface: #FFFFFF;
  --ink: #1A1D27;
  --ink-2: #4A4F63;
  --muted: #8A8FA3;
  --line: #E4E2DA;
  --red: #C0392B;
  --red-soft: #FBEAE8;
  --green: #1E8E5A;
  --green-soft: #E3F4EB;
  --amber: #B7791F;
  --amber-soft: #FBF1DE;
  --blue: #2F6FB3;
  --blue-soft: #E5EEF8;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}
[hidden] { display: none !important; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; padding-bottom: calc(72px + var(--safe-b));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

/* --- Шапка --- */
#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--ink); color: #fff;
}
#title { flex: 1; margin: 0; font-size: 18px; font-weight: 700; letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#who { font-size: 12px; color: #9AA0B8; }
.icon-btn { background: none; border: 0; color: #fff; font-size: 30px; line-height: 1; padding: 0 8px 4px 0; cursor: pointer; }

/* --- Нижні вкладки --- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
#tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 11px; color: var(--muted); }
#tabs a .ti { font-size: 22px; line-height: 1.1; }
#tabs a.on { color: var(--red); font-weight: 600; }

main { padding: 16px; max-width: 640px; margin: 0 auto; }
.loading, .empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* --- Картки, блоки --- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.section-title { margin: 20px 4px 8px; font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }

/* --- Кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; cursor: pointer; width: 100%;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #EBC4BF; }
.btn.sm { min-height: 38px; font-size: 14px; padding: 0 12px; width: auto; }
.btn:disabled { opacity: .5; }
.btn-big { min-height: 64px; font-size: 18px; }
.actions { display: grid; gap: 8px; margin-top: 12px; }
.actions.two { grid-template-columns: 1fr 1fr; }

/* --- Плитки на головній --- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.tile { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 14px; min-height: 86px; display: flex; flex-direction: column; justify-content: space-between; }
.tile b { font-size: 16px; padding-right: 30px; }
.tile span { font-size: 12px; color: var(--muted); }
.tile .count { position: absolute; top: 10px; right: 10px; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px;
  background: var(--red); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; }

/* --- Форми --- */
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=tel], input[type=email], input[type=password], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px; /* 16px — щоб iPhone не збільшував сторінку */
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.req::after { content: " *"; color: var(--red); }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { flex: 1 0 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; min-height: 44px; line-height: 42px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 600; font-size: 15px; cursor: pointer; }
.seg input:checked + span { background: var(--ink); color: #fff; border-color: var(--ink); }

/* --- OEM-чіпи --- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); font-family: var(--mono); font-size: 14px; }
.chip button { border: 0; background: none; padding: 2px 6px; font-size: 16px; cursor: pointer; color: var(--muted); }
.chip.ok { background: var(--green-soft); border-color: #BFE3CF; }
.chip .v { font-family: -apple-system, sans-serif; font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 999px; border: 0; }
.chip .v.on { background: var(--green); color: #fff; }
.chip .v.off { background: var(--line); color: var(--ink-2); }

/* --- Фото --- */
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--line); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .x { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border-radius: 14px; border: 0;
  background: rgba(26,29,39,.75); color: #fff; font-size: 16px; cursor: pointer; }
.ph select { position: absolute; left: 4px; right: 4px; bottom: 4px; min-height: 30px; padding: 2px 6px; font-size: 12px; border-radius: 6px; }
.ph .tag { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(26,29,39,.75); color: #fff; padding: 2px 6px; border-radius: 6px; }
.add-photo { aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 10px; display: grid; place-items: center;
  color: var(--muted); font-weight: 600; font-size: 14px; text-align: center; cursor: pointer; background: #fff; }
.strip { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -14px; padding: 0 14px; }
.strip img { height: 150px; border-radius: 10px; scroll-snap-align: start; cursor: zoom-in; }
#lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: grid; place-items: center; }
#lightbox[hidden] { display: none; }
#lightbox img { max-width: 100%; max-height: 100%; }

/* --- Список деталей --- */
.plist { display: grid; gap: 8px; }
.pitem { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; }
.pitem .thumb { width: 56px; height: 56px; border-radius: 10px; background: var(--bg); flex: none; overflow: hidden;
  display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.pitem .thumb img { width: 100%; height: 100%; object-fit: cover; }
.pitem .body { flex: 1; min-width: 0; }
.pitem .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pitem .m { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sku { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--ink-2); }

/* --- Бейджі статусів --- */
.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.st-created { background: var(--blue-soft); color: var(--blue); }
.st-needs_photos, .st-needs_id { background: var(--amber-soft); color: var(--amber); }
.st-in_stock { background: var(--green-soft); color: var(--green); }
.st-reserved { background: #EFE7FB; color: #6B46C1; }
.st-sold { background: var(--ink); color: #fff; }
.st-written_off { background: var(--line); color: var(--ink-2); }
.flag { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--amber-soft); color: var(--amber); font-weight: 600; margin: 2px 4px 0 0; }

/* --- Картка деталі --- */
.hero { text-align: center; }
.hero .bigsku { font-family: var(--mono); font-size: 30px; font-weight: 800; letter-spacing: 1px; }
.hero h2 { font-size: 19px; margin: 4px 0 8px; }
.barcode { background: #fff; border-radius: 10px; padding: 8px; margin-top: 10px; }
.barcode svg { width: 100%; height: auto; max-height: 120px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 15px; }
dl.kv dt { color: var(--muted); font-size: 13px; padding-top: 2px; }
dl.kv dd { margin: 0; font-weight: 500; word-break: break-word; }
.banner { background: var(--green-soft); color: var(--green); border-radius: 12px; padding: 12px 14px; font-weight: 600; margin-bottom: 12px; }
.banner.warn { background: var(--amber-soft); color: var(--amber); }
.hist { font-size: 13px; color: var(--ink-2); padding: 6px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.money { font-weight: 700; }
.lst { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lst:last-child { border-bottom: 0; }

/* --- Сканер --- */
#reader { width: 100%; min-height: 220px; border-radius: var(--radius); overflow: hidden; background: #000; }
#reader video { object-fit: cover; }
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.step { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fff; min-height: 64px; }
.step .n { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.step .v { font-family: var(--mono); font-weight: 800; font-size: 17px; margin-top: 2px; }
.step.on { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.step.done { border-color: #BFE3CF; background: var(--green-soft); }

/* --- Тост --- */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-b)); z-index: 60;
  max-width: 600px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: #fff; font-weight: 600; text-align: center;
  opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
#toast.show { opacity: 1; transform: none; }
#toast.err { background: var(--red); }

.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { font-size: 44px; font-weight: 900; text-align: center; margin-bottom: 4px; }
.login .logo i { color: var(--red); font-style: normal; }
.progress { font-size: 14px; color: var(--ink-2); text-align: center; padding: 8px; }

/* --- Згорнуті форми --- */
details.fold > summary { list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { display: none; }
details.fold > form { margin-top: 2px; }
