/* Telegram passes its theme; these are the fallbacks outside it. */
:root {
  --bg: #ffffff;
  --section: #ffffff;
  --secondary: #f1f2f5;
  --text: #141414;
  --hint: #70757d;
  --link: #2a7ae2;
  --button: #2a7ae2;
  --button-text: #ffffff;
  --good: #1f8a4c;
  --warn: #b7791f;
  --bad: #c9372c;
  --line: rgba(127, 127, 127, 0.18);
  --radius: 14px;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", "Noto Sans Ethiopic", Roboto, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.themed) {
    --bg: #17191c;
    --section: #212428;
    --secondary: #17191c;
    --text: #f2f3f5;
    --hint: #9aa0a8;
    --link: #6aa9ff;
    --button: #3d8af7;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--secondary);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px calc(96px + env(safe-area-inset-bottom));
}

h1 { font-size: 22px; margin: 8px 4px 2px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 20px 4px 8px; }
p { margin: 0; }
a { color: var(--link); }
button, input, textarea { font: inherit; color: inherit; }

.hint { color: var(--hint); font-size: 14px; }
.status { color: var(--hint); text-align: center; padding: 48px 16px; }
.status strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.subtitle { margin: 0 4px 14px; }

/* List */
.cards { display: grid; gap: 8px; }

.card {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px;
  text-align: left;
  background: var(--section);
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}
.card:active { opacity: .7; }

.thumb {
  width: 76px;
  height: 76px;
  border-radius: 10px;
  background: var(--secondary);
  object-fit: cover;
  display: grid;
  place-items: center;
  font-size: 28px;
  overflow: hidden;
}

.card-body { min-width: 0; display: grid; gap: 4px; }
.card-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 15px;
}
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.price { font-weight: 700; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.in_stock { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.few_left { color: var(--warn); background: color-mix(in srgb, var(--warn) 16%, transparent); }
.pill.sold_out { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }

/* Detail */
.back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0 0 8px;
  padding: 6px 4px;
  background: none;
  border: 0;
  color: var(--link);
  cursor: pointer;
}

.gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  border-radius: var(--radius);
  scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery .slide {
  flex: 0 0 100%;
  aspect-ratio: 1;
  scroll-snap-align: center;
  border-radius: var(--radius);
  background: var(--section);
  object-fit: cover;
  width: 100%;
}
.gallery-count { text-align: center; margin-top: 6px; }

.section {
  background: var(--section);
  border-radius: var(--radius);
  padding: 14px;
}
.where { display: grid; gap: 4px; margin-top: 12px; }
.where strong { font-size: 17px; }

.stock {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
}
.stock button {
  padding: 12px 6px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  background: var(--secondary);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
}
.stock button[aria-pressed="true"].in_stock { border-color: var(--good); color: var(--good); }
.stock button[aria-pressed="true"].few_left { border-color: var(--warn); color: var(--warn); }
.stock button[aria-pressed="true"].sold_out { border-color: var(--bad); color: var(--bad); }
.stock button .icon { display: block; font-size: 20px; margin-bottom: 4px; }

label { display: grid; gap: 6px; }
.field + .field { margin-top: 14px; }
.input-row { display: flex; align-items: center; gap: 8px; }

input, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--secondary);
}
textarea { min-height: 160px; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--button); outline-offset: -1px; }
.counter { text-align: right; }
.counter.over { color: var(--bad); }

.actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--secondary);
  border-top: 1px solid var(--line);
}
.actions .inner { max-width: 640px; margin: 0 auto; }

.primary {
  width: 100%;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 600;
  cursor: pointer;
}
.primary:disabled { opacity: .45; cursor: default; }

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  max-width: 616px;
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
  z-index: 10;
}
.toast button {
  margin-left: 8px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

@media (prefers-reduced-motion: no-preference) {
  .toast:not([hidden]) { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(8px); opacity: 0; } }
}

/* Home and lists */
.lead { margin: 0 4px 12px; }
.empty { padding: 16px 4px; }
.center { text-align: center; margin-top: 16px; }
.block { display: block; }

.links, .list { display: grid; gap: 2px; margin: 16px 0 4px; border-radius: var(--radius); overflow: hidden; }
.row-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border: 0;
  background: var(--section);
  text-align: left;
  font-size: 16px;
  cursor: pointer;
}
.row-link::after { content: '›'; color: var(--hint); font-size: 20px; line-height: 1; }
.row-link.business::after { display: none; }
.row-link:active { opacity: .7; }
.row-link:disabled { opacity: .5; }

.secondary {
  width: 100%;
  margin-top: 12px;
  padding: 13px;
  border: 0;
  border-radius: 12px;
  background: color-mix(in srgb, var(--button) 12%, var(--section));
  color: var(--button);
  font-weight: 600;
  cursor: pointer;
}
.secondary:disabled { opacity: .5; }

.link {
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 600;
  cursor: pointer;
}
.danger { color: var(--bad); }

/* Forms */
.label { font-size: 14px; font-weight: 600; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field .hint { font-size: 13px; }
select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--secondary);
  color: var(--text);
  font: inherit;
}
.switch {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.switch input { width: 22px; height: 22px; accent-color: var(--button); }
.switch + .hint { margin-top: 6px; }

/* Channels */
.channel { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.channel-head { display: grid; gap: 2px; margin-bottom: 10px; }
.channel-actions { display: flex; justify-content: space-between; margin-top: 6px; }

/* Photos of a draft */
.photo-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--secondary); }
.photo-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .badge, .photo .chip {
  position: absolute;
  bottom: 6px;
  left: 6px;
  padding: 3px 8px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.photo .chip { cursor: pointer; }
.photo .chip.danger { left: auto; right: 6px; top: 6px; bottom: auto; width: 26px; height: 26px; padding: 0; }
img.broken { visibility: hidden; }

/* Preview, drawn like a post in a Telegram chat */
.post-preview { background: var(--section); border-radius: var(--radius); overflow: hidden; }
.post-preview .gallery, .post-preview .gallery .slide { border-radius: 0; }
.caption { padding: 12px 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.post-buttons { display: grid; gap: 4px; padding: 0 6px 6px; }
.post-button-row { display: flex; gap: 4px; }
.post-button {
  flex: 1;
  padding: 9px 6px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--button) 14%, var(--secondary));
  color: var(--link);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

.status.done { display: grid; gap: 12px; }
.big { font-size: 48px; }
.status .primary, .status .secondary { margin-top: 4px; }
