:root {
  --bg: #ffffff;
  --secondary-bg: #f2f3f5;
  --card: #ffffff;
  --text: #16181c;
  --hint: #8a9099;
  --link: #2f7bf6;
  --accent: #2f7bf6;
  --button: #2f7bf6;
  --button-text: #ffffff;
  --border: rgba(0,0,0,.08);
  --danger: #e5484d;
  --ok: #2ec27e;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --tap: rgba(47,123,246,.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Naskh Arabic", Tahoma, sans-serif;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 12px 16px calc(12px + env(safe-area-inset-top)) 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 4px rgba(46,194,126,.15); flex: none; }
.chat-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw; }
.chat-sub { font-size: 12px; color: var(--hint); margin-top: -2px; }
.lic-badge {
  font-size: 12px; font-weight: 700; padding: 6px 11px; border-radius: 999px;
  background: rgba(46,194,126,.14); color: var(--ok); white-space: nowrap;
}
.lic-badge.expired { background: rgba(229,72,77,.14); color: var(--danger); }

/* ---------- Tabs ---------- */
.tabs {
  position: sticky; top: 0; z-index: 15;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 12px 14px; background: var(--secondary-bg);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 8px 15px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  background: var(--bg); color: var(--hint); border: 1px solid var(--border);
  cursor: pointer; transition: all .18s ease; user-select: none; white-space: nowrap;
}
.tab.active { background: var(--accent); color: var(--button-text); border-color: transparent; box-shadow: var(--shadow); }

/* ---------- Sections / cards ---------- */
main { padding: 4px 14px calc(40px + env(safe-area-inset-bottom)) 14px; }
.section { display: none; animation: fade .25s ease; }
.section.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); margin: 12px 0; overflow: hidden;
}
.card-head { padding: 14px 16px 4px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-desc { font-size: 12.5px; color: var(--hint); margin-top: 2px; }

.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-top: 1px solid var(--border);
}
.card > .row:first-of-type, .card-head + .row { border-top: 1px solid var(--border); }
.row-main { min-width: 0; }
.row-label { font-size: 14.5px; font-weight: 600; }
.row-hint { font-size: 12px; color: var(--hint); margin-top: 1px; }
.row-control { flex: none; }

/* ---------- Toggle ---------- */
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; border-radius: 999px; background: #c7ccd1;
  transition: background .2s ease; cursor: pointer;
}
.slider::before {
  content: ""; position: absolute; height: 24px; width: 24px; right: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .22s cubic-bezier(.3,1.3,.5,1); box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::before { transform: translateX(-20px); }

/* ---------- Inputs ---------- */
input[type="text"], input[type="number"], textarea, select {
  font-family: inherit; font-size: 14.5px; color: var(--text);
  background: var(--secondary-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; width: 100%; outline: none; transition: border-color .15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.num { width: 96px; text-align: center; }
textarea { resize: vertical; min-height: 92px; line-height: 1.8; }
.field { padding: 13px 16px; border-top: 1px solid var(--border); }
.field-label { font-size: 13px; font-weight: 600; margin-bottom: 8px; display: block; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* segmented control */
.seg { display: inline-flex; background: var(--secondary-bg); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: none; background: transparent; font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--hint); padding: 7px 13px; border-radius: 999px; cursor: pointer; transition: all .15s;
}
.seg button.active { background: var(--bg); color: var(--text); box-shadow: var(--shadow); }

/* chips / blacklist */
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; background: var(--secondary-bg);
  border: 1px solid var(--border); border-radius: 999px; padding: 6px 8px 6px 12px; font-size: 13px; font-weight: 600;
}
.chip button { border: none; background: rgba(229,72,77,.14); color: var(--danger); width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 14px; line-height: 1; }
.chip-empty { color: var(--hint); font-size: 13px; padding: 4px 4px 12px; }
.adder { display: flex; gap: 8px; padding: 0 16px 14px; }

/* buttons */
.btn {
  font-family: inherit; font-weight: 700; font-size: 14px; border: none; cursor: pointer;
  background: var(--accent); color: var(--button-text); border-radius: var(--radius-sm); padding: 11px 16px;
  transition: transform .1s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--secondary-bg); color: var(--text); }
.btn.sm { padding: 9px 14px; font-size: 13px; }
.btn:disabled { opacity: .5; }

/* preview */
.preview {
  margin: 12px 16px 16px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: linear-gradient(0deg, rgba(47,123,246,.05), rgba(47,123,246,.05)), var(--secondary-bg);
  border: 1px dashed var(--border); font-size: 14px; white-space: pre-wrap; word-break: break-word; min-height: 40px;
}
.preview b, .preview a { color: var(--link); font-weight: 700; text-decoration: none; }

/* admins & logs */
.list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.li-main { min-width: 0; }
.li-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 12px; color: var(--hint); }
.tier-badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: rgba(47,123,246,.13); color: var(--accent); }
.log-line { padding: 10px 16px; border-top: 1px solid var(--border); font-size: 13px; }
.log-line .lt { color: var(--hint); font-size: 11px; }

/* license big card */
.lic-hero { text-align: center; padding: 26px 16px 20px; }
.lic-days { font-size: 46px; font-weight: 800; line-height: 1; }
.lic-days.expired { color: var(--danger); }
.lic-days.ok { color: var(--ok); }
.lic-caption { color: var(--hint); font-size: 13px; margin-top: 6px; }
.lic-until { margin-top: 14px; font-size: 14px; }
.lic-note { font-size: 12px; color: var(--hint); padding: 0 16px 18px; text-align: center; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px; }
.tile { background: var(--secondary-bg); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.tile-num { font-size: 26px; font-weight: 800; }
.tile-cap { font-size: 12px; color: var(--hint); margin-top: 2px; }

/* loader / error / toast */
.loader { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--secondary-bg); }
.spinner { width: 38px; height: 38px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--hint); font-size: 14px; }
.errbox { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px; text-align: center; background: var(--secondary-bg); }
.err-emoji { font-size: 46px; }
.err-text { color: var(--text); font-size: 15px; max-width: 320px; }
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px);
  background: #16181c; color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .28s cubic-bezier(.3,1.2,.5,1); z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17212b; --secondary-bg: #0e1621; --card: #17212b; --text: #f5f5f5;
    --hint: #7d8b99; --border: rgba(255,255,255,.08); --tap: rgba(47,123,246,.2);
  }
  .seg button.active { background: #2b3b4d; }
  .toast { background: #2b3b4d; }
}
