:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #1c1c1e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2ea6ff);
  --ok: #34c759;
  --warn: #ff9500;
  --bad: #ff3b30;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0 14px 40px;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Vazirmatn, Tahoma, sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

.hidden { display: none !important; }

.loading, .empty {
  text-align: center;
  color: var(--hint);
  padding: 48px 12px;
}

/* ---------- header ---------- */
.head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 10px;
}
.head h1 { font-size: 18px; margin: 0; flex: 1; }
.back {
  background: none;
  border: none;
  color: var(--link);
  font-size: 15px;
  cursor: pointer;
  padding: 4px;
}

/* ---------- stat cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--hint); font-size: 12px; }

/* ---------- cards / list ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.card.tap { cursor: pointer; }
.card.tap:active { opacity: .7; }
.card .row {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.card .title { font-weight: 600; }
.card .meta { color: var(--hint); font-size: 12.5px; }

.badge {
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.live   { background: rgba(52,199,89,.16);  color: var(--ok); }
.badge.closed { background: rgba(255,59,48,.16);  color: var(--bad); }
.badge.draft  { background: rgba(142,142,147,.2); color: var(--hint); }

/* ---------- bars ---------- */
.bar {
  height: 8px;
  background: rgba(127,127,127,.18);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 6px;
}
.bar i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}
.bar i.ok   { background: var(--ok); }
.bar i.warn { background: var(--warn); }
.bar i.bad  { background: var(--bad); }

.section-title {
  font-size: 13px;
  color: var(--hint);
  margin: 18px 2px 8px;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  background: var(--card);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
  margin-bottom: 12px;
}
.tabs button {
  flex: 1;
  border: none;
  background: none;
  color: var(--hint);
  padding: 8px 4px;
  border-radius: 10px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}
.tabs button.on {
  background: var(--bg);
  color: var(--fg);
  font-weight: 600;
}

/* ---------- table-ish rows ---------- */
.rowline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(127,127,127,.14);
}
.rowline:last-child { border-bottom: none; }
.rowline .rank {
  width: 26px;
  text-align: center;
  color: var(--hint);
  font-size: 13px;
}
.rowline .who { flex: 1; min-width: 0; }
.rowline .who b { display: block; font-weight: 600; font-size: 14px; }
.rowline .who small { color: var(--hint); font-size: 11.5px; }
.rowline .pct { font-weight: 700; font-size: 15px; }

/* ---------- settings ---------- */
.set {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(127,127,127,.14);
}
.set:last-child { border-bottom: none; }
.set label { flex: 1; }
.set small { display: block; color: var(--hint); font-size: 11.5px; }

.switch { position: relative; width: 46px; height: 27px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute;
  inset: 0;
  background: rgba(127,127,127,.35);
  border-radius: 999px;
  transition: .2s;
}
.switch i::before {
  content: "";
  position: absolute;
  width: 21px; height: 21px;
  top: 3px; right: 3px;
  background: #fff;
  border-radius: 50%;
  transition: .2s;
}
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::before { transform: translateX(-19px); }

select, input[type="text"], input[type="number"] {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid rgba(127,127,127,.3);
  border-radius: 10px;
  padding: 7px 10px;
  font-family: inherit;
  font-size: 14px;
}

/* ---------- buttons ---------- */
.btn {
  display: block;
  width: 100%;
  border: none;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 12px;
  border-radius: 12px;
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}
.btn.ghost {
  background: var(--card);
  color: var(--fg);
}
.btn.danger { background: rgba(255,59,48,.15); color: var(--bad); }
.btn:active { opacity: .8; }

.link-box {
  background: var(--bg);
  border: 1px dashed rgba(127,127,127,.4);
  border-radius: 10px;
  padding: 9px 10px;
  font-size: 12.5px;
  direction: ltr;
  text-align: left;
  word-break: break-all;
  margin-top: 6px;
}

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.82);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 50;
}
