/* ============================================================================
   components.css — product cards, rails, filter drawer, modals, chips
   ========================================================================= */

/* ── search suggestions ──────────────────────────────────────────────────── */
.suggest { position: absolute; inset-inline: 0; top: calc(100% + 6px); background: var(--white);
  border: var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; z-index: 40; }
.suggest[hidden] { display: none; }
.suggest a { display: flex; gap: 12px; align-items: baseline; padding: 9px 13px; border-bottom: var(--line); }
.suggest a:last-child { border-bottom: 0; }
.suggest a:hover { background: var(--amber-wash); }
.suggest .s-name { flex: 1; }
.suggest .s-pn { font-family: var(--mono); font-size: .76rem; color: var(--steel-500); }
.suggest .s-price { font-family: var(--mono); font-size: .8rem; }

/* ── product card ────────────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 16px; }

.card { background: var(--white); border: var(--line); border-radius: var(--r);
  display: flex; flex-direction: column; position: relative; overflow: hidden;
  transition: border-color .18s, box-shadow .18s; }
.card:hover { border-color: var(--steel-700); box-shadow: var(--shadow); }

.card-media { position: relative; aspect-ratio: 1 / 1; display: grid; place-items: center;
  background:
    linear-gradient(var(--steel-100) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, var(--steel-100) 1px, transparent 1px) 0 0 / 24px 100%, var(--white);
  border-bottom: var(--line); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: contain; padding: 10px; transition: transform .3s ease; }
.card:hover .card-media img { transform: scale(1.05); }
.card-media .placeholder { color: var(--steel-300); font-size: .78rem; }

.card-flags { position: absolute; top: 8px; inset-inline-start: 8px; display: grid; gap: 5px; justify-items: start; }
.flag { font-size: .68rem; font-weight: 700; padding: 2px 7px; border-radius: var(--r); line-height: 1.7; }
.flag.off { background: var(--gone); color: var(--white); font-family: var(--mono); }
.flag.fit { background: var(--amber); color: var(--ink); }
.flag.orig { background: var(--steel-800); color: var(--white); }

.card-stock { position: absolute; bottom: 8px; inset-inline-end: 8px; background: rgba(255,255,255,.94);
  border: var(--line); border-radius: var(--r); padding: 2px 8px; font-size: .7rem;
  display: flex; align-items: center; gap: 5px; }
.card-stock::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.card-stock.ok { color: var(--ok); } .card-stock.low { color: var(--low); } .card-stock.gone { color: var(--gone); }

.card-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card h3 { margin: 0; font-size: .9rem; font-weight: 600; line-height: 1.65;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .pn { font-family: var(--mono); font-size: .72rem; color: var(--steel-500); }
.card-foot { margin-top: auto; padding-top: 9px; border-top: 1px dashed var(--steel-150);
  display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .price { font-family: var(--mono); font-weight: 700; font-size: 1rem; line-height: 1.3; }
.card .price small { font-family: "Vazirmatn", Tahoma, sans-serif; font-weight: 400;
  font-size: .7rem; color: var(--steel-500); }
.card del { display: block; font-family: var(--mono); font-size: .72rem; color: var(--steel-300); }
.card .add-btn { width: 40px; height: 40px; flex-shrink: 0; border: 1px solid var(--steel-800);
  background: var(--steel-800); color: var(--white); border-radius: var(--r);
  display: grid; place-items: center; cursor: pointer; transition: background .15s; }
.card .add-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.card .add-btn:hover { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.card .add-btn.done { background: var(--ok); border-color: var(--ok); }
.card .add-btn[disabled] { background: var(--white); border-color: var(--steel-150); color: var(--steel-300); cursor: not-allowed; }

/* ── rails ───────────────────────────────────────────────────────────────── */
.rail { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(228px, 1fr); gap: 16px;
  overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; scrollbar-width: thin; }
.rail > * { scroll-snap-align: start; }
.rail-nav { display: flex; gap: 6px; }
.rail-nav button { width: 30px; height: 30px; border: var(--line); background: var(--white);
  border-radius: var(--r); cursor: pointer; display: grid; place-items: center; }
.rail-nav button:hover { background: var(--steel-800); color: var(--white); border-color: var(--steel-800); }

/* ── category cards ──────────────────────────────────────────────────────── */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.cat-card { background: var(--white); border: var(--line); border-radius: var(--r); padding: 13px 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border-inline-start: 3px solid var(--steel-150); transition: border-color .18s; }
.cat-card:hover { border-inline-start-color: var(--amber); }
.cat-card b { font-weight: 600; font-size: .9rem; }
.cat-card .count { font-family: var(--mono); font-size: .74rem; color: var(--steel-500); }

/* ── filter drawer ───────────────────────────────────────────────────────── */
.filters { background: var(--white); border: var(--line); border-radius: var(--r); position: sticky; top: 14px; }
.filters > h3 { margin: 0; padding: 12px 15px; border-bottom: var(--line); font-size: .92rem;
  font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.filters .close-filters { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; line-height: 1; }
.filter-group { padding: 13px 15px; border-bottom: var(--line); }
.filter-group:last-of-type { border-bottom: 0; }
.filter-group .title { display: block; font-size: .76rem; color: var(--steel-500); margin-bottom: 7px; }
.filter-group .pair { display: flex; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: .86rem; cursor: pointer; }
.check input { width: auto; }
.filter-actions { padding: 13px 15px; display: flex; gap: 8px; border-top: var(--line); }
.filter-toggle { display: none; }
.scrim { position: fixed; inset: 0; background: rgba(21,25,28,.5); z-index: 65; }
.scrim[hidden] { display: none; }

@media (max-width: 820px) {
  .filter-toggle { display: inline-flex; }
  /* Opens from the RIGHT (the start edge in RTL) and is hidden with display,
     not transform — a translated panel still occupies layout and used to push
     the whole page sideways. */
  .filters { position: fixed; inset-block: 0; inset-inline-start: 0; width: min(330px, 88vw);
    z-index: 70; overflow-y: auto; border-radius: 0; border: 0;
    transform: translateX(100%); visibility: hidden;
    transition: transform .26s cubic-bezier(.22,.61,.36,1), visibility .26s;
    box-shadow: -18px 0 40px -24px rgba(0,0,0,.6); }
  .filters.open { transform: none; visibility: visible; }
  .filters .close-filters { display: block; }
  .filters > h3 { position: sticky; top: 0; background: var(--white); z-index: 2; }
  .filters .filter-actions { position: sticky; bottom: 0; background: var(--white); }
}
@keyframes drawer-in { from { transform: translateX(30%); opacity: .4; } to { transform: none; opacity: 1; } }

/* ── modals (login + machine picker) ─────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(21,25,28,.55); display: grid; place-items: center;
  z-index: 80; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--white); border-radius: var(--r-lg); width: min(400px, 100%);
  position: relative; border-top: 4px solid var(--amber); max-height: 92vh; overflow-y: auto; }
.modal-card > div { padding: 24px 22px 20px; display: grid; gap: 12px; }
.modal-card > div[hidden] { display: none; }
.modal-card h3 { margin: 0; font-size: 1.08rem; font-weight: 800; }
.modal-card input { border: 2px solid var(--steel-150); }
#login-modal .modal-card input { font-family: var(--mono); letter-spacing: .08em; text-align: center; }
.modal-close { position: absolute; top: 8px; inset-inline-start: 12px; background: none; border: 0;
  font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--steel-500); }
.form-error { color: var(--gone); font-size: .85rem; min-height: 1.3em; margin: 0 22px 14px; }

/* machine picker */
.picker { width: min(560px, 100%); }
.picker-head { padding: 20px 22px 14px; border-bottom: var(--line); display: grid; gap: 10px; }
.picker-head p { margin: 0; font-size: .85rem; color: var(--steel-500); }
.picker-body { padding: 6px 0 0; max-height: 58vh; overflow-y: auto; }
.picker-group { padding: 10px 22px 14px; }
.picker-group h4 { margin: 0 0 9px; font-size: .78rem; color: var(--steel-500); font-weight: 600;
  display: flex; align-items: center; gap: 8px; }
.picker-group h4::after { content: ""; flex: 1; height: 1px; background: var(--steel-150); }
.picker-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.picker-list button { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; border: var(--line); border-radius: var(--r); background: var(--white);
  cursor: pointer; text-align: start; font-size: .88rem; }
.picker-list button:hover { border-color: var(--amber); background: var(--amber-wash); }
.picker-list button.current { border-color: var(--amber); background: var(--amber); font-weight: 700; }
.picker-list .n { font-family: var(--mono); font-size: .72rem; color: var(--steel-500); }
.picker-foot { padding: 12px 22px 18px; border-top: var(--line); display: flex; gap: 8px; }

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .rail { grid-auto-columns: minmax(158px, 1fr); gap: 10px; }
  .card h3 { font-size: .84rem; }
  .card .price { font-size: .92rem; }
  .card .add-btn { width: 36px; height: 36px; }
  .cat-grid { grid-template-columns: 1fr 1fr; }
  /* modals become bottom sheets on phones */
  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 88vh;
    animation: sheet-up .22s ease; }
  .picker-body { max-height: 62vh; }
}
@keyframes sheet-up { from { transform: translateY(22px); opacity: .6; } to { transform: none; opacity: 1; } }

/* ── garage: pick your machine (home page) ───────────────────────────────── */
.garage { background: var(--white); border-block: var(--line); }
.garage .wrap { padding: 26px 0 28px; }
.garage-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; }
.garage-head h2 { margin: 0 0 4px; font-size: 1.12rem; font-weight: 800; }
.garage-head p { margin: 0; font-size: .85rem; color: var(--steel-500); }
.garage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
.garage-maker { border: var(--line); border-radius: var(--r); padding: 12px 13px 13px; background: var(--paper); }
.maker-name { display: block; font-size: .74rem; color: var(--steel-500); margin-bottom: 9px;
  text-transform: uppercase; letter-spacing: .04em; }
.garage-models { display: grid; gap: 7px; }
.garage-models button { display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 11px; border: var(--line); border-radius: var(--r); background: var(--white);
  cursor: pointer; text-align: start; }
.garage-models button:hover { border-color: var(--amber); background: var(--amber-wash); }
.garage-models button.current { background: var(--amber); border-color: var(--amber); }
.garage-models b { font-weight: 700; font-size: .9rem; }
.garage-models .n { font-family: var(--mono); font-size: .72rem; color: var(--steel-500); }
.garage-models button.current .n { color: var(--ink); }

@media (max-width: 560px) {
  .garage .wrap { padding: 20px 0; }
  .garage-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .garage-head .btn { width: 100%; }
  .garage-grid { grid-template-columns: 1fr; gap: 10px; }
}

/* ── infinite scroll footer ──────────────────────────────────────────────── */
.load-more { display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 22px 0 6px; flex-wrap: wrap; }
.load-more .load-count { font-family: var(--mono); font-size: .76rem; }
.load-status { font-size: .84rem; color: var(--steel-500); display: inline-flex; align-items: center; gap: 8px; }
.load-status[hidden] { display: none; }
.load-status::before { content: ""; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--steel-150); border-top-color: var(--amber); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.list-end { text-align: center; font-size: .82rem; padding: 20px 0 6px; }
