/* Labtrack — calm, light and minimal, in the spirit of Apple's design: system type, generous
   space, white surfaces on a soft grey, one blue accent used sparingly. Light theme only. */
:root {
  --bg: #f7f7f9;
  --surface: #ffffff;
  --fill: #eeeef2;          /* secondary buttons, chips, inputs */
  --fill-2: #f4f4f7;
  --text: #1d1d1f;
  --muted: #86868b;
  --line: rgba(0, 0, 0, .07);
  --accent: #0071e3;
  --accent-text: #ffffff;
  --accent-soft: rgba(0, 113, 227, .1);
  --ok: #248a3d;   --ok-soft: rgba(52, 199, 89, .14);
  --warn: #b25000; --warn-soft: rgba(255, 149, 0, .16);
  --danger: #d70015; --danger-soft: rgba(255, 59, 48, .12);
  --radius: 14px;
  --tabbar: 58px;
  --shadow: 0 0 0 .5px rgba(0, 0, 0, .05), 0 2px 10px rgba(0, 0, 0, .03);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, sans-serif;
  letter-spacing: -0.01em; -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; letter-spacing: -0.022em; }
h1 { font-size: 1.9rem; font-weight: 600; line-height: 1.12; }
h2 { font-size: 1.2rem; font-weight: 600; margin: 28px 0 10px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: 0; }
.strong { font-weight: 600; }
.end { text-align: right; }
.mt { margin-top: 8px; }
.section { margin-top: 20px; }
.desc { white-space: pre-wrap; margin: 8px 0 0; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }

#view { max-width: 720px; margin: 0 auto; padding: 14px 20px 32px; }

/* ---- tab bar: translucent, hairline ---- */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex;
  background: rgba(247, 247, 249, .9); background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
/* On wide screens the tabs stay over the content column. */
#tabs { padding-left: max(0px, calc(50% - 360px)); padding-right: max(0px, calc(50% - 360px)); }
#tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: var(--tabbar); font-size: .7rem; color: var(--muted); }
#tabs a.active { color: var(--accent); }
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---- header ---- */
.top { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; min-height: 44px; }
.top h1 { flex: 1; min-width: 0; font-size: 1.7rem; }
.back { font-size: 2rem; line-height: 1; padding: 0 8px 4px 0; color: var(--accent); font-weight: 300; }

/* ---- buttons: pill-shaped; primary = filled blue, others = soft grey ---- */
button, .btn {
  font: inherit; font-size: 1rem; font-weight: 500; border: 0; border-radius: 980px;
  background: var(--fill); color: var(--accent); padding: 10px 18px; min-height: 44px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: opacity .15s, transform .1s;
}
button:active, .btn:active { transform: scale(.98); opacity: .85; }
button.primary { background: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.link { background: none; color: var(--accent); padding: 4px; min-height: 0; border-radius: 6px; }
button.link.danger { color: var(--danger); }
button.link.muted { color: var(--muted); }
button.sm, .btn.sm { min-height: 36px; padding: 4px 14px; font-size: .9rem; }
button.star { background: none; font-size: 1.5rem; padding: 0 6px; color: var(--muted); }
button.star[aria-pressed="true"] { color: var(--accent); }
button.wide, .wide { width: 100%; }
button.big { width: 100%; min-height: 54px; font-size: 1.06rem; margin-top: 12px; }
button:disabled { opacity: .4; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .grow, .grow { flex: 1; min-width: 0; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }

/* ---- inputs: filled, no borders ---- */
input, select, textarea {
  font: inherit; font-size: 17px; width: 100%; color: var(--text); background: var(--fill-2);
  border: 0; border-radius: 12px; padding: 12px 14px; min-height: 46px; outline: none; appearance: none;
}
.sheet input, .sheet select, .sheet textarea { background: var(--fill); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px var(--accent-soft); }
button:focus-visible, a:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0; flex: none; appearance: auto; accent-color: var(--accent); background: none; }
label { display: block; margin: 16px 0 0; font-size: .82rem; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 6px; }
.hint { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.hint.danger-text { color: var(--danger); }
label > .hint:last-child { margin-bottom: 6px; }
label.check { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 1rem; }
.form-head { margin-top: 18px; font-weight: 600; }
/* "What applies to this item?": tick everything relevant */
.attrs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
.attr { background: var(--surface); color: var(--text); box-shadow: var(--shadow); min-height: 40px; padding: 8px 14px 8px 10px; font-size: .95rem; font-weight: 500; }
.attr .tick { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--muted); font-size: .75rem; }
.attr.on { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.attr.on .tick { background: var(--accent); border-color: var(--accent); color: #fff; }
button.pending { position: relative; padding: 0; border-radius: 10px; overflow: hidden; }
button.pending img { width: 84px; height: 84px; object-fit: cover; }
button.pending span { position: absolute; top: 2px; right: 6px; color: #fff; text-shadow: 0 0 3px #000; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
details > summary { cursor: pointer; color: var(--accent); margin-top: 18px; list-style: none; }
details > summary::-webkit-details-marker { display: none; }

.search { position: sticky; top: 0; z-index: 10; margin: 0 -20px; padding: 8px 20px;
  background: rgba(247, 247, 249, .92); background: color-mix(in srgb, var(--bg) 85%, transparent); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); }
.search input { padding-left: 40px; box-shadow: var(--shadow); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='m16 16 4.5 4.5'/%3E%3C/svg%3E") 12px center / 19px no-repeat; }

/* ---- chips and segmented controls ---- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 6px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.chip { flex: none; background: var(--fill); color: var(--text); border-radius: 980px; padding: 6px 14px; min-height: 34px; font-size: .9rem; font-weight: 500; white-space: nowrap; }
.chip.on { background: var(--accent-soft); color: var(--accent); }
.chip .n { color: var(--muted); margin-left: 5px; font-size: .78rem; }
.chip.on .n { color: inherit; opacity: .7; }
.chip.new { background: var(--warn-soft); color: var(--warn); outline: 1px dashed var(--warn); }
.row.nowrap { flex-wrap: nowrap; }
.filter { margin-top: 16px; }
.filter .form-head { margin: 0 0 6px; }
.tag { display: inline-block; background: var(--fill); border-radius: 6px; padding: 2px 8px; font-size: .8rem; margin: 2px 5px 2px 0; color: var(--text); }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.toolbar h2 { margin: 0; }
.toolbar.section { margin-top: 20px; }
.chips.tabs { margin-top: 20px; border-bottom: .5px solid var(--line); padding-bottom: 10px; }
.seg { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { background: none; border-radius: 7px; min-height: 30px; padding: 4px 12px; font-size: .88rem; color: var(--text); }
.seg button.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.select-sm { width: auto; min-height: 34px; padding: 4px 30px 4px 12px; font-size: .9rem; border-radius: 980px; background-color: var(--fill); }

.banner { display: block; background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; margin: 10px 0; font-size: .9rem; }
.banner.danger { background: var(--danger-soft); color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.err { color: var(--danger); font-size: .9rem; margin-top: 10px; }

/* ---- gallery ---- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(156px, 1fr)); gap: 14px; }
.card { background: var(--surface); border-radius: 18px; overflow: hidden; color: var(--text); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.card .ph { aspect-ratio: 1; background: var(--fill-2); position: relative; }
.card .ph img { width: 100%; height: 100%; object-fit: cover; }
.card .ph .code { position: absolute; left: 8px; top: 8px; background: rgba(255, 255, 255, .82); color: var(--text); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-radius: 7px; padding: 2px 7px; font-size: .74rem; }
.card .ph .state { position: absolute; left: 6px; bottom: 6px; }
.card .body { padding: 10px 12px 12px; }
.card .name { font-weight: 600; font-size: .95rem; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .where { font-size: .78rem; color: var(--muted); margin-top: 3px; }
.noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 1.5rem; font-weight: 600; letter-spacing: .02em; }

/* ---- grouped lists (inset, iOS style) ---- */
.list, .group { background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.li, .row-button {
  display: flex; gap: 12px; align-items: center; width: 100%; padding: 11px 16px; color: var(--text);
  background: none; border: 0; border-radius: 0; text-align: left; font-weight: 400; min-height: 52px; position: relative;
}
.li + .li::before, .row-button + .row-button::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line); }
.row-button { justify-content: space-between; font-size: 1.02rem; }
.row-button.danger { color: var(--danger); }
.chev { color: var(--muted); opacity: .6; font-size: 1.3rem; }
.li .thumb { width: 50px; height: 50px; border-radius: 10px; overflow: hidden; background: var(--fill-2); flex: none; }
.li .thumb img { width: 100%; height: 100%; object-fit: cover; }
.li .thumb .noimg { font-size: .75rem; }
.li .main { flex: 1; min-width: 0; }
.li .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .side { text-align: right; font-size: .85rem; flex: none; }

.badge { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: .74rem; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--fill); color: var(--muted); }

/* floating add button */
.fab {
  position: fixed; right: max(20px, calc(50% - 340px)); bottom: calc(var(--tabbar) + 18px + env(safe-area-inset-bottom)); z-index: 15;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font-size: 1.9rem; font-weight: 300; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(0, 113, 227, .22);
}

/* ---- home ---- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
.tile { display: flex; flex-direction: column; gap: 4px; min-height: 136px; padding: 18px; background: var(--surface); border-radius: 20px; color: var(--text); box-shadow: var(--shadow); }
.tile-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); font-size: 1.15rem; line-height: 1; margin-bottom: auto; color: var(--accent); }
.tile-title { font-weight: 500; font-size: 1.05rem; line-height: 1.2; letter-spacing: -0.02em; }
.tile-sub { font-size: .82rem; color: var(--muted); }
.home .search { position: static; margin: 0; padding: 0; background: none; backdrop-filter: none; }
.home .search input { min-height: 52px; font-size: 18px; }
.home .hello { margin: 12px 0 4px; }
.home h1 { font-size: 1.6rem; margin-bottom: 14px; }
.ml { margin-left: 6px; }
.li .sub.danger-text { color: var(--danger); }

/* ---- item page ---- */
.photos { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -20px; padding: 0 20px; scrollbar-width: none; }
.photos::-webkit-scrollbar { display: none; }
.photos .p { flex: none; width: 80%; max-width: 380px; aspect-ratio: 4/3; border-radius: 20px; overflow: hidden; background: var(--fill-2); scroll-snap-align: start; position: relative; padding: 0; }
.photos .p img { width: 100%; height: 100%; object-fit: cover; }
.photos .p.add { display: grid; place-items: center; color: var(--accent); width: 44%; font-weight: 500; }
.photos .star { position: absolute; right: 8px; top: 8px; background: rgba(255, 255, 255, .82); color: var(--text); border-radius: 7px; padding: 2px 8px; font-size: .74rem; }
.headline { margin: 18px 0 6px; }
.headline .code { font-size: .9rem; font-weight: 600; color: var(--muted); }
.headline h1 { font-size: 1.75rem; margin-top: 2px; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; box-shadow: var(--shadow); }
.panel.alert { background: var(--danger-soft); box-shadow: none; }
.where { display: flex; gap: 14px; align-items: center; color: var(--text); }
.where-link { display: contents; color: inherit; }
.where > button { flex: none; }
.att { display: flex; gap: 4px; align-items: center; }
.att a { overflow-wrap: anywhere; }
details .timeline { margin-top: 8px; }
.where .lp { width: 60px; height: 60px; border-radius: 12px; overflow: hidden; background: var(--fill-2); flex: none; }
.where .lp img { width: 100%; height: 100%; object-fit: cover; }
.stock { font-size: 2rem; font-weight: 600; letter-spacing: -0.03em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .95rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 20px; }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--fill); }
.timeline li::after { content: ""; position: absolute; left: 6.5px; top: 20px; bottom: 2px; width: 1px; background: var(--line); }
.timeline li:last-child::after { display: none; }
.timeline li.t-comment::before { background: var(--accent); }
.timeline li.t-missing::before, .timeline li.t-found::before { background: var(--danger); }
.timeline li.t-purchase::before, .timeline li.t-attachment::before { background: var(--ok); }
.timeline .meta { font-size: .78rem; color: var(--muted); }
.timeline .meta a { color: inherit; }
.timeline .sum { white-space: pre-wrap; overflow-wrap: anywhere; }
.timeline li.t-comment .sum { background: var(--surface); border-radius: 12px; padding: 9px 12px; margin-top: 3px; box-shadow: var(--shadow); }
.timeline li.voided .sum { text-decoration: line-through; color: var(--muted); }
.timeline .changes { font-size: .8rem; color: var(--muted); margin-top: 2px; }

/* ---- sheets ---- */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--bg); color: var(--text); border-radius: 16px 16px 0 0;
}
dialog.sheet::before { content: ""; display: block; width: 36px; height: 5px; border-radius: 3px; background: var(--fill); margin: 8px auto 0; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .18); }
@media (min-width: 600px) { dialog.sheet { margin: auto; border-radius: 16px; } }
.sheet form, .sheet-body { padding: 10px 20px calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; }
.sheet-head h2 { margin: 0; font-size: 1.25rem; }
.sheet-foot { display: flex; gap: 10px; margin-top: 20px; position: sticky; bottom: 0; background: var(--bg); padding: 10px 0 calc(4px + env(safe-area-inset-bottom)); }
.sheet-foot button { flex: 1; }

dialog.viewer { border: 0; padding: 0; background: #000; max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh; }
dialog.viewer img { width: 100%; height: 100%; object-fit: contain; }
dialog.viewer .bar { position: absolute; top: env(safe-area-inset-top); left: 0; right: 0; display: flex; justify-content: space-between; padding: 12px; }
dialog.viewer .bar button { background: rgba(255, 255, 255, .18); color: #fff; -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--tabbar) + 22px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .95); background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--text); border-radius: 980px; padding: 10px 18px;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  max-width: 90vw; font-size: .92rem; box-shadow: 0 0 0 .5px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .1);
}

/* ---- sign-in and PIN pad ---- */
.auth { max-width: 380px; margin: 9vh auto 0; }
.auth .logo { width: 64px; height: 64px; border-radius: 15px; margin-bottom: 16px; }
.auth h1 { font-size: 2.2rem; }
.auth h2 { margin-top: 28px; }
.auth .group { margin-bottom: 10px; }
.pin { text-align: center; padding-top: 4vh; }
.pin h1 { font-size: 1.6rem; }
.dots { display: flex; gap: 16px; justify-content: center; margin: 26px 0 8px; min-height: 14px; }
.pin p.muted { min-height: 1.47em; }
.pin .err { min-height: 1.4em; margin-top: 0; }
.dots span { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--text); }
.dots span.on { background: var(--text); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.keys { display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 26px; justify-content: center; margin: 24px 0 16px; }
.key { width: 76px; height: 76px; border-radius: 50%; background: var(--fill); color: var(--text); font-size: 1.9rem; font-weight: 400; padding: 0; }

/* ---- labels (printing) ---- */
.label-sheet { display: none; }
@media print {
  @page { margin: 8mm; }
  body { background: #fff; padding: 0; }
  #tabs, #toast, .no-print, .fab { display: none !important; }
  #view { max-width: none; padding: 0; }
  .label-sheet { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 3mm; color: #000; }
  .label { border: 0.3mm dashed #999; border-radius: 2mm; padding: 2.5mm 3mm; break-inside: avoid; }
  .label .lc { font: 700 var(--code-size, 16pt)/1.1 ui-monospace, Menlo, monospace; }
  .label .ln { font-size: 8pt; line-height: 1.2; margin-top: 1mm; }
}
