/* ============================================================
   Kofeynya menyusi — mobile-first
   ============================================================ */

@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../fonts/Nunito-SemiBold.ttf") format("truetype");
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  --white: #FFFFFF;
  --gray:  #EFEFEF;
  --blue:  #008CFF;
  --ink:   #1A1A1A;
  --muted: #8E8E93;


  --r-card: 22px;
  --r-story: 20px;
  --r-pill: 999px;

  --gutter: 16px;   /* yagona yon chekinish */
  --gap:    12px;   /* setka oralig'i */

  --tap: 120ms ease;
  --header-h: 76px;
  --tabbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--gray);
  color: var(--ink);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.35;
  letter-spacing: -.05em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  border: 0;
  margin: 0;
  background: none;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 6px;
}

body.is-locked { overflow: hidden; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--gray);
  position: relative;
}

/* ---------- 1. Manzil ---------- */

.header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--white);
}

.header__btn {
  display: block;
  width: 100%;
  padding: 12px var(--gutter) 16px;
  text-align: center;
  transition: transform var(--tap);
}
.header__btn:active { transform: scale(.97); }

.header__label {
  display: block;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

/* 1fr auto 1fr: manzil o'rtadagi ustunda — shevron markazni siljitmaydi */
.header__row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 4px;
}

.header__row .header__address { grid-column: 2; }

.header__row .header__chevron {
  grid-column: 3;
  justify-self: start;
}

.header__address {
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
}

.header__chevron { color: var(--ink); flex: 0 0 auto; }

/* ---------- 2. Dolzarb (stories) ---------- */

/* Skroll-konteynerning o'zi butun kenglikni egallaydi,
   yon chekinish faqat unda — birinchi element karta bilan bir chiziqda */
.stories {
  width: 100%;
  display: flex;
  gap: 12px;
  padding-block: 16px;
  padding-inline: var(--gutter);
  scroll-padding-inline: var(--gutter);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;
}
.stories::-webkit-scrollbar { display: none; }

.story {
  flex: 0 0 96px;
  height: 96px;
  padding: 12px;
  border-radius: var(--r-story);
  display: flex;
  align-items: flex-start;
  text-align: left;
  transition: transform var(--tap);
}
.story:active { transform: scale(.97); }

.story__title {
  font-weight: 500;
  font-size: 13px;
  line-height: 1.2;
}

.story--t1 { background: rgba(0, 140, 255, .12); }
.story--t2 { background: rgba(0, 140, 255, .24); }
.story--t3 { background: rgba(0, 140, 255, .40); }
.story--t4 { background: rgba(0, 140, 255, .70); }
.story--t4 .story__title { color: var(--white); }

/* ---------- 3. Kategoriyalar ---------- */

.chips {
  width: 100%;
  display: flex;
  gap: 8px;
  padding-block: 0 24px;
  padding-inline: var(--gutter);
  scroll-padding-inline: var(--gutter);
  background: var(--gray);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 8px 16px;
  border-radius: var(--r-pill);
  background: var(--white);
  font-weight: 500;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  transition: background-color var(--tap), color var(--tap), transform var(--tap);
}
.chip:active { transform: scale(.97); }

.chip--active {
  background: var(--blue);
  color: var(--white);
}

/* ---------- 4. Menyu ---------- */

.menu {
  padding: 0 var(--gutter) calc(24px + var(--tabbar-h) + env(safe-area-inset-bottom));
}

.section__title {
  margin: 24px 0 12px;
  font-weight: 600;
  font-size: 17px;
  color: var(--ink);
}
.section:first-child .section__title { margin-top: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  column-gap: var(--gap);
  row-gap: var(--gap);
}

/* ---------- Karta ---------- */

/* Skelet barcha pozitsiyalarda bir xil: rasm -> nom -> narx qatori */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-radius: var(--r-card);
  background: var(--white);
}

.card__media {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: var(--gray);
  overflow: hidden;
}

.card__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 200ms ease;
}
.card--loaded .card__img { opacity: 1; }

.card__badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 8px;
  border-radius: var(--r-pill);
  background: var(--blue);
  color: var(--white);
  font-weight: 500;
  font-size: 10px;
  line-height: 1.2;
}

.card__name {
  margin: 12px 0 0;
  /* Doim 2 qator joy egallaydi — bir qatorli nomlar ham kartani qisqartirmaydi */
  min-height: calc(2 * 1.2 * 15px);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Balandligi qat'iy — o'lcham tanlagichi bor-yo'qligidan qat'i nazar */
.card__row {
  margin-top: 12px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.card__price {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 8px 12px;
  border-radius: var(--r-pill);
  background: var(--blue);
  color: var(--white);
  font-weight: 600;
  font-size: clamp(11.5px, 3.3vw, 14px);
  white-space: nowrap;
}

/* o'lcham / hajm pilyulasi */
.card__meta {
  flex: 0 0 auto;
  min-width: 24px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-pill);
  background: var(--gray);
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
}

.card__meta--size {
  font-weight: 600;
  font-size: 12px;
  color: var(--ink);
}

/* o'lcham tanlagich */
.sizes { position: relative; flex: 0 0 auto; }

.sizes__toggle {
  gap: 4px;
  transition: transform var(--tap);
}
.sizes__toggle:active { transform: scale(.94); }

.sizes__caret {
  color: var(--muted);
  transition: transform 160ms ease;
}
.sizes.is-open .sizes__caret { transform: rotate(180deg); }

.sizes__list {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease, visibility 160ms;
}
.sizes.is-open .sizes__list {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.sizes__opt {
  min-width: 24px;
  height: 28px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-pill);
  background: var(--gray);
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  transition: transform var(--tap), color var(--tap);
}
.sizes__opt:active { transform: scale(.94); }
.sizes__opt--active { color: var(--blue); }

/* ---------- 5. Tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: 100%;
  max-width: 480px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  background: var(--white);
  border-top: 1px solid var(--gray);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 12px;
  color: var(--muted);
  transition: transform var(--tap);
}
.tab:active { transform: scale(.97); }

.tab__label {
  font-weight: 500;
  font-size: 12px;
}

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

/* ---------- Ekranlar ---------- */

.screen[hidden] { display: none; }

.header--chat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px var(--gutter) 16px;
  text-align: center;
}

/* ---------- Manzil shtorkasi ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }

.sheet__overlay {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, .4);
  opacity: 0;
  transition: opacity 200ms ease;
}
.sheet.is-open .sheet__overlay { opacity: 1; }

.sheet__panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  padding: 12px var(--gutter) calc(24px + env(safe-area-inset-bottom));
  background: var(--white);
  border-radius: var(--r-card) var(--r-card) 0 0;
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(.22, .8, .3, 1);
}
.sheet.is-open .sheet__panel { transform: none; }

.sheet__grip {
  display: block;
  width: 36px;
  height: 4px;
  margin: 0 auto 16px;
  border-radius: var(--r-pill);
  background: var(--gray);
}

.sheet__title {
  margin: 0;
  font-weight: 600;
  font-size: 18px;
}

.sheet__address {
  margin: 4px 0 0;
  font-weight: 400;
  font-size: 14px;
  color: var(--muted);
}

.sheet__facts {
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.sheet__fact {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.sheet__key {
  font-weight: 400;
  font-size: 13px;
  color: var(--muted);
}

.sheet__value {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
  text-align: right;
}

.sheet__link {
  color: var(--blue);
  text-decoration: none;
}

.sheet__hint {
  margin: 16px 0 8px;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
}

.sheet__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sheet__map {
  padding: 12px 0;
  border-radius: var(--r-pill);
  background: var(--gray);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  text-decoration: none;
  transition: transform var(--tap);
}
.sheet__map:active { transform: scale(.97); }

.sheet__close {
  width: 100%;
  margin-top: 8px;
  padding: 12px 0;
  border-radius: var(--r-pill);
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
  transition: transform var(--tap);
}
.sheet__close:active { transform: scale(.97); }

/* ---------- Storis ko'ruvchi ---------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  background: var(--gray);
}
.viewer[hidden] { display: none; }

.viewer::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 140, 255, var(--tint, .24));
}

.viewer__bars {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  z-index: 2;
  display: flex;
  gap: 4px;
}

.viewer__bar {
  flex: 1 1 0;
  height: 4px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .45);
  overflow: hidden;
}

.viewer__bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--white);
}
.viewer__bar--done span { width: 100%; }
.viewer__bar--live span { animation: story 6s linear forwards; }

@keyframes story {
  from { width: 0; }
  to   { width: 100%; }
}

.viewer__close {
  position: absolute;
  top: calc(24px + env(safe-area-inset-top));
  right: 12px;
  z-index: 3;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--white);
  color: var(--ink);
}

.viewer__zone {
  position: absolute;
  top: 0;
  bottom: 0;
  z-index: 1;
  width: 34%;
}
.viewer__zone--prev { left: 0; }
.viewer__zone--next { right: 0; width: 66%; }

.viewer__content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(48px + env(safe-area-inset-bottom));
  pointer-events: none;
}

.viewer__heading {
  margin: 0 0 8px;
  font-weight: 600;
  font-size: 24px;
  color: var(--ink);
}

.viewer__body {
  margin: 0;
  font-weight: 400;
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
}

.viewer--dark .viewer__heading,
.viewer--dark .viewer__body { color: var(--white); }

/* ---------- Chat ---------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px var(--gutter)
           calc(var(--tabbar-h) + var(--composer-h, 64px) + env(safe-area-inset-bottom) + 16px);
}

.msg {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  font-weight: 400;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--in {
  align-self: flex-start;
  background: var(--white);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.msg--out {
  align-self: flex-end;
  background: var(--blue);
  color: var(--white);
  border-bottom-right-radius: 6px;
}

.msg--note {
  align-self: center;
  max-width: 100%;
  padding: 8px 0;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.msg__time {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: .6;
}

.msg--pending { opacity: .55; }

.msg--failed {
  background: var(--white);
  color: var(--muted);
}

.composer {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 25;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px var(--gutter);
  background: var(--gray);
}

.composer__label {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.composer__input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 108px;
  padding: 12px 16px;
  border: 0;
  border-radius: 20px;
  background: var(--white);
  color: var(--ink);
  font-family: inherit;
  font-weight: 400;
  font-size: 14px;
  letter-spacing: inherit;
  line-height: 1.35;
  resize: none;
}
.composer__input::placeholder { color: var(--muted); }
.composer__input:focus { outline: none; }
.composer__input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.composer__send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: var(--r-pill);
  background: var(--blue);
  color: var(--white);
  transition: transform var(--tap), opacity var(--tap);
}
.composer__send:active { transform: scale(.94); }
.composer__send:disabled {
  background: var(--white);
  color: var(--muted);
  cursor: default;
}

/* ---------- Kichik ekranlar ---------- */

/* Yon chekinish 16px o'zgarmaydi — faqat pilyulalar torayadi */
@media (max-width: 359px) {
  .card__row { gap: 4px; }
  .card__price { padding: 4px; font-size: 11px; }
  .card__meta,
  .sizes__opt { min-width: 24px; padding: 0 4px; }
}

/* ---------- Harakatni kamaytirish ---------- */

@media (prefers-reduced-motion: reduce) {
  .viewer__bar--live span { animation: none; width: 100%; }
  .card__img,
  .chip,
  .sizes__list,
  .sizes__caret,
  .sizes__opt,
  .story,
  .tab,
  .header__btn,
  .sheet__overlay,
  .sheet__panel,
  .sheet__map,
  .sheet__close,
  .composer__send { transition: none; }
}
