:root {
  --bg: #f5f5f4;
  --surface: #ffffff;
  --surface-2: #f0efed;
  --line: #e2e0dd;
  --text: #1c1917;
  --muted: #78716c;
  --accent: #1c1917;
  --accent-text: #fafaf9;
  --amber: #d97706;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --green: #15803d;
  --checker-a: #ffffff;
  --checker-b: #ebe9e6;
  --shadow: 0 1px 2px rgba(28, 25, 23, .06), 0 6px 20px rgba(28, 25, 23, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0a09;
    --surface: #1c1917;
    --surface-2: #26221f;
    --line: #34302c;
    --text: #fafaf9;
    --muted: #a8a29e;
    --accent: #fafaf9;
    --accent-text: #1c1917;
    --red: #f87171;
    --red-soft: #3b1414;
    --green: #4ade80;
    --checker-a: #2a2623;
    --checker-b: #221f1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0a09; --surface: #1c1917; --surface-2: #26221f; --line: #34302c; --text: #fafaf9; --muted: #a8a29e;
  --accent: #fafaf9; --accent-text: #1c1917; --red: #f87171; --red-soft: #3b1414; --green: #4ade80;
  --checker-a: #2a2623; --checker-b: #221f1c; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--red); font-size: 14px; margin: 8px 0 0; min-height: 1em; }
.error:empty { min-height: 0; margin: 0; }
.no { color: var(--red); }
.code { font-variant-numeric: tabular-nums; font-weight: 600; letter-spacing: .02em; }
.grow { flex: 1; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 100px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.quiet { background: transparent; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.icon-btn {
  width: 42px; height: 42px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 100px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-size: 22px; line-height: 1; cursor: pointer;
}

/* sign-in */
.signin { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.signin-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; padding: 32px 24px;
  box-shadow: var(--shadow); text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: stretch;
}
.signin-card img { align-self: center; border-radius: 12px; }
.signin-card h1 { margin: 4px 0 0; font-size: 24px; }
.signin-card p { margin: 0; }
input, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 13px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--text); outline-offset: 0; border-color: transparent; }
textarea { resize: vertical; min-height: 70px; }

/* header */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.top .icon-btn { border-color: transparent; background: transparent; margin-left: -10px; }
.titles { flex: 1; min-width: 0; }
.kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kicker:empty { display: none; }
.top h1 { margin: 0; font-size: 21px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
.view { max-width: 980px; margin: 0 auto; padding: 16px 16px calc(110px + env(safe-area-inset-bottom)); }

/* inventories */
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.inv-card {
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); color: inherit; text-decoration: none; border: 0; padding: 0; font: inherit; text-align: left; cursor: pointer;
}
.inv-cover {
  aspect-ratio: 4 / 3; display: grid; place-items: center; overflow: hidden;
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 50% / 18px 18px;
}
.inv-cover img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.inv-cover span { font-size: 26px; font-weight: 800; letter-spacing: .06em; color: var(--muted); }
.inv-card.new .inv-cover { background: var(--surface-2); }
.inv-card.new .inv-cover span { font-size: 40px; font-weight: 300; }
.inv-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; }
.inv-info b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-info small { color: var(--muted); font-size: 13px; }

/* one inventory */
.inv-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.stats { margin: 0; color: var(--muted); font-size: 14px; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); color: inherit; text-decoration: none; font-size: 13px; font-weight: 600; text-align: center;
}
.tool svg { width: 24px; height: 24px; }
.search { border-radius: 100px; padding-left: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 100px;
  padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chips.small { margin-top: 8px; flex-wrap: wrap; }
.chips.small .chip { padding: 4px 10px; font-size: 13px; }

.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.item-card {
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); border: 0; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.thumb { position: relative; aspect-ratio: 1; display: grid; place-items: center; background: var(--surface-2); overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.cut { background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 50% / 16px 16px; }
.thumb.cut img { object-fit: contain; padding: 8px; }
.noimg { color: var(--muted); font-size: 13px; }
.qty {
  position: absolute; top: 8px; right: 8px; background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 100px;
}
.meta { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.meta b { font-size: 15px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meta small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { align-self: flex-start; margin-top: 4px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 100px; }
.badge.no { background: var(--red-soft); color: var(--red); }

.fab {
  position: fixed; z-index: 4; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px; height: 54px; padding: 0 22px 0 18px; border-radius: 100px; border: 0;
  background: var(--accent); color: var(--accent-text); font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.fab span { font-size: 26px; font-weight: 400; line-height: 1; }

/* dialogs */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(12, 10, 9, .5); }
.modal { width: min(440px, calc(100vw - 32px)); border-radius: 18px; box-shadow: var(--shadow); }
.modal form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { margin: 0; font-size: 19px; }
.modal-btns { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }

.sheet {
  width: 100vw; max-width: 560px; height: 100dvh; max-height: 100dvh; margin: 0 auto;
}
@media (min-width: 600px) {
  .sheet { height: min(860px, calc(100dvh - 48px)); margin: auto; border-radius: 18px; box-shadow: var(--shadow); }
}
.sheet form { display: flex; flex-direction: column; height: 100%; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px; border-bottom: 1px solid var(--line); flex: none;
}
.sheet-head h2 { margin: 0; font-size: 17px; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head .btn.primary { min-width: 76px; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }

.photo-box { display: flex; flex-direction: column; gap: 10px; }
.photo-frame {
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--radius); overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center;
}
.photo-frame.cut { background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 50% / 20px 20px; }
.photo-frame img { width: 100%; height: 100%; object-fit: contain; }
.photo-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.photo-busy {
  position: absolute; inset: auto 10px 10px 10px; display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 12px; background: rgba(12, 10, 9, .78); color: #fafaf9; font-size: 13.5px;
}
.spinner { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.photo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.photo-actions .btn { flex: 1; }
.photo-actions .btn.quiet { flex: none; }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px;
  border-radius: 12px; background: var(--surface-2); cursor: pointer;
}
.switch-row > span { display: flex; flex-direction: column; font-size: 15px; }
.switch-row small { font-size: 13px; font-weight: 400; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 50px; height: 30px; padding: 0; margin: 0;
  border-radius: 100px; border: 0; background: var(--line); position: relative; cursor: pointer; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: default; }
.switch:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper input { width: 96px; text-align: center; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; -moz-appearance: textfield; }
.stepper input::-webkit-inner-spin-button, .stepper input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.item-extra { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.item-extra p { margin: 0; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* export */
.export-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.ex-list { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.ex-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ex-row:last-child { border-bottom: 0; }
.ex-row.off .ex-thumb, .ex-row.off .ex-text { opacity: .4; }
.check { width: 22px; height: 22px; flex: none; accent-color: var(--text); margin: 0; }
.ex-thumb { width: 48px; height: 48px; flex: none; border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.ex-thumb.cut { background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 50% / 10px 10px; }
.ex-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ex-thumb.cut img { object-fit: contain; padding: 3px; }
.ex-text { display: flex; flex-direction: column; min-width: 0; }
.ex-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-text small { color: var(--muted); font-size: 13px; }
.export-bar {
  position: fixed; z-index: 4; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.export-bar .btn { flex: 1; max-width: 200px; }

.toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--accent); color: var(--accent-text); padding: 10px 18px; border-radius: 100px; font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .tools { grid-template-columns: repeat(3, minmax(0, 180px)); }
  .item-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
