/* =========================================================
   СТРОКА НИТКИ — общая для страницы «Нитки» и демо на главной.
   Раскладка зависит от ширины самого списка (container query), а не окна:
   демо на главной узкое даже на большом мониторе.

   Широкий список (≥ 960px) — одна строка:
     [✓][🛒][■] 0001 ……… [Ozon][Wildberries]  есть [−1+]  купить [−0+]  [Купил]
   Средний (планшет, демо на компьютере) — две строки:
     [✓][🛒][■] 0001 ……………………………………  есть [−1+]  купить [−0+]
     [Ozon][Wildberries] ……………………………………………………………… [Купил]
   Узкий (< 540px, телефон) — четыре строки: цвет, магазины, счётчики, «Купил».

   У контейнера списка должен быть container-type: inline-size.
   ========================================================= */

.thread-row {
    display: grid;
    grid-template-columns: 24px 24px 28px minmax(64px, 1fr) auto auto 78px;
    grid-template-areas: "chk cart sw code shop cnt buy";
    column-gap: 12px;
    align-items: center;
    padding: 11px 14px;
    background: var(--surface-2);
    border: 1px solid var(--line-2);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.thread-row:hover { border-color: #5a5a5a; }
.thread-row:active { background: var(--line-2); }
.thread-row.state-owned { background: #2b3a2f; border-color: var(--green); }
.thread-row.state-buy { background: #3a3620; border-color: var(--yellow); }
.thread-row.state-owned.state-buy { background: #2b3a2f; border-color: var(--yellow); }

/* Галочка «есть» и корзина «купить» */
.tw-checkbox, .tw-cart { width: 24px; height: 24px; border: 2px solid #666; border-radius: 5px; display: flex; align-items: center; justify-content: center; transition: 0.1s; }
.tw-checkbox { grid-area: chk; }
.thread-row.state-owned .tw-checkbox { background: var(--green); border-color: var(--green); }
.tw-checkbox::after { content: "✓"; color: #000; font-size: 16px; font-weight: 800; display: none; }
.thread-row.state-owned .tw-checkbox::after { display: block; }
.tw-cart { grid-area: cart; color: #888; }
.tw-cart svg { width: 15px; height: 15px; }
.tw-cart:hover { border-color: var(--yellow); color: var(--yellow); }
.thread-row.state-buy .tw-cart { background: var(--yellow); border-color: var(--yellow); color: #000; }

.tw-color { grid-area: sw; width: 28px; height: 28px; border-radius: 6px; border: 1px solid #111; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); }
.tw-code { grid-area: code; min-width: 0; font-size: 17px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Ссылки на маркетплейсы */
.tw-shop { grid-area: shop; display: flex; gap: 6px; min-width: 0; }
.shop-link { height: 32px; padding: 0 11px; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line-3); color: var(--text-2); font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; transition: border-color 0.15s, color 0.15s; }
.shop-link:hover { color: #fff; }
.shop-ozon:hover { border-color: #005bff; }
.shop-wb:hover { border-color: #cb11ab; }
.shop-link:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* Счётчики «есть» и «купить» */
.tw-counters { grid-area: cnt; display: flex; align-items: center; gap: 14px; cursor: default; }
.tw-counter { display: flex; align-items: center; gap: 6px; }
.cnt-label { min-width: 46px; text-align: right; font-size: 12px; font-weight: 600; color: var(--text-3); }
.thread-row.state-owned .tw-counter:not(.is-buy) .cnt-label { color: var(--green); }
.thread-row.state-buy .tw-counter.is-buy .cnt-label { color: var(--yellow); }
.cnt-btn { width: 32px; height: 32px; border-radius: 8px; background: var(--bg-2); color: #fff; border: 1px solid var(--line-3); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; font-family: inherit; line-height: 1; cursor: pointer; transition: background 0.1s, transform 0.1s; outline: none; padding: 0; }
.cnt-btn:hover { background: var(--line-3); }
.cnt-btn:active { transform: scale(0.9); }
.cnt-btn:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.cnt-val { width: 24px; text-align: center; font-weight: 700; font-size: 16px; }

/* «Купил»: мотки из «купить» переходят в «есть». Место держим, чтобы строки не прыгали */
.tw-bought { grid-area: buy; justify-self: end; height: 32px; min-width: 78px; padding: 0 12px; border-radius: 8px; background: var(--yellow); color: #000; border: 0; font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.tw-bought:hover { filter: brightness(0.92); }
.tw-bought:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.tw-bought[hidden] { display: block; visibility: hidden; }

/* ---------- Средний список: две строки ---------- */
@container (max-width: 959px) {
    .thread-row {
        grid-template-columns: 24px 24px 28px minmax(0, 1fr) auto;
        grid-template-areas:
            "chk  cart sw   code cnt"
            "shop shop shop shop buy";
        row-gap: 10px;
    }
    .tw-counters { justify-self: end; }
}

/* ---------- Узкий список (телефон): четыре строки ---------- */
@container (max-width: 539px) {
    .thread-row {
        grid-template-columns: 22px 22px 24px minmax(0, 1fr);
        grid-template-areas:
            "chk  cart sw   code"
            "shop shop shop shop"
            "cnt  cnt  cnt  cnt"
            "buy  buy  buy  buy";
        column-gap: 9px;
        row-gap: 10px;
        padding: 10px;
    }
    .tw-checkbox, .tw-cart { width: 22px; height: 22px; }
    .tw-checkbox::after { font-size: 14px; }
    .tw-cart svg { width: 13px; height: 13px; }
    .tw-color { width: 24px; height: 24px; }
    .tw-code { font-size: 15px; }

    .tw-shop { display: grid; grid-template-columns: 1fr 1fr; }
    .shop-link { display: block; min-width: 0; height: 34px; line-height: 32px; padding: 0 6px; font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; }

    .tw-counters { justify-self: stretch; justify-content: space-between; gap: 8px; }
    .tw-counter { gap: 4px; }
    .cnt-label { min-width: 0; text-align: left; margin-right: 4px; }
    .cnt-btn { width: 30px; height: 30px; font-size: 18px; }
    .cnt-val { width: 22px; font-size: 14px; }

    .tw-bought { justify-self: stretch; height: 38px; border-radius: 10px; font-size: 14px; }
    .tw-bought[hidden] { display: none; }
}

/* Узко для «Поискать на Wildberries» — короткие подписи «Ozon» и «Wildberries» */
@container (max-width: 370px) {
    .shop-prefix { display: none; }
}
