:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-header-bg-color, var(--bg));
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 14px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg2); color: var(--text); }
body {
  font-family: Vazirmatn, "Vazir", Tahoma, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.7;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--header);
  border-bottom: 1px solid var(--sep);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 20px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #8e44ad));
  color: var(--accent-text);
}
.titles { min-width: 0; }
.app-name { font-weight: 800; font-size: 17px; line-height: 1.3; }
.chat-title {
  background: none; border: 0; padding: 0; color: var(--hint); font-size: 13px;
  max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: right;
}
.chat-title.switchable { color: var(--link); cursor: pointer; }
.chat-title.switchable::after { content: " ▾"; }
.chip {
  flex: none; font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

.tabs {
  display: flex; gap: 6px; padding: 10px 12px; background: var(--header);
  position: sticky; top: 65px; z-index: 4; overflow-x: auto;
}
.tab {
  flex: 1; border: 0; background: var(--bg2); color: var(--text);
  padding: 8px 10px; border-radius: 10px; font-weight: 600; font-size: 14px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--accent); color: var(--accent-text); }

main { padding: 12px; }
.panel {
  background: var(--section); border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.section-title { margin: 0 0 6px; font-size: 16px; font-weight: 800; }
.muted { color: var(--hint); }
.small { font-size: 13px; margin: 0 0 12px; }

.segmented {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px;
  background: var(--bg2); border-radius: 12px; margin: 10px 0 14px;
}
.segmented.small { margin: 0; min-width: 210px; }
.seg {
  border: 0; background: transparent; padding: 8px 0; border-radius: 9px;
  font-weight: 700; font-size: 14px; color: var(--text);
}
.segmented.small .seg { padding: 5px 0; font-size: 13px; }
.seg.active { background: var(--section); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.seg small { display: block; font-weight: 400; font-size: 10px; color: var(--hint); line-height: 1.2; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 700; font-size: 15px; cursor: pointer;
  transition: opacity .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.wide { width: 100%; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0 14px; }

textarea {
  width: 100%; resize: vertical; border: 1px solid var(--sep); border-radius: 12px;
  background: var(--bg2); color: var(--text); padding: 10px 12px; font: inherit; outline: none;
}
textarea:focus { border-color: var(--accent); }

.list { display: flex; flex-direction: column; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 10px 4px; border: 0; background: none;
  text-align: right; width: 100%; border-bottom: 1px solid var(--sep); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--bg2); }
.item.static { cursor: default; }
.item.static:active { background: none; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 16px;
}
.item-body { flex: 1; min-width: 0; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12px; color: var(--hint); }
.item .count {
  font-size: 12px; color: var(--hint); background: var(--bg2); border-radius: 999px; padding: 2px 8px; flex: none;
}
.badge { font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-inline-start: 6px; }
.badge.denied { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.badge.owner { background: var(--accent-soft); color: var(--accent); }
.item.selected { background: var(--accent-soft); border-radius: 10px; }

.switch { position: relative; width: 46px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--sep); transition: background .2s;
}
.switch span::before {
  content: ""; position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::before { transform: translateX(-18px); }
.switch input:disabled + span { opacity: .5; }

.result {
  margin-top: 14px; padding: 14px; border-radius: 12px; background: var(--bg2);
  animation: fade .2s ease-out;
}
.result .gist {
  font-weight: 700; padding: 10px 12px; border-radius: 10px; margin-bottom: 10px;
  background: var(--accent-soft); border-inline-start: 4px solid var(--accent);
}
.result .person { margin-top: 10px; }
.result .person-name { font-weight: 800; color: var(--accent); margin-bottom: 2px; }
.result ul { margin: 0; padding-inline-start: 18px; }
.result li { margin: 2px 0; }
.result li::marker { color: var(--accent); }
.result p { margin: 4px 0; }
.result .result-head {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;
  font-size: 12px; color: var(--hint);
}
.copy-btn { border: 0; background: none; color: var(--link); font-size: 12px; cursor: pointer; padding: 0; }
.result.error { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); font-weight: 600; }
.result.loading { display: flex; gap: 10px; align-items: center; color: var(--hint); }
.skeleton { height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--sep), transparent, var(--sep)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 8px 0; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.center-state {
  min-height: 55vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  text-align: center; padding: 24px;
}
.big-emoji { font-size: 48px; }
.fatal-text { font-weight: 600; max-width: 320px; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--sep); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: none;
}
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--hint); padding: 20px 0; }

.toast {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(30,30,30,.92); color: #fff; padding: 9px 16px; border-radius: 12px; font-size: 14px; z-index: 20;
  max-width: 90vw; text-align: center;
}
