/* ==== Icons ==== */
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ==== Buttons & links ==== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4);
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-weight: 600; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-text { color: var(--danger); }
.btn-small { min-height: 32px; padding: 0 var(--s3); font-size: .8125rem; }
.btn-block { width: 100%; }
.link { font-size: .8125rem; font-weight: 550; color: var(--accent); }
.link:hover, .link-button:hover { text-decoration: underline; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 550; cursor: pointer; font-size: inherit; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ==== Shell ==== */
.sidebar { display: none; }
.main { min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: calc(var(--s3) + env(safe-area-inset-top)) max(var(--s4), env(safe-area-inset-right)) var(--s3) max(var(--s4), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.375rem; font-weight: 650; letter-spacing: -.01em; margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#page-title:focus { outline: none; }

.search {
  order: 3; flex: 1 0 100%;
  display: flex; align-items: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s3);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; color: var(--muted);
}
.search:focus-within { border-color: var(--focus); }
.search svg { width: 18px; height: 18px; }
.search input[type=search] { flex: 1; min-width: 0; min-height: 0; height: 100%; padding: 0; border: 0; border-radius: 0; background: none; outline: none; color: var(--text); }
.search input::placeholder { color: var(--muted); }
.btn-add { display: none; }

.content {
  display: grid; gap: var(--s4); align-content: start;
  padding: var(--s4) max(var(--s4), env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(var(--s4), env(safe-area-inset-left));
  max-width: 1200px;
}

.view { display: grid; gap: var(--s4); align-content: start; min-width: 0; }
@media (min-width: 960px) { .view { gap: var(--s5); } }

/* ==== Notices, states ==== */
.notice { font-size: .875rem; color: var(--warn); background: var(--warn-soft); border-radius: var(--radius-sm); padding: var(--s2) var(--s3); }
.notice-error { color: var(--danger); background: var(--danger-soft); display: grid; gap: var(--s2); }
.notice-error ul { padding-left: var(--s4); list-style: disc; }
.hint { font-size: .8125rem; color: var(--muted); }
.center { text-align: center; }
.unknown { color: var(--muted); font-style: italic; }
.meta { font-size: .8125rem; color: var(--muted); }
.loading { display: flex; align-items: center; justify-content: center; gap: var(--s2); padding: var(--s6); color: var(--muted); }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.empty { display: grid; justify-items: center; text-align: center; gap: var(--s2); padding: var(--s6) var(--s5); }
.empty > svg { width: 32px; height: 32px; color: var(--accent); margin-bottom: var(--s2); }
.empty h2 { font-size: 1.0625rem; font-weight: 650; }
.empty p { color: var(--muted); max-width: 40ch; }
.empty .actions { margin-top: var(--s3); justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 420px); padding: var(--s3) var(--s4); border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 550; font-size: .875rem;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.dialog { margin: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: var(--s5); max-width: min(92vw, 420px); display: grid; gap: var(--s3); }
.dialog::backdrop { background: rgb(0 0 0 / .4); }
.dialog h2 { font-size: 1.0625rem; }
.dialog p { color: var(--muted); }
.dialog .actions { justify-content: flex-end; }

.dev-banner { position: fixed; top: 0; left: 0; right: 0; padding: 4px; text-align: center; font-size: .75rem; font-weight: 600; background: var(--warn-soft); color: var(--warn); }
.noscript { padding: var(--s5); text-align: center; }

/* ==== Segmented control ==== */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: .875rem; font-weight: 550; color: var(--muted); white-space: nowrap; }
.segmented input:checked + label { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .08); }
.segmented input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ==== Cards ==== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--s4); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--s3); }
.card-head h2, .card h3 { font-size: .9375rem; font-weight: 650; }
.card h3 { margin-bottom: var(--s3); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
.stat h2 { font-size: .8125rem; font-weight: 550; color: var(--muted); }
.stat-value { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; margin-top: var(--s1); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-value .unit { font-size: .75rem; font-weight: 550; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.stat-meta { font-size: .8125rem; color: var(--muted); margin-top: 2px; }
.stat-link:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

.grid, .stack { display: grid; gap: var(--s4); align-content: start; min-width: 0; }

.welcome { display: grid; gap: var(--s3); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.welcome h2 { font-size: 1.125rem; }
.welcome-points { display: grid; gap: var(--s2); list-style: none; }
.welcome-points li { color: var(--muted); }
.welcome-points strong { color: var(--text); }

/* ==== Rows ==== */
.rows > li + li { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; }
a.row { margin: 0 calc(-1 * var(--s2)); padding-inline: var(--s2); border-radius: var(--radius-sm); }
a.row:hover { background: var(--surface-2); }
.row > svg { color: var(--muted); }
.row-main { display: grid; min-width: 0; flex: 1; }
.row-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: .8125rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows-compact .row { padding: var(--s2) 0; }
ul.card.rows { padding-block: var(--s2); }

.thumb { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 10px; font-weight: 650; font-size: .875rem; object-fit: cover; background: var(--surface-2); color: var(--muted); }
.thumb-lg { width: 100%; height: auto; aspect-ratio: 1; border-radius: 12px; font-size: 1.75rem; }
.tone-lego { background: #fde8e8; color: #b42318; }
.tone-vinyl { background: #e8effd; color: #1d4ed8; }
.tone-funko { background: #e7f6ee; color: #15803d; }

.chip { flex: none; font-size: .75rem; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); justify-self: start; }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-muted { background: var(--surface-2); color: var(--muted); }

/* ==== Meters ==== */
.meters { display: grid; gap: var(--s3); }
.meters li { display: grid; grid-template-columns: 7.5rem 1fr 4.5rem; align-items: center; gap: var(--s3); font-size: .875rem; }
.meters .num { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
meter { width: 100%; height: 6px; appearance: none; -webkit-appearance: none; border: 0; border-radius: 99px; background: var(--surface-2); }
meter::-webkit-meter-bar { background: var(--surface-2); border: 0; border-radius: 99px; height: 6px; }
meter::-webkit-meter-optimum-value, meter::-webkit-meter-suboptimum-value, meter::-webkit-meter-even-less-good-value { background: var(--accent); border-radius: 99px; }
meter::-moz-meter-bar { background: var(--accent); border-radius: 99px; }

/* ==== Inventory ==== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); min-width: 0; }
.scroll-x { overflow-x: auto; max-width: 100%; scrollbar-width: none; }
.sort { display: flex; align-items: center; gap: var(--s2); font-size: .875rem; color: var(--muted); }
.result-count { font-size: .875rem; color: var(--muted); margin-bottom: var(--s3); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--s3); }
.item-card { display: grid; gap: var(--s2); padding: var(--s2); border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); height: 100%; align-content: start; }
.item-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.item-card-body { display: grid; gap: 2px; min-width: 0; padding: 0 var(--s1) var(--s1); }

/* ==== Forms ==== */
:where(input:not([type=radio], [type=checkbox], [type=file]), select, textarea) {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
:where(input, select, textarea):focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.search input[type=search]:focus { outline: none; }
[aria-invalid="true"] { border-color: var(--danger) !important; }
label { font-size: .875rem; font-weight: 600; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field-error { color: var(--danger); font-size: .8125rem; font-weight: 550; }
.field-error:empty { display: none; }
.grid-fields { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1fr); }
.grid-fields + .grid-fields { margin-top: var(--s4); }
.form-sections, .item-form { display: grid; gap: var(--s4); }
.form-card { display: grid; gap: var(--s4); }
.form-card h2 { font-size: 1rem; font-weight: 650; }
details.form-card > summary { list-style: none; cursor: pointer; display: grid; gap: 2px; }
details.form-card > summary::-webkit-details-marker { display: none; }
details.form-card > summary h2::after { content: ' ▾'; color: var(--muted); font-weight: 400; }
details.form-card[open] > summary h2::after { content: ' ▴'; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; }
.form-msg { color: var(--danger); font-weight: 550; }
.form-msg:empty { display: none; }
.scope-note { display: flex; align-items: center; gap: var(--s2); font-size: .875rem; color: var(--muted); }
.saved { display: grid; gap: var(--s3); }
.saved h2 { font-size: 1.25rem; }

/* Photo picker */
.photo-picker { display: grid; gap: var(--s3); }
.photo-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: var(--s2); }
.photo-list:empty { display: none; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo-none { display: grid; place-items: center; align-content: center; gap: 4px; height: 100%; color: var(--muted); font-size: .75rem; }
.photo-remove { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: 50%; background: rgb(0 0 0 / .6); color: #fff; cursor: pointer; }
.photo-remove svg { width: 16px; height: 16px; }
.photo-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.photo-actions label { cursor: pointer; }
.btn-camera { display: none; }
@media (pointer: coarse) { .btn-camera { display: inline-flex; } }

/* ==== Item page ==== */
.back { display: inline-flex; align-items: center; gap: 4px; font-size: .875rem; font-weight: 550; color: var(--muted); justify-self: start; }
.back svg { width: 18px; height: 18px; }
.item-layout { display: grid; gap: var(--s4); }
.item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.eyebrow { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.item-title { font-size: 1.375rem; font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
.item-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s4); }
.kvs { display: grid; }
.kv { display: grid; grid-template-columns: minmax(7rem, 40%) 1fr; gap: var(--s3); padding: var(--s2) 0; font-size: .9375rem; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv dt { color: var(--muted); }
.kv dd { overflow-wrap: anywhere; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; }
.gallery { display: grid; gap: var(--s3); align-content: start; }
.gallery-main { position: relative; display: grid; gap: var(--s2); }
.gallery-main img { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 10px; background: var(--surface-2); }
.gallery-tools { display: flex; gap: var(--s2); }
.gallery-empty { display: grid; place-items: center; align-content: center; gap: var(--s2); aspect-ratio: 4 / 3; border-radius: 10px; background: var(--surface-2); color: var(--muted); text-align: center; padding: var(--s4); }
.gallery-empty svg { width: 32px; height: 32px; }
.gallery-strip { display: flex; gap: var(--s2); overflow-x: auto; }
.gallery-strip button { width: 64px; height: 64px; padding: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.gallery-strip img { width: 100%; height: 100%; object-fit: cover; }
.add-photos > summary { list-style: none; display: inline-flex; }
.add-photos > summary::-webkit-details-marker { display: none; }
.add-photos[open] { display: grid; gap: var(--s3); }
.settings { max-width: 640px; }

/* ==== Sign in ==== */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: max(var(--s5), env(safe-area-inset-top)) var(--s4) var(--s5); }
.signin-card { width: 100%; max-width: 380px; display: grid; gap: var(--s4); }
.signin-logo { width: 48px; height: 48px; }
.signin-card h1 { font-size: 1.625rem; letter-spacing: -.02em; }
.lede { color: var(--muted); }
.signin-form { display: grid; gap: var(--s3); }
.signin-form input { font-size: 1.0625rem; }
#code { letter-spacing: .3em; font-variant-numeric: tabular-nums; font-size: 1.25rem; }
.fineprint { font-size: .75rem; color: var(--muted); }

/* ==== Mobile tab bar ==== */
.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  padding: 6px max(var(--s2), env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(var(--s2), env(safe-area-inset-left));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar a { display: grid; justify-items: center; gap: 2px; font-size: .6875rem; font-weight: 550; color: var(--muted); padding: 4px 0; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; }
.tabbar .tab-add { justify-self: center; width: 48px; height: 48px; border-radius: 16px; place-content: center; background: var(--accent); color: var(--accent-ink); }
.tabbar .tab-add svg { stroke-width: 2.2; }

/* ==== Tablet+ ==== */
@media (min-width: 640px) {
  .search { order: 0; flex: 0 1 320px; }
  .btn-add { display: inline-flex; }
  .btn-add svg { stroke-width: 2.2; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-wide { grid-column: 1 / -1; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
  .toast { bottom: var(--s5); }
}

/* ==== Desktop ==== */
@media (min-width: 960px) {
  .tabbar { display: none; }
  .shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100dvh; }
  .sidebar {
    position: sticky; top: 0; height: 100dvh;
    display: flex; flex-direction: column; gap: var(--s5);
    padding: var(--s5) var(--s3);
    border-right: 1px solid var(--border); background: var(--surface);
  }
  .brand { display: flex; align-items: center; gap: var(--s2); padding: 0 var(--s2); font-weight: 700; font-size: 1.0625rem; }
  .brand-mark { width: 28px; height: 28px; }
  .nav { display: grid; gap: 2px; }
  .nav-secondary { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--border); }
  .nav a { display: flex; align-items: center; gap: var(--s3); padding: 8px var(--s2); border-radius: var(--radius-sm); color: var(--muted); font-weight: 550; }
  .nav a:hover { background: var(--surface-2); color: var(--text); }
  .nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
  .sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: var(--s3); padding: var(--s2); font-size: .875rem; border-radius: var(--radius-sm); min-width: 0; }
  .sidebar-foot:hover { background: var(--surface-2); }
  .sidebar-foot span:last-child { display: grid; min-width: 0; }
  .sidebar-foot strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-foot small { color: var(--muted); font-size: .75rem; }
  .sidebar-domain { padding: 0 var(--s2); margin-top: calc(-1 * var(--s4)); font-size: .75rem; color: var(--muted); }
  .avatar { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 650; }

  .topbar { padding-inline: var(--s6); }
  .content { padding: var(--s5) var(--s6) var(--s6); gap: var(--s5); }
  .grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .item-layout { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); align-items: start; }
  .item-form { max-width: 880px; }
}

@media (prefers-color-scheme: dark) {
  .tone-lego { background: #3b1a1a; color: #fca5a5; }
  .tone-vinyl { background: #18233d; color: #93b4fd; }
  .tone-funko { background: #14301f; color: #86efac; }
}
.form-card h2 .chip { margin-left: var(--s2); vertical-align: middle; }
.form-card > .btn { justify-self: start; }
