/* Stud Stash - Night Sort, part 2: lists, feed, widgets, motion.
   Tokens and shell live in base.css. */

/* ---------- inventory: add-part picker ---------- */

.part-results {
  list-style: none;
  margin: var(--sp-3) 0 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.part-results li + li { border-top: 1px solid var(--line-soft); }

.part-result-btn {
  width: 100%;
  text-align: left;
  background: var(--panel-raised);
  border: none;
  padding: var(--sp-2) var(--sp-3);
  cursor: pointer;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}

.part-result-btn:hover,
.part-result-btn.is-selected {
  background: var(--badge-build-bg);
}

/* The results list scrolls; keep the focus ring inside it so it never clips. */
.part-result-btn:focus-visible {
  outline-offset: -2px;
}

.part-result-cat {
  font-size: 0.75rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.add-part-form {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px dashed var(--line);
}

.add-part-form-title {
  font-size: 0.9rem;
  margin-bottom: var(--sp-2);
}

/* ---------- inventory list ---------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.inv-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
  background: var(--panel-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

/* Color swatches read as loose studs: round, with a smaller inner circle
   like a stud seen from above. */
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  flex: none;
  position: relative;
}

.swatch::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.inv-item-main { min-width: 0; }

.inv-item-name {
  font-weight: 600;
  display: block;
}

.inv-item-meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.inv-item-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

/* ---------- quantity steppers ---------- */

.qty-stepper {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.qty-stepper button {
  min-width: 30px;
  height: 30px;
  padding: 0 var(--sp-1);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-raised);
  color: var(--ink);
  cursor: pointer;
  font-family: var(--font-mono);
  font-weight: 700;
  line-height: 1;
}

.qty-stepper button:hover {
  border-color: var(--ink-soft);
}

.qty-stepper button:active {
  transform: translateY(1px);
}

/* The +10 stepper is the workhorse for by-the-pound logging; give it the
   bold treatment so it reads as the fast lane. */
.qty-step-ten {
  background: var(--badge-almost-bg) !important;
  border-color: var(--yellow-deep) !important;
  color: var(--badge-almost-fg) !important;
}

.qty-stepper input {
  width: 48px;
  text-align: center;
  padding: var(--sp-1);
  font-family: var(--font-mono);
}

/* ---------- empty states ---------- */

.empty-state {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.empty-state .btn { margin-top: var(--sp-3); }

/* ---------- feed cards ---------- */

.feed-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--sp-4);
  box-shadow: var(--shadow);
  border-top-width: 3px;
}

/* The bold color moment: a card's top edge takes the match verdict's color,
   so a scan down the feed reads like sorted bins. */
.feed-card-buildable { border-top-color: var(--green-deep); }
.feed-card-almost { border-top-color: var(--yellow-deep); }
.feed-card-none { border-top-color: var(--line); }

.feed-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}

.feed-card-title {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0;
}

.feed-meta {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: var(--sp-1) 0 var(--sp-2);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-buildable { background: var(--badge-build-bg); color: var(--badge-build-fg); }
.badge-almost { background: var(--badge-almost-bg); color: var(--badge-almost-fg); }
.badge-example { background: var(--badge-example-bg); color: var(--badge-example-fg); }
.badge-none { background: var(--panel-raised); color: var(--ink-soft); }

/* ---------- stud meter ---------- */
/* Ten studs, filled left to right: the app's progress bar is made of the
   thing it counts. Unfilled studs are empty sockets; filled ones get a
   highlight so they read as molded plastic, not dots. */

.stud-meter {
  display: flex;
  gap: 5px;
  margin: var(--sp-2) 0 var(--sp-1);
}

.stud {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.stud-filled {
  background: radial-gradient(circle at 35% 30%, #b8e5a6, var(--green-deep) 70%);
  border-color: var(--green-deep);
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.4);
}

.match-line { margin-bottom: var(--sp-1); }

.match-pct {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
}

.feed-parts-toggle {
  background: none;
  border: none;
  color: var(--yellow);
  font-weight: 600;
  cursor: pointer;
  padding: var(--sp-1) 0;
  font-size: 0.85rem;
}

.feed-parts-toggle:hover {
  text-decoration: underline;
}

.feed-parts-list {
  list-style: none;
  margin: var(--sp-2) 0 0;
  padding: 0;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  border-top: 1px dashed var(--line);
  padding-top: var(--sp-2);
}

.feed-parts-list li {
  display: flex;
  justify-content: space-between;
  padding: var(--sp-1) 0;
}

.feed-parts-list .have-yes { color: var(--green); }
.feed-parts-list .have-no { color: var(--danger); }

.feed-card-foot {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--sp-2);
}

/* ---------- photos ---------- */

.photo-strip {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin: var(--sp-2) 0;
}

.photo-strip:empty { margin: 0; }

.photo-thumb {
  position: relative;
  display: inline-flex;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-raised);
  cursor: pointer;
  overflow: hidden;
}

.photo-thumb img {
  display: block;
  width: 76px;
  height: 76px;
  object-fit: cover;
}

.photo-thumb:hover { border-color: var(--ink-soft); }

.photo-preview { cursor: default; }

.photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(23, 19, 15, 0.85);
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  cursor: pointer;
}

.photo-remove:hover { color: var(--danger); }

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(23, 19, 15, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
}

.lightbox[hidden] { display: none; }

.lightbox img {
  max-width: min(92vw, 600px);
  max-height: 80vh;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  /* Photos are stored at ~300px; let them scale up softly. */
  image-rendering: auto;
}

.lightbox-close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  background: var(--panel-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--sp-1) var(--sp-3);
  font-weight: 700;
  cursor: pointer;
}

body.lightbox-open { overflow: hidden; }

/* ---------- post form part rows ---------- */

.post-part-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: var(--sp-2);
  align-items: center;
  background: var(--panel-raised);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: var(--sp-2);
}

.post-part-row input[type="text"] { min-width: 0; }
.post-part-row select { width: auto; min-width: 9rem; }
.post-part-row input[type="number"] { width: 4.5rem; }

/* ---------- stub list ---------- */

.stub-list {
  margin: 0 0 var(--sp-2);
  padding-left: 1.2rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.stub-list li { margin-bottom: var(--sp-1); }

/* ---------- tab bar ---------- */

.tab-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg-deep);
  padding: var(--sp-1) var(--sp-1) max(var(--sp-1), env(safe-area-inset-bottom));
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  padding: var(--sp-2) var(--sp-1);
  color: var(--ink-soft);
  cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
}

.tab-btn svg {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 0.72rem;
  font-weight: 600;
}

.tab-btn:hover {
  color: var(--ink);
}

.tab-btn.active {
  color: var(--yellow);
}

/* Active tab carries a single stud above its icon, in stud yellow. */
.tab-btn.active::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe49a, var(--yellow-deep) 75%);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  background: var(--panel-raised);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 4px solid var(--yellow);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: calc(100% - var(--sp-6));
  text-align: center;
}

.toast[hidden] { display: none; }

/* ---------- motion ---------- */
/* All small and mechanical: things settle, nothing bounces like a toy. */

@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 0.16s ease-out;
  }

  .row-flash {
    animation: row-flash 0.9s ease-out;
  }

  .tab-bump svg {
    animation: tab-bump 0.35s ease-out;
  }
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes row-flash {
  0% { background-color: var(--badge-almost-bg); border-color: var(--yellow-deep); }
  100% { background-color: var(--panel-raised); border-color: var(--line-soft); }
}

@keyframes tab-bump {
  0% { transform: translateY(0); }
  40% { transform: translateY(-4px); }
  100% { transform: translateY(0); }
}

/* The stud chip that pops off "Add to bin": a loose yellow stud carrying
   the count, drifting up and gone. Created only when motion is allowed. */
.stud-chip {
  position: fixed;
  z-index: 30;
  transform: translateX(-50%);
  min-width: 34px;
  height: 34px;
  padding: 0 6px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 30%, #ffe49a, var(--yellow) 60%, var(--yellow-deep));
  color: var(--on-yellow);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  animation: stud-pop 0.8s ease-out forwards;
}

@keyframes stud-pop {
  0% { opacity: 0; margin-top: 0; }
  15% { opacity: 1; }
  100% { opacity: 0; margin-top: -56px; }
}

/* ---------- responsive ---------- */

@media (max-width: 420px) {
  .field-row {
    flex-direction: column;
  }
  .field-row > * {
    flex: 1 1 auto;
  }
}

/* Narrow screens: give the quantity controls their own ruled line under the
   part name instead of squeezing everything onto one row. */
@media (max-width: 520px) {
  .inv-item {
    grid-template-columns: auto 1fr;
  }
  .inv-item-controls {
    grid-column: 1 / -1;
    justify-content: flex-end;
    border-top: 1px dashed var(--line-soft);
    padding-top: var(--sp-2);
  }
}

/* Post form part rows: part name gets a full line, color/qty/remove share
   the next one, so nothing collapses to an unusable sliver on a phone. */
@media (max-width: 560px) {
  .post-part-row {
    grid-template-columns: 1fr auto auto;
  }
  .post-part-row .post-part-input {
    grid-column: 1 / -1;
  }
}

/* Touch devices: 44px minimum targets on every control that gets tapped. */
@media (pointer: coarse) {
  .btn,
  .btn-small,
  input[type="text"],
  input[type="search"],
  input[type="number"],
  input[type="url"],
  select {
    min-height: 44px;
  }
  .qty-stepper button {
    min-width: 44px;
    height: 44px;
  }
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }
  .part-result-btn {
    min-height: 44px;
    align-items: center;
  }
  .feed-parts-toggle {
    min-height: 44px;
  }
}

@media (min-width: 720px) {
  .app-shell {
    margin: var(--sp-6) auto;
    min-height: calc(100vh - var(--sp-7) * 2);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 0 0 1px var(--line-soft), 0 24px 60px rgba(0, 0, 0, 0.5);
  }
  .tab-bar {
    border-radius: 0 0 var(--radius) var(--radius);
  }
}
