/* ==========================================================================
   Napiy Mini App — design system
   Tokens extracted live from napiy.com (Manrope, vanilla #FFD16D, #231F20 …).
   Mobile-first; layered on top of Telegram theme params where sensible.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Manrope, self-hosted.
   Previously two <link>s to fonts.googleapis.com in index.html: a stylesheet
   round-trip to one host before a font round-trip to another, both before any
   text can paint, on a phone inside a webview. Same files, served from our own
   origin, no third-party DNS/TLS.

   These are the variable font (wght 200-800), so ONE file per subset covers
   every weight the UI asks for - there is no per-weight download.

   Three subsets, not six. The interface is Ukrainian, so cyrillic carries
   essentially all of it; latin covers the wordmark, digits and Latin product
   names; cyrillic-ext carries ₴ (u+20b4), which ui.js prints on every price.
   greek, vietnamese and latin-ext are not shipped - nothing here renders them,
   and the browser only fetches a subset it actually needs anyway.

   unicode-range is what makes that work: it tells the browser which file to
   fetch for which characters, so a Ukrainian screen never downloads the latin
   file at all. Dropping it would make the browser fetch all three.

   Manrope is SIL OFL 1.1 (github.com/sharpType/Manrope). Files are byte-copies
   of the ones Google Fonts serves.
   -------------------------------------------------------------------------- */

@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('../assets/fonts/manrope-cyrillic.woff2') format('woff2');
  unicode-range: u+0301, u+0400-045f, u+0490-0491, u+04b0-04b1, u+2116;
}

@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('../assets/fonts/manrope-cyrillic-ext.woff2') format('woff2');
  unicode-range: u+0460-052f, u+1c80-1c8a, u+20b4, u+2de0-2dff, u+a640-a69f, u+fe2e-fe2f;
}

@font-face {
  font-family: 'Manrope';
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url('../assets/fonts/manrope-latin.woff2') format('woff2');
  unicode-range: u+0000-00ff, u+0131, u+0152-0153, u+02bb-02bc, u+02c6, u+02da, u+02dc,
    u+0304, u+0308, u+0329, u+2000-206f, u+20ac, u+2122, u+2191, u+2193, u+2212, u+2215,
    u+feff, u+fffd;
}

:root {
  /* Brand */
  --c-primary: #FFD16D;      /* vanilla / accent */
  --c-base: #231F20;         /* near-black text & borders */
  --c-bg: #f6f6f6;           /* page background */
  --c-white: #ffffff;
  --c-muted: rgba(35, 31, 32, 0.64);
  --c-light-gray: #F1F1F1;
  --c-border: #E0E0E0;
  --c-link: #2FA6BA;         /* teal */
  --c-success: #40B240;
  --c-error: #FD6963;

  /* Telegram theme (fallbacks to brand when not in Telegram) */
  --tg-bg: var(--tg-theme-bg-color, var(--c-bg));
  --tg-text: var(--tg-theme-text-color, var(--c-base));
  --tg-hint: var(--tg-theme-hint-color, var(--c-muted));
  --tg-card: var(--tg-theme-secondary-bg-color, var(--c-white));

  --radius-pill: 2rem;
  --radius-card: 20px;
  --radius-sm: 12px;
  --shadow-card: 0 2px 14px rgba(35, 31, 32, 0.06);
  --shadow-pop: 0 6px 24px rgba(35, 31, 32, 0.14);
  --font: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --bar-h: 76px; /* bottom bar height */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.4;
  color: var(--tg-text);
  background: var(--tg-bg);
  -webkit-font-smoothing: antialiased;
}

.app { min-height: 100vh; padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px)); }
.hidden { display: none !important; }

h1, h2, h3 { font-weight: 700; line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; text-transform: uppercase; }
h2 { font-size: 1.15rem; }
.muted { color: var(--tg-hint); }
.center { text-align: center; }

/* ---------- Header ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px calc(14px + env(safe-area-inset-top, 0px));
  background: var(--tg-bg);
}
.brand { font-weight: 800; font-size: 1.4rem; letter-spacing: -0.02em; color: var(--tg-text); }
.brand b { color: var(--c-primary); -webkit-text-stroke: 0.4px var(--c-base); }
.appbar .greeting { font-size: 0.82rem; color: var(--tg-hint); }

/* ---------- Category chips ---------- */
.chips {
  position: sticky; z-index: 15;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 6px 16px 12px; background: var(--tg-bg);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--c-border); background: var(--tg-card);
  color: var(--tg-text); border-radius: var(--radius-pill);
  padding: 8px 16px; font-size: 0.82rem; font-weight: 600; white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer; transition: .15s;
}
.chip.active { background: var(--c-base); color: var(--c-white); border-color: var(--c-base); }

/* ---------- Product grid ---------- */
.grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; padding: 4px 16px 24px;
}
.card {
  position: relative; display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--radius-card); background: var(--tg-card);
  box-shadow: var(--shadow-card); cursor: pointer; transition: transform .12s;
}
.card:active { transform: scale(0.985); }
.card .thumb {
  aspect-ratio: 1 / 1; display: grid; place-items: center; padding: 8px;
  background: var(--card-tint, #faf6ee);
}
.card .thumb img { width: 100%; height: 100%; object-fit: contain;
  filter: drop-shadow(0 8px 10px rgba(0,0,0,0.12)); }
.card .body { padding: 10px 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.card .title { font-weight: 700; font-size: 0.95rem; line-height: 1.15; }
.card .weight { font-size: 0.75rem; color: var(--tg-hint); }
.card .prices { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px; margin-top: 2px;
  padding-right: 46px; /* reserve space for the round add button */ }
.price { font-weight: 800; font-size: 1.05rem; }
.old-price { font-size: 0.8rem; color: var(--tg-hint); text-decoration: line-through; }
.price.discounted { color: var(--c-success); }
.badge {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  background: var(--c-error); color: #fff; font-size: 0.68rem; font-weight: 700;
  padding: 4px 8px; border-radius: var(--radius-pill); text-transform: uppercase;
}
.card .add {
  position: absolute; right: 10px; bottom: 10px; z-index: 2;
  width: 38px; height: 38px; border-radius: 50%; border: none;
  background: var(--c-base); color: #fff; font-size: 1.3rem; line-height: 1;
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-pop);
}
.card.out { opacity: 0.55; }
.card .out-label {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(255,255,255,0.4); font-weight: 700; text-transform: uppercase;
}

/* qty stepper (shared) */
.stepper { display: inline-flex; align-items: center; gap: 0; border-radius: var(--radius-pill);
  background: var(--c-light-gray); overflow: hidden; }
.stepper button { width: 34px; height: 34px; border: none; background: transparent;
  font-size: 1.2rem; color: var(--c-base); cursor: pointer; }
.stepper .val { min-width: 28px; text-align: center; font-weight: 700; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-pill); border: 1px solid transparent;
  font-family: var(--font); font-weight: 700; font-size: 0.9rem; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 15px 24px; cursor: pointer; transition: .15s;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--c-primary); color: var(--c-base); }
.btn-dark { background: var(--c-base); color: #fff; }
.btn-white { background: #fff; color: var(--c-base); border-color: var(--c-base); }
.btn-outline { background: transparent; color: var(--tg-text); border-color: var(--c-border); }
.btn-block { width: 100%; }

/* ---------- Product detail ---------- */
.detail { padding: 0 16px 24px; }
.detail .hero { border-radius: var(--radius-card); background: var(--card-tint, #faf6ee);
  display: grid; place-items: center; padding: 18px; margin-bottom: 16px; }
.detail .hero img { width: 72%; max-height: 320px; object-fit: contain;
  filter: drop-shadow(0 12px 16px rgba(0,0,0,0.14)); }
.detail .name { font-size: 1.5rem; font-weight: 800; text-transform: uppercase; }
.detail .desc { color: var(--tg-hint); font-size: 0.92rem; white-space: pre-line; margin: 10px 0 16px; }
.detail .price-row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 18px; }
.detail .price-row .price { font-size: 1.6rem; }

/* variant size tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; text-align: center; padding: 12px; border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.tab.active { border-color: var(--c-primary); box-shadow: inset 0 0 0 1px var(--c-primary); }

/* ---------- Cart & checkout ---------- */
.section { padding: 8px 16px 20px; }
.section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--tg-hint); font-weight: 700; margin: 16px 0 8px; }
.line {
  display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--c-light-gray);
}
.line .li-img { width: 56px; height: 56px; border-radius: var(--radius-sm); object-fit: contain;
  background: var(--card-tint, #faf6ee); flex: 0 0 auto; }
.line .li-main { flex: 1; min-width: 0; }
.line .li-title { font-weight: 700; font-size: 0.9rem; }
.line .li-sub { font-size: 0.78rem; color: var(--tg-hint); }
.line .li-price { font-weight: 800; white-space: nowrap; }

.summary { margin-top: 14px; padding: 14px 16px; background: var(--tg-card);
  border-radius: var(--radius-card); box-shadow: var(--shadow-card); }
.summary .row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 0.92rem; }
.summary .row.total { font-size: 1.15rem; font-weight: 800; padding-top: 10px; }
.summary .row .save { color: var(--c-success); font-weight: 700; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--tg-hint); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; font-family: var(--font); font-size: 1rem; color: var(--tg-text);
  padding: 13px 14px; border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  background: var(--tg-card); outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--c-primary); }
.field .hint { font-size: 0.75rem; color: var(--tg-hint); margin-top: 4px; }
.radio-row { display: flex; gap: 8px; }
.radio-row .opt { flex: 1; text-align: center; padding: 13px; border: 1px solid var(--c-border);
  border-radius: var(--radius-sm); font-weight: 700; font-size: 0.85rem; cursor: pointer; }
.radio-row .opt.active { border-color: var(--c-primary); box-shadow: inset 0 0 0 1px var(--c-primary); }

/* address suggestions (Nova Poshta) */
.combo { position: relative; }
.suggestions { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 30;
  background: var(--tg-card); border: 1px solid var(--c-border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); max-height: 220px; overflow-y: auto; }
.suggestions .opt { padding: 12px 14px; border-bottom: 1px solid var(--c-light-gray); cursor: pointer; font-size: 0.9rem; }
.suggestions .opt:active { background: var(--c-light-gray); }

/* ---------- Orders / buy-again ---------- */
.order-card { padding: 14px 16px; background: var(--tg-card); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); margin-bottom: 12px; }
.order-card .oc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.order-card .oc-items { font-size: 0.85rem; color: var(--tg-hint); }
.status-pill { font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: var(--radius-pill);
  text-transform: uppercase; }
.status-pill.paid { background: rgba(64,178,64,0.14); color: var(--c-success); }
.status-pill.wait { background: rgba(255,209,109,0.28); color: #8a6d1f; }
.status-pill.fail { background: rgba(253,105,99,0.16); color: var(--c-error); }
.status-pill.neutral { background: var(--c-light-gray); color: var(--tg-text); }

/* ---------- Bottom bar ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--tg-card); box-shadow: 0 -4px 20px rgba(35,31,32,0.10);
}
.bottombar .bb-info { flex: 1; }
.bottombar .bb-total { font-weight: 800; font-size: 1.1rem; }
.bottombar .bb-sub { font-size: 0.75rem; color: var(--tg-hint); }

/* ---------- States ---------- */
.empty { text-align: center; padding: 64px 24px; color: var(--tg-hint); }
.empty .emoji { font-size: 3rem; margin-bottom: 12px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--c-light-gray);
  border-top-color: var(--c-primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 50%; bottom: calc(var(--bar-h) + 20px); transform: translateX(-50%);
  z-index: 60; background: var(--c-base); color: #fff; padding: 12px 18px; border-radius: var(--radius-pill);
  font-size: 0.88rem; font-weight: 600; box-shadow: var(--shadow-pop); max-width: 88%; text-align: center; }

/* nav back row */
.subhead { display: flex; align-items: center; gap: 10px; padding: 8px 16px 4px; }
.subhead .back { font-size: 1.4rem; cursor: pointer; color: var(--tg-text); }

@media (min-width: 520px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
}
