/* Dream Pool — mobile-first UI, orientated on Telegram Mini App palette */
:root {
  --bg:        var(--tg-theme-bg-color, #f4f7fb);
  --card:      var(--tg-theme-secondary-bg-color, #ffffff);
  --text:      var(--tg-theme-text-color, #101827);
  --muted:     var(--tg-theme-hint-color, #6b7280);
  --brand:     var(--tg-theme-button-color, #0ea5e9);
  --brand-fg:  var(--tg-theme-button-text-color, #ffffff);
  --border:    #e4e9f0;
  --danger:    #dc2626;
  --ok:        #16a34a;
  --warn:      #b45309;
  --shadow:    0 2px 12px rgba(15, 23, 42, .06);
  --radius:    14px;
  --safe-top:  env(safe-area-inset-top, 0px);
  --safe-bot:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
             font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
             font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased;
             overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---------- Top bar --------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 20;
          background: var(--card); border-bottom: 1px solid var(--border);
          padding: calc(10px + var(--safe-top)) 12px 10px;
          display: grid; grid-template-columns: 40px 1fr 40px;
          align-items: center; gap: 8px; }
.topbar__back, .topbar__cart {
  width: 40px; height: 40px; border-radius: 12px; display: flex;
  align-items: center; justify-content: center; font-size: 20px;
  background: var(--bg); position: relative; user-select: none;
}
.topbar__title { font-size: 16px; font-weight: 600; text-align: center;
                 white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cart-badge { position: absolute; top: -4px; right: -4px;
              background: var(--danger); color: #fff; font-size: 11px;
              min-width: 18px; height: 18px; padding: 0 5px;
              border-radius: 9px; display: flex; align-items: center;
              justify-content: center; font-weight: 700; }

/* ---------- Search ---------------------------------------------------- */
.search { position: sticky; top: calc(60px + var(--safe-top)); z-index: 15;
          padding: 10px 12px; background: var(--bg); }
.search__input { width: 100%; padding: 12px 14px; border-radius: 12px;
                 border: 1px solid var(--border); background: var(--card);
                 font-size: 15px; color: var(--text); outline: none;
                 box-shadow: var(--shadow); }
.search__input:focus { border-color: var(--brand); }
.search__results { position: absolute; left: 12px; right: 12px; top: calc(100% - 4px);
                   max-height: 60vh; overflow-y: auto; background: var(--card);
                   border: 1px solid var(--border); border-radius: 12px;
                   box-shadow: var(--shadow); padding: 6px; }
.search__result { display: flex; gap: 10px; padding: 8px; border-radius: 10px;
                  align-items: center; }
.search__result + .search__result { border-top: 1px solid var(--border); }
.search__result:active { background: var(--bg); }
.search__result img { width: 46px; height: 46px; object-fit: contain;
                      background: var(--bg); border-radius: 8px; }
.search__result-name { font-weight: 500; font-size: 14px; line-height: 1.3;
                       display: -webkit-box; -webkit-line-clamp: 2;
                       -webkit-box-orient: vertical; overflow: hidden; }
.search__result-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.search__result-price { font-weight: 700; margin-left: auto; white-space: nowrap; }
.search__empty { padding: 14px; text-align: center; color: var(--muted); }

/* ---------- Page ------------------------------------------------------ */
.page { padding: 12px 12px calc(24px + var(--safe-bot)); max-width: 720px;
        margin: 0 auto; }
.page-title { margin: 6px 4px 12px; font-size: 20px; font-weight: 700; }

/* ---------- Tiles (home) --------------------------------------------- */
.tiles { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 480px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tile { background: var(--card); border-radius: var(--radius); padding: 20px;
        box-shadow: var(--shadow); display: flex; flex-direction: column;
        align-items: flex-start; gap: 6px; transition: transform .06s ease; }
.tile:active { transform: scale(.98); }
.tile__icon { font-size: 34px; }
.tile__title { font-weight: 600; font-size: 16px; }
.tile__count { color: var(--muted); font-size: 13px; }

/* ---------- Product list --------------------------------------------- */
.list { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 480px) { .list { grid-template-columns: 1fr 1fr; } }
.list__loading, .list__empty { grid-column: 1 / -1; text-align: center;
                               color: var(--muted); padding: 32px 0; }
.card { background: var(--card); border-radius: var(--radius);
        padding: 10px; box-shadow: var(--shadow); display: flex;
        flex-direction: column; gap: 8px; }
.card__img { width: 100%; aspect-ratio: 1 / 1; object-fit: contain;
             background: var(--bg); border-radius: 10px; }
.card__name { font-size: 14px; line-height: 1.3; font-weight: 500;
              display: -webkit-box; -webkit-line-clamp: 3;
              -webkit-box-orient: vertical; overflow: hidden;
              min-height: calc(14px * 1.3 * 2); }
.card__row { display: flex; align-items: center; justify-content: space-between;
             gap: 6px; margin-top: auto; }
.card__price { font-weight: 700; font-size: 16px; white-space: nowrap; }

/* ---------- Buttons --------------------------------------------------- */
.btn { border: 0; padding: 10px 14px; border-radius: 10px;
       font-size: 14px; font-weight: 600; cursor: pointer;
       background: var(--bg); color: var(--text); }
.btn--primary { background: var(--brand); color: var(--brand-fg); }
.btn--sm { padding: 6px 10px; font-size: 13px; }
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--icon { width: 34px; height: 34px; display: inline-flex;
             align-items: center; justify-content: center; padding: 0;
             font-size: 18px; font-weight: 700; background: var(--bg); }

/* ---------- Product page --------------------------------------------- */
.product { display: flex; flex-direction: column; gap: 14px; }
.gallery { background: var(--card); border-radius: var(--radius);
           padding: 12px; box-shadow: var(--shadow); }
.gallery__main { width: 100%; aspect-ratio: 1 / 1; object-fit: contain;
                 background: var(--bg); border-radius: 10px; display: block; }
.gallery__placeholder { text-align: center; padding: 40px 0;
                        color: var(--muted); background: var(--bg);
                        border-radius: 10px; }
.gallery__thumbs { display: flex; gap: 8px; margin-top: 10px;
                   overflow-x: auto; padding-bottom: 4px; }
.gallery__thumb { width: 60px; height: 60px; object-fit: contain;
                  background: var(--bg); border-radius: 8px;
                  border: 2px solid transparent; cursor: pointer; flex: 0 0 auto; }
.gallery__thumb.is-active { border-color: var(--brand); }
.product__name { font-size: 20px; font-weight: 700; margin: 0; line-height: 1.25; }
.product__meta { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border: 1px solid var(--border);
        border-radius: 999px; padding: 4px 10px; font-size: 12px;
        color: var(--muted); }
.chip--ok   { color: var(--ok);     border-color: rgba(22,163,74,.3);   background: rgba(22,163,74,.08); }
.chip--warn { color: var(--warn);   border-color: rgba(180,83,9,.3);    background: rgba(180,83,9,.08); }
.product__buy { display: flex; align-items: center; gap: 12px;
                background: var(--card); padding: 12px; border-radius: var(--radius);
                box-shadow: var(--shadow); }
.product__price { font-size: 22px; font-weight: 800; }
.product__buy .btn { margin-left: auto; padding: 12px 20px; font-size: 15px; }
.product__section h2 { font-size: 15px; font-weight: 700;
                       margin: 12px 4px 8px; text-transform: uppercase;
                       color: var(--muted); letter-spacing: .04em; }
.product__desc { background: var(--card); border-radius: var(--radius);
                 padding: 14px; box-shadow: var(--shadow); margin: 0;
                 white-space: pre-line; }
.specs { width: 100%; border-collapse: collapse; background: var(--card);
         border-radius: var(--radius); overflow: hidden;
         box-shadow: var(--shadow); }
.specs th, .specs td { text-align: left; padding: 10px 12px; font-size: 14px;
                       vertical-align: top; }
.specs th { color: var(--muted); font-weight: 500; width: 45%; }
.specs tr + tr th, .specs tr + tr td { border-top: 1px solid var(--border); }

/* ---------- Cart ------------------------------------------------------ */
.cart__loading, .cart__empty { text-align: center; padding: 40px 0;
                               color: var(--muted); }
.cart__empty a { color: var(--brand); font-weight: 600; }
.cart__items { display: flex; flex-direction: column; gap: 10px; }
.cart-item { display: grid; grid-template-columns: 64px 1fr auto;
             gap: 10px; align-items: center; background: var(--card);
             border-radius: var(--radius); padding: 10px;
             box-shadow: var(--shadow); }
.cart-item__img { width: 64px; height: 64px; object-fit: contain;
                  background: var(--bg); border-radius: 8px; }
.cart-item__name { font-size: 14px; font-weight: 500; line-height: 1.3;
                   display: -webkit-box; -webkit-line-clamp: 2;
                   -webkit-box-orient: vertical; overflow: hidden; }
.cart-item__meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cart-item__ctl { display: flex; flex-direction: column; gap: 6px;
                  align-items: flex-end; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty__val { min-width: 26px; text-align: center; font-weight: 600; }
.cart-item__price { font-weight: 700; white-space: nowrap; }
.cart-item__remove { background: transparent; border: 0; color: var(--muted);
                     font-size: 12px; cursor: pointer; padding: 0; }
.cart__totals { position: sticky; bottom: 0; margin: 16px -12px -24px;
                background: var(--card); border-top: 1px solid var(--border);
                padding: 14px 16px calc(14px + var(--safe-bot));
                display: flex; align-items: center; gap: 12px; }
.cart__total-label { color: var(--muted); font-size: 13px; }
.cart__total-value { font-size: 20px; font-weight: 800; }
.cart__totals .btn { margin-left: auto; padding: 12px 18px; font-size: 15px; }
.toast { position: fixed; bottom: calc(24px + var(--safe-bot)); left: 50%;
         transform: translateX(-50%); background: rgba(15,23,42,.9);
         color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px;
         opacity: 0; transition: opacity .2s ease; pointer-events: none; z-index: 50; }
.toast.is-visible { opacity: 1; }
