:root {
  --bg: var(--tg-theme-bg-color, #1F2E3D);
  --text: var(--tg-theme-text-color, #FFFFFF);
  --hint: var(--tg-theme-hint-color, #8a9aab);
  --link: var(--tg-theme-link-color, #FB6A09);
  --button: var(--tg-theme-button-color, #FB6A09);
  --button-text: var(--tg-theme-button-text-color, #FFFFFF);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #182431);
  --section-bg: var(--tg-theme-section-bg-color, #29394a);
  --accent-from: #FB6A09;
  --accent-to: #d6580a;
  --gradient: linear-gradient(135deg, var(--accent-from), var(--accent-to));
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  padding-bottom: 84px;
  min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.back-btn {
  border: none;
  background: var(--section-bg);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Views ===== */
.view { padding: 4px 16px 12px; }
.section-title { font-size: 16px; font-weight: 700; margin: 8px 0 12px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.section-head .section-title { margin: 8px 0; }
.empty { color: var(--hint); text-align: center; padding: 40px 0; }

/* ===== Hero banner ===== */
.hero {
  background: var(--gradient);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 16px;
  color: #fff;
  box-shadow: 0 8px 24px rgba(251, 106, 9, 0.35);
}
.hero-title {
  font-size: 19px;
  font-weight: 800;
}
.hero-subtitle {
  font-size: 13px;
  opacity: 0.85;
  margin-top: 4px;
}

/* ===== Ads banner carousel ===== */
.banner-carousel {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  margin-bottom: 16px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.banner-carousel::-webkit-scrollbar { display: none; }
.banner-carousel img {
  width: 100%;
  flex: 0 0 100%;
  aspect-ratio: 16 / 7;
  object-fit: cover;
  border-radius: 16px;
  scroll-snap-align: start;
  background: var(--secondary-bg);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* ===== Category grid ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.cat-card {
  background: var(--section-bg);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.cat-card .img-wrap {
  position: relative;
}
.cat-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--secondary-bg);
}
.cat-card .cat-info {
  padding: 10px 12px;
}
.cat-card .cat-title {
  font-weight: 700;
  font-size: 14px;
}
.cat-card .cat-count {
  color: var(--hint);
  font-size: 12px;
  margin-top: 3px;
}

/* ===== Accounts grid ===== */
.list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.acc-card {
  background: var(--section-bg);
  border-radius: 16px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.acc-card .img-wrap {
  position: relative;
}
.acc-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--secondary-bg);
}
.acc-card .acc-info {
  padding: 10px 12px;
}
.acc-card .acc-title {
  font-weight: 700;
  font-size: 14px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.acc-card .acc-price {
  color: var(--link);
  font-weight: 800;
  margin-top: 5px;
  font-size: 14px;
}

/* ===== Badges ===== */
.top-badge, .sold-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 8px;
  color: #fff;
  text-transform: uppercase;
}
.top-badge {
  background: var(--gradient);
  box-shadow: 0 2px 8px rgba(251, 106, 9, 0.5);
}
.sold-badge {
  background: rgba(20, 20, 31, 0.85);
  color: var(--hint);
}
/* inline variants used inside text titles (account detail) */
.acc-title .top-badge,
.acc-title .sold-badge {
  position: static;
  margin-right: 6px;
  vertical-align: middle;
}

/* ===== Account detail ===== */
.account-detail img {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 16px;
  background: var(--secondary-bg);
}
.account-detail .acc-video {
  width: 100%;
  max-height: 260px;
  border-radius: 16px;
  margin-top: 10px;
  background: #000;
}
.account-detail .acc-title {
  font-size: 20px;
  font-weight: 800;
  margin-top: 14px;
}
.account-detail .acc-price {
  font-size: 22px;
  font-weight: 800;
  color: var(--link);
  margin: 6px 0 14px;
}
.account-detail .acc-description {
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  background: var(--section-bg);
  border-radius: 14px;
  padding: 14px;
}
.account-detail .acc-description ul {
  padding-left: 20px;
}
.account-detail .buy-btn {
  width: 100%;
  margin-top: 16px;
}

/* ===== Forms ===== */
.form { display: flex; flex-direction: column; gap: 14px; padding-bottom: 24px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.field .row { display: flex; gap: 8px; }
.field input[type=text],
.field input[type=number],
.field select {
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--secondary-bg);
  background: var(--section-bg);
  color: var(--text);
  font-size: 15px;
  width: 100%;
}
.field input[type=file] {
  font-size: 13px;
}
.img-preview {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 12px;
  margin-top: 6px;
}
.btn-primary {
  background: var(--gradient);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(251, 106, 9, 0.4);
}
.btn-secondary {
  background: var(--section-bg);
  color: var(--text);
  border: none;
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.form-status {
  font-size: 13px;
  color: var(--hint);
  min-height: 18px;
}
.form-status.error { color: #ff5c5c; }
.form-status.success { color: #34c759; }

/* Rich text editor */
.rte-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 4px;
}
.rte-toolbar button {
  border: none;
  background: var(--section-bg);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
}
.rte {
  min-height: 100px;
  border: 1px solid var(--secondary-bg);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--section-bg);
  color: var(--text);
}
.rte:empty:before {
  content: attr(data-placeholder);
  color: var(--hint);
}

/* ===== Manage list ===== */
.manage-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.manage-row {
  background: var(--section-bg);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
}
.manage-row .top {
  display: flex;
  gap: 10px;
  align-items: center;
}
.manage-row img {
  width: 56px; height: 56px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--secondary-bg);
  flex-shrink: 0;
}
.manage-row .info { flex: 1; min-width: 0; }
.manage-row .acc-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.manage-row .acc-price { color: var(--link); font-weight: 800; font-size: 13px; }
.manage-row .toggles {
  display: flex;
  gap: 14px;
  margin-top: 10px;
  font-size: 13px;
  align-items: center;
}
.manage-row .toggles label {
  display: flex;
  align-items: center;
  gap: 4px;
}
.manage-row .delete-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: #ff5c5c;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
}
.manage-row .info input[type=text] {
  width: 100%;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--secondary-bg);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
.manage-row .toggles input[type=number] {
  width: 64px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--secondary-bg);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
}
.manage-row .toggles .img-edit-label {
  cursor: pointer;
  color: var(--link);
  font-weight: 600;
}

/* ===== Bottom nav ===== */
.bottomnav {
  position: fixed;
  bottom: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  background: var(--section-bg);
  border-radius: 20px;
  padding: 6px;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--hint);
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: background 0.15s, color 0.15s;
}
.nav-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-btn.active {
  color: #fff;
  background: var(--gradient);
}
